@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.
92 lines • 3.94 kB
TypeScript
import { REASONS } from "./reasons.js";
interface ReasonToEventMap {
[]: Event;
[]: MouseEvent | PointerEvent | TouchEvent | KeyboardEvent;
[]: MouseEvent;
[]: FocusEvent;
[]: MouseEvent | PointerEvent | TouchEvent;
[]: MouseEvent | KeyboardEvent | PointerEvent;
[]: MouseEvent | KeyboardEvent | PointerEvent;
[]: MouseEvent | PointerEvent;
[]: PointerEvent | MouseEvent | KeyboardEvent;
[]: PointerEvent | MouseEvent | KeyboardEvent;
[]: PointerEvent | MouseEvent | TouchEvent;
[]: PointerEvent | MouseEvent | TouchEvent;
[]: PointerEvent | MouseEvent | TouchEvent;
[]: InputEvent | Event;
[]: InputEvent | FocusEvent | Event;
[]: FocusEvent;
[]: ClipboardEvent;
[]: FocusEvent | KeyboardEvent;
[]: KeyboardEvent;
[]: KeyboardEvent;
[]: KeyboardEvent;
[]: PointerEvent;
[]: PointerEvent | TouchEvent;
[]: WheelEvent;
[]: PointerEvent;
[]: MouseEvent;
[]: Event;
[]: Event;
[]: Event;
[]: UIEvent;
}
/**
* Maps a change `reason` string to the corresponding native event type.
*/
export type ReasonToEvent<Reason extends string> = Reason extends keyof ReasonToEventMap ? ReasonToEventMap[Reason] : Event;
type BaseUIChangeEventDetail<Reason extends string, CustomProperties extends object> = {
/**
* The reason for the event.
*/
reason: Reason;
/**
* The native event associated with the custom event.
*/
event: ReasonToEvent<Reason>;
/**
* 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;
/**
* The element that triggered the event, if applicable.
*/
trigger: Element | undefined;
} & CustomProperties;
/**
* Details of custom change events emitted by Base UI components.
*/
export type BaseUIChangeEventDetails<Reason extends string, CustomProperties extends object = {}> = Reason extends string ? BaseUIChangeEventDetail<Reason, CustomProperties> : never;
/**
* Details of custom generic events emitted by Base UI components.
*/
type BaseUIGenericEventDetail<Reason extends string, CustomProperties extends object> = {
/**
* The reason for the event.
*/
reason: Reason;
/**
* The native event associated with the custom event.
*/
event: ReasonToEvent<Reason>;
} & CustomProperties;
export type BaseUIGenericEventDetails<Reason extends string, CustomProperties extends object = {}> = Reason extends string ? BaseUIGenericEventDetail<Reason, CustomProperties> : never;
/**
* Creates a Base UI event details object with the given reason and utilities
* for preventing Base UI's internal event handling.
*/
export declare function createChangeEventDetails<Reason extends string, CustomProperties extends object = {}>(reason: Reason, event?: ReasonToEvent<Reason>, trigger?: HTMLElement, customProperties?: CustomProperties): BaseUIChangeEventDetails<Reason, CustomProperties>;
export declare function createGenericEventDetails<Reason extends string, CustomProperties extends object = {}>(reason: Reason, event?: ReasonToEvent<Reason>, customProperties?: CustomProperties): BaseUIGenericEventDetails<Reason, CustomProperties>;
export {};