-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathComments.tsx
50 lines (46 loc) · 1.73 KB
/
Comments.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
49
50
import React from 'react';
import { Controller, useFormContext } from 'react-hook-form';
import { FormControlLabel, Radio, RadioGroup } from '@mui/material';
import '../../styles/feedback.scss';
/**
* Types for the Comments Component Props.
*/
interface CommentsProps {
/**
* Type of array of the values passed to the Radioboxes. Required.
*/
values: Array<string>,
/**
* Types of Any other Props. Optional.
*/
[x: string]: any,
}
/**
* Suggested Commments Component for the User to choose one out of four suggested comments.
* Constructed via {@link https://mui.com/api/radio-group/ | RadioGroup}
* @param props - Props
* @returns - Controlled Comments Components with four radio boxes (via {@link https://react-hook-form.com/api/usecontroller/controller | Controller})
*/
export default function Comments({ values }: CommentsProps) {
/**
* Form context passed via {@link https://react-hook-form.com/api/useformcontext | Form Provider}.
*/
const context = useFormContext();
return(
<Controller
name={"suggestedComment"}
control={context.control}
render={({ field }) => (
<RadioGroup {...field}>
{values.map((value, index) =>
<FormControlLabel
key={index}
value={value}
control={<Radio size={"medium"} classes={{root: "radioboxStyle", checked: "radioboxStyle:checked"}} />}
label={value}
/>)}
</RadioGroup>
)}
/>
)
}