UNPKG

@base-ui/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.

124 lines 5.61 kB
import * as React from 'react'; import { type DrawerSwipeDirection, type DrawerSnapPoint } from "./DrawerRootContext.js"; import { type BaseUIChangeEventDetails } from "../../utils/createBaseUIEventDetails.js"; import { REASONS } from "../../utils/reasons.js"; import type { DialogHandle } from "../../dialog/store/DialogHandle.js"; import type { PayloadChildRenderFunction } from "../../utils/popups/index.js"; /** * Groups all parts of the drawer. * Doesn't render its own HTML element. * * Documentation: [Base UI Drawer](https://base-ui.com/react/components/drawer) */ export declare function DrawerRoot<Payload = unknown>(props: DrawerRoot.Props<Payload>): import("react/jsx-runtime").JSX.Element; export interface DrawerRootProps<Payload = unknown> { /** * Whether the drawer is currently open. */ open?: boolean | undefined; /** * Whether the drawer is initially open. * * To render a controlled drawer, use the `open` prop instead. * @default false */ defaultOpen?: boolean | undefined; /** * Determines if the drawer enters a modal state when open. * - `true`: user interaction is limited to just the drawer: focus is trapped, document page scroll is locked, and pointer interactions on outside elements are disabled. * - `false`: user interaction with the rest of the document is allowed. * - `'trap-focus'`: focus is trapped inside the drawer, but document page scroll is not locked and pointer interactions outside of it remain enabled. * @default true */ modal?: (boolean | 'trap-focus') | undefined; /** * Event handler called when the drawer is opened or closed. */ onOpenChange?: ((open: boolean, eventDetails: DrawerRoot.ChangeEventDetails) => void) | undefined; /** * Event handler called after any animations complete when the drawer is opened or closed. */ onOpenChangeComplete?: ((open: boolean) => void) | undefined; /** * Determines whether the drawer should close on outside clicks. * @default false */ disablePointerDismissal?: boolean | undefined; /** * A ref to imperative actions. * - `unmount`: When specified, the drawer will not be unmounted when closed. * Instead, the `unmount` function must be called to unmount the drawer manually. * Useful when the drawer's animation is controlled by an external library. * - `close`: Closes the drawer imperatively when called. */ actionsRef?: React.RefObject<DrawerRoot.Actions | null> | undefined; /** * A handle to associate the drawer with a trigger. * If specified, allows detached triggers to control the drawer's open state. * Can be created with the Drawer.createHandle() method. */ handle?: DialogHandle<Payload> | undefined; /** * ID of the trigger that the drawer is associated with. * This is useful in conjunction with the `open` prop to create a controlled drawer. * There's no need to specify this prop when the drawer is uncontrolled (i.e. when the `open` prop is not set). */ triggerId?: (string | null) | undefined; /** * ID of the trigger that the drawer is associated with. * This is useful in conjunction with the `defaultOpen` prop to create an initially open drawer. */ defaultTriggerId?: (string | null) | undefined; /** * The content of the drawer. */ children?: React.ReactNode | PayloadChildRenderFunction<Payload>; /** * The swipe direction used to dismiss the drawer. * @default 'down' */ swipeDirection?: DrawerSwipeDirection | undefined; /** * Snap points used to position the drawer. * Use numbers between 0 and 1 to represent fractions of the viewport height, * numbers greater than 1 as pixel values, or strings in `px`/`rem` units * (for example, `'148px'` or `'30rem'`). */ snapPoints?: DrawerSnapPoint[] | undefined; /** * Disables velocity-based snap skipping so drag distance determines the next snap point. * @default false */ snapToSequentialPoints?: boolean | undefined; /** * The currently active snap point. Use with `onSnapPointChange` to control the snap point. */ snapPoint?: DrawerSnapPoint | null | undefined; /** * The initial snap point value when uncontrolled. */ defaultSnapPoint?: DrawerSnapPoint | null | undefined; /** * Callback fired when the snap point changes. */ onSnapPointChange?: ((snapPoint: DrawerSnapPoint | null, eventDetails: DrawerRoot.SnapPointChangeEventDetails) => void) | undefined; } export interface DrawerRootActions { unmount: () => void; close: () => void; } export type DrawerRootChangeEventReason = typeof REASONS.triggerPress | typeof REASONS.outsidePress | typeof REASONS.escapeKey | typeof REASONS.closeWatcher | typeof REASONS.closePress | typeof REASONS.focusOut | typeof REASONS.imperativeAction | typeof REASONS.swipe | typeof REASONS.none; export type DrawerRootChangeEventDetails = BaseUIChangeEventDetails<DrawerRoot.ChangeEventReason> & { preventUnmountOnClose(): void; }; export type DrawerRootSnapPointChangeEventReason = DrawerRootChangeEventReason; export type DrawerRootSnapPointChangeEventDetails = BaseUIChangeEventDetails<DrawerRootSnapPointChangeEventReason>; export declare namespace DrawerRoot { type Props<Payload = unknown> = DrawerRootProps<Payload>; type Actions = DrawerRootActions; type ChangeEventReason = DrawerRootChangeEventReason; type ChangeEventDetails = DrawerRootChangeEventDetails; type SnapPointChangeEventReason = DrawerRootSnapPointChangeEventReason; type SnapPointChangeEventDetails = DrawerRootSnapPointChangeEventDetails; type SnapPoint = DrawerSnapPoint; }