import * as React from 'react'; import classNames from 'classnames'; import { classNameModifier, classNameModifierByFlag } from '../shared/utils'; import { ComponentClassNames } from '../shared'; import { Flex } from '../Flex'; import { Input } from '../Input'; import { BaseRadioProps, RadioProps, ForwardRefPrimitive, Primitive, } from '../types'; import { Text } from '../Text'; import { useRadioGroupContext } from '../RadioGroupField/context'; export const RadioPrimitive: Primitive = ( { children, className, id, isDisabled, testId, value, labelPosition: radioLabelPosition, height, // @TODO: remove custom destructuring for 3.0 release width, // @TODO: remove custom destructuring for 3.0 release bottom, // @TODO: remove custom destructuring for 3.0 release left, // @TODO: remove custom destructuring for 3.0 release position, // @TODO: remove custom destructuring for 3.0 release padding, // @TODO: remove custom destructuring for 3.0 release right, // @TODO: remove custom destructuring for 3.0 release top, // @TODO: remove custom destructuring for 3.0 release ...rest }, ref ) => { const { currentValue, defaultValue, name, hasError, isGroupDisabled, isRequired, isReadOnly, onChange, size, labelPosition: groupLabelPosition, } = useRadioGroupContext(); const shouldBeDisabled = isGroupDisabled || isDisabled || (isReadOnly && defaultValue !== value); // for controlled component const checked = currentValue !== undefined ? value === currentValue : undefined; // for uncontrolled component const defaultChecked = defaultValue !== undefined ? value === defaultValue : undefined; const labelPosition = radioLabelPosition ? radioLabelPosition : groupLabelPosition; return ( {children && ( {children} )} ); }; export const Radio: ForwardRefPrimitive = React.forwardRef(RadioPrimitive); Radio.displayName = 'Radio';