UNPKG

2.37 kBTypeScriptView Raw
1import * as Popper from '@popperjs/core';
2export declare type Modifier<Name, Options> = Popper.Modifier<Name, Options>;
3export declare type Options = Popper.Options;
4export declare type Instance = Popper.Instance;
5export declare type Placement = Popper.Placement;
6export declare type VirtualElement = Popper.VirtualElement;
7export declare type State = Popper.State;
8export declare type OffsetValue = [
9 number | null | undefined,
10 number | null | undefined
11];
12export declare type OffsetFunction = (details: {
13 popper: Popper.Rect;
14 reference: Popper.Rect;
15 placement: Placement;
16}) => OffsetValue;
17export declare type Offset = OffsetFunction | OffsetValue;
18export declare type ModifierMap = Record<string, Partial<Modifier<any, any>>>;
19export declare type Modifiers = Popper.Options['modifiers'] | Record<string, Partial<Modifier<any, any>>>;
20export declare type UsePopperOptions = Omit<Options, 'modifiers' | 'placement' | 'strategy'> & {
21 enabled?: boolean;
22 placement?: Options['placement'];
23 strategy?: Options['strategy'];
24 modifiers?: Options['modifiers'];
25};
26export interface UsePopperState {
27 placement: Placement;
28 update: () => void;
29 forceUpdate: () => void;
30 attributes: Record<string, Record<string, any>>;
31 styles: Record<string, Partial<CSSStyleDeclaration>>;
32 state?: State;
33}
34/**
35 * Position an element relative some reference element using Popper.js
36 *
37 * @param referenceElement
38 * @param popperElement
39 * @param {object} options
40 * @param {object=} options.modifiers Popper.js modifiers
41 * @param {boolean=} options.enabled toggle the popper functionality on/off
42 * @param {string=} options.placement The popper element placement relative to the reference element
43 * @param {string=} options.strategy the positioning strategy
44 * @param {boolean=} options.eventsEnabled have Popper listen on window resize events to reposition the element
45 * @param {function=} options.onCreate called when the popper is created
46 * @param {function=} options.onUpdate called when the popper is updated
47 *
48 * @returns {UsePopperState} The popper state
49 */
50declare function usePopper(referenceElement: VirtualElement | null | undefined, popperElement: HTMLElement | null | undefined, { enabled, placement, strategy, modifiers, ...config }?: UsePopperOptions): UsePopperState;
51export default usePopper;