UNPKG

@base-ui-components/react

Version:

Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.

107 lines 3.38 kB
import * as React from 'react'; import type { BaseUIComponentProps, NonNativeButtonProps } from "../../utils/types.js"; import type { FieldRoot } from "../../field/root/FieldRoot.js"; import { BaseUIChangeEventDetails } from "../../utils/createBaseUIEventDetails.js"; import { REASONS } from "../../utils/reasons.js"; export declare const PARENT_CHECKBOX = "data-parent"; /** * Represents the checkbox itself. * Renders a `<span>` element and a hidden `<input>` beside. * * Documentation: [Base UI Checkbox](https://base-ui.com/react/components/checkbox) */ export declare const CheckboxRoot: React.ForwardRefExoticComponent<CheckboxRootProps & React.RefAttributes<HTMLElement>>; export interface CheckboxRootState extends FieldRoot.State { /** * Whether the checkbox is currently ticked. */ checked: boolean; /** * Whether the component should ignore user interaction. */ disabled: boolean; /** * Whether the user should be unable to tick or untick the checkbox. */ readOnly: boolean; /** * Whether the user must tick the checkbox before submitting a form. */ required: boolean; /** * Whether the checkbox is in a mixed state: neither ticked, nor unticked. */ indeterminate: boolean; } export interface CheckboxRootProps extends NonNativeButtonProps, Omit<BaseUIComponentProps<'span', CheckboxRoot.State>, 'onChange' | 'value'> { /** * The id of the input element. */ id?: string; /** * Identifies the field when a form is submitted. * @default undefined */ name?: string; /** * Whether the checkbox is currently ticked. * * To render an uncontrolled checkbox, use the `defaultChecked` prop instead. * @default undefined */ checked?: boolean; /** * Whether the checkbox is initially ticked. * * To render a controlled checkbox, use the `checked` prop instead. * @default false */ defaultChecked?: boolean; /** * Whether the component should ignore user interaction. * @default false */ disabled?: boolean; /** * Event handler called when the checkbox is ticked or unticked. */ onCheckedChange?: (checked: boolean, eventDetails: CheckboxRootChangeEventDetails) => void; /** * Whether the user should be unable to tick or untick the checkbox. * @default false */ readOnly?: boolean; /** * Whether the user must tick the checkbox before submitting a form. * @default false */ required?: boolean; /** * Whether the checkbox is in a mixed state: neither ticked, nor unticked. * @default false */ indeterminate?: boolean; /** * A ref to access the hidden `<input>` element. */ inputRef?: React.Ref<HTMLInputElement>; /** * Whether the checkbox controls a group of child checkboxes. * * Must be used in a [Checkbox Group](https://base-ui.com/react/components/checkbox-group). * @default false */ parent?: boolean; /** * The value of the selected checkbox. */ value?: string; } export type CheckboxRootChangeEventReason = typeof REASONS.none; export type CheckboxRootChangeEventDetails = BaseUIChangeEventDetails<CheckboxRoot.ChangeEventReason>; export declare namespace CheckboxRoot { type State = CheckboxRootState; type Props = CheckboxRootProps; type ChangeEventReason = CheckboxRootChangeEventReason; type ChangeEventDetails = CheckboxRootChangeEventDetails; }