-
Notifications
You must be signed in to change notification settings - Fork 3
/
CustomRating.tsx
48 lines (44 loc) · 1.43 KB
/
CustomRating.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import React from 'react';
import {BsLightningChargeFill} from "react-icons/bs"
import { Rating } from '@mui/material';
import { Controller, useFormContext } from 'react-hook-form';
import '../../styles/feedback.scss';
/**
* Types for the Comments Component Props.
*/
interface RatingProps {
/**
* Type of the name to be registered in the Controller. Required.
*/
name: string
/**
* Type of Any other Props. Optional.
*/
[x: string]: any,
}
/**
* "5-bolt" Rating used in the Feedback Form.
* @param name - Name of the registered Input
* @returns - Custom Rating Controlled Component (via {@link https://react-hook-form.com/api/usecontroller/controller | Controller})
*/
export default function CustomRating({ name }: RatingProps) {
/**
* Form context passed via {@link https://react-hook-form.com/api/useformcontext | Form Context Hook}.
*/
const context = useFormContext();
return(
<Controller
control={context.control}
name={name}
render={({ field }) => (
<Rating {...field}
value={parseInt(field.value)}
size={"large"}
defaultValue={0}
precision={1}
icon={<BsLightningChargeFill className={"ratedButton"} fontSize="inherit" />}
emptyIcon={<BsLightningChargeFill className={"unratedButton"} fontSize="inherit" />}
/>
)}/>
)
}