-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRadioGroup.tsx
More file actions
85 lines (80 loc) · 2.02 KB
/
RadioGroup.tsx
File metadata and controls
85 lines (80 loc) · 2.02 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { type ChangeEvent } from "react";
import MuiRadio from "@mui/material/Radio";
import MuiRadioGroup from "@mui/material/RadioGroup";
import MuiFormControl from "@mui/material/FormControl";
import MuiFormControlLabel from "@mui/material/FormControlLabel";
import MuiFormLabel from "@mui/material/FormLabel";
import { Tooltip } from "./Tooltip";
import type { ComponentProps, ComponentState } from "@/index";
interface RadioState extends ComponentState {
type: "Radio";
value?: boolean | number | string | undefined;
label?: string;
size?: "medium" | "small" | string;
}
interface RadioGroupState extends ComponentState {
children?: RadioState[];
label?: string;
row?: boolean;
dense?: boolean;
tooltip?: string;
}
interface RadioGroupProps extends ComponentProps, RadioGroupState {}
export function RadioGroup({
type,
id,
name,
value,
disabled,
style,
label,
row,
tooltip,
dense,
children: radioButtons,
onChange,
}: RadioGroupProps) {
const handleChange = (
_event: ChangeEvent<HTMLInputElement>,
value: string,
) => {
if (id) {
return onChange({
componentType: type,
id: id,
property: "value",
value,
});
}
};
return (
<Tooltip title={tooltip}>
<MuiFormControl disabled={disabled}>
<MuiFormLabel>{label}</MuiFormLabel>
<MuiRadioGroup
id={id}
name={name}
row={row}
value={value}
style={style}
onChange={handleChange}
>
{radioButtons &&
radioButtons.map((radioButton) => (
<MuiFormControlLabel
value={radioButton.value}
label={radioButton.label}
disabled={radioButton.disabled}
control={
<MuiRadio
id={radioButton.id}
size={dense ? "small" : "medium"}
/>
}
/>
))}
</MuiRadioGroup>
</MuiFormControl>
</Tooltip>
);
}