|
1 | | -import React, { Children, isValidElement, cloneElement } from "react" |
| 1 | +import React, { Children, isValidElement, cloneElement, useCallback } from "react" |
2 | 2 | import Flex from "@/components/templates/flex" |
3 | 3 | import { Button } from "./button" |
4 | 4 |
|
@@ -30,24 +30,28 @@ const Content = ({ children }) => { |
30 | 30 | ) |
31 | 31 | } |
32 | 32 |
|
33 | | -const RadioButtons = ({ items, checked, buttonProps = {}, onChange }) => ( |
34 | | - <> |
35 | | - {items.map(({ label, value, title }, index) => { |
36 | | - const buttonGroupProps = getButtonGroupProps(index, items.length) |
37 | | - return ( |
38 | | - <Button |
39 | | - key={value} |
40 | | - label={label} |
41 | | - onClick={() => onChange(value)} |
42 | | - {...(title ? { title } : {})} |
43 | | - {...(checked != value ? { flavour: "hollow" } : {})} |
44 | | - {...buttonGroupProps} |
45 | | - {...buttonProps} |
46 | | - /> |
47 | | - ) |
48 | | - })} |
49 | | - </> |
50 | | -) |
| 33 | +const RadioButtons = ({ items, checked, buttonProps = {}, onChange }) => { |
| 34 | + return ( |
| 35 | + <> |
| 36 | + {items.map(({ label, value, title }, index) => { |
| 37 | + const buttonGroupProps = getButtonGroupProps(index, items.length) |
| 38 | + const isChecked = checked === value || (Array.isArray(checked) && checked.includes(value)) |
| 39 | + |
| 40 | + return ( |
| 41 | + <Button |
| 42 | + key={value} |
| 43 | + label={label} |
| 44 | + onClick={() => onChange(value)} |
| 45 | + {...(title ? { title } : {})} |
| 46 | + {...(!isChecked ? { flavour: "hollow" } : {})} |
| 47 | + {...buttonGroupProps} |
| 48 | + {...buttonProps} |
| 49 | + /> |
| 50 | + ) |
| 51 | + })} |
| 52 | + </> |
| 53 | + ) |
| 54 | +} |
51 | 55 |
|
52 | 56 | export const ButtonGroup = ({ items, checked, onChange, children, buttonProps, ...props }) => ( |
53 | 57 | <Flex alignItems="center" {...props}> |
|
0 commit comments