@atlaskit/top-layer 0.12.0 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/animations/presets.js +5 -5
  3. package/dist/cjs/dialog/create-close-event.js +1 -1
  4. package/dist/cjs/dialog/dialog-content.js +5 -5
  5. package/dist/cjs/entry-points/use-arrow-navigation.js +3 -2
  6. package/dist/cjs/internal/ensure-preset-styles.js +1 -1
  7. package/dist/cjs/internal/placement-to-position-area.js +43 -0
  8. package/dist/cjs/internal/placement-to-try-fallbacks.js +82 -0
  9. package/dist/cjs/internal/reduced-motion.js +1 -1
  10. package/dist/cjs/internal/resolve-placement.js +2 -2
  11. package/dist/cjs/internal/role-types.js +1 -1
  12. package/dist/cjs/internal/slot.js +3 -3
  13. package/dist/cjs/internal/use-anchor-position.js +33 -161
  14. package/dist/cjs/internal/use-animated-visibility.js +10 -10
  15. package/dist/cjs/internal/use-animation-preset.js +1 -1
  16. package/dist/cjs/internal/use-preset-styles.js +1 -1
  17. package/dist/cjs/internal/use-width-from-anchor.js +4 -4
  18. package/dist/cjs/popover/create-close-event.js +1 -1
  19. package/dist/cjs/popover/popover.js +3 -3
  20. package/dist/cjs/popup/popup-content.js +6 -6
  21. package/dist/cjs/popup/popup-context.js +2 -38
  22. package/dist/cjs/popup/popup-provider.js +15 -0
  23. package/dist/cjs/popup/popup-trigger-function.js +2 -2
  24. package/dist/cjs/popup/popup-trigger.js +2 -2
  25. package/dist/cjs/popup/popup.js +2 -2
  26. package/dist/cjs/popup/use-maybe-popup-context.js +17 -0
  27. package/dist/cjs/popup/use-popup-context.js +20 -0
  28. package/dist/cjs/testing/polyfill.js +8 -8
  29. package/dist/cjs/testing/to-be-visible.js +5 -5
  30. package/dist/cjs/use-arrow-navigation/index.js +3 -2
  31. package/dist/cjs/use-arrow-navigation/is-at-current-menu-level.js +94 -0
  32. package/dist/cjs/use-arrow-navigation/use-arrow-navigation.js +0 -82
  33. package/dist/cjs/use-simple-light-dismiss/index.js +3 -3
  34. package/dist/es2019/animations/presets.js +5 -5
  35. package/dist/es2019/dialog/create-close-event.js +1 -1
  36. package/dist/es2019/dialog/dialog-content.js +5 -5
  37. package/dist/es2019/entry-points/use-arrow-navigation.js +2 -1
  38. package/dist/es2019/internal/ensure-preset-styles.js +1 -1
  39. package/dist/es2019/internal/placement-to-position-area.js +40 -0
  40. package/dist/es2019/internal/placement-to-try-fallbacks.js +77 -0
  41. package/dist/es2019/internal/reduced-motion.js +1 -1
  42. package/dist/es2019/internal/resolve-placement.js +2 -2
  43. package/dist/es2019/internal/role-types.js +1 -1
  44. package/dist/es2019/internal/slot.js +3 -3
  45. package/dist/es2019/internal/use-anchor-position.js +15 -132
  46. package/dist/es2019/internal/use-animated-visibility.js +10 -10
  47. package/dist/es2019/internal/use-animation-preset.js +1 -1
  48. package/dist/es2019/internal/use-preset-styles.js +1 -1
  49. package/dist/es2019/internal/use-width-from-anchor.js +4 -4
  50. package/dist/es2019/popover/create-close-event.js +1 -1
  51. package/dist/es2019/popover/popover.js +3 -3
  52. package/dist/es2019/popup/popup-content.js +6 -5
  53. package/dist/es2019/popup/popup-context.js +2 -36
  54. package/dist/es2019/popup/popup-provider.js +10 -0
  55. package/dist/es2019/popup/popup-trigger-function.js +1 -1
  56. package/dist/es2019/popup/popup-trigger.js +2 -1
  57. package/dist/es2019/popup/popup.js +1 -1
  58. package/dist/es2019/popup/use-maybe-popup-context.js +12 -0
  59. package/dist/es2019/popup/use-popup-context.js +15 -0
  60. package/dist/es2019/testing/polyfill.js +8 -8
  61. package/dist/es2019/testing/to-be-visible.js +5 -5
  62. package/dist/es2019/use-arrow-navigation/index.js +2 -1
  63. package/dist/es2019/use-arrow-navigation/is-at-current-menu-level.js +88 -0
  64. package/dist/es2019/use-arrow-navigation/use-arrow-navigation.js +0 -81
  65. package/dist/es2019/use-simple-light-dismiss/index.js +3 -3
  66. package/dist/esm/animations/presets.js +5 -5
  67. package/dist/esm/dialog/create-close-event.js +1 -1
  68. package/dist/esm/dialog/dialog-content.js +5 -5
  69. package/dist/esm/entry-points/use-arrow-navigation.js +2 -1
  70. package/dist/esm/internal/ensure-preset-styles.js +1 -1
  71. package/dist/esm/internal/placement-to-position-area.js +38 -0
  72. package/dist/esm/internal/placement-to-try-fallbacks.js +76 -0
  73. package/dist/esm/internal/reduced-motion.js +1 -1
  74. package/dist/esm/internal/resolve-placement.js +2 -2
  75. package/dist/esm/internal/role-types.js +1 -1
  76. package/dist/esm/internal/slot.js +3 -3
  77. package/dist/esm/internal/use-anchor-position.js +31 -157
  78. package/dist/esm/internal/use-animated-visibility.js +10 -10
  79. package/dist/esm/internal/use-animation-preset.js +1 -1
  80. package/dist/esm/internal/use-preset-styles.js +1 -1
  81. package/dist/esm/internal/use-width-from-anchor.js +4 -4
  82. package/dist/esm/popover/create-close-event.js +1 -1
  83. package/dist/esm/popover/popover.js +3 -3
  84. package/dist/esm/popup/popup-content.js +6 -5
  85. package/dist/esm/popup/popup-context.js +2 -36
  86. package/dist/esm/popup/popup-provider.js +10 -0
  87. package/dist/esm/popup/popup-trigger-function.js +1 -1
  88. package/dist/esm/popup/popup-trigger.js +2 -1
  89. package/dist/esm/popup/popup.js +1 -1
  90. package/dist/esm/popup/use-maybe-popup-context.js +12 -0
  91. package/dist/esm/popup/use-popup-context.js +15 -0
  92. package/dist/esm/testing/polyfill.js +8 -8
  93. package/dist/esm/testing/to-be-visible.js +5 -5
  94. package/dist/esm/use-arrow-navigation/index.js +2 -1
  95. package/dist/esm/use-arrow-navigation/is-at-current-menu-level.js +88 -0
  96. package/dist/esm/use-arrow-navigation/use-arrow-navigation.js +0 -81
  97. package/dist/esm/use-simple-light-dismiss/index.js +3 -3
  98. package/dist/types/dialog/create-close-event.d.ts +1 -1
  99. package/dist/types/dialog/types.d.ts +8 -0
  100. package/dist/types/entry-points/use-arrow-navigation.d.ts +2 -1
  101. package/dist/types/internal/placement-to-position-area.d.ts +21 -0
  102. package/dist/types/internal/placement-to-try-fallbacks.d.ts +36 -0
  103. package/dist/types/internal/reduced-motion.d.ts +1 -1
  104. package/dist/types/internal/resolve-placement.d.ts +2 -2
  105. package/dist/types/internal/slot.d.ts +4 -4
  106. package/dist/types/internal/use-anchor-position.d.ts +0 -55
  107. package/dist/types/internal/use-animated-visibility.d.ts +3 -3
  108. package/dist/types/internal/use-animation-preset.d.ts +1 -1
  109. package/dist/types/internal/use-preset-styles.d.ts +1 -1
  110. package/dist/types/internal/use-width-from-anchor.d.ts +2 -2
  111. package/dist/types/popover/create-close-event.d.ts +1 -1
  112. package/dist/types/popover/popover.d.ts +1 -1
  113. package/dist/types/popup/popup-context.d.ts +2 -22
  114. package/dist/types/popup/popup-provider.d.ts +10 -0
  115. package/dist/types/popup/use-maybe-popup-context.d.ts +8 -0
  116. package/dist/types/popup/use-popup-context.d.ts +7 -0
  117. package/dist/types/testing/to-be-visible.d.ts +3 -3
  118. package/dist/types/use-arrow-navigation/index.d.ts +2 -1
  119. package/dist/types/use-arrow-navigation/is-at-current-menu-level.d.ts +48 -0
  120. package/dist/types/use-arrow-navigation/use-arrow-navigation.d.ts +0 -48
  121. package/dist/types/use-simple-light-dismiss/index.d.ts +1 -1
  122. package/dist/types-ts4.5/dialog/create-close-event.d.ts +1 -1
  123. package/dist/types-ts4.5/dialog/types.d.ts +8 -0
  124. package/dist/types-ts4.5/entry-points/use-arrow-navigation.d.ts +2 -1
  125. package/dist/types-ts4.5/internal/placement-to-position-area.d.ts +21 -0
  126. package/dist/types-ts4.5/internal/placement-to-try-fallbacks.d.ts +36 -0
  127. package/dist/types-ts4.5/internal/reduced-motion.d.ts +1 -1
  128. package/dist/types-ts4.5/internal/resolve-placement.d.ts +2 -2
  129. package/dist/types-ts4.5/internal/slot.d.ts +4 -4
  130. package/dist/types-ts4.5/internal/use-anchor-position.d.ts +0 -55
  131. package/dist/types-ts4.5/internal/use-animated-visibility.d.ts +3 -3
  132. package/dist/types-ts4.5/internal/use-animation-preset.d.ts +1 -1
  133. package/dist/types-ts4.5/internal/use-preset-styles.d.ts +1 -1
  134. package/dist/types-ts4.5/internal/use-width-from-anchor.d.ts +2 -2
  135. package/dist/types-ts4.5/popover/create-close-event.d.ts +1 -1
  136. package/dist/types-ts4.5/popover/popover.d.ts +1 -1
  137. package/dist/types-ts4.5/popup/popup-context.d.ts +2 -22
  138. package/dist/types-ts4.5/popup/popup-provider.d.ts +10 -0
  139. package/dist/types-ts4.5/popup/use-maybe-popup-context.d.ts +8 -0
  140. package/dist/types-ts4.5/popup/use-popup-context.d.ts +7 -0
  141. package/dist/types-ts4.5/testing/to-be-visible.d.ts +3 -3
  142. package/dist/types-ts4.5/use-arrow-navigation/index.d.ts +2 -1
  143. package/dist/types-ts4.5/use-arrow-navigation/is-at-current-menu-level.d.ts +48 -0
  144. package/dist/types-ts4.5/use-arrow-navigation/use-arrow-navigation.d.ts +0 -48
  145. package/dist/types-ts4.5/use-simple-light-dismiss/index.d.ts +1 -1
  146. package/package.json +2 -2
  147. package/dist/cjs/arrow/index.js +0 -131
  148. package/dist/cjs/arrow/types.js +0 -5
  149. package/dist/es2019/arrow/index.js +0 -269
  150. package/dist/es2019/arrow/types.js +0 -1
  151. package/dist/esm/arrow/index.js +0 -124
  152. package/dist/esm/arrow/types.js +0 -1
  153. package/dist/types/arrow/index.d.ts +0 -24
  154. package/dist/types/arrow/types.d.ts +0 -29
  155. package/dist/types-ts4.5/arrow/index.d.ts +0 -24
  156. package/dist/types-ts4.5/arrow/types.d.ts +0 -29
