-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: multi-lang all up view refinement (#3847)
* search box for multilang adding * pretty tablelist column space * fine-grain updateTemplate * when blur submit updated value * refine api * editable tablelist * eable multiline * update test * adjust column width Co-authored-by: Chris Whitten <christopher.whitten@microsoft.com>
- Loading branch information
Showing
10 changed files
with
461 additions
and
114 deletions.
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
Composer/packages/client/src/components/EditableField.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import React, { useState, useEffect } from 'react'; | ||
import { TextField, ITextFieldStyles, ITextFieldProps } from 'office-ui-fabric-react/lib/TextField'; | ||
import { NeutralColors } from '@uifabric/fluent-theme'; | ||
import { mergeStyleSets } from '@uifabric/styling'; | ||
|
||
interface EditableFieldProps extends Omit<ITextFieldProps, 'onChange' | 'onFocus' | 'onBlur'> { | ||
fontSize?: string; | ||
styles?: Partial<ITextFieldStyles>; | ||
transparentBorder?: boolean; | ||
ariaLabel?: string; | ||
error?: string | JSX.Element; | ||
|
||
className?: string; | ||
depth: number; | ||
description?: string; | ||
disabled?: boolean; | ||
id: string; | ||
name: string; | ||
placeholder?: string; | ||
readonly?: boolean; | ||
required?: boolean; | ||
value?: string; | ||
|
||
onChange: (newValue?: string) => void; | ||
onFocus?: (id: string, value?: string) => void; | ||
onBlur?: (id: string, value?: string) => void; | ||
} | ||
|
||
const EditableField: React.FC<EditableFieldProps> = (props) => { | ||
const { | ||
depth, | ||
styles = {}, | ||
placeholder, | ||
fontSize, | ||
multiline = false, | ||
onChange, | ||
onBlur, | ||
value, | ||
id, | ||
error, | ||
className, | ||
transparentBorder, | ||
ariaLabel, | ||
} = props; | ||
const [editing, setEditing] = useState<boolean>(false); | ||
const [hasFocus, setHasFocus] = useState<boolean>(false); | ||
const [localValue, setLocalValue] = useState<string | undefined>(value); | ||
const [hasBeenEdited, setHasBeenEdited] = useState<boolean>(false); | ||
|
||
useEffect(() => { | ||
if (!hasBeenEdited || value !== localValue) { | ||
setLocalValue(value); | ||
} | ||
}, [value]); | ||
|
||
const handleChange = (_e: any, newValue?: string) => { | ||
setLocalValue(newValue); | ||
setHasBeenEdited(true); | ||
onChange(newValue); | ||
}; | ||
|
||
const handleCommit = () => { | ||
setHasFocus(false); | ||
setEditing(false); | ||
onBlur && onBlur(id, localValue); | ||
}; | ||
|
||
let borderColor: string | undefined = undefined; | ||
|
||
if (!editing && !error) { | ||
borderColor = localValue || transparentBorder || depth > 1 ? 'transparent' : NeutralColors.gray30; | ||
} | ||
|
||
return ( | ||
<div | ||
className={className} | ||
onMouseEnter={() => setEditing(true)} | ||
onMouseLeave={() => !hasFocus && setEditing(false)} | ||
> | ||
<TextField | ||
ariaLabel={ariaLabel} | ||
autoComplete="off" | ||
errorMessage={error as string} | ||
multiline={multiline} | ||
placeholder={placeholder || value} | ||
styles={ | ||
mergeStyleSets( | ||
{ | ||
root: { margin: '0', width: '100%' }, | ||
field: { | ||
fontSize: fontSize, | ||
selectors: { | ||
'::placeholder': { | ||
fontSize: fontSize, | ||
}, | ||
}, | ||
}, | ||
fieldGroup: { | ||
borderColor, | ||
transition: 'border-color 0.1s linear', | ||
selectors: { | ||
':hover': { | ||
borderColor: hasFocus ? undefined : NeutralColors.gray30, | ||
}, | ||
}, | ||
}, | ||
}, | ||
styles | ||
) as Partial<ITextFieldStyles> | ||
} | ||
value={localValue} | ||
onBlur={handleCommit} | ||
onChange={handleChange} | ||
onFocus={() => setHasFocus(true)} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export { EditableField }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.