@styleless-ui/react
Version:
Completely unstyled, headless and accessible React UI components.
73 lines (72 loc) • 2.27 kB
TypeScript
import * as React from "react";
import type { Classes, MergeElementProps } from "../typings";
type RadioClassesMap = Classes<"root" | "label" | "check">;
type ClassesContext = {
/** The `checked` state of the radio. */
checked: boolean;
/** The `disabled` state of the radio. */
disabled: boolean;
/** The `:focus-visible` of the radio. */
focusedVisible: boolean;
};
interface OwnProps {
/**
* Map of sub-components and their correlated classNames.
*/
classes?: ((ctx: ClassesContext) => RadioClassesMap) | RadioClassesMap;
/**
* The label of the radio.
*/
label: string | {
/**
* The label to use as `aria-label` property.
*/
screenReaderLabel: string;
} | {
/**
* Identifies the element (or elements) that labels the radio.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-labelledby MDN Web Docs} for more information.
*/
labelledBy: string;
};
/**
* The value of the radio.
*/
value?: string;
/**
* If `true`, the radio will be focused automatically.
* @default false
*/
autoFocus?: boolean;
/**
* If `true`, the radio will be checked.
* @default false
*/
checked?: boolean;
/**
* The default state of `checked`. Use when the component is not controlled.
* @default false
*/
defaultChecked?: boolean;
/**
* If `true`, the radio will be disabled.
* @default false
*/
disabled?: boolean;
/**
* The Callback is fired when the state changes.
*/
onChange?: (checkedState: boolean) => void;
/**
* The component to be used as the check element.
*/
checkComponent?: React.ReactElement;
onFocus?: React.FocusEventHandler<HTMLButtonElement>;
onBlur?: React.FocusEventHandler<HTMLButtonElement>;
onKeyDown?: React.KeyboardEventHandler<HTMLButtonElement>;
onKeyUp?: React.KeyboardEventHandler<HTMLButtonElement>;
}
export type Props = Omit<MergeElementProps<"button", OwnProps>, "defaultValue" | "className">;
declare const Radio: (props: Props, ref: React.Ref<HTMLButtonElement>) => JSX.Element;
export default Radio;