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.

102 lines 3.13 kB
import * as React from 'react'; import type { BaseUIComponentProps, NativeButtonProps } from "../../utils/types.js"; import type { FieldRoot } from "../../field/root/FieldRoot.js"; export declare const PARENT_CHECKBOX = "data-parent"; /** * Represents the checkbox itself. * Renders a `<button>` element and a hidden `<input>` beside. * * Documentation: [Base UI Checkbox](https://base-ui.com/react/components/checkbox) */ export declare const CheckboxRoot: React.ForwardRefExoticComponent<CheckboxRoot.Props & React.RefAttributes<HTMLButtonElement>>; export declare namespace CheckboxRoot { interface State 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; } interface Props extends NativeButtonProps, Omit<BaseUIComponentProps<'button', 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. * * @param {boolean} checked The new checked state. * @param {Event} event The corresponding event that initiated the change. */ onCheckedChange?: (checked: boolean, event: Event) => 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; } }