|
|
@ -1,7 +1,13 @@ |
|
|
|
|
|
|
|
import { FC, useState } from 'react'; |
|
|
|
import { |
|
|
|
import { |
|
|
|
FormControl as MUIFormControl, |
|
|
|
FormControl as MUIFormControl, |
|
|
|
FormControlProps as MUIFormControlProps, |
|
|
|
FormControlProps as MUIFormControlProps, |
|
|
|
|
|
|
|
IconButton as MUIIconButton, |
|
|
|
|
|
|
|
InputAdornment as MUIInputAdornment, |
|
|
|
} from '@mui/material'; |
|
|
|
} from '@mui/material'; |
|
|
|
|
|
|
|
import { QuestionMark as MUIQuestionMarkIcon } from '@mui/icons-material'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { GREY } from '../lib/consts/DEFAULT_THEME'; |
|
|
|
|
|
|
|
|
|
|
|
import InputMessageBox from './InputMessageBox'; |
|
|
|
import InputMessageBox from './InputMessageBox'; |
|
|
|
import { MessageBoxProps } from './MessageBox'; |
|
|
|
import { MessageBoxProps } from './MessageBox'; |
|
|
@ -12,6 +18,7 @@ import OutlinedInputLabel, { |
|
|
|
|
|
|
|
|
|
|
|
type OutlinedInputWithLabelOptionalProps = { |
|
|
|
type OutlinedInputWithLabelOptionalProps = { |
|
|
|
formControlProps?: Partial<MUIFormControlProps>; |
|
|
|
formControlProps?: Partial<MUIFormControlProps>; |
|
|
|
|
|
|
|
helpMessageBoxProps?: Partial<MessageBoxProps>; |
|
|
|
id?: string; |
|
|
|
id?: string; |
|
|
|
inputProps?: Partial<OutlinedInputProps>; |
|
|
|
inputProps?: Partial<OutlinedInputProps>; |
|
|
|
inputLabelProps?: Partial<OutlinedInputLabelProps>; |
|
|
|
inputLabelProps?: Partial<OutlinedInputLabelProps>; |
|
|
@ -29,6 +36,7 @@ const OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS: Required< |
|
|
|
> & |
|
|
|
> & |
|
|
|
Pick<OutlinedInputWithLabelOptionalProps, 'onChange'> = { |
|
|
|
Pick<OutlinedInputWithLabelOptionalProps, 'onChange'> = { |
|
|
|
formControlProps: {}, |
|
|
|
formControlProps: {}, |
|
|
|
|
|
|
|
helpMessageBoxProps: {}, |
|
|
|
id: '', |
|
|
|
id: '', |
|
|
|
inputProps: {}, |
|
|
|
inputProps: {}, |
|
|
|
inputLabelProps: {}, |
|
|
|
inputLabelProps: {}, |
|
|
@ -37,33 +45,82 @@ const OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS: Required< |
|
|
|
value: '', |
|
|
|
value: '', |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const OutlinedInputWithLabel = ({ |
|
|
|
const OutlinedInputWithLabel: FC<OutlinedInputWithLabelProps> = ({ |
|
|
|
formControlProps = OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS.formControlProps, |
|
|
|
formControlProps = OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS.formControlProps, |
|
|
|
|
|
|
|
helpMessageBoxProps = OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS.helpMessageBoxProps, |
|
|
|
id = OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS.id, |
|
|
|
id = OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS.id, |
|
|
|
inputProps = OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS.inputProps, |
|
|
|
inputProps: { |
|
|
|
|
|
|
|
endAdornment, |
|
|
|
|
|
|
|
...restInputProps |
|
|
|
|
|
|
|
} = OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS.inputProps, |
|
|
|
inputLabelProps = OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS.inputLabelProps, |
|
|
|
inputLabelProps = OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS.inputLabelProps, |
|
|
|
label, |
|
|
|
label, |
|
|
|
messageBoxProps = OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS.messageBoxProps, |
|
|
|
messageBoxProps = OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS.messageBoxProps, |
|
|
|
onChange, |
|
|
|
onChange, |
|
|
|
value = OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS.value, |
|
|
|
value = OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS.value, |
|
|
|
}: OutlinedInputWithLabelProps): JSX.Element => ( |
|
|
|
}) => { |
|
|
|
|
|
|
|
const { text: helpText } = helpMessageBoxProps; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [isShowHelp, setIsShowHelp] = useState<boolean>(false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
<MUIFormControl {...formControlProps}> |
|
|
|
<MUIFormControl {...formControlProps}> |
|
|
|
<OutlinedInputLabel {...{ htmlFor: id, ...inputLabelProps }}> |
|
|
|
<OutlinedInputLabel {...{ htmlFor: id, ...inputLabelProps }}> |
|
|
|
{label} |
|
|
|
{label} |
|
|
|
</OutlinedInputLabel> |
|
|
|
</OutlinedInputLabel> |
|
|
|
<OutlinedInput |
|
|
|
<OutlinedInput |
|
|
|
{...{ |
|
|
|
{...{ |
|
|
|
|
|
|
|
endAdornment: ( |
|
|
|
|
|
|
|
<MUIInputAdornment |
|
|
|
|
|
|
|
position="end" |
|
|
|
|
|
|
|
sx={{ |
|
|
|
|
|
|
|
display: 'flex', |
|
|
|
|
|
|
|
flexDirection: 'row', |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'& > :not(:first-child)': { |
|
|
|
|
|
|
|
marginLeft: '.3em', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
{endAdornment} |
|
|
|
|
|
|
|
{helpText && ( |
|
|
|
|
|
|
|
<MUIIconButton |
|
|
|
|
|
|
|
onClick={() => { |
|
|
|
|
|
|
|
setIsShowHelp(true); |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
sx={{ |
|
|
|
|
|
|
|
color: GREY, |
|
|
|
|
|
|
|
padding: '.1em', |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<MUIQuestionMarkIcon /> |
|
|
|
|
|
|
|
</MUIIconButton> |
|
|
|
|
|
|
|
)} |
|
|
|
|
|
|
|
</MUIInputAdornment> |
|
|
|
|
|
|
|
), |
|
|
|
fullWidth: formControlProps.fullWidth, |
|
|
|
fullWidth: formControlProps.fullWidth, |
|
|
|
id, |
|
|
|
id, |
|
|
|
label, |
|
|
|
label, |
|
|
|
onChange, |
|
|
|
onChange, |
|
|
|
value, |
|
|
|
value, |
|
|
|
...inputProps, |
|
|
|
...restInputProps, |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
{isShowHelp && ( |
|
|
|
|
|
|
|
<InputMessageBox |
|
|
|
|
|
|
|
{...{ |
|
|
|
|
|
|
|
onClose: () => { |
|
|
|
|
|
|
|
setIsShowHelp(false); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
...helpMessageBoxProps, |
|
|
|
}} |
|
|
|
}} |
|
|
|
/> |
|
|
|
/> |
|
|
|
|
|
|
|
)} |
|
|
|
<InputMessageBox {...messageBoxProps} /> |
|
|
|
<InputMessageBox {...messageBoxProps} /> |
|
|
|
</MUIFormControl> |
|
|
|
</MUIFormControl> |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
OutlinedInputWithLabel.defaultProps = OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS; |
|
|
|
OutlinedInputWithLabel.defaultProps = OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS; |
|
|
|
|
|
|
|
|
|
|
|