import { ForwardedRef, forwardRef, ReactNode } from 'react'; import { FormControl, FormControlLabel, FormControlLabelProps, FormControlProps, FormHelperText, FormHelperTextProps, Switch as MuiSwitch, SwitchProps as MuiSwitchProps } from '@mui/material'; import { useDefaultProps } from '../../hooks'; export type SwitchProps = Omit & { label?: string; required?: boolean; helperText?: ReactNode; value?: boolean; error?: boolean; disabled?: boolean; name?: string; slotProps?: { formControlLabel?: Omit; helperText?: FormHelperTextProps; formControl?: Omit; }; }; const Switch = forwardRef(function Switch(inProps: SwitchProps, ref: ForwardedRef) { const { label, required, helperText, onChange, onBlur, value, name, error, disabled, slotProps: { formControl: formControlProps, formControlLabel: formControlLabelProps, helperText: helperTextProps, ...switchSlotProps } = {}, ...switchProps } = useDefaultProps({ name: 'ReevolveSwitch', props: inProps }); return ( } ref={ref} label={label} required={required} /> {helperText && {helperText}} ); }); declare module '@mui/material' { interface Components { ReevolveSwitch?: { defaultProps?: Partial; }; } } export default Switch;