Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3656 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3719 stevensc 1
import React from 'react';
2
import { Controller, useFormContext } from 'react-hook-form';
3
import { FormControl, FormHelperText, FormLabel, Rating } from '@mui/material';
4
 
5
export function FormInputRating({
6
  name = 'rating',
7
  label = '',
8
  rules = {},
9
  readOnly = false,
10
  size = 'large',
11
  defaultValue = 0,
12
  style = {}
13
}) {
14
  const { control } = useFormContext();
15
 
16
  return (
17
    <Controller
18
      control={control}
19
      name={name}
20
      rules={rules}
21
      defaultValue={defaultValue}
22
      render={({ field, fieldState: { error } }) => (
23
        <FormControl error={!!error} variant='standard' fullWidth style={style}>
24
          {label && <FormLabel shrink>{label}</FormLabel>}
25
          <Rating
26
            onChange={(_, value) => field.onChange(value)}
27
            value={field.value}
28
            readOnly={readOnly}
29
            size={size}
30
          />
31
          {error && <FormHelperText error={!!error}>{error.message}</FormHelperText>}
32
        </FormControl>
33
      )}
34
    />
35
  );
36
}