diff --git a/ts/components/conversation/right-panel/overlay/OverlayRightPanelSettings.tsx b/ts/components/conversation/right-panel/overlay/OverlayRightPanelSettings.tsx index 25ac3ea17..67ef2d8c2 100644 --- a/ts/components/conversation/right-panel/overlay/OverlayRightPanelSettings.tsx +++ b/ts/components/conversation/right-panel/overlay/OverlayRightPanelSettings.tsx @@ -234,9 +234,16 @@ export const OverlayRightPanelSettings = () => { const handleInputChanged = (name: string) => { sanitizeDisplayNameOrToast(name, setInputValue, setInputError); + if (name.length > MAX_USERNAME_BYTES) { + setInputError(window.i18n('displayNameTooLong')); + } }; - const handleEnterPressed = () => { + const handleEnterPressed = (name?: string) => { + if (name && name.length >= MAX_USERNAME_BYTES) { + setInputError(window.i18n('displayNameTooLong')); + return; + } ToastUtils.pushToastSuccess('success', window.i18n('done')); }; @@ -335,10 +342,9 @@ export const OverlayRightPanelSettings = () => { /> any; - onEnterPressed?: any; - autoFocus?: boolean; - ref?: any; - inputDataTestId?: string; -}; - -const StyledInputWithLabelContainer = styled.label` - height: 46.5px; +const StyledInputContainer = styled(Flex)<{ error: boolean }>` width: 280px; - font-family: var(--font-default); - color: var(--text-primary-color); - - padding: 2px 0 2px 0; - transition: opacity var(--default-duration); - opacity: 1; - position: relative; label { - line-height: 14px; - opacity: 0; color: var(--text-primary-color); + opacity: 0; + transition: opacity var(--default-duration); - font-size: 10px; - line-height: 11px; - position: absolute; - top: 0px; - } + &.filled { + opacity: 1; + } - &.filled { - opacity: 1; + &.error { + color: var(--danger-color); + font-weight: 700; + } } - &.error { - color: var(--danger-color); - } + ${props => + props.error && + ` + input { + color: var(--danger-color); + border-color: var(--danger-color); + + &::placeholder { + color: var(--danger-color); + opacity: 1; + } + } + `} +`; - input { - border: none; - outline: 0; - height: 14px; - width: 280px; - background: transparent; - color: var(--input-text-color); - - font-family: var(--font-default); - font-size: 12px; - line-height: 14px; - position: absolute; - top: 50%; - transform: translateY(-50%); - - &::placeholder { - color: var(--input-text-placeholder-color); - } +const StyledInput = styled.input` + border: 1px solid var(--input-border-color); + border-radius: 13px; + outline: 0; + width: 280px; + background: transparent; + color: var(--input-text-color); + + font-family: var(--font-default); + font-size: 12px; + line-height: 14px; + padding: var(--margins-lg); + + &::placeholder { + color: var(--input-text-placeholder-color); } `; -const LabelItem = (props: { inputValue: string; label?: string }) => { - return ( - - {props.label} - - ); -}; - -const ErrorItem = (props: { error: string | undefined }) => { +const ErrorItem = (props: { id: string; error: string }) => { return ( - + + ); }; @@ -108,18 +81,33 @@ const ShowHideButton = (props: { toggleForceShow: Noop }) => { ); }; +type Props = { + error?: string; + type?: string; + value?: string; + placeholder: string; + maxLength?: number; + enableShowHide?: boolean; + onValueChanged?: (value: string) => any; + onEnterPressed?: (value?: string) => any; + autoFocus?: boolean; + ref?: any; + inputDataTestId?: string; + id?: string; +}; + export const SessionInput2 = (props: Props) => { const { autoFocus, placeholder, - type, + type = 'text', value, maxLength, enableShowHide, error, - label, onValueChanged, inputDataTestId, + id = 'session-input-floating-label', } = props; const [inputValue, setInputValue] = useState(''); const [forceShow, setForceShow] = useState(false); @@ -136,14 +124,15 @@ export const SessionInput2 = (props: Props) => { }; return ( - - {error ? ( - - ) : ( - - )} - + { onBlur={updateInputValue} onKeyDown={event => { if (event.key === 'Enter' && props.onEnterPressed) { - props.onEnterPressed(); + props.onEnterPressed(inputValue !== '' ? inputValue : undefined); } }} /> @@ -168,6 +157,12 @@ export const SessionInput2 = (props: Props) => { }} /> )} - + {!isEmpty(error) ? ( + <> + + + + ) : null} + ); };