flexipop
Version:
104 lines (97 loc) • 3.44 kB
TypeScript
declare type Alignment = 'start' | 'middle' | 'end';
/**
* Flexilla Popper -- A small, powerful, and efficient positioning solution
* Creates and manages a popper element that can be positioned relative to a reference element
* @class
*/
export declare class CreatePopper {
private reference;
private popper;
private offsetDistance;
private placement;
private disableOnResize;
private disableOnScroll;
private onUpdate;
private isWindowEventsRegistered;
/**
* Flexilla Popper
* @param reference
* @param popper
* @param options
*/
/**
* Creates an instance of CreatePopper
* @param {HTMLElement} reference - The reference element to position against
* @param {HTMLElement} popper - The element to be positioned
* @param {PopperOptions} [options] - Configuration options
* @param {number} [options.offsetDistance] - Distance between popper and reference element
* @param {Placement} [options.placement] - Preferred placement of the popper
* @param {Object} [options.eventEffect] - Event handling configuration
* @param {boolean} [options.eventEffect.disableOnResize] - Disable position updates on window resize
* @param {boolean} [options.eventEffect.disableOnScroll] - Disable position updates on scroll
* @param {Function} [options.onUpdate] - Callback function when position updates
*/
constructor(reference: HTMLElement, popper: HTMLElement, options?: PopperOptions);
/**
* Validate Elements, check if reference and popper are valid HtmlELment
*/
private validateElements;
/**
* Set Style Property
*/
private setPopperStyleProperty;
private setInitialStyles;
private initPlacement;
private removeWindowEvents;
/**
* Add event Listeners : window resize and scroll
* These events depend on if it's disable or not
*/
private attachWindowEvent;
/**
* Resets the popper position by clearing positioning styles
* @public
*/
resetPosition: () => void;
/**
* Updates the popper position based on current reference element position
* @public
*/
updatePosition: () => void;
/**
* Updates popper configuration and recalculates position
* @public
* @param {Object} options - New configuration options
* @param {Placement} options.placement - New placement value
* @param {number} [options.offsetDistance] - New offset distance
*/
setOptions({ placement, offsetDistance }: {
placement: Placement;
offsetDistance?: number;
}): void;
/**
* Remove event listerners in case they are no longer needed
*/
/**
* Removes all event listeners and cleans up positioning styles
* @public
*/
cleanupEvents: () => void;
}
declare type Direction = 'top' | 'left' | 'bottom' | 'right';
declare type EventEffect = {
disableOnScroll?: boolean;
disableOnResize?: boolean;
};
export declare type Placement = `${Direction}-${Alignment}` | Direction;
export declare type PopperOptions = {
placement?: Placement;
offsetDistance?: number;
eventEffect?: EventEffect;
onUpdate?: ({ x, y, placement }: {
x: number;
y: number;
placement?: Placement;
}) => void;
};
export { }