@@ -3,8 +3,8 @@ import type { TWidthFromAnchorMode } from '../popover/types';
3
3
  /**
4
4
  * Sets the width of a popover element relative to its anchor element.
5
5
  *
6
- * - `'match-anchor'` → `width: anchor-size(width)` — popover matches anchor width exactly.
7
- * - `'min-anchor'` → `min-width: anchor-size(width)` — popover is at least as wide as anchor,
6
+ * - `'match-anchor'` → `width: anchor-size(width)` - popover matches anchor width exactly.
7
+ * - `'min-anchor'` → `min-width: anchor-size(width)` - popover is at least as wide as anchor,
8
8
  * but can grow wider.
9
9
  * - `'none'` → no explicit width is set (default behaviour)
10
10
  *
@@ -3,7 +3,7 @@ import type { TPopoverCloseReason } from './types';
3
3
  * Creates a synthetic DOM event from a `TPopoverCloseReason`.
4
4
  *
5
5
  * Useful when bridging the Popover primitive's `onClose({ reason })` callback
6
- * to a legacy API that expects a native DOM event — for example,
6
+ * to a legacy API that expects a native DOM event - for example,
7
7
  * `@atlaskit/inline-dialog`'s `onClose(event)` contract.
8
8
  *
9
9
  * - `'escape'` → `KeyboardEvent('keydown', { key: 'Escape' })`
@@ -8,7 +8,7 @@ import { type TPopoverForwardedProps } from './types';
8
8
  * Unopinionated top-layer primitive.
9
9
  *
10
10
  * Manages only visibility (isOpen) and animation (animate). Has no knowledge
11
- * of positioning — compose with `useAnchorPosition` for anchor positioning
11
+ * of positioning - compose with `useAnchorPosition` for anchor positioning
12
12
  * and optionally `useWidthFromAnchor` for setting the width of a popover element
13
13
  * relative to its anchor trigger.
14
14
  *
@@ -79,7 +79,7 @@ export type TPopupContextValue = {
79
79
  */
