vira
Version:
A simple and highly versatile design system using element-vir.
147 lines (146 loc) • 5.15 kB
TypeScript
import { type MaybePromise } from '@augment-vir/common';
import { type Coords, type NavController } from 'device-navigation';
import { type ExtractEventByType, type ExtractEventTypes, type ListenOptions, type RemoveListenerCallback } from 'typed-event-target';
/**
* A type used for representing a rectangle's position.
*
* @category Internal
*/
export type PositionRect = {
top: number;
left: number;
right: number;
bottom: number;
};
/**
* The default empty {@link PositionRect}, with all values set to 0.
*
* @category Internal
*/
export declare const emptyPositionRect: PositionRect;
/**
* Options for {@link PopUpManager}.
*
* @category PopUp
*/
export type PopUpManagerOptions = {
/**
* The minimum number of pixels for allowing the pop-up to go downwards. If the downward
* available space is less than this, and if the upwards available space is
* `verticalDiffThreshold` more than the downwards space, the pop-up will be directed upwards.
*
* Equation:
*
* const directUpwards =
* downwardsSpace < minDownSpace &&
* upwardsSpace > DownwardsSpace + verticalDiffThreshold;
*
* @default 200
*/
minDownSpace: number;
/**
* The number of pixels required for the upwards available space to be bigger than the downwards
* available space before directing the pop-up upwards.
*
* Equation:
*
* const directUpwards =
* downwardsSpace < minDownSpace &&
* upwardsSpace > DownwardsSpace + verticalDiffThreshold;
*
* @default 20
*/
verticalDiffThreshold: number;
/**
* Supports navigation of the pop up via the `device-navigation` package.
*
* @default true
*/
supportNavigation: boolean;
};
/**
* Output type from `PopUpManager.showPopUp`
*
* @category PopUp
*/
export type ShowPopUpResult = {
/**
* Indicates if the "pop up" should pop in the downwards direction or not. If not, it should pop
* in the upwards direction. This is determined by how much space is available on either side of
* the root element.
*/
popDown: boolean;
positions: Record<'root' | 'container' | 'diff', PositionRect>;
};
declare const HidePopUpEvent_base: (new (eventInitDict?: EventInit) => import("typed-event-target").TypedEvent<"hide-pop-up">) & Pick<{
new (type: string, eventInitDict?: EventInit): Event;
prototype: Event;
readonly NONE: 0;
readonly CAPTURING_PHASE: 1;
readonly AT_TARGET: 2;
readonly BUBBLING_PHASE: 3;
}, "prototype" | "NONE" | "CAPTURING_PHASE" | "AT_TARGET" | "BUBBLING_PHASE"> & Pick<import("typed-event-target").TypedEvent<"hide-pop-up">, "type">;
/**
* An event fired from {@link PopUpManager} when the pop up should be hidden.
*
* @category PopUp
*/
export declare class HidePopUpEvent extends HidePopUpEvent_base {
}
declare const NavSelectEvent_base: (new (eventInitDict: {
bubbles?: boolean;
cancelable?: boolean;
composed?: boolean;
detail: Coords;
}) => import("typed-event-target").TypedCustomEvent<Coords, "nav-select">) & Pick<{
new (type: string, eventInitDict?: EventInit): Event;
prototype: Event;
readonly NONE: 0;
readonly CAPTURING_PHASE: 1;
readonly AT_TARGET: 2;
readonly BUBBLING_PHASE: 3;
}, "prototype" | "NONE" | "CAPTURING_PHASE" | "AT_TARGET" | "BUBBLING_PHASE"> & Pick<import("typed-event-target").TypedCustomEvent<Coords, "nav-select">, "type">;
/**
* An event fired from {@link PopUpManager} when an individual item in the pop up has been selected
* by the user.
*
* @category PopUp
*/
export declare class NavSelectEvent extends NavSelectEvent_base {
}
/**
* All events that can be emitted by {@link PopUpManager}.
*
* @category Internal
*/
export type PopUpManagerEvents = HidePopUpEvent | NavSelectEvent;
/**
* A "pop up" manager for items that pop up from the HTML page, like dropdowns or menus.
*
* @category PopUp
*/
export declare class PopUpManager {
readonly navController: NavController;
private listenTarget;
options: PopUpManagerOptions;
private cleanupCallbacks;
private lastRootElement;
constructor(navController: NavController, options?: Partial<PopUpManagerOptions> | undefined);
private attachGlobalListeners;
/** Listen to events emitted from a {@link PopUpManager} instance. */
listen<const EventDefinition extends Readonly<{
type: ExtractEventTypes<PopUpManagerEvents>;
}>>(event: EventDefinition, listener: (event: ExtractEventByType<PopUpManagerEvents, EventDefinition['type']>) => MaybePromise<void>, options?: ListenOptions | undefined): RemoveListenerCallback;
/** Trigger removal or hiding of the pop up. */
removePopUp(): void;
/** Trigger showing the pop up. */
showPopUp(rootElement: HTMLElement, options?: Partial<PopUpManagerOptions> | undefined): ShowPopUpResult;
/**
* Cleanup and destroy the {@link PopUpManager} instance. This:
*
* - Removes the existing pop up
* - Cleans up all internal and external listeners
*/
destroy(): void;
}
export {};