Rev 3655 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React from 'react';
import { Controller, useFormContext } from 'react-hook-form';
import { FormControl, FormHelperText, FormLabel, Rating } from '@mui/material';
export function FormInputRating({
name = 'rating',
label = '',
rules = {},
readOnly = false,
size = 'large',
defaultValue = 0,
style = {}
}) {
const { control } = useFormContext();
return (
<Controller
control={control}
name={name}
rules={rules}
defaultValue={defaultValue}
render={({ field, fieldState: { error } }) => (
<FormControl error={!!error} variant='standard' fullWidth style={style}>
{label && <FormLabel shrink>{label}</FormLabel>}
<Rating
onChange={(_, value) => field.onChange(value)}
value={field.value}
readOnly={readOnly}
size={size}
/>
{error && <FormHelperText error={!!error}>{error.message}</FormHelperText>}
</FormControl>
)}
/>
);
}