80
80
  ariaHasPopup: TAriaHasPopupValue;
81
81
  /**
82
- * Updates `ariaHasPopup` — called by Content on mount/role change.
82
+ * Updates `ariaHasPopup` - called by Content on mount/role change.
83
83
  */
84
84
  setAriaHasPopup: (value: TAriaHasPopupValue) => void;
85
85
  /**
@@ -93,24 +93,4 @@ export type TPopupContextValue = {
93
93
  */
94
94
  forceFallbackPositioning?: boolean;
95
95
  };
96
- /**
97
- * __Popup provider__
98
- *
99
- * Provides shared popup state (placement, popoverId, triggerRef,
100
- * isOpen, onClose) to compound child components such as `Popup.Trigger` and
101
- * `Popup.Content`.
102
- */
103
- export declare const PopupProvider: React.Provider<TPopupContextValue | null>;
104
- /**
105
- * Returns the nearest `Popup` context value.
106
- *
107
- * Throws if called outside of a `<Popup>` compound component.
108
- */
109
- export declare function usePopupContext(): TPopupContextValue;
110
- /**
111
- * Returns the popup context if available, or `null` when used outside `<Popup>`.
112
- *
113
- * Used by `PopupContent` to support standalone usage (e.g. tooltip)
114
- * where values are passed as props instead of coming from a compound component.
115
- */
116
- export declare function useMaybePopupContext(): TPopupContextValue | null;
96
+ export declare const PopupContext: React.Context<TPopupContextValue | null>;
@@ -0,0 +1,10 @@
1
+ import { type Provider } from 'react';
2
+ import { type TPopupContextValue } from './popup-context';
3
+ /**
4
+ * __Popup provider__
5
+ *
6
+ * Provides shared popup state (placement, popoverId, triggerRef,
7
+ * isOpen, onClose) to compound child components such as `Popup.Trigger` and
8
+ * `Popup.Content`.
9
+ */
10
+ export declare const PopupProvider: Provider<TPopupContextValue | null>;
@@ -0,0 +1,8 @@
1
+ import { type TPopupContextValue } from './popup-context';
2
+ /**
3
+ * Returns the popup context if available, or `null` when used outside `<Popup>`.
4
+ *
5
+ * Used by `PopupContent` to support standalone usage (e.g. tooltip)
6
+ * where values are passed as props instead of coming from a compound component.
7
+ */
8
+ export declare function useMaybePopupContext(): TPopupContextValue | null;
@@ -0,0 +1,7 @@
1
+ import { type TPopupContextValue } from './popup-context';
2
+ /**
3
+ * Returns the nearest `Popup` context value.
4
+ *
5
+ * Throws if called outside of a `<Popup>` compound component.
6
+ */
7
+ export declare function usePopupContext(): TPopupContextValue;
@@ -3,13 +3,13 @@
3
3
  *
4
4
  * jest-dom's `toBeVisible()` does not know about the Popover API. In real
5
5
  * browsers the UA stylesheet hides `[popover]` with `display: none`, but
6
- * jsdom has no such stylesheet — so closed popovers incorrectly appear visible.
6
+ * jsdom has no such stylesheet - so closed popovers incorrectly appear visible.
7
7
  *
8
8
  * Raw jest-dom results in jsdom:
9
9
  *
10
- * closed popover / child → true (WRONG — should be false)
10
+ * closed popover / child → true (WRONG - should be false)
11
11
  * open popover / child → true (correct)
12
- * closed dialog / child → false (correct — jsdom natively hides <dialog>)
12
+ * closed dialog / child → false (correct - jsdom natively hides <dialog>)
13
13
  * open dialog / child → true (correct)
14
14
  *
15
15
  * We correct both false positives and false negatives:
@@ -1,2 +1,3 @@
1
- export { useArrowNavigation, isAtCurrentMenuLevel } from './use-arrow-navigation';
1
+ export { useArrowNavigation } from './use-arrow-navigation';
2
2
  export type { TUseArrowNavigationArgs } from './use-arrow-navigation';
