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.

79 lines 2.49 kB
import * as React from 'react'; import type { BaseUIComponentProps, NativeButtonProps } from "../../utils/types.js"; import type { FieldRoot } from "../../field/root/FieldRoot.js"; import { BaseUIEventDetails } from "../../types/index.js"; /** * Represents the switch itself. * Renders a `<button>` element and a hidden `<input>` beside. * * Documentation: [Base UI Switch](https://base-ui.com/react/components/switch) */ export declare const SwitchRoot: React.ForwardRefExoticComponent<SwitchRoot.Props & React.RefAttributes<HTMLButtonElement>>; export declare namespace SwitchRoot { interface Props extends NativeButtonProps, Omit<BaseUIComponentProps<'button', SwitchRoot.State>, 'onChange'> { /** * The id of the switch element. */ id?: string; /** * Whether the switch is currently active. * * To render an uncontrolled switch, use the `defaultChecked` prop instead. */ checked?: boolean; /** * Whether the switch is initially active. * * To render a controlled switch, use the `checked` prop instead. * @default false */ defaultChecked?: boolean; /** * Whether the component should ignore user interaction. * @default false */ disabled?: boolean; /** * A ref to access the hidden `<input>` element. */ inputRef?: React.Ref<HTMLInputElement>; /** * Identifies the field when a form is submitted. */ name?: string; /** * Event handler called when the switch is activated or deactivated. */ onCheckedChange?: (checked: boolean, eventDetails: ChangeEventDetails) => void; /** * Whether the user should be unable to activate or deactivate the switch. * @default false */ readOnly?: boolean; /** * Whether the user must activate the switch before submitting a form. * @default false */ required?: boolean; } interface State extends FieldRoot.State { /** * Whether the switch is currently active. */ checked: boolean; /** * Whether the component should ignore user interaction. */ disabled: boolean; /** * Whether the user should be unable to activate or deactivate the switch. */ readOnly: boolean; /** * Whether the user must activate the switch before submitting a form. */ required: boolean; } type ChangeEventReason = 'none'; type ChangeEventDetails = BaseUIEventDetails<ChangeEventReason>; }