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.

92 lines 3.94 kB
import { REASONS } from "./reasons.js"; interface ReasonToEventMap { [REASONS.none]: Event; [REASONS.triggerPress]: MouseEvent | PointerEvent | TouchEvent | KeyboardEvent; [REASONS.triggerHover]: MouseEvent; [REASONS.triggerFocus]: FocusEvent; [REASONS.outsidePress]: MouseEvent | PointerEvent | TouchEvent; [REASONS.itemPress]: MouseEvent | KeyboardEvent | PointerEvent; [REASONS.closePress]: MouseEvent | KeyboardEvent | PointerEvent; [REASONS.linkPress]: MouseEvent | PointerEvent; [REASONS.clearPress]: PointerEvent | MouseEvent | KeyboardEvent; [REASONS.chipRemovePress]: PointerEvent | MouseEvent | KeyboardEvent; [REASONS.trackPress]: PointerEvent | MouseEvent | TouchEvent; [REASONS.incrementPress]: PointerEvent | MouseEvent | TouchEvent; [REASONS.decrementPress]: PointerEvent | MouseEvent | TouchEvent; [REASONS.inputChange]: InputEvent | Event; [REASONS.inputClear]: InputEvent | FocusEvent | Event; [REASONS.inputBlur]: FocusEvent; [REASONS.inputPaste]: ClipboardEvent; [REASONS.focusOut]: FocusEvent | KeyboardEvent; [REASONS.escapeKey]: KeyboardEvent; [REASONS.listNavigation]: KeyboardEvent; [REASONS.keyboard]: KeyboardEvent; [REASONS.pointer]: PointerEvent; [REASONS.drag]: PointerEvent | TouchEvent; [REASONS.wheel]: WheelEvent; [REASONS.scrub]: PointerEvent; [REASONS.cancelOpen]: MouseEvent; [REASONS.siblingOpen]: Event; [REASONS.disabled]: Event; [REASONS.imperativeAction]: Event; [REASONS.windowResize]: 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 {};