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.

55 lines (54 loc) 1.88 kB
import * as React from 'react'; import { GenericHTMLProps } from '../utils/types.js'; export declare function useToggle(parameters: useToggle.Parameters): useToggle.ReturnValue; export declare namespace useToggle { interface Parameters { buttonRef?: React.Ref<HTMLElement>; /** * Whether the toggle button is currently active. */ pressed?: boolean; /** * The default pressed state. Use when the component is not controlled. * @default false */ defaultPressed?: boolean; /** * Whether the component should ignore user interaction. * @default false */ disabled: boolean; /** * Callback fired when the pressed state is changed. * * @param {boolean} pressed The new pressed state. * @param {Event} event The corresponding event that initiated the change. */ onPressedChange: (pressed: boolean, event: Event) => void; /** * State setter for toggle group value when used in a toggle group */ setGroupValue: (newValue: string, nextPressed: boolean, event: Event) => void; /** * A unique string that identifies the component when used * inside a ToggleGroup. */ value: string; } interface ReturnValue { /** * Resolver for the root slot's props. * @param externalProps props for the root slot. * @returns props that should be spread on the root slot. */ getRootProps: (externalProps?: GenericHTMLProps) => GenericHTMLProps; /** * Whether the component should ignore user interaction. */ disabled: boolean; /** * Whether the toggle button is currently active. */ pressed: boolean; } }