// form import { useFormContext, Controller } from 'react-hook-form'; // @mui import { Checkbox, FormControlLabel, FormGroup, FormControlLabelProps } from '@mui/material'; // ---------------------------------------------------------------------- interface RHFCheckboxProps extends Omit { name: string; } export function RHFCheckbox({ name, ...other }: RHFCheckboxProps) { const { control } = useFormContext(); return ( } /> } {...other} /> ); } // ---------------------------------------------------------------------- interface RHFMultiCheckboxProps extends Omit { name: string; options: string[]; } export function RHFMultiCheckbox({ name, options, ...other }: RHFMultiCheckboxProps) { const { control } = useFormContext(); return ( { const onSelected = (option: string) => field.value.includes(option) ? field.value.filter((value: string) => value !== option) : [...field.value, option]; return ( {options.map((option) => ( field.onChange(onSelected(option))} /> } label={option} {...other} /> ))} ); }} /> ); } // ---------------------------------------------------------------------- interface optionsCustomInterface { value: string; label: string; } interface RHFCustomMultiCheckboxProps { name: string; options: optionsCustomInterface[]; } export function RHFCustomMultiCheckbox({ name, options, ...other }: RHFCustomMultiCheckboxProps) { const { control } = useFormContext(); return ( { const onSelected = (option: optionsCustomInterface) => field.value.includes(option.value) ? field.value.filter((value: string) => value !== option.value) : [...field.value, option.value]; return ( {options.map((option, index) => ( field.onChange(onSelected(option))} /> } label={option.label} {...other} /> ))} ); }} /> ); }