UNPKG

3 kBTypeScriptView Raw
1import BaseComponent, { GetInstanceFactory, GetOrCreateInstanceFactory } from "./base-component";
2
3declare class ScrollSpy extends BaseComponent {
4 /**
5 * Static method which allows you to get the scrollspy instance associated
6 * with a DOM element
7 */
8 static getInstance: GetInstanceFactory<ScrollSpy>;
9
10 /**
11 * Static method which allows you to get the scrollspy instance associated with
12 * a DOM element, or create a new one in case it wasn’t initialised
13 */
14 static getOrCreateInstance: GetOrCreateInstanceFactory<ScrollSpy, Partial<ScrollSpy.Options>>;
15
16 static jQueryInterface: ScrollSpy.jQueryInterface;
17
18 /**
19 * Default settings of this plugin
20 *
21 * @link https://getbootstrap.com/docs/5.0/getting-started/javascript/#default-settings
22 */
23 static Default: ScrollSpy.Options;
24 constructor(element: string | Element, options?: Partial<ScrollSpy.Options>);
25
26 /**
27 * When using scrollspy in conjunction with adding or removing of
28 * elements from the DOM, you’ll need to call the refresh method like
29 * so:
30 */
31 refresh(): void;
32}
33
34declare namespace ScrollSpy {
35 enum Events {
36 /**
37 * This event fires on the scroll element whenever a new item becomes
38 * activated by the scrollspy.
39 */
40 activate = "activate.bs.scrollspy",
41 }
42
43 interface Options {
44 /**
45 * Pixels to offset from top when calculating position of scroll.
46 *
47 * @default 10
48 */
49 offset: number;
50
51 /**
52 * Finds which section the spied element is in. auto will choose the
53 * best method to get scroll coordinates. offset will use the
54 * Element.getBoundingClientRect() method to get scroll coordinates.
55 * position will use the HTMLElement.offsetTop and
56 * HTMLElement.offsetLeft properties to get scroll coordinates.
57 *
58 * @default 'auto'
59 */
60 method: "auto" | "offset" | "position";
61
62 /**
63 * Intersection Observer [rootMargin](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/rootMargin)
64 * valid units, when calculating scroll position.
65 *
66 * @default '0px 0px -25%'
67 */
68 rootMargin: string;
69
70 /**
71 * Enables smooth scrolling when a user clicks on a link that refers to ScrollSpy observables.
72 *
73 * @default false
74 */
75 smoothScroll: boolean;
76
77 /**
78 * Specifies element to apply Scrollspy plugin.
79 */
80 target: string | Element | JQuery;
81
82 /**
83 * `IntersectionObserver` [threshold](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/IntersectionObserver#threshold) valid input, when calculating scroll position.
84 */
85 threshold?: number[] | string;
86 }
87
88 type jQueryInterface = (config?: Partial<Options> | "refresh" | "dispose") => JQuery;
89}
90
91export default ScrollSpy;