import React, { useId } from 'react'; import { FormRow } from '../../FormRow/FormRow'; import type { FormRowHelperTextOwnProps } from '../../FormRow/FormRowHelperText'; import { FormRowLabel } from '../../FormRow/FormRowLabel'; import type { RadioGroupOwnProps, SelectKey } from '../../Inputs/RadioGroup/RadioGroup'; import { RadioGroup } from '../../Inputs/RadioGroup/RadioGroup'; export interface RadioFieldProps extends RadioGroupOwnProps, Partial { /** * Renders a label for the entire group. */ label: string; /** * Whether the label should be visually hidden. */ hiddenLabel?: boolean; } export const RadioField = Object.assign( function RadioField({ id, name, label, hiddenLabel, error, warning, hint, value, defaultValue, onChange, disabled, disabledValues = [], getOptionValue, getOptionLabel, getOptionTooltip, options, required, renderOption, layout, orientation, minColumnWidth, gap, ...rest }: RadioFieldProps) { rest satisfies Record; const baseId = useId(); const descId = error || warning || hint ? `${baseId}-desc` : undefined; const labelId = `${baseId}-label`; const finalValidity = error ? 'error' : warning ? 'warning' : undefined; return ( {!hiddenLabel && ( {label} )}
); }, { Option: RadioGroup.Option, ImageOption: RadioGroup.ImageOption, } );