'use client' import { forwardRef } from 'react' import * as React from 'react' import * as RadioGroupPrimitive from '@radix-ui/react-radio-group' import classNames from 'classnames' import useId from '~/src/hooks/useId' import { getFormFieldSizeClassName } from '~/src/types/props-helpers' import { BaseButton } from '~/src/components/BaseButton' import { useFormFieldProps } from '~/src/components/FormControl' import { Stack } from '~/src/components/Stack' import { Text } from '~/src/components/Text' import { type RadioGroupProps, type RadioProps } from './RadioGroup.types' import styles from './RadioGroup.module.scss' function RadioGroupImpl( { children, spacing = 0, direction = 'vertical', ...rest }: RadioGroupProps, forwardedRef: React.Ref ) { const { hasError, ...formFieldProps } = useFormFieldProps(rest) return ( {children} ) } /** * `RadioGroup` is a set of checkable buttons, known as radio buttons. * * `RadioGroup` is a context of the `Radio` components. also, it renders an element which has the 'radiogroup' role. * It controls all the parts of a radio group. * @example * * ```tsx * // Anatomy of the RadioGroup * * * * ``` */ export const RadioGroup = forwardRef(RadioGroupImpl) as ( props: RadioGroupProps & { ref?: React.ForwardedRef } ) => ReturnType> function RadioImpl( { children, className, id: idProp, ...rest }: RadioProps, forwardedRef: React.Ref ) { const id = useId(idProp, 'bezier-radio') return ( {children && ( {children} )} ) } /** * `Radio` is a checkable button, known as a radio button. * It should be a child of `RadioGroup`. */ export const Radio = forwardRef(RadioImpl) as ( props: RadioProps & { ref?: React.ForwardedRef } ) => ReturnType>