floating-ui.dom.d.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. import { AlignedPlacement } from '@floating-ui/core';
  2. import { Alignment } from '@floating-ui/core';
  3. import type { ArrowOptions as ArrowOptions_2 } from '@floating-ui/core';
  4. import type { AutoPlacementOptions as AutoPlacementOptions_2 } from '@floating-ui/core';
  5. import { Axis } from '@floating-ui/core';
  6. import { ClientRectObject } from '@floating-ui/core';
  7. import type { ComputePositionConfig as ComputePositionConfig_2 } from '@floating-ui/core';
  8. import { ComputePositionReturn } from '@floating-ui/core';
  9. import { Coords } from '@floating-ui/core';
  10. import type { DetectOverflowOptions as DetectOverflowOptions_2 } from '@floating-ui/core';
  11. import { Dimensions } from '@floating-ui/core';
  12. import { ElementContext } from '@floating-ui/core';
  13. import { ElementRects } from '@floating-ui/core';
  14. import type { FlipOptions as FlipOptions_2 } from '@floating-ui/core';
  15. import { getOverflowAncestors } from '@floating-ui/utils/dom';
  16. import type { HideOptions as HideOptions_2 } from '@floating-ui/core';
  17. import { InlineOptions } from '@floating-ui/core';
  18. import { Length } from '@floating-ui/core';
  19. import { LimitShiftOptions } from '@floating-ui/core';
  20. import type { Middleware as Middleware_2 } from '@floating-ui/core';
  21. import { MiddlewareData } from '@floating-ui/core';
  22. import { MiddlewareReturn } from '@floating-ui/core';
  23. import type { MiddlewareState as MiddlewareState_2 } from '@floating-ui/core';
  24. import { Padding } from '@floating-ui/core';
  25. import { Placement } from '@floating-ui/core';
  26. import { Rect } from '@floating-ui/core';
  27. import { RootBoundary } from '@floating-ui/core';
  28. import type { ShiftOptions as ShiftOptions_2 } from '@floating-ui/core';
  29. import { Side } from '@floating-ui/core';
  30. import { SideObject } from '@floating-ui/core';
  31. import type { SizeOptions as SizeOptions_2 } from '@floating-ui/core';
  32. import { Strategy } from '@floating-ui/core';
  33. export { AlignedPlacement }
  34. export { Alignment }
  35. /**
  36. * Provides data to position an inner element of the floating element so that it
  37. * appears centered to the reference element.
  38. * @see https://floating-ui.com/docs/arrow
  39. */
  40. export declare const arrow: (options: ArrowOptions | Derivable<ArrowOptions>) => Middleware;
  41. export declare type ArrowOptions = Prettify<Omit<ArrowOptions_2, 'element'> & {
  42. element: Element;
  43. }>;
  44. /**
  45. * Optimizes the visibility of the floating element by choosing the placement
  46. * that has the most space available automatically, without needing to specify a
  47. * preferred placement. Alternative to `flip`.
  48. * @see https://floating-ui.com/docs/autoPlacement
  49. */
  50. export declare const autoPlacement: (options?: AutoPlacementOptions | Derivable<AutoPlacementOptions>) => Middleware;
  51. export declare type AutoPlacementOptions = Prettify<Omit<AutoPlacementOptions_2, 'boundary'> & DetectOverflowOptions>;
  52. /**
  53. * Automatically updates the position of the floating element when necessary.
  54. * Should only be called when the floating element is mounted on the DOM or
  55. * visible on the screen.
  56. * @returns cleanup function that should be invoked when the floating element is
  57. * removed from the DOM or hidden from the screen.
  58. * @see https://floating-ui.com/docs/autoUpdate
  59. */
  60. export declare function autoUpdate(reference: ReferenceElement, floating: FloatingElement, update: () => void, options?: AutoUpdateOptions): () => void;
  61. export declare interface AutoUpdateOptions {
  62. /**
  63. * Whether to update the position when an overflow ancestor is scrolled.
  64. * @default true
  65. */
  66. ancestorScroll?: boolean;
  67. /**
  68. * Whether to update the position when an overflow ancestor is resized. This
  69. * uses the native `resize` event.
  70. * @default true
  71. */
  72. ancestorResize?: boolean;
  73. /**
  74. * Whether to update the position when either the reference or floating
  75. * elements resized. This uses a `ResizeObserver`.
  76. * @default true
  77. */
  78. elementResize?: boolean;
  79. /**
  80. * Whether to update the position when the reference relocated on the screen
  81. * due to layout shift.
  82. * @default true
  83. */
  84. layoutShift?: boolean;
  85. /**
  86. * Whether to update on every animation frame if necessary. Only use if you
  87. * need to update the position in response to an animation using transforms.
  88. * @default false
  89. */
  90. animationFrame?: boolean;
  91. }
  92. export { Axis }
  93. /**
  94. * The clipping boundary area of the floating element.
  95. */
  96. export declare type Boundary = 'clippingAncestors' | Element | Array<Element> | Rect;
  97. export { ClientRectObject }
  98. /**
  99. * Computes the `x` and `y` coordinates that will place the floating element
  100. * next to a given reference element.
  101. */
  102. export declare const computePosition: (reference: ReferenceElement, floating: FloatingElement, options?: Partial<ComputePositionConfig>) => Promise<ComputePositionReturn>;
  103. export declare type ComputePositionConfig = Prettify<Omit<ComputePositionConfig_2, 'middleware' | 'platform'> & {
  104. /**
  105. * Array of middleware objects to modify the positioning or provide data for
  106. * rendering.
  107. */
  108. middleware?: Array<Middleware | null | undefined | false>;
  109. /**
  110. * Custom or extended platform object.
  111. */
  112. platform?: Platform;
  113. }>;
  114. export { ComputePositionReturn }
  115. export { Coords }
  116. export declare type Derivable<T> = (state: MiddlewareState) => T;
  117. /**
  118. * Resolves with an object of overflow side offsets that determine how much the
  119. * element is overflowing a given clipping boundary on each side.
  120. * - positive = overflowing the boundary by that number of pixels
  121. * - negative = how many pixels left before it will overflow
  122. * - 0 = lies flush with the boundary
  123. * @see https://floating-ui.com/docs/detectOverflow
  124. */
  125. export declare const detectOverflow: (state: MiddlewareState, options?: DetectOverflowOptions | Derivable<DetectOverflowOptions>) => Promise<SideObject>;
  126. export declare type DetectOverflowOptions = Prettify<Omit<DetectOverflowOptions_2, 'boundary'> & {
  127. boundary?: Boundary;
  128. }>;
  129. export { Dimensions }
  130. export { ElementContext }
  131. export { ElementRects }
  132. export declare interface Elements {
  133. reference: ReferenceElement;
  134. floating: FloatingElement;
  135. }
  136. /**
  137. * Optimizes the visibility of the floating element by flipping the `placement`
  138. * in order to keep it in view when the preferred placement(s) will overflow the
  139. * clipping boundary. Alternative to `autoPlacement`.
  140. * @see https://floating-ui.com/docs/flip
  141. */
  142. export declare const flip: (options?: FlipOptions | Derivable<FlipOptions>) => Middleware;
  143. export declare type FlipOptions = Prettify<Omit<FlipOptions_2, 'boundary'> & DetectOverflowOptions>;
  144. export declare type FloatingElement = HTMLElement;
  145. export { getOverflowAncestors }
  146. /**
  147. * Provides data to hide the floating element in applicable situations, such as
  148. * when it is not in the same clipping context as the reference element.
  149. * @see https://floating-ui.com/docs/hide
  150. */
  151. export declare const hide: (options?: HideOptions | Derivable<HideOptions>) => Middleware;
  152. export declare type HideOptions = Prettify<Omit<HideOptions_2, 'boundary'> & DetectOverflowOptions>;
  153. /**
  154. * Provides improved positioning for inline reference elements that can span
  155. * over multiple lines, such as hyperlinks or range selections.
  156. * @see https://floating-ui.com/docs/inline
  157. */
  158. export declare const inline: (options?: InlineOptions | Derivable<InlineOptions>) => Middleware;
  159. export { InlineOptions }
  160. export { Length }
  161. /**
  162. * Built-in `limiter` that will stop `shift()` at a certain point.
  163. */
  164. export declare const limitShift: (options?: LimitShiftOptions | Derivable<LimitShiftOptions>) => {
  165. options: any;
  166. fn: (state: MiddlewareState) => Coords;
  167. };
  168. export { LimitShiftOptions }
  169. export declare type Middleware = Prettify<Omit<Middleware_2, 'fn'> & {
  170. fn(state: MiddlewareState): Promisable<MiddlewareReturn>;
  171. }>;
  172. /**
  173. * @deprecated use `MiddlewareState` instead.
  174. */
  175. export declare type MiddlewareArguments = MiddlewareState;
  176. export { MiddlewareData }
  177. export { MiddlewareReturn }
  178. export declare type MiddlewareState = Prettify<Omit<MiddlewareState_2, 'elements'> & {
  179. elements: Elements;
  180. }>;
  181. export declare interface NodeScroll {
  182. scrollLeft: number;
  183. scrollTop: number;
  184. }
  185. /**
  186. * Modifies the placement by translating the floating element along the
  187. * specified axes.
  188. * A number (shorthand for `mainAxis` or distance), or an axes configuration
  189. * object may be passed.
  190. * @see https://floating-ui.com/docs/offset
  191. */
  192. export declare const offset: (options?: OffsetOptions) => Middleware;
  193. export declare type OffsetOptions = OffsetValue | Derivable<OffsetValue>;
  194. declare type OffsetValue = number | {
  195. /**
  196. * The axis that runs along the side of the floating element. Represents
  197. * the distance (gutter or margin) between the reference and floating
  198. * element.
  199. * @default 0
  200. */
  201. mainAxis?: number;
  202. /**
  203. * The axis that runs along the alignment of the floating element.
  204. * Represents the skidding between the reference and floating element.
  205. * @default 0
  206. */
  207. crossAxis?: number;
  208. /**
  209. * The same axis as `crossAxis` but applies only to aligned placements
  210. * and inverts the `end` alignment. When set to a number, it overrides the
  211. * `crossAxis` value.
  212. *
  213. * A positive number will move the floating element in the direction of
  214. * the opposite edge to the one that is aligned, while a negative number
  215. * the reverse.
  216. * @default null
  217. */
  218. alignmentAxis?: number | null;
  219. };
  220. export { Padding }
  221. export { Placement }
  222. export declare interface Platform {
  223. getElementRects: (args: {
  224. reference: ReferenceElement;
  225. floating: FloatingElement;
  226. strategy: Strategy;
  227. }) => Promisable<ElementRects>;
  228. getClippingRect: (args: {
  229. element: Element;
  230. boundary: Boundary;
  231. rootBoundary: RootBoundary;
  232. strategy: Strategy;
  233. }) => Promisable<Rect>;
  234. getDimensions: (element: Element) => Promisable<Dimensions>;
  235. convertOffsetParentRelativeRectToViewportRelativeRect: (args: {
  236. elements?: Elements;
  237. rect: Rect;
  238. offsetParent: Element;
  239. strategy: Strategy;
  240. }) => Promisable<Rect>;
  241. getOffsetParent: (element: Element, polyfill?: (element: HTMLElement) => Element | null) => Promisable<Element | Window>;
  242. isElement: (value: unknown) => Promisable<boolean>;
  243. getDocumentElement: (element: Element) => Promisable<HTMLElement>;
  244. getClientRects: (element: Element) => Promisable<Array<ClientRectObject>>;
  245. isRTL: (element: Element) => Promisable<boolean>;
  246. getScale: (element: HTMLElement) => Promisable<{
  247. x: number;
  248. y: number;
  249. }>;
  250. }
  251. export declare const platform: Platform;
  252. declare type Prettify<T> = {
  253. [K in keyof T]: T[K];
  254. } & {};
  255. declare type Promisable<T> = T | Promise<T>;
  256. export { Rect }
  257. export declare type ReferenceElement = Element | VirtualElement;
  258. export { RootBoundary }
  259. /**
  260. * Optimizes the visibility of the floating element by shifting it in order to
  261. * keep it in view when it will overflow the clipping boundary.
  262. * @see https://floating-ui.com/docs/shift
  263. */
  264. export declare const shift: (options?: ShiftOptions | Derivable<ShiftOptions>) => Middleware;
  265. export declare type ShiftOptions = Prettify<Omit<ShiftOptions_2, 'boundary'> & DetectOverflowOptions>;
  266. export { Side }
  267. export { SideObject }
  268. /**
  269. * Provides data that allows you to change the size of the floating element —
  270. * for instance, prevent it from overflowing the clipping boundary or match the
  271. * width of the reference element.
  272. * @see https://floating-ui.com/docs/size
  273. */
  274. export declare const size: (options?: SizeOptions | Derivable<SizeOptions>) => Middleware;
  275. export declare type SizeOptions = Prettify<Omit<SizeOptions_2, 'apply' | 'boundary'> & DetectOverflowOptions & {
  276. /**
  277. * Function that is called to perform style mutations to the floating element
  278. * to change its size.
  279. * @default undefined
  280. */
  281. apply?(args: MiddlewareState & {
  282. availableWidth: number;
  283. availableHeight: number;
  284. }): Promisable<void>;
  285. }>;
  286. export { Strategy }
  287. /**
  288. * Custom positioning reference element.
  289. * @see https://floating-ui.com/docs/virtual-elements
  290. */
  291. export declare interface VirtualElement {
  292. getBoundingClientRect(): ClientRectObject;
  293. getClientRects?(): Array<ClientRectObject> | DOMRectList;
  294. contextElement?: Element;
  295. }
  296. export { }