2022-10-28 09:04:57 +00:00
|
|
|
import {
|
|
|
|
FormControl,
|
|
|
|
FormControlProps,
|
|
|
|
FormLabel,
|
|
|
|
FormLabelProps,
|
|
|
|
Switch,
|
|
|
|
SwitchProps,
|
|
|
|
} from '@chakra-ui/react';
|
2023-03-09 09:30:29 +00:00
|
|
|
import { memo } from 'react';
|
2022-09-16 17:18:15 +00:00
|
|
|
|
|
|
|
interface Props extends SwitchProps {
|
|
|
|
label?: string;
|
|
|
|
width?: string | number;
|
2022-10-28 09:04:57 +00:00
|
|
|
formControlProps?: FormControlProps;
|
|
|
|
formLabelProps?: FormLabelProps;
|
2022-09-16 17:18:15 +00:00
|
|
|
}
|
|
|
|
|
2022-09-17 06:32:59 +00:00
|
|
|
/**
|
|
|
|
* Customized Chakra FormControl + Switch multi-part component.
|
|
|
|
*/
|
2022-10-03 16:15:26 +00:00
|
|
|
const IAISwitch = (props: Props) => {
|
2022-09-16 17:18:15 +00:00
|
|
|
const {
|
|
|
|
label,
|
|
|
|
isDisabled = false,
|
2022-10-03 16:15:26 +00:00
|
|
|
width = 'auto',
|
2022-10-28 09:04:57 +00:00
|
|
|
formControlProps,
|
|
|
|
formLabelProps,
|
2022-09-16 17:18:15 +00:00
|
|
|
...rest
|
|
|
|
} = props;
|
|
|
|
return (
|
2022-10-27 04:24:00 +00:00
|
|
|
<FormControl
|
|
|
|
isDisabled={isDisabled}
|
|
|
|
width={width}
|
2022-12-24 18:23:21 +00:00
|
|
|
display="flex"
|
2023-03-06 09:02:40 +00:00
|
|
|
gap={4}
|
2022-12-24 18:23:21 +00:00
|
|
|
alignItems="center"
|
2022-10-28 09:04:57 +00:00
|
|
|
{...formControlProps}
|
2022-10-27 04:24:00 +00:00
|
|
|
>
|
2023-06-03 05:05:49 +00:00
|
|
|
{label && (
|
|
|
|
<FormLabel my={1} flexGrow={1} {...formLabelProps}>
|
|
|
|
{label}
|
|
|
|
</FormLabel>
|
|
|
|
)}
|
2023-03-06 09:02:40 +00:00
|
|
|
<Switch {...rest} />
|
2022-09-16 17:18:15 +00:00
|
|
|
</FormControl>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-03-09 09:30:29 +00:00
|
|
|
export default memo(IAISwitch);
|