fix(striker-ui): apply InputMessageBox to Slider and labeled input

main
Tsu-ba-me 3 years ago
parent e48963fc27
commit 8c4f62c862
  1. 59
      striker-ui/components/OutlinedInputWithLabel.tsx
  2. 37
      striker-ui/components/Slider.tsx

@ -3,7 +3,8 @@ import {
FormControlProps as MUIFormControlProps, FormControlProps as MUIFormControlProps,
} from '@mui/material'; } from '@mui/material';
import MessageBox, { MessageBoxProps } from './MessageBox'; import InputMessageBox from './InputMessageBox';
import { MessageBoxProps } from './MessageBox';
import OutlinedInput, { OutlinedInputProps } from './OutlinedInput'; import OutlinedInput, { OutlinedInputProps } from './OutlinedInput';
import OutlinedInputLabel, { import OutlinedInputLabel, {
OutlinedInputLabelProps, OutlinedInputLabelProps,
@ -37,42 +38,26 @@ const OutlinedInputWithLabel = ({
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,
}: OutlinedInputWithLabelProps): JSX.Element => { }: OutlinedInputWithLabelProps): JSX.Element => (
const { // eslint-disable-next-line react/jsx-props-no-spreading
sx: messageBoxSx, <MUIFormControl {...formControlProps}>
text: messageBoxText, {/* eslint-disable-next-line react/jsx-props-no-spreading */}
...messageBoxRestProps <OutlinedInputLabel {...{ htmlFor: id, ...inputLabelProps }}>
} = messageBoxProps; {label}
</OutlinedInputLabel>
return ( <OutlinedInput
// eslint-disable-next-line react/jsx-props-no-spreading // eslint-disable-next-line react/jsx-props-no-spreading
<MUIFormControl {...formControlProps}> {...{
{/* eslint-disable-next-line react/jsx-props-no-spreading */} fullWidth: formControlProps.fullWidth,
<OutlinedInputLabel {...{ htmlFor: id, ...inputLabelProps }}> id,
{label} label,
</OutlinedInputLabel> ...inputProps,
<OutlinedInput }}
// eslint-disable-next-line react/jsx-props-no-spreading />
{...{ {/* eslint-disable-next-line react/jsx-props-no-spreading */}
fullWidth: formControlProps.fullWidth, <InputMessageBox {...messageBoxProps} />
id, </MUIFormControl>
label, );
...inputProps,
}}
/>
{messageBoxText && (
<MessageBox
// eslint-disable-next-line react/jsx-props-no-spreading
{...{
...messageBoxRestProps,
sx: { marginTop: '.4em', ...messageBoxSx },
text: messageBoxText,
}}
/>
)}
</MUIFormControl>
);
};
OutlinedInputWithLabel.defaultProps = OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS; OutlinedInputWithLabel.defaultProps = OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS;

