import { useFormContext, Controller } from 'react-hook-form'; // @mui import Checkbox from '@mui/material/Checkbox'; import FormGroup from '@mui/material/FormGroup'; import FormLabel from '@mui/material/FormLabel'; import FormControl from '@mui/material/FormControl'; import FormHelperText from '@mui/material/FormHelperText'; import FormControlLabel, { FormControlLabelProps, formControlLabelClasses, } from '@mui/material/FormControlLabel'; // ---------------------------------------------------------------------- interface RHFCheckboxProps extends Omit { name: string; helperText?: React.ReactNode; } export function RHFCheckbox({ name, helperText, ...other }: RHFCheckboxProps) { const { control } = useFormContext(); return ( (
} {...other} /> {(!!error || helperText) && ( {error ? error?.message : helperText} )}
)} /> ); } // ---------------------------------------------------------------------- interface RHFMultiCheckboxProps extends Omit { name: string; options: { label: string; value: any }[]; row?: boolean; label?: string; spacing?: number; helperText?: React.ReactNode; } export function RHFMultiCheckbox({ row, name, label, options, spacing, helperText, sx, ...other }: RHFMultiCheckboxProps) { const { control } = useFormContext(); const getSelected = (selectedItems: string[], item: string) => selectedItems.includes(item) ? selectedItems.filter((value) => value !== item) : [...selectedItems, item]; return ( ( {label && ( {label} )} {options.map((option) => ( field.onChange(getSelected(field.value, option.value))} /> } label={option.label} {...other} /> ))} {(!!error || helperText) && ( {error ? error?.message : helperText} )} )} /> ); }