index.d.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /**
  2. * @fileoverview This file only declares the public portions of the API.
  3. * It should not define internal pieces such as utils or modifier details.
  4. *
  5. * Original definitions by: edcarroll <https://github.com/edcarroll>, ggray <https://github.com/giladgray>, rhysd <https://rhysd.github.io>, joscha <https://github.com/joscha>, seckardt <https://github.com/seckardt>, marcfallows <https://github.com/marcfallows>
  6. */
  7. /**
  8. * This kind of namespace declaration is not necessary, but is kept here for backwards-compatibility with
  9. * popper.js 1.x. It can be removed in 2.x so that the default export is simply the Popper class
  10. * and all the types / interfaces are top-level named exports.
  11. */
  12. declare namespace Popper {
  13. export type Position = 'top' | 'right' | 'bottom' | 'left';
  14. export type Placement = 'auto-start'
  15. | 'auto'
  16. | 'auto-end'
  17. | 'top-start'
  18. | 'top'
  19. | 'top-end'
  20. | 'right-start'
  21. | 'right'
  22. | 'right-end'
  23. | 'bottom-end'
  24. | 'bottom'
  25. | 'bottom-start'
  26. | 'left-end'
  27. | 'left'
  28. | 'left-start';
  29. export type Boundary = 'scrollParent' | 'viewport' | 'window';
  30. export type Behavior = 'flip' | 'clockwise' | 'counterclockwise';
  31. export type ModifierFn = (data: Data, options: Object) => Data;
  32. export interface BaseModifier {
  33. order?: number;
  34. enabled?: boolean;
  35. fn?: ModifierFn;
  36. }
  37. export interface Modifiers {
  38. shift?: BaseModifier;
  39. offset?: BaseModifier & {
  40. offset?: number | string,
  41. };
  42. preventOverflow?: BaseModifier & {
  43. priority?: Position[],
  44. padding?: number,
  45. boundariesElement?: Boundary | Element,
  46. escapeWithReference?: boolean
  47. };
  48. keepTogether?: BaseModifier;
  49. arrow?: BaseModifier & {
  50. element?: string | Element,
  51. };
  52. flip?: BaseModifier & {
  53. behavior?: Behavior | Position[],
  54. padding?: number,
  55. boundariesElement?: Boundary | Element,
  56. };
  57. inner?: BaseModifier;
  58. hide?: BaseModifier;
  59. applyStyle?: BaseModifier & {
  60. onLoad?: Function,
  61. gpuAcceleration?: boolean,
  62. };
  63. computeStyle?: BaseModifier & {
  64. gpuAcceleration?: boolean;
  65. x?: 'bottom' | 'top',
  66. y?: 'left' | 'right'
  67. };
  68. [name: string]: (BaseModifier & Record<string, any>) | undefined;
  69. }
  70. export interface Offset {
  71. top: number;
  72. left: number;
  73. width: number;
  74. height: number;
  75. }
  76. export interface Data {
  77. instance: Popper;
  78. placement: Placement;
  79. originalPlacement: Placement;
  80. flipped: boolean;
  81. hide: boolean;
  82. arrowElement: Element;
  83. styles: CSSStyleDeclaration;
  84. arrowStyles: CSSStyleDeclaration;
  85. boundaries: Object;
  86. offsets: {
  87. popper: Offset,
  88. reference: Offset,
  89. arrow: {
  90. top: number,
  91. left: number,
  92. },
  93. };
  94. }
  95. export interface PopperOptions {
  96. placement?: Placement;
  97. positionFixed?: boolean;
  98. eventsEnabled?: boolean;
  99. modifiers?: Modifiers;
  100. removeOnDestroy?: boolean;
  101. onCreate?(data: Data): void;
  102. onUpdate?(data: Data): void;
  103. }
  104. export interface ReferenceObject {
  105. clientHeight: number;
  106. clientWidth: number;
  107. getBoundingClientRect(): ClientRect;
  108. }
  109. }
  110. // Re-export types in the Popper namespace so that they can be accessed as top-level named exports.
  111. // These re-exports should be removed in 2.x when the "declare namespace Popper" syntax is removed.
  112. export type Position = Popper.Position;
  113. export type Placement = Popper.Placement;
  114. export type Boundary = Popper.Boundary;
  115. export type Behavior = Popper.Behavior;
  116. export type ModifierFn = Popper.ModifierFn;
  117. export type BaseModifier = Popper.BaseModifier;
  118. export type Modifiers = Popper.Modifiers;
  119. export type Offset = Popper.Offset;
  120. export type Data = Popper.Data;
  121. export type PopperOptions = Popper.PopperOptions;
  122. export type ReferenceObject = Popper.ReferenceObject;
  123. declare class Popper {
  124. static modifiers: (BaseModifier & { name: string })[];
  125. static placements: Placement[];
  126. static Defaults: PopperOptions;
  127. options: PopperOptions;
  128. constructor(reference: Element | ReferenceObject, popper: Element, options?: PopperOptions);
  129. destroy(): void;
  130. update(): void;
  131. scheduleUpdate(): void;
  132. enableEventListeners(): void;
  133. disableEventListeners(): void;
  134. }
  135. export default Popper;