-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRadios.tsx
More file actions
executable file
·35 lines (31 loc) · 1.09 KB
/
Radios.tsx
File metadata and controls
executable file
·35 lines (31 loc) · 1.09 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
import React from "react";
import { RadiosProps } from "./Radios.types";
import Boolean from "../Boolean/Boolean";
import { BooleanItem } from "../Boolean/Boolean.types";
const Radios: React.FC<RadiosProps> = (props) => {
const { value, defaultValue, items, ...restProps } = props;
const processedItems: BooleanItem[] | undefined = items
? items.map((item) => {
if (item) {
// Only set checked/defaultChecked - not both
if (value != null) {
return {
...item,
checked: item.value === value,
defaultChecked: undefined, // Remove defaultChecked if value is provided
};
} else if (defaultValue != null) {
return {
...item,
defaultChecked: item.value === defaultValue,
checked: undefined, // Remove checked if defaultValue is provided
};
}
return item;
}
return item;
})
: undefined;
return <Boolean items={processedItems} {...restProps} controlType="radios" />;
};
export default Radios;