3
+ export { isAtCurrentMenuLevel } from './is-at-current-menu-level';
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Returns true if the element belongs to the current menu level of the
3
+ * container, i.e. it is NOT inside a nested `role="menu"` sub-container.
4
+ *
5
+ * Uses `element.closest('[role="menu"]')` to determine the nearest menu
6
+ * scope. If the nearest scope is the container's own `role="menu"` element,
7
+ * the element belongs to this level. If it is a different (nested) menu,
8
+ * the element belongs to a child level and should be excluded.
9
+ *
10
+ * Supports two container patterns:
11
+ *
12
+ * **1. Container has `role="menu"` directly** (preferred, used by avatar-group):
13
+ * ```
14
+ * <div ref={containerRef} role="menu">
15
+ * <button role="menuitem" /> ← isAtCurrentMenuLevel → true
16
+ * <div role="menu"> ← nested sub-menu
17
+ * <button role="menuitem" /> ← isAtCurrentMenuLevel → false
18
+ * </div>
19
+ * </div>
20
+ * ```
21
+ * Uses the simple check: `element.closest('[role="menu"]') === container`
22
+ *
23
+ * **2. Container is a wrapper without `role="menu"`** (used by dropdown-menu,
24
+ * where `MenuGroup` owns `role="menu"` but does not accept a ref):
25
+ * ```
26
+ * <div ref={containerRef}> ← wrapper (no role="menu")
27
+ * <MenuGroup role="menu">
28
+ * <button role="menuitem" /> ← isAtCurrentMenuLevel → true
29
+ * <div role="menu"> ← nested sub-menu
30
+ * <button role="menuitem" /> ← isAtCurrentMenuLevel → false
31
+ * </div>
32
+ * </MenuGroup>
33
+ * </div>
34
+ * ```
35
+ * Falls back to walking the DOM to check that the element's closest
36
+ * `role="menu"` is the container's own menu (not doubly nested).
37
+ *
38
+ * Ideally all consumers should use pattern 1 (place the ref directly on the
39
+ * `role="menu"` element). Pattern 2 exists because `@atlaskit/menu`'s
40
+ * `MenuGroup` does not currently accept a ref. If `MenuGroup` gains ref
41
+ * support in the future, dropdown-menu should switch to pattern 1 and the
42
+ * fallback path can be removed.
43
+ *
44
+ * Used both as a `TFocusableFilter` (to scope getNextFocusable etc.) and as
45
+ * a guard to prevent parent menu handlers from acting on events that
46
+ * belong to a nested menu.
47
+ */
48
+ export declare function isAtCurrentMenuLevel(element: Element, container: HTMLElement): boolean;
@@ -1,53 +1,5 @@
1
1
  import { type RefObject } from 'react';
2
2
  import { type TFocusableFilter } from '../focus';
