UNPKG

contain-by-screen

Version:

Position a dropdown element near a button in a way that fits on the screen.

47 lines (46 loc) 1.97 kB
export type PositionOption = "top" | "bottom" | "left" | "right" | "cover"; /** * This option is used when position is "cover", "top", or "bottom". * It controls the horizontal alignment of the element relative to the anchor. * "center" means the element's center is aligned with the anchor's center. * "left" and "right" means that edge of the element is aligned with the same edge of the anchor. * "unaligned" means the element may not be aligned with the anchor at all. Currently * this works by doing the same thing as "center" and then adjusting the result to fit on screen. */ export type HAlignOption = "center" | "left" | "right" | "unaligned"; /** * Similar to {@link HAlignOption}, except this controls the vertical alignment of the element * relative to the anchor when the position is "cover", "left", or "right". */ export type VAlignOption = "center" | "top" | "bottom" | "unaligned"; export type Position = PositionOption | PositionOption[]; export type HAlign = HAlignOption | HAlignOption[]; export type VAlign = VAlignOption | VAlignOption[]; export interface Choice { position: PositionOption; hAlign: HAlignOption; vAlign: VAlignOption; } export interface Coordinates { top: number; left: number; } export interface ChoiceAndCoordinates { choice: Choice; coordinates: Coordinates; } export interface Options { position?: Position | null; forcePosition?: boolean | null; hAlign?: HAlign | null; forceHAlign?: boolean | null; vAlign?: VAlign | null; forceVAlign?: boolean | null; buffer?: number | null; topBuffer?: number | null; bottomBuffer?: number | null; leftBuffer?: number | null; rightBuffer?: number | null; } export declare function containByScreen(element: HTMLElement, anchorPoint: HTMLElement, options: Options): Choice; export declare function getContainByScreenResults(element: HTMLElement, anchorPoint: HTMLElement, options: Options): ChoiceAndCoordinates;