main
Last change
on this file since 5d6f37a was 5d6f37a, checked in by Naum Shapkarovski <naumshapkarovski@…>, 8 weeks ago |
add customer
|
-
Property mode
set to
100644
|
File size:
994 bytes
|
Rev | Line | |
---|
[5d6f37a] | 1 | import { useFormContext, Controller } from 'react-hook-form';
|
---|
| 2 | // @mui
|
---|
| 3 | import Switch from '@mui/material/Switch';
|
---|
| 4 | import FormHelperText from '@mui/material/FormHelperText';
|
---|
| 5 | import FormControlLabel, { FormControlLabelProps } from '@mui/material/FormControlLabel';
|
---|
| 6 |
|
---|
| 7 | // ----------------------------------------------------------------------
|
---|
| 8 |
|
---|
| 9 | interface Props extends Omit<FormControlLabelProps, 'control'> {
|
---|
| 10 | name: string;
|
---|
| 11 | helperText?: React.ReactNode;
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 | export default function RHFSwitch({ name, helperText, ...other }: Props) {
|
---|
| 15 | const { control } = useFormContext();
|
---|
| 16 |
|
---|
| 17 | return (
|
---|
| 18 | <Controller
|
---|
| 19 | name={name}
|
---|
| 20 | control={control}
|
---|
| 21 | render={({ field, fieldState: { error } }) => (
|
---|
| 22 | <div>
|
---|
| 23 | <FormControlLabel control={<Switch {...field} checked={field.value} />} {...other} />
|
---|
| 24 |
|
---|
| 25 | {(!!error || helperText) && (
|
---|
| 26 | <FormHelperText error={!!error}>{error ? error?.message : helperText}</FormHelperText>
|
---|
| 27 | )}
|
---|
| 28 | </div>
|
---|
| 29 | )}
|
---|
| 30 | />
|
---|
| 31 | );
|
---|
| 32 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.