|
|
@ -1,48 +1,15 @@ |
|
|
|
import { FC, useCallback, useMemo } from 'react'; |
|
|
|
|
|
|
|
import { |
|
|
|
import { |
|
|
|
Checkbox as MUICheckbox, |
|
|
|
Checkbox as MUICheckbox, |
|
|
|
FormControl as MUIFormControl, |
|
|
|
FormControl as MUIFormControl, |
|
|
|
selectClasses as muiSelectClasses, |
|
|
|
selectClasses as muiSelectClasses, |
|
|
|
} from '@mui/material'; |
|
|
|
} from '@mui/material'; |
|
|
|
|
|
|
|
import { FC, useCallback, useMemo } from 'react'; |
|
|
|
|
|
|
|
|
|
|
|
import InputMessageBox from './InputMessageBox'; |
|
|
|
import InputMessageBox from './InputMessageBox'; |
|
|
|
import MenuItem from './MenuItem'; |
|
|
|
import MenuItem from './MenuItem'; |
|
|
|
import { MessageBoxProps } from './MessageBox'; |
|
|
|
|
|
|
|
import OutlinedInput from './OutlinedInput'; |
|
|
|
import OutlinedInput from './OutlinedInput'; |
|
|
|
import OutlinedInputLabel, { |
|
|
|
import OutlinedInputLabel from './OutlinedInputLabel'; |
|
|
|
OutlinedInputLabelProps, |
|
|
|
import Select from './Select'; |
|
|
|
} from './OutlinedInputLabel'; |
|
|
|
|
|
|
|
import Select, { SelectProps } from './Select'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type SelectWithLabelOptionalProps = { |
|
|
|
|
|
|
|
checkItem?: ((value: string) => boolean) | null; |
|
|
|
|
|
|
|
disableItem?: ((value: string) => boolean) | null; |
|
|
|
|
|
|
|
hideItem?: ((value: string) => boolean) | null; |
|
|
|
|
|
|
|
isCheckableItems?: boolean; |
|
|
|
|
|
|
|
isReadOnly?: boolean; |
|
|
|
|
|
|
|
inputLabelProps?: Partial<OutlinedInputLabelProps>; |
|
|
|
|
|
|
|
label?: string | null; |
|
|
|
|
|
|
|
messageBoxProps?: Partial<MessageBoxProps>; |
|
|
|
|
|
|
|
selectProps?: Partial<SelectProps>; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type SelectWithLabelProps = SelectWithLabelOptionalProps & { |
|
|
|
|
|
|
|
id: string; |
|
|
|
|
|
|
|
selectItems: Array<SelectItem | string>; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const SELECT_WITH_LABEL_DEFAULT_PROPS: Required<SelectWithLabelOptionalProps> = |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
checkItem: null, |
|
|
|
|
|
|
|
disableItem: null, |
|
|
|
|
|
|
|
hideItem: null, |
|
|
|
|
|
|
|
isReadOnly: false, |
|
|
|
|
|
|
|
isCheckableItems: false, |
|
|
|
|
|
|
|
inputLabelProps: {}, |
|
|
|
|
|
|
|
label: null, |
|
|
|
|
|
|
|
messageBoxProps: {}, |
|
|
|
|
|
|
|
selectProps: {}, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const SelectWithLabel: FC<SelectWithLabelProps> = ({ |
|
|
|
const SelectWithLabel: FC<SelectWithLabelProps> = ({ |
|
|
|
id, |
|
|
|
id, |
|
|
@ -51,14 +18,19 @@ const SelectWithLabel: FC<SelectWithLabelProps> = ({ |
|
|
|
checkItem, |
|
|
|
checkItem, |
|
|
|
disableItem, |
|
|
|
disableItem, |
|
|
|
hideItem, |
|
|
|
hideItem, |
|
|
|
inputLabelProps, |
|
|
|
inputLabelProps = {}, |
|
|
|
isReadOnly, |
|
|
|
isReadOnly = false, |
|
|
|
messageBoxProps, |
|
|
|
messageBoxProps = {}, |
|
|
|
selectProps = {}, |
|
|
|
onChange, |
|
|
|
isCheckableItems = selectProps?.multiple, |
|
|
|
selectProps: { |
|
|
|
|
|
|
|
multiple: selectMultiple, |
|
|
|
|
|
|
|
sx: selectSx, |
|
|
|
|
|
|
|
...restSelectProps |
|
|
|
|
|
|
|
} = {}, |
|
|
|
|
|
|
|
value: selectValue, |
|
|
|
|
|
|
|
// Props with initial value that depend on others.
|
|
|
|
|
|
|
|
isCheckableItems = selectMultiple, |
|
|
|
}) => { |
|
|
|
}) => { |
|
|
|
const { sx: selectSx } = selectProps; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const combinedSx = useMemo( |
|
|
|
const combinedSx = useMemo( |
|
|
|
() => |
|
|
|
() => |
|
|
|
isReadOnly |
|
|
|
isReadOnly |
|
|
@ -124,8 +96,11 @@ const SelectWithLabel: FC<SelectWithLabelProps> = ({ |
|
|
|
<Select |
|
|
|
<Select |
|
|
|
id={id} |
|
|
|
id={id} |
|
|
|
input={inputElement} |
|
|
|
input={inputElement} |
|
|
|
|
|
|
|
multiple={selectMultiple} |
|
|
|
|
|
|
|
onChange={onChange} |
|
|
|
readOnly={isReadOnly} |
|
|
|
readOnly={isReadOnly} |
|
|
|
{...selectProps} |
|
|
|
value={selectValue} |
|
|
|
|
|
|
|
{...restSelectProps} |
|
|
|
sx={combinedSx} |
|
|
|
sx={combinedSx} |
|
|
|
> |
|
|
|
> |
|
|
|
{menuItemElements} |
|
|
|
{menuItemElements} |
|
|
@ -135,8 +110,4 @@ const SelectWithLabel: FC<SelectWithLabelProps> = ({ |
|
|
|
); |
|
|
|
); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
SelectWithLabel.defaultProps = SELECT_WITH_LABEL_DEFAULT_PROPS; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export type { SelectWithLabelProps }; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default SelectWithLabel; |
|
|
|
export default SelectWithLabel; |
|
|
|