3
- /**
4
- * Returns true if the element belongs to the current menu level of the
5
- * container, i.e. it is NOT inside a nested `role="menu"` sub-container.
6
- *
7
- * Uses `element.closest('[role="menu"]')` to determine the nearest menu
8
- * scope. If the nearest scope is the container's own `role="menu"` element,
9
- * the element belongs to this level. If it is a different (nested) menu,
10
- * the element belongs to a child level and should be excluded.
11
- *
12
- * Supports two container patterns:
13
- *
14
- * **1. Container has `role="menu"` directly** (preferred, used by avatar-group):
15
- * ```
16
- * <div ref={containerRef} role="menu">
17
- * <button role="menuitem" /> ← isAtCurrentMenuLevel → true
18
- * <div role="menu"> ← nested sub-menu
19
- * <button role="menuitem" /> ← isAtCurrentMenuLevel → false
20
- * </div>
21
- * </div>
22
- * ```
23
- * Uses the simple check: `element.closest('[role="menu"]') === container`
24
- *
25
- * **2. Container is a wrapper without `role="menu"`** (used by dropdown-menu,
26
- * where `MenuGroup` owns `role="menu"` but does not accept a ref):
27
- * ```
28
- * <div ref={containerRef}> ← wrapper (no role="menu")
29
- * <MenuGroup role="menu">
30
- * <button role="menuitem" /> ← isAtCurrentMenuLevel → true
31
- * <div role="menu"> ← nested sub-menu
32
- * <button role="menuitem" /> ← isAtCurrentMenuLevel → false
33
- * </div>
34
- * </MenuGroup>
35
- * </div>
36
- * ```
37
- * Falls back to walking the DOM to check that the element's closest
38
- * `role="menu"` is the container's own menu (not doubly nested).
39
- *
40
- * Ideally all consumers should use pattern 1 (place the ref directly on the
41
- * `role="menu"` element). Pattern 2 exists because `@atlaskit/menu`'s
42
- * `MenuGroup` does not currently accept a ref. If `MenuGroup` gains ref
43
- * support in the future, dropdown-menu should switch to pattern 1 and the
44
- * fallback path can be removed.
45
- *
46
- * Used both as a `TFocusableFilter` (to scope getNextFocusable etc.) and as
47
- * a guard to prevent parent menu handlers from acting on events that
48
- * belong to a nested menu.
49
- */
50
- export declare function isAtCurrentMenuLevel(element: Element, container: HTMLElement): boolean;
51
3
  /**
52
4
  * Args for `useArrowNavigation`.
53
5
  *
@@ -34,7 +34,7 @@ type TUseSimpleLightDismissOptions = {
34
34
  * **No stacking awareness:** This hook does not track a popover stack.
35
35
  * If multiple manual popovers are open and all use this hook, a single
36
36
  * Escape press or outside click will dismiss **all of them simultaneously**.
37
- * This is by design — the hook is intentionally simple for cases where
37
+ * This is by design - the hook is intentionally simple for cases where
38
38
  * only one manual popover is open at a time.
39
39
  *
40
40
  * For stacked/nested popovers that should dismiss one-at-a-time, use
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/top-layer",
3
- "version": "0.12.0",
3
+ "version": "0.12.2",
4
4
  "description": "Low-level layering primitives based on popover and dialog",
5
5
  "homepage": "https://atlassian.design/components/top-layer",
6
6
  "repository": "https://bitbucket.org/atlassian/atlassian-frontend-mirror",
@@ -38,7 +38,7 @@
38
38
  "@atlaskit/css": "^0.19.0",
39
39
  "@atlaskit/ds-lib": "^7.0.0",
40
40
  "@atlaskit/layering": "^3.7.0",
41
- "@atlaskit/tokens": "^13.0.0",
41
+ "@atlaskit/tokens": "^13.1.0",
42
42
  "@babel/runtime": "^7.0.0",
43
43
  "@compiled/react": "^0.20.0",
44
44
  "bind-event-listener": "^3.0.0",
@@ -1,131 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.arrow = void 0;
8
- var _once = _interopRequireDefault(require("@atlaskit/ds-lib/once"));
9
- var _resolvePlacement = require("../internal/resolve-placement");
10
- var _useAnchorPosition = require("../internal/use-anchor-position");
11
- /**
12
- * CSS for popover arrows using the `clip-path: inset() margin-box` technique.
13
- *
14
- * How it works:
15
- * 1. Four arrow shapes exist simultaneously as `::before` (top/bottom) and
16
- * `::after` (left/right) hexagonal pseudo-elements.
17
- * 2. `clip-path: inset(0) margin-box` clips the popover to its margin-box.
18
- * 3. Margin on the anchor-facing side pushes the popover away, creating space
19
- * where one arrow "escapes" the clip boundary and becomes visible.
20
- * 4. `@position-try` rules change both `position-area` and `margin` when
21
- * flipping, ensuring the correct arrow is always shown.
22
- *
23
- * Constraints:
24
- * - `box-shadow` must be `none` (interferes with `clip-path: inset() margin-box`)
25
- * - `::before` and `::after` are consumed - consumers cannot use them
26
- * - Arrow pseudo-elements use `background: inherit` from the popover element
27
- *
28
- * @see https://goulet.dev/posts/tooltip-with-popover-and-anchor-positioning/
29
- */
30
- var ARROW_CSS = "\n[data-ds-popover-arrow] {\n clip-path: inset(var(--ds-arrow-offset, 0px)) margin-box;\n box-shadow: none;\n}\n\n/* Top and Bottom arrows (vertical hexagon) */\n[data-ds-popover-arrow]::before {\n content: \"\";\n position: absolute;\n z-index: -1;\n background: inherit;\n left: 50%;\n transform: translateX(-50%);\n width: calc(var(--ds-arrow-size, 8px) * 2);\n height: calc(100% + var(--ds-arrow-size, 8px) * 2);\n top: calc(var(--ds-arrow-size, 8px) * -1);\n clip-path: polygon(\n 0 var(--ds-arrow-size, 8px),\n 50% 0,\n 100% var(--ds-arrow-size, 8px),\n 100% calc(100% - var(--ds-arrow-size, 8px)),\n 50% 100%,\n 0 calc(100% - var(--ds-arrow-size, 8px))\n );\n}\n\n/* Left and Right arrows (horizontal hexagon) */\n[data-ds-popover-arrow]::after {\n content: \"\";\n position: absolute;\n z-index: -1;\n background: inherit;\n top: 50%;\n transform: translateY(-50%);\n height: calc(var(--ds-arrow-size, 8px) * 2);\n width: calc(100% + var(--ds-arrow-size, 8px) * 2);\n left: calc(var(--ds-arrow-size, 8px) * -1);\n clip-path: polygon(\n var(--ds-arrow-size, 8px) 0,\n calc(100% - var(--ds-arrow-size, 8px)) 0,\n 100% 50%,\n calc(100% - var(--ds-arrow-size, 8px)) 100%,\n var(--ds-arrow-size, 8px) 100%,\n 0 50%\n );\n}\n\n/* \u2500\u2500 @position-try rules \u2500\u2500\n * One rule per possible position-area value.\n * Each sets the position-area and the correct margin direction\n * so the arrow on the anchor-facing side is revealed.\n *\n * Margin direction per edge:\n * block-start (above anchor) \u2192 margin-block-end (bottom, facing anchor)\n * block-end (below anchor) \u2192 margin-block-start (top, facing anchor)\n * inline-start (left of anchor) \u2192 margin-inline-end (right, facing anchor)\n * inline-end (right of anchor) \u2192 margin-inline-start (left, facing anchor)\n */\n\n/* Each rule sets two margins: the anchor-facing margin for the gap\n (via --ds-arrow-size) and one cross-axis margin for the shift\n (via one of --ds-cross-axis-shift-margin-start, --ds-cross-axis-shift-margin-end,\n --ds-cross-axis-shift-margin-block-start, or --ds-cross-axis-shift-margin-block-end). The\n side matches the popover's anchored cross-axis edge per align. Only\n one of the four properties is non-zero at a time; useAnchorPosition\n picks it. See notes/architecture/positioning.md for details. */\n/* Single-axis centered (align: center) */\n@position-try --ds-arrow-block-start {\n position-area: block-start;\n margin: 0;\n margin-block-end: var(--ds-arrow-size, 8px);\n margin-inline-start: var(--ds-cross-axis-shift-margin-start, 0px);\n}\n@position-try --ds-arrow-block-end {\n position-area: block-end;\n margin: 0;\n margin-block-start: var(--ds-arrow-size, 8px);\n margin-inline-start: var(--ds-cross-axis-shift-margin-start, 0px);\n}\n@position-try --ds-arrow-inline-start {\n position-area: inline-start;\n margin: 0;\n margin-inline-end: var(--ds-arrow-size, 8px);\n margin-block-start: var(--ds-cross-axis-shift-margin-block-start, 0px);\n}\n@position-try --ds-arrow-inline-end {\n position-area: inline-end;\n margin: 0;\n margin-inline-start: var(--ds-arrow-size, 8px);\n margin-block-start: var(--ds-cross-axis-shift-margin-block-start, 0px);\n}\n\n/* Block edge + inline span (align: start uses span-inline-end; align: end uses span-inline-start) */\n@position-try --ds-arrow-block-start-span-inline-start {\n position-area: block-start span-inline-start;\n margin: 0;\n margin-block-end: var(--ds-arrow-size, 8px);\n margin-inline-end: var(--ds-cross-axis-shift-margin-end, 0px);\n}\n@position-try --ds-arrow-block-start-span-inline-end {\n position-area: block-start span-inline-end;\n margin: 0;\n margin-block-end: var(--ds-arrow-size, 8px);\n margin-inline-start: var(--ds-cross-axis-shift-margin-start, 0px);\n}\n@position-try --ds-arrow-block-end-span-inline-start {\n position-area: block-end span-inline-start;\n margin: 0;\n margin-block-start: var(--ds-arrow-size, 8px);\n margin-inline-end: var(--ds-cross-axis-shift-margin-end, 0px);\n}\n@position-try --ds-arrow-block-end-span-inline-end {\n position-area: block-end span-inline-end;\n margin: 0;\n margin-block-start: var(--ds-arrow-size, 8px);\n margin-inline-start: var(--ds-cross-axis-shift-margin-start, 0px);\n}\n\n/* Inline edge + block span (align: start uses span-block-end; align: end uses span-block-start) */\n@position-try --ds-arrow-inline-start-span-block-start {\n position-area: inline-start span-block-start;\n margin: 0;\n margin-inline-end: var(--ds-arrow-size, 8px);\n margin-block-end: var(--ds-cross-axis-shift-margin-block-end, 0px);\n}\n@position-try --ds-arrow-inline-start-span-block-end {\n position-area: inline-start span-block-end;\n margin: 0;\n margin-inline-end: var(--ds-arrow-size, 8px);\n margin-block-start: var(--ds-cross-axis-shift-margin-block-start, 0px);\n}\n@position-try --ds-arrow-inline-end-span-block-start {\n position-area: inline-end span-block-start;\n margin: 0;\n margin-inline-start: var(--ds-arrow-size, 8px);\n margin-block-end: var(--ds-cross-axis-shift-margin-block-end, 0px);\n}\n@position-try --ds-arrow-inline-end-span-block-end {\n position-area: inline-end span-block-end;\n margin: 0;\n margin-inline-start: var(--ds-arrow-size, 8px);\n margin-block-start: var(--ds-cross-axis-shift-margin-block-start, 0px);\n}\n";
31
-
32
- // ── Placement utilities ──
33
-
34
- /**
35
- * Converts a `position-area` value to a CSS rule name by replacing spaces with hyphens
36
- * and prepending `--ds-arrow-`.
37
- *
38
- * @example positionAreaToRuleName('block-end span-inline-start') → '--ds-arrow-block-end-span-inline-start'
39
- */
40
- function positionAreaToRuleName(_ref) {
41
- var positionArea = _ref.positionArea;
42
- return "--ds-arrow-".concat(positionArea.replace(/ /g, '-'));
43
- }
44
-
45
- /**
46
- * Returns `position-try-fallbacks` using named `@position-try` rules
47
- * that change both `position-area` and `margin` when flipping.
48
- *
49
- * This is required for the arrow technique because built-in keywords
50
- * (`flip-block`, `flip-inline`) only flip `position-area` - they do
51
- * not update the margin direction needed to reveal the correct arrow.
52
- */
53
- function getTryFallbacks(_ref2) {
54
- var placement = _ref2.placement;
55
- var _getPlacement = (0, _resolvePlacement.getPlacement)({
56
- placement: placement
57
- }),
58
- axis = _getPlacement.axis,
59
- edge = _getPlacement.edge,
60
- align = _getPlacement.align;
61
- if (align === 'center') {
62
- // Single-axis: only flip the edge
63
- var _flippedEdge = edge === 'start' ? 'end' : 'start';
64
- return positionAreaToRuleName({
65
- positionArea: (0, _useAnchorPosition.placementToPositionArea)({
66
- placement: {
67
- axis: axis,
68
- edge: _flippedEdge
69
- }
70
- })
71
- });
72
- }
73
-
74
- // Compound placement: try flipping edge, alignment, and both
75
- var flippedEdge = edge === 'start' ? 'end' : 'start';
76
- var flippedAlign = align === 'start' ? 'end' : 'start';
77
- return [positionAreaToRuleName({
78
- positionArea: (0, _useAnchorPosition.placementToPositionArea)({
79
- placement: {
80
- axis: axis,
81
- edge: flippedEdge,
82
- align: align
83
- }
84
- })
85
- }), positionAreaToRuleName({
86
- positionArea: (0, _useAnchorPosition.placementToPositionArea)({
87
- placement: {
88
- axis: axis,
89
- edge: edge,
90
- align: flippedAlign
91
- }
92
- })
93
- }), positionAreaToRuleName({
94
- positionArea: (0, _useAnchorPosition.placementToPositionArea)({
95
- placement: {
96
- axis: axis,
97
- edge: flippedEdge,
98
- align: flippedAlign
99
- }
100
- })
101
- })].join(', ');
102
- }
103
-
104
- /**
105
- * Creates an arrow preset for popover content.
106
- *
107
- * The returned object is passed to `PopoverContent`'s `arrow` prop.
108
- * It carries the CSS string and fallback logic so that consumers who
109
- * do not use arrows pay no bundle cost.
110
- *
111
- * The arrows inherit their background from the popover element.
112
- * When `arrow` is active, `PopoverContent` does not reset `background`
113
- * to `transparent`, allowing the UA default (`canvas`) or a consumer-set
114
- * background to show through.
115
- *
116
- * @example
117
- * ```tsx
118
- * import { arrow } from '@atlaskit/top-layer/arrow';
119
- *
120
- * const myArrow = arrow();
121
- *
122
- * <Popup.Content arrow={myArrow} />
123
- * ```
124
- */
125
- var arrow = exports.arrow = (0, _once.default)(function () {
126
- return {
127
- name: 'arrow',
128
- css: ARROW_CSS,
129
- getTryFallbacks: getTryFallbacks
130
- };
131
- });
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
@@ -1,269 +0,0 @@
1
- import once from '@atlaskit/ds-lib/once';
2
- import { getPlacement } from '../internal/resolve-placement';
3
- import { placementToPositionArea } from '../internal/use-anchor-position';
4
- /**
5
- * CSS for popover arrows using the `clip-path: inset() margin-box` technique.
6
- *
7
- * How it works:
8
- * 1. Four arrow shapes exist simultaneously as `::before` (top/bottom) and
9
- * `::after` (left/right) hexagonal pseudo-elements.
10
- * 2. `clip-path: inset(0) margin-box` clips the popover to its margin-box.
11
- * 3. Margin on the anchor-facing side pushes the popover away, creating space
12
- * where one arrow "escapes" the clip boundary and becomes visible.
13
- * 4. `@position-try` rules change both `position-area` and `margin` when
14
- * flipping, ensuring the correct arrow is always shown.
15
- *
16
- * Constraints:
17
- * - `box-shadow` must be `none` (interferes with `clip-path: inset() margin-box`)
18
- * - `::before` and `::after` are consumed - consumers cannot use them
19
- * - Arrow pseudo-elements use `background: inherit` from the popover element
20
- *
21
- * @see https://goulet.dev/posts/tooltip-with-popover-and-anchor-positioning/
22
- */
23
- const ARROW_CSS = `
24
- [data-ds-popover-arrow] {
25
- clip-path: inset(var(--ds-arrow-offset, 0px)) margin-box;
26
- box-shadow: none;
27
- }
28
-
29
- /* Top and Bottom arrows (vertical hexagon) */
30
- [data-ds-popover-arrow]::before {
31
- content: "";
32
- position: absolute;
33
- z-index: -1;
34
- background: inherit;
35
- left: 50%;
36
- transform: translateX(-50%);
37
- width: calc(var(--ds-arrow-size, 8px) * 2);
38
- height: calc(100% + var(--ds-arrow-size, 8px) * 2);
39
- top: calc(var(--ds-arrow-size, 8px) * -1);
40
- clip-path: polygon(
41
- 0 var(--ds-arrow-size, 8px),
42
- 50% 0,
43
- 100% var(--ds-arrow-size, 8px),
44
- 100% calc(100% - var(--ds-arrow-size, 8px)),
45
- 50% 100%,
46
- 0 calc(100% - var(--ds-arrow-size, 8px))
47
- );
48
- }
49
-
50
- /* Left and Right arrows (horizontal hexagon) */
51
- [data-ds-popover-arrow]::after {
52
- content: "";
53
- position: absolute;
54
- z-index: -1;
55
- background: inherit;
56
- top: 50%;
57
- transform: translateY(-50%);
58
- height: calc(var(--ds-arrow-size, 8px) * 2);
59
- width: calc(100% + var(--ds-arrow-size, 8px) * 2);
60
- left: calc(var(--ds-arrow-size, 8px) * -1);
61
- clip-path: polygon(
62
- var(--ds-arrow-size, 8px) 0,
63
- calc(100% - var(--ds-arrow-size, 8px)) 0,
64
- 100% 50%,
65
- calc(100% - var(--ds-arrow-size, 8px)) 100%,
66
- var(--ds-arrow-size, 8px) 100%,
67
- 0 50%
68
- );
69
- }
70
-
71
- /* ── @position-try rules ──
72
- * One rule per possible position-area value.
73
- * Each sets the position-area and the correct margin direction
74
- * so the arrow on the anchor-facing side is revealed.
75
- *
76
- * Margin direction per edge:
77
- * block-start (above anchor) → margin-block-end (bottom, facing anchor)
78
- * block-end (below anchor) → margin-block-start (top, facing anchor)
79
- * inline-start (left of anchor) → margin-inline-end (right, facing anchor)
80
- * inline-end (right of anchor) → margin-inline-start (left, facing anchor)
81
- */
82
-
83
- /* Each rule sets two margins: the anchor-facing margin for the gap
84
- (via --ds-arrow-size) and one cross-axis margin for the shift
85
- (via one of --ds-cross-axis-shift-margin-start, --ds-cross-axis-shift-margin-end,
86
- --ds-cross-axis-shift-margin-block-start, or --ds-cross-axis-shift-margin-block-end). The
87
- side matches the popover's anchored cross-axis edge per align. Only
88
- one of the four properties is non-zero at a time; useAnchorPosition
89
- picks it. See notes/architecture/positioning.md for details. */
90
- /* Single-axis centered (align: center) */
91
- @position-try --ds-arrow-block-start {
92
- position-area: block-start;
93
- margin: 0;
94
- margin-block-end: var(--ds-arrow-size, 8px);
95
- margin-inline-start: var(--ds-cross-axis-shift-margin-start, 0px);
96
- }
97
- @position-try --ds-arrow-block-end {
98
- position-area: block-end;
99
- margin: 0;
100
- margin-block-start: var(--ds-arrow-size, 8px);
101
- margin-inline-start: var(--ds-cross-axis-shift-margin-start, 0px);
102
- }
103
- @position-try --ds-arrow-inline-start {
104
- position-area: inline-start;
105
- margin: 0;
106
- margin-inline-end: var(--ds-arrow-size, 8px);
107
- margin-block-start: var(--ds-cross-axis-shift-margin-block-start, 0px);
108
- }
109
- @position-try --ds-arrow-inline-end {
110
- position-area: inline-end;
111
- margin: 0;
112
- margin-inline-start: var(--ds-arrow-size, 8px);
113
- margin-block-start: var(--ds-cross-axis-shift-margin-block-start, 0px);
114
- }
115
-
116
- /* Block edge + inline span (align: start uses span-inline-end; align: end uses span-inline-start) */
117
- @position-try --ds-arrow-block-start-span-inline-start {
118
- position-area: block-start span-inline-start;
119
- margin: 0;
120
- margin-block-end: var(--ds-arrow-size, 8px);
121
- margin-inline-end: var(--ds-cross-axis-shift-margin-end, 0px);
122
- }
123
- @position-try --ds-arrow-block-start-span-inline-end {
124
- position-area: block-start span-inline-end;
125
- margin: 0;
126
- margin-block-end: var(--ds-arrow-size, 8px);
127
- margin-inline-start: var(--ds-cross-axis-shift-margin-start, 0px);
128
- }
129
- @position-try --ds-arrow-block-end-span-inline-start {
130
- position-area: block-end span-inline-start;
131
- margin: 0;
132
- margin-block-start: var(--ds-arrow-size, 8px);
133
- margin-inline-end: var(--ds-cross-axis-shift-margin-end, 0px);
134
- }
135
- @position-try --ds-arrow-block-end-span-inline-end {
136
- position-area: block-end span-inline-end;
137
- margin: 0;
138
- margin-block-start: var(--ds-arrow-size, 8px);
139
- margin-inline-start: var(--ds-cross-axis-shift-margin-start, 0px);
140
- }
141
-
142
- /* Inline edge + block span (align: start uses span-block-end; align: end uses span-block-start) */
143
- @position-try --ds-arrow-inline-start-span-block-start {
144
- position-area: inline-start span-block-start;
145
- margin: 0;
146
- margin-inline-end: var(--ds-arrow-size, 8px);
147
- margin-block-end: var(--ds-cross-axis-shift-margin-block-end, 0px);
148
- }
149
- @position-try --ds-arrow-inline-start-span-block-end {
150
- position-area: inline-start span-block-end;
151
- margin: 0;
152
- margin-inline-end: var(--ds-arrow-size, 8px);
153
- margin-block-start: var(--ds-cross-axis-shift-margin-block-start, 0px);
154
- }
155
- @position-try --ds-arrow-inline-end-span-block-start {
156
- position-area: inline-end span-block-start;
157
- margin: 0;
158
- margin-inline-start: var(--ds-arrow-size, 8px);
159
- margin-block-end: var(--ds-cross-axis-shift-margin-block-end, 0px);
160
- }
161
- @position-try --ds-arrow-inline-end-span-block-end {
162
- position-area: inline-end span-block-end;
163
- margin: 0;
164
- margin-inline-start: var(--ds-arrow-size, 8px);
165
- margin-block-start: var(--ds-cross-axis-shift-margin-block-start, 0px);
166
- }
167
- `;
168
-
169
- // ── Placement utilities ──
170
-
171
- /**
172
- * Converts a `position-area` value to a CSS rule name by replacing spaces with hyphens
173
- * and prepending `--ds-arrow-`.
174
- *
175
- * @example positionAreaToRuleName('block-end span-inline-start') → '--ds-arrow-block-end-span-inline-start'
176
- */
177
- function positionAreaToRuleName({
178
- positionArea
179
- }) {
180
- return `--ds-arrow-${positionArea.replace(/ /g, '-')}`;
181
- }
182
-
183
- /**
184
- * Returns `position-try-fallbacks` using named `@position-try` rules
185
- * that change both `position-area` and `margin` when flipping.
186
- *
187
- * This is required for the arrow technique because built-in keywords
188
- * (`flip-block`, `flip-inline`) only flip `position-area` - they do
189
- * not update the margin direction needed to reveal the correct arrow.
190
- */
191
- function getTryFallbacks({
192
- placement
193
- }) {
194
- const {
195
- axis,
196
- edge,
197
- align
198
- } = getPlacement({
199
- placement
200
- });
201
- if (align === 'center') {
202
- // Single-axis: only flip the edge
203
- const flippedEdge = edge === 'start' ? 'end' : 'start';
204
- return positionAreaToRuleName({
205
- positionArea: placementToPositionArea({
206
- placement: {
207
- axis,
208
- edge: flippedEdge
209
- }
210
- })
211
- });
212
- }
213
-
214
- // Compound placement: try flipping edge, alignment, and both
215
- const flippedEdge = edge === 'start' ? 'end' : 'start';
216
- const flippedAlign = align === 'start' ? 'end' : 'start';
217
- return [positionAreaToRuleName({
218
- positionArea: placementToPositionArea({
219
- placement: {
220
- axis,
221
- edge: flippedEdge,
222
- align
223
- }
224
- })
225
- }), positionAreaToRuleName({
226
- positionArea: placementToPositionArea({
227
- placement: {
228
- axis,
229
- edge,
230
- align: flippedAlign
231
- }
232
- })
233
- }), positionAreaToRuleName({
234
- positionArea: placementToPositionArea({
235
- placement: {
236
- axis,
237
- edge: flippedEdge,
238
- align: flippedAlign
239
- }
240
- })
241
- })].join(', ');
242
- }
243
-
244
- /**
245
- * Creates an arrow preset for popover content.
246
- *
247
- * The returned object is passed to `PopoverContent`'s `arrow` prop.
248
- * It carries the CSS string and fallback logic so that consumers who
249
- * do not use arrows pay no bundle cost.
250
- *
251
- * The arrows inherit their background from the popover element.
252
- * When `arrow` is active, `PopoverContent` does not reset `background`
253
- * to `transparent`, allowing the UA default (`canvas`) or a consumer-set
254
- * background to show through.
255
- *
256
- * @example
257
- * ```tsx
258
- * import { arrow } from '@atlaskit/top-layer/arrow';
259
- *
260
- * const myArrow = arrow();
261
- *
262
- * <Popup.Content arrow={myArrow} />
263
- * ```
264
- */
265
- export const arrow = once(() => ({
266
- name: 'arrow',
267
- css: ARROW_CSS,
268
- getTryFallbacks
269
- }));
@@ -1 +0,0 @@
1
- export {};