scrollspy.d.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { default as default_2 } from '@thednp/position-observer';
  2. import { MouseEvent as MouseEvent_2 } from '@thednp/shorty';
  3. /** Returns a new `BaseComponent` instance. */
  4. declare class BaseComponent {
  5. element: Element;
  6. options?: BaseOptions;
  7. /**
  8. * @param target `Element` or selector string
  9. * @param config component instance options
  10. */
  11. constructor(target: Element | string, config?: BaseOptions);
  12. get version(): string;
  13. get name(): string;
  14. get defaults(): {};
  15. /** just to have something to extend from */
  16. _toggleEventListeners: () => void;
  17. /** Removes component from target element. */
  18. dispose(): void;
  19. }
  20. declare interface BaseOptions {
  21. [key: string]: unknown;
  22. }
  23. /** Returns a new `ScrollSpy` instance. */
  24. declare class ScrollSpy extends BaseComponent {
  25. static selector: string;
  26. static init: (element: Element) => ScrollSpy;
  27. static getInstance: (element: Element) => ScrollSpy | null;
  28. element: HTMLElement;
  29. options: ScrollSpyOptions;
  30. target: HTMLElement;
  31. scrollTarget: HTMLElement;
  32. _itemsLength: number;
  33. _activeItem: HTMLElement | null;
  34. _observables: Map<HTMLElement, HTMLElement>;
  35. _observer: default_2;
  36. /**
  37. * @param target the target element
  38. * @param config the instance options
  39. */
  40. constructor(target: Element | string, config?: Partial<ScrollSpyOptions>);
  41. /**
  42. * Returns component name string.
  43. */
  44. get name(): string;
  45. /**
  46. * Returns component default options.
  47. */
  48. get defaults(): Partial<ScrollSpyOptions>;
  49. /** Updates all items. */
  50. refresh: () => void;
  51. /**
  52. * This method provides an event handle
  53. * for scrollspy
  54. * @param e the event listener object
  55. */
  56. _scrollTo: (e: MouseEvent_2<HTMLAnchorElement>) => void;
  57. /**
  58. * Toggles on/off the component observer.
  59. *
  60. * @param self the ScrollSpy instance
  61. * @param add when `true`, listener is added
  62. */
  63. _toggleEventListeners: (add?: boolean) => void;
  64. /** Removes `ScrollSpy` from the target element. */
  65. dispose(): void;
  66. }
  67. export default ScrollSpy;
  68. declare interface ScrollSpyOptions extends BaseOptions {
  69. offset: number;
  70. target: HTMLElement | string;
  71. threshold: number | number[];
  72. rootMargin: string;
  73. }
  74. export { }