@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.
39 lines • 1.7 kB
TypeScript
import type { BaseUIChangeEventReason } from "./types.js";
/**
* Maps an open-change `reason` string to the corresponding native event type.
*/
export type ReasonToEvent<Reason extends string> = Reason extends 'trigger-press' ? MouseEvent | PointerEvent | TouchEvent | KeyboardEvent : Reason extends 'trigger-hover' ? MouseEvent : Reason extends 'outside-press' ? MouseEvent | PointerEvent : Reason extends 'item-press' | 'close-press' ? MouseEvent | KeyboardEvent | PointerEvent : Reason extends 'cancel-open' ? MouseEvent : Reason extends 'trigger-focus' | 'focus-out' ? FocusEvent : Reason extends 'escape-key' | 'list-navigation' ? KeyboardEvent : Event;
/**
* Details of custom events emitted by Base UI components.
*/
export type BaseUIEventDetails<Reason extends string = BaseUIChangeEventReason> = { [K in Reason]: {
/**
* The reason for the event.
*/
reason: K;
/**
* The native event associated with the custom event.
*/
event: ReasonToEvent<K>;
/**
* Cancels Base UI from handling the event.
*/
cancel: () => void;
/**
* Allows the event to propagate in cases where Base UI will stop the propagation.
*/
allowPropagation: () => void;
/**
* Indicates whether the event has been canceled.
*/
isCanceled: boolean;
/**
* Indicates whether the event is allowed to propagate.
*/
isPropagationAllowed: boolean;
} }[Reason];
/**
* Creates a Base UI event details object with the given reason and utilities
* for preventing Base UI's internal event handling.
*/
export declare function createBaseUIEventDetails<Reason extends string = BaseUIChangeEventReason>(reason: Reason, event?: ReasonToEvent<Reason>): BaseUIEventDetails<Reason>;