You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.7 KiB

7 months ago
  1. // @flow
  2. export const top: 'top' = 'top';
  3. export const bottom: 'bottom' = 'bottom';
  4. export const right: 'right' = 'right';
  5. export const left: 'left' = 'left';
  6. export const auto: 'auto' = 'auto';
  7. export type BasePlacement =
  8. | typeof top
  9. | typeof bottom
  10. | typeof right
  11. | typeof left;
  12. export const basePlacements: Array<BasePlacement> = [top, bottom, right, left];
  13. export const start: 'start' = 'start';
  14. export const end: 'end' = 'end';
  15. export type Variation = typeof start | typeof end;
  16. export const clippingParents: 'clippingParents' = 'clippingParents';
  17. export const viewport: 'viewport' = 'viewport';
  18. export type Boundary = Element | Array<Element> | typeof clippingParents;
  19. export type RootBoundary = typeof viewport | 'document';
  20. export const popper: 'popper' = 'popper';
  21. export const reference: 'reference' = 'reference';
  22. export type Context = typeof popper | typeof reference;
  23. export type VariationPlacement =
  24. | 'top-start'
  25. | 'top-end'
  26. | 'bottom-start'
  27. | 'bottom-end'
  28. | 'right-start'
  29. | 'right-end'
  30. | 'left-start'
  31. | 'left-end';
  32. export type AutoPlacement = 'auto' | 'auto-start' | 'auto-end';
  33. export type ComputedPlacement = VariationPlacement | BasePlacement;
  34. export type Placement = AutoPlacement | BasePlacement | VariationPlacement;
  35. export const variationPlacements: Array<VariationPlacement> = basePlacements.reduce(
  36. (acc: Array<VariationPlacement>, placement: BasePlacement) =>
  37. acc.concat([(`${placement}-${start}`: any), (`${placement}-${end}`: any)]),
  38. []
  39. );
  40. export const placements: Array<Placement> = [...basePlacements, auto].reduce(
  41. (
  42. acc: Array<Placement>,
  43. placement: BasePlacement | typeof auto
  44. ): Array<Placement> =>
  45. acc.concat([
  46. placement,
  47. (`${placement}-${start}`: any),
  48. (`${placement}-${end}`: any),
  49. ]),
  50. []
  51. );
  52. // modifiers that need to read the DOM
  53. export const beforeRead: 'beforeRead' = 'beforeRead';
  54. export const read: 'read' = 'read';
  55. export const afterRead: 'afterRead' = 'afterRead';
  56. // pure-logic modifiers
  57. export const beforeMain: 'beforeMain' = 'beforeMain';
  58. export const main: 'main' = 'main';
  59. export const afterMain: 'afterMain' = 'afterMain';
  60. // modifier with the purpose to write to the DOM (or write into a framework state)
  61. export const beforeWrite: 'beforeWrite' = 'beforeWrite';
  62. export const write: 'write' = 'write';
  63. export const afterWrite: 'afterWrite' = 'afterWrite';
  64. export const modifierPhases: Array<ModifierPhases> = [
  65. beforeRead,
  66. read,
  67. afterRead,
  68. beforeMain,
  69. main,
  70. afterMain,
  71. beforeWrite,
  72. write,
  73. afterWrite,
  74. ];
  75. export type ModifierPhases =
  76. | typeof beforeRead
  77. | typeof read
  78. | typeof afterRead
  79. | typeof beforeMain
  80. | typeof main
  81. | typeof afterMain
  82. | typeof beforeWrite
  83. | typeof write
  84. | typeof afterWrite;