@styleless-ui/react
Version:
Completely unstyled, headless and accessible React UI components.
77 lines (76 loc) • 2.59 kB
TypeScript
import type { RequireOnlyOne } from "../typings";
import { type ClientRect } from "../utils";
export type Alignment = "start" | "end";
export type Side = "top" | "right" | "bottom" | "left";
export type AlignedPlacement = `${Side}-${Alignment}`;
export type Placement = Side | AlignedPlacement;
export type Strategy = "absolute" | "fixed";
export type Coordinates = {
x: number;
y: number;
};
export type Dimensions = {
width: number;
height: number;
};
export type Rect = Coordinates & Dimensions;
export type ElementRects = {
anchorRect: Rect;
popperRect: Rect;
};
export type VirtualElement = {
getBoundingClientRect(): ClientRect;
};
export type Elements = {
anchorElement: HTMLElement | VirtualElement;
popperElement: HTMLDivElement;
};
export type OffsetMiddleware = number | {
/**
* The axis that runs along the side of the popper element.
*/
mainAxis?: number;
/**
* The axis that runs along the alignment of the popper element.
*/
crossAxis?: number;
};
export type AutoPlacementMiddleware = boolean | {
excludeSides: Side[];
};
type MiddlewareResult = RequireOnlyOne<{
coordinates: Partial<Coordinates>;
placement: Placement;
}>;
export type ComputationMiddlewareArgs = {
elementRects: ElementRects;
elements: Elements;
coordinates: Coordinates;
placement: Placement;
strategy: Strategy;
overflow: Record<Side, number>;
};
export type ComputationMiddlewareResult = MiddlewareResult;
export type ComputationMiddlewareOrder = "beforeAutoPlacement" | "afterAutoPlacement";
export type ComputationMiddleware = (args: ComputationMiddlewareArgs) => ComputationMiddlewareResult;
export type ComputationResult = Coordinates & {
placement: Placement;
};
export type ComputationConfig = {
placement: Placement;
strategy: Strategy;
isRtl: boolean;
autoPlacement: AutoPlacementMiddleware;
offset: OffsetMiddleware;
computationMiddleware?: ComputationMiddleware;
computationMiddlewareOrder: ComputationMiddlewareOrder;
};
export declare const sides: readonly ["top", "right", "bottom", "left"];
export declare const alignments: readonly ["end", "start"];
export declare const strategies: readonly ["absolute", "fixed"];
/**
* Computes the `x` and `y` coordinates that will place the popper element
* next to a anchor element when it is given a certain positioning strategy.
*/
export declare const computePosition: (anchorElement: HTMLElement | VirtualElement, popperElement: HTMLDivElement, config: ComputationConfig) => ComputationResult;
export {};