index.d.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 Attributes {
  33. 'x-out-of-boundaries': '' | false;
  34. 'x-placement': Placement;
  35. }
  36. export interface Padding {
  37. top?: number,
  38. bottom?: number,
  39. left?: number,
  40. right?: number,
  41. }
  42. export interface BaseModifier {
  43. order?: number;
  44. enabled?: boolean;
  45. fn?: ModifierFn;
  46. }
  47. export interface Modifiers {
  48. shift?: BaseModifier;
  49. offset?: BaseModifier & {
  50. offset?: number | string,
  51. };
  52. preventOverflow?: BaseModifier & {
  53. priority?: Position[],
  54. padding?: number | Padding,
  55. boundariesElement?: Boundary | Element,
  56. escapeWithReference?: boolean
  57. };
  58. keepTogether?: BaseModifier;
  59. arrow?: BaseModifier & {
  60. element?: string | Element,
  61. };
  62. flip?: BaseModifier & {
  63. behavior?: Behavior | Position[],
  64. padding?: number | Padding,
  65. boundariesElement?: Boundary | Element,
  66. flipVariations?: boolean,
  67. flipVariationsByContent?: boolean,
  68. };
  69. inner?: BaseModifier;
  70. hide?: BaseModifier;
  71. applyStyle?: BaseModifier & {
  72. onLoad?: Function,
  73. gpuAcceleration?: boolean,
  74. };
  75. computeStyle?: BaseModifier & {
  76. gpuAcceleration?: boolean;
  77. x?: 'bottom' | 'top',
  78. y?: 'left' | 'right'
  79. };
  80. [name: string]: (BaseModifier & Record<string, any>) | undefined;
  81. }
  82. export interface Offset {
  83. top: number;
  84. left: number;
  85. width: number;
  86. height: number;
  87. }
  88. export interface Data {
  89. instance: Popper;
  90. placement: Placement;
  91. originalPlacement: Placement;
  92. flipped: boolean;
  93. hide: boolean;
  94. arrowElement: Element;
  95. styles: CSSStyleDeclaration;
  96. arrowStyles: CSSStyleDeclaration;
  97. attributes: Attributes;
  98. boundaries: Object;
  99. offsets: {
  100. popper: Offset,
  101. reference: Offset,
  102. arrow: {
  103. top: number,
  104. left: number,
  105. },
  106. };
  107. }
  108. export interface PopperOptions {
  109. placement?: Placement;
  110. positionFixed?: boolean;
  111. eventsEnabled?: boolean;
  112. modifiers?: Modifiers;
  113. removeOnDestroy?: boolean;
  114. onCreate?(data: Data): void;
  115. onUpdate?(data: Data): void;
  116. }
  117. export interface ReferenceObject {
  118. clientHeight: number;
  119. clientWidth: number;
  120. referenceNode?: Node;
  121. getBoundingClientRect(): ClientRect;
  122. }
  123. }
  124. // Re-export types in the Popper namespace so that they can be accessed as top-level named exports.
  125. // These re-exports should be removed in 2.x when the "declare namespace Popper" syntax is removed.
  126. export type Padding = Popper.Padding;
  127. export type Position = Popper.Position;
  128. export type Placement = Popper.Placement;
  129. export type Boundary = Popper.Boundary;
  130. export type Behavior = Popper.Behavior;
  131. export type ModifierFn = Popper.ModifierFn;
  132. export type BaseModifier = Popper.BaseModifier;
  133. export type Modifiers = Popper.Modifiers;
  134. export type Offset = Popper.Offset;
  135. export type Data = Popper.Data;
  136. export type PopperOptions = Popper.PopperOptions;
  137. export type ReferenceObject = Popper.ReferenceObject;
  138. declare class Popper {
  139. static modifiers: (BaseModifier & { name: string })[];
  140. static placements: Placement[];
  141. static Defaults: PopperOptions;
  142. options: PopperOptions;
  143. popper: Element;
  144. reference: Element | ReferenceObject;
  145. constructor(reference: Element | ReferenceObject, popper: Element, options?: PopperOptions);
  146. destroy(): void;
  147. update(): void;
  148. scheduleUpdate(): void;
  149. enableEventListeners(): void;
  150. disableEventListeners(): void;
  151. }
  152. export default Popper;