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