import { Box, Flex, Stack, useColorModeValue, useRadio, useRadioGroup, UseRadioProps, } from '@chakra-ui/react' import { ReactNode } from 'react' type Props = { options: readonly (T | { value: T; label: ReactNode })[] value?: T defaultValue?: T direction?: 'row' | 'column' size?: 'md' | 'sm' onSelect: (newValue: T) => void } export const RadioButtons = ({ options, value, defaultValue, direction = 'row', size = 'md', onSelect, }: Props) => { const { getRootProps, getRadioProps } = useRadioGroup({ value, defaultValue, onChange: onSelect, }) const group = getRootProps() return ( {options.map((item) => { const radio = getRadioProps({ value: parseValue(item) }) return ( {parseLabel(item)} ) })} ) } export const RadioCard = ( props: UseRadioProps & { children: ReactNode; size?: 'md' | 'sm' } ) => { const { getInputProps, getCheckboxProps } = useRadio(props) const input = getInputProps() const checkbox = getCheckboxProps() return ( {props.children} ) } const parseValue = (item: string | { value: string; label: ReactNode }) => typeof item === 'string' ? item : item.value const parseLabel = (item: string | { value: string; label: ReactNode }) => typeof item === 'string' ? item : item.label