1 | import Popper from 'popper.js';
|
2 |
|
3 | export type BasePlacement = 'top' | 'bottom' | 'left' | 'right';
|
4 |
|
5 | export type Placement = Popper.Placement;
|
6 |
|
7 | export type Boundary = Popper.Boundary | HTMLElement;
|
8 |
|
9 | export type Content = string | Element | ((ref: Element) => Element | string);
|
10 |
|
11 | export type SingleTarget = Element;
|
12 |
|
13 | export type MultipleTargets = string | Element[] | NodeList;
|
14 |
|
15 | export type Targets = SingleTarget | MultipleTargets;
|
16 |
|
17 | export interface ReferenceElement<TProps = Props> extends Element {
|
18 | _tippy?: Instance<TProps>;
|
19 | }
|
20 |
|
21 | export interface PopperElement<TProps = Props> extends HTMLDivElement {
|
22 | _tippy?: Instance<TProps>;
|
23 | }
|
24 |
|
25 | export interface PopperInstance extends Popper {
|
26 | // Undo the static so we can mutate values inside for `tippyDistance`
|
27 | modifiers: Popper.BaseModifier[];
|
28 | }
|
29 |
|
30 | export interface LifecycleHooks<TProps = Props> {
|
31 | onAfterUpdate(
|
32 | instance: Instance<TProps>,
|
33 | partialProps: Partial<TProps>,
|
34 | ): void;
|
35 | onBeforeUpdate(
|
36 | instance: Instance<TProps>,
|
37 | partialProps: Partial<TProps>,
|
38 | ): void;
|
39 | onCreate(instance: Instance<TProps>): void;
|
40 | onDestroy(instance: Instance<TProps>): void;
|
41 | onHidden(instance: Instance<TProps>): void;
|
42 | onHide(instance: Instance<TProps>): void | false;
|
43 | onMount(instance: Instance<TProps>): void;
|
44 | onShow(instance: Instance<TProps>): void | false;
|
45 | onShown(instance: Instance<TProps>): void;
|
46 | onTrigger(instance: Instance<TProps>, event: Event): void;
|
47 | onUntrigger(instance: Instance<TProps>, event: Event): void;
|
48 | }
|
49 |
|
50 | export interface Props extends LifecycleHooks {
|
51 | allowHTML: boolean;
|
52 | animateFill: boolean;
|
53 | animation: string;
|
54 | appendTo: 'parent' | Element | ((ref: Element) => Element);
|
55 | aria: 'describedby' | 'labelledby' | null;
|
56 | arrow: boolean | string | SVGElement;
|
57 | boundary: Boundary;
|
58 | content: Content;
|
59 | delay: number | [number | null, number | null];
|
60 | distance: number | string;
|
61 | duration: number | [number | null, number | null];
|
62 | flip: boolean;
|
63 | flipBehavior: 'flip' | Placement[];
|
64 | flipOnUpdate: boolean;
|
65 | followCursor: boolean | 'horizontal' | 'vertical' | 'initial';
|
66 | hideOnClick: boolean | 'toggle';
|
67 | ignoreAttributes: boolean;
|
68 | inertia: boolean;
|
69 | inlinePositioning: boolean;
|
70 | interactive: boolean;
|
71 | interactiveBorder: number;
|
72 | interactiveDebounce: number;
|
73 | lazy: boolean;
|
74 | maxWidth: number | string;
|
75 | multiple: boolean;
|
76 | offset: number | string;
|
77 | placement: Placement;
|
78 | plugins: Plugin[];
|
79 | popperOptions: Popper.PopperOptions;
|
80 | role: string;
|
81 | showOnCreate: boolean;
|
82 | sticky: boolean | 'reference' | 'popper';
|
83 | theme: string;
|
84 | touch: boolean | 'hold' | ['hold', number];
|
85 | trigger: string;
|
86 | triggerTarget: Element | Element[] | null;
|
87 | updateDuration: number;
|
88 | zIndex: number;
|
89 | }
|
90 |
|
91 | export interface DefaultProps extends Props {
|
92 | delay: number | [number, number];
|
93 | duration: number | [number, number];
|
94 | }
|
95 |
|
96 | export interface Instance<TProps = Props> {
|
97 | clearDelayTimeouts(): void;
|
98 | destroy(): void;
|
99 | disable(): void;
|
100 | enable(): void;
|
101 | hide(duration?: number): void;
|
102 | id: number;
|
103 | plugins: Plugin<TProps>[];
|
104 | popper: PopperElement<TProps>;
|
105 | popperChildren: PopperChildren;
|
106 | popperInstance: PopperInstance | null;
|
107 | props: TProps;
|
108 | reference: ReferenceElement<TProps>;
|
109 | setContent(content: Content): void;
|
110 | setProps(partialProps: Partial<TProps>): void;
|
111 | show(duration?: number): void;
|
112 | state: {
|
113 | currentPlacement: Placement | null;
|
114 | isEnabled: boolean;
|
115 | isVisible: boolean;
|
116 | isDestroyed: boolean;
|
117 | isMounted: boolean;
|
118 | isShown: boolean;
|
119 | };
|
120 | }
|
121 |
|
122 | export interface PopperChildren {
|
123 | tooltip: HTMLDivElement;
|
124 | content: HTMLDivElement;
|
125 | arrow: HTMLDivElement | null;
|
126 | }
|
127 |
|
128 | export interface TippyStatics {
|
129 | readonly currentInput: {isTouch: boolean};
|
130 | readonly defaultProps: DefaultProps;
|
131 | readonly version: string;
|
132 | setDefaultProps(partialProps: Partial<DefaultProps>): void;
|
133 | }
|
134 |
|
135 | export interface Tippy<TProps = Props> extends TippyStatics {
|
136 | (
|
137 | targets: SingleTarget,
|
138 | optionalProps?: Partial<TProps>,
|
139 |
|
140 | plugins?: Plugin<TProps>[],
|
141 | ): Instance<TProps>;
|
142 | }
|
143 |
|
144 | export interface Tippy<TProps = Props> extends TippyStatics {
|
145 | (
|
146 | targets: MultipleTargets,
|
147 | optionalProps?: Partial<TProps>,
|
148 |
|
149 | plugins?: Plugin<TProps>[],
|
150 | ): Instance<TProps>[];
|
151 | }
|
152 |
|
153 | declare const tippy: Tippy;
|
154 |
|
155 | // =============================================================================
|
156 | // Addon types
|
157 | // =============================================================================
|
158 | export interface DelegateInstance<TProps = Props> extends Instance<TProps> {
|
159 | destroy(shouldDestroyTargetInstances?: boolean): void;
|
160 | }
|
161 |
|
162 | export interface Delegate<TProps = Props> {
|
163 | (
|
164 | targets: SingleTarget,
|
165 | props: Partial<TProps> & {target: string},
|
166 |
|
167 | plugins?: Plugin<TProps>[],
|
168 | ): DelegateInstance<TProps>;
|
169 | }
|
170 |
|
171 | export interface Delegate<TProps = Props> {
|
172 | (
|
173 | targets: MultipleTargets,
|
174 | props: Partial<TProps> & {target: string},
|
175 |
|
176 | plugins?: Plugin<TProps>[],
|
177 | ): DelegateInstance<TProps>[];
|
178 | }
|
179 |
|
180 | export type CreateSingleton<TProps = Props> = (
|
181 | tippyInstances: Instance<TProps | Props>[],
|
182 | optionalProps?: Partial<TProps>,
|
183 |
|
184 | plugins?: Plugin<TProps>[],
|
185 | ) => Instance<TProps>;
|
186 |
|
187 | declare const delegate: Delegate;
|
188 | declare const createSingleton: CreateSingleton;
|
189 |
|
190 |
|
191 |
|
192 |
|
193 | export interface Plugin<TProps = Props> {
|
194 | name?: string;
|
195 | defaultValue?: any;
|
196 | fn(instance: Instance<TProps>): Partial<LifecycleHooks<TProps>>;
|
197 | }
|
198 |
|
199 | export interface AnimateFillInstance extends Instance {
|
200 | popperChildren: PopperChildren & {
|
201 | backdrop: HTMLDivElement | null;
|
202 | };
|
203 | }
|
204 |
|
205 | export interface AnimateFill extends Plugin {
|
206 | name: 'animateFill';
|
207 | defaultValue: false;
|
208 | fn(instance: AnimateFillInstance): Partial<LifecycleHooks>;
|
209 | }
|
210 |
|
211 | export interface FollowCursor extends Plugin {
|
212 | name: 'followCursor';
|
213 | defaultValue: false;
|
214 | }
|
215 |
|
216 | export interface InlinePositioning extends Plugin {
|
217 | name: 'inlinePositioning';
|
218 | defaultValue: false;
|
219 | }
|
220 |
|
221 | export interface Sticky extends Plugin {
|
222 | name: 'sticky';
|
223 | defaultValue: false;
|
224 | }
|
225 |
|
226 | declare const animateFill: AnimateFill;
|
227 | declare const followCursor: FollowCursor;
|
228 | declare const inlinePositioning: InlinePositioning;
|
229 | declare const sticky: Sticky;
|
230 |
|
231 |
|
232 |
|
233 |
|
234 | export interface HideAllOptions {
|
235 | duration?: number;
|
236 | exclude?: Instance | ReferenceElement;
|
237 | }
|
238 |
|
239 | export type HideAll = (options?: HideAllOptions) => void;
|
240 |
|
241 | declare const hideAll: HideAll;
|
242 | declare const roundArrow: string;
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 | export type CreateTippyWithPlugins = (outerPlugins: Plugin[]) => Tippy;
|
251 | declare const createTippyWithPlugins: CreateTippyWithPlugins;
|
252 |
|
253 |
|
254 | export interface AnimateFillProps {
|
255 | animateFill: Props['animateFill'];
|
256 | }
|
257 |
|
258 |
|
259 | export interface FollowCursorProps {
|
260 | followCursor: Props['followCursor'];
|
261 | }
|
262 |
|
263 |
|
264 | export interface InlinePositioningProps {
|
265 | inlinePositioning: Props['inlinePositioning'];
|
266 | }
|
267 |
|
268 |
|
269 | export interface StickyProps {
|
270 | sticky: Props['sticky'];
|
271 | }
|
272 |
|
273 | export default tippy;
|
274 | export {
|
275 | hideAll,
|
276 | createTippyWithPlugins,
|
277 | delegate,
|
278 | createSingleton,
|
279 | animateFill,
|
280 | followCursor,
|
281 | inlinePositioning,
|
282 | sticky,
|
283 | roundArrow,
|
284 | };
|