/** * This file is a slightly modified version of Chakra UI's internal Radio * implementation, which can be found here: * https://github.com/chakra-ui/chakra-ui/blob/main/packages/radio/src/radio.tsx * * Limitations of Chakra's Radio mean that we cannot implement our desired * design with the existing implementation. In particular, the "disabled" * attribute does not apply to the label which wraps the component, meaning * we cannot apply the correct styles to the Radio container when the button * inside it is disabled (e.g. { cursor: 'not-allowed', bg: 'none' }). * * Hence this code is adapted to apply the desired styles to the label which * wraps the component. * * The relevant issue in the Chakra UI repo is here: * https://github.com/chakra-ui/chakra-ui/issues/4295 */ import { ChangeEvent } from 'react'; import { ComponentWithAs, HTMLChakraProps, SystemProps, SystemStyleObject, ThemingProps, UseRadioProps } from '@chakra-ui/react'; import { InputProps } from '../Input'; import { RadioGroup } from './RadioGroup'; type Omitted = 'onChange' | 'defaultChecked' | 'checked'; type BaseControlProps = Omit, Omitted>; export interface RadioProps extends UseRadioProps, ThemingProps<'Radio'>, BaseControlProps { /** * The spacing between the checkbox and its label text * @default 0.5rem * @type SystemProps["marginLeft"] */ spacing?: SystemProps['marginLeft']; /** * Additional overriding styles. This is a change from the Chakra UI * implementation, which previously did not allow overriding styles. */ __css?: SystemStyleObject; /** * Function called when checked state of the input changes * If provided and if allowDeselect is true, will be called * with empty string when user attempts to deselect the radio. */ onChange?: (event: ChangeEvent) => void; /** * Additional props to be forwarded to the `input` element */ inputProps?: React.InputHTMLAttributes; /** * Whether the radio button can be deselected once radio group has a value. * @default true */ allowDeselect?: boolean; } type RadioWithSubcomponentProps = ComponentWithAs<'input', RadioProps> & { OthersWrapper: typeof OthersWrapper; RadioGroup: typeof RadioGroup; OthersInput: typeof OthersInput; }; /** * Radio component is used in forms when a user needs to select a single value from * several options. * * @see Docs https://chakra-ui.com/radio */ export declare const Radio: RadioWithSubcomponentProps; /** * Wrapper for the input part of the Others option. */ export declare const OthersInput: ComponentWithAs<"input", InputProps>; export interface OthersProps extends RadioProps { children: React.ReactNode; } declare const OthersWrapper: ComponentWithAs<"input", OthersProps>; export {};