@ -7,15 +7,17 @@ import {
Slider as MUISlider, Slider as MUISlider,
sliderClasses as muiSliderClasses, sliderClasses as muiSliderClasses,
SliderProps as MUISliderProps, SliderProps as MUISliderProps,
TypographyProps as MUITypographyProps,
FormControl, FormControl,
} from '@mui/material'; } from '@mui/material';
import { BORDER_RADIUS, GREY } from '../lib/consts/DEFAULT_THEME'; import { BORDER_RADIUS, GREY } from '../lib/consts/DEFAULT_THEME';
import MessageBox, { MessageBoxProps } from './MessageBox'; import InputMessageBox from './InputMessageBox';
import { MessageBoxProps } from './MessageBox';
import OutlinedInput from './OutlinedInput'; import OutlinedInput from './OutlinedInput';
import OutlinedInputLabel from './OutlinedInputLabel'; import OutlinedInputLabel, {
OutlinedInputLabelProps,
} from './OutlinedInputLabel';
import { BodyText } from './Text'; import { BodyText } from './Text';
type SliderOnBlur = Exclude<MUISliderProps['onBlur'], undefined>; type SliderOnBlur = Exclude<MUISliderProps['onBlur'], undefined>;
@ -24,9 +26,9 @@ type SliderOnFocus = Exclude<MUISliderProps['onFocus'], undefined>;
type SliderValue = Exclude<MUISliderProps['value'], undefined>; type SliderValue = Exclude<MUISliderProps['value'], undefined>;
type SliderOptionalProps = { type SliderOptionalProps = {
inputLabelProps?: Partial<OutlinedInputLabelProps>;
isAllowTextInput?: boolean; isAllowTextInput?: boolean;
labelId?: string; labelId?: string;
labelProps?: MUITypographyProps;
messageBoxProps?: Partial<MessageBoxProps>; messageBoxProps?: Partial<MessageBoxProps>;
sliderProps?: Omit<MUISliderProps, 'onChange'> & { sliderProps?: Omit<MUISliderProps, 'onChange'> & {
onChange?: (value: number | number[]) => void; onChange?: (value: number | number[]) => void;
@ -41,9 +43,9 @@ type SliderProps = {
type TextInputOnChange = Exclude<MUIOutlinedInputProps['onChange'], undefined>; type TextInputOnChange = Exclude<MUIOutlinedInputProps['onChange'], undefined>;
const SLIDER_DEFAULT_PROPS: Required<SliderOptionalProps> = { const SLIDER_DEFAULT_PROPS: Required<SliderOptionalProps> = {
inputLabelProps: {},
isAllowTextInput: false, isAllowTextInput: false,
labelId: '', labelId: '',
labelProps: {},
messageBoxProps: {}, messageBoxProps: {},
sliderProps: {}, sliderProps: {},
}; };
@ -154,16 +156,10 @@ const Slider = ({
isAllowTextInput = SLIDER_DEFAULT_PROPS.isAllowTextInput, isAllowTextInput = SLIDER_DEFAULT_PROPS.isAllowTextInput,
label, label,
labelId = SLIDER_DEFAULT_PROPS.labelId, labelId = SLIDER_DEFAULT_PROPS.labelId,
labelProps = SLIDER_DEFAULT_PROPS.labelProps, inputLabelProps = SLIDER_DEFAULT_PROPS.inputLabelProps,
sliderProps = SLIDER_DEFAULT_PROPS.sliderProps, sliderProps = SLIDER_DEFAULT_PROPS.sliderProps,
value, value,
}: SliderProps): JSX.Element => { }: SliderProps): JSX.Element => {
const {
sx: messageBoxSx,
text: messageBoxText,
...messageBoxRestProps
} = messageBoxProps;
const { sx: labelSx } = labelProps;
const { const {
max, max,
min, min,
@ -195,12 +191,11 @@ const Slider = ({
return ( return (
<FormControl sx={{ display: 'flex', flexDirection: 'column' }}> <FormControl sx={{ display: 'flex', flexDirection: 'column' }}>
<OutlinedInputLabel <OutlinedInputLabel
// eslint-disable-next-line react/jsx-props-no-spreading
{...{ {...{
className: isFocused ? muiInputLabelClasses.focused : '', className: isFocused ? muiInputLabelClasses.focused : '',
id: labelId, id: labelId,
sx: { ...inputLabelProps,
...labelSx,
},
}} }}
> >
{label} {label}
@ -254,16 +249,8 @@ const Slider = ({
}, },
})} })}
</Box> </Box>
{messageBoxText && ( {/* eslint-disable-next-line react/jsx-props-no-spreading */}
<MessageBox <InputMessageBox {...messageBoxProps} />
// eslint-disable-next-line react/jsx-props-no-spreading
{...{
...messageBoxRestProps,
sx: { marginTop: '.4em', ...messageBoxSx },
text: messageBoxText,
}}
/>
)}
</FormControl> </FormControl>
); );
}; };

Loading…
Cancel
Save