UNPKG

7.88 kBTypeScriptView Raw
1import Popper from 'popper.js';
2
3export type BasePlacement = 'top' | 'bottom' | 'left' | 'right';
4
5export type Placement = Popper.Placement;
6
7export type Boundary = Popper.Boundary | HTMLElement;
8
9export type Content = string | Element | ((ref: Element) => Element | string);
10
11export type SingleTarget = Element;
12
13export type MultipleTargets = string | Element[] | NodeList;
14
15export type Targets = SingleTarget | MultipleTargets;
16
17export interface ReferenceElement<TProps = Props> extends Element {
18 _tippy?: Instance<TProps>;
19}
20
21export interface PopperElement<TProps = Props> extends HTMLDivElement {
22 _tippy?: Instance<TProps>;
23}
24
25export interface PopperInstance extends Popper {
26 // Undo the static so we can mutate values inside for `tippyDistance`
27 modifiers: Popper.BaseModifier[];
28}
29
30export 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
50export 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
91export interface DefaultProps extends Props {
92 delay: number | [number, number];
93 duration: number | [number, number];
94}
95
96export 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
122export interface PopperChildren {
123 tooltip: HTMLDivElement;
124 content: HTMLDivElement;
125 arrow: HTMLDivElement | null;
126}
127
128export interface TippyStatics {
129 readonly currentInput: {isTouch: boolean};
130 readonly defaultProps: DefaultProps;
131 readonly version: string;
132 setDefaultProps(partialProps: Partial<DefaultProps>): void;
133}
134
135export interface Tippy<TProps = Props> extends TippyStatics {
136 (
137 targets: SingleTarget,
138 optionalProps?: Partial<TProps>,
139 /** @deprecated use Props.plugins */
140 plugins?: Plugin<TProps>[],
141 ): Instance<TProps>;
142}
143
144export interface Tippy<TProps = Props> extends TippyStatics {
145 (
146 targets: MultipleTargets,
147 optionalProps?: Partial<TProps>,
148 /** @deprecated use Props.plugins */
149 plugins?: Plugin<TProps>[],
150 ): Instance<TProps>[];
151}
152
153declare const tippy: Tippy;
154
155// =============================================================================
156// Addon types
157// =============================================================================
158export interface DelegateInstance<TProps = Props> extends Instance<TProps> {
159 destroy(shouldDestroyTargetInstances?: boolean): void;
160}
161
162export interface Delegate<TProps = Props> {
163 (
164 targets: SingleTarget,
165 props: Partial<TProps> & {target: string},
166 /** @deprecated use Props.plugins */
167 plugins?: Plugin<TProps>[],
168 ): DelegateInstance<TProps>;
169}
170
171export interface Delegate<TProps = Props> {
172 (
173 targets: MultipleTargets,
174 props: Partial<TProps> & {target: string},
175 /** @deprecated use Props.plugins */
176 plugins?: Plugin<TProps>[],
177 ): DelegateInstance<TProps>[];
178}
179
180export type CreateSingleton<TProps = Props> = (
181 tippyInstances: Instance<TProps | Props>[],
182 optionalProps?: Partial<TProps>,
183 /** @deprecated use Props.plugins */
184 plugins?: Plugin<TProps>[],
185) => Instance<TProps>;
186
187declare const delegate: Delegate;
188declare const createSingleton: CreateSingleton;
189
190// =============================================================================
191// Plugin types
192// =============================================================================
193export interface Plugin<TProps = Props> {
194 name?: string;
195 defaultValue?: any;
196 fn(instance: Instance<TProps>): Partial<LifecycleHooks<TProps>>;
197}
198
199export interface AnimateFillInstance extends Instance {
200 popperChildren: PopperChildren & {
201 backdrop: HTMLDivElement | null;
202 };
203}
204
205export interface AnimateFill extends Plugin {
206 name: 'animateFill';
207 defaultValue: false;
208 fn(instance: AnimateFillInstance): Partial<LifecycleHooks>;
209}
210
211export interface FollowCursor extends Plugin {
212 name: 'followCursor';
213 defaultValue: false;
214}
215
216export interface InlinePositioning extends Plugin {
217 name: 'inlinePositioning';
218 defaultValue: false;
219}
220
221export interface Sticky extends Plugin {
222 name: 'sticky';
223 defaultValue: false;
224}
225
226declare const animateFill: AnimateFill;
227declare const followCursor: FollowCursor;
228declare const inlinePositioning: InlinePositioning;
229declare const sticky: Sticky;
230
231// =============================================================================
232// Misc types
233// =============================================================================
234export interface HideAllOptions {
235 duration?: number;
236 exclude?: Instance | ReferenceElement;
237}
238
239export type HideAll = (options?: HideAllOptions) => void;
240
241declare const hideAll: HideAll;
242declare const roundArrow: string;
243
244// =============================================================================
245// Deprecated types - these will be removed in the next major
246// =============================================================================
247/**
248 * @deprecated use tippy.setDefaultProps({plugins: [...]});
249 */
250export type CreateTippyWithPlugins = (outerPlugins: Plugin[]) => Tippy;
251declare const createTippyWithPlugins: CreateTippyWithPlugins;
252
253/** @deprecated */
254export interface AnimateFillProps {
255 animateFill: Props['animateFill'];
256}
257
258/** @deprecated */
259export interface FollowCursorProps {
260 followCursor: Props['followCursor'];
261}
262
263/** @deprecated */
264export interface InlinePositioningProps {
265 inlinePositioning: Props['inlinePositioning'];
266}
267
268/** @deprecated */
269export interface StickyProps {
270 sticky: Props['sticky'];
271}
272
273export default tippy;
274export {
275 hideAll,
276 createTippyWithPlugins,
277 delegate,
278 createSingleton,
279 animateFill,
280 followCursor,
281 inlinePositioning,
282 sticky,
283 roundArrow,
284};