@atlaskit/top-layer 0.12.0 → 0.12.1

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 (79) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/entry-points/use-arrow-navigation.js +3 -2
  3. package/dist/cjs/internal/placement-to-position-area.js +43 -0
  4. package/dist/cjs/internal/placement-to-try-fallbacks.js +82 -0
  5. package/dist/cjs/internal/use-anchor-position.js +18 -131
  6. package/dist/cjs/popup/popup-content.js +2 -2
  7. package/dist/cjs/popup/popup-context.js +2 -38
  8. package/dist/cjs/popup/popup-provider.js +15 -0
  9. package/dist/cjs/popup/popup-trigger-function.js +2 -2
  10. package/dist/cjs/popup/popup-trigger.js +2 -2
  11. package/dist/cjs/popup/popup.js +2 -2
  12. package/dist/cjs/popup/use-maybe-popup-context.js +17 -0
  13. package/dist/cjs/popup/use-popup-context.js +20 -0
  14. package/dist/cjs/use-arrow-navigation/index.js +3 -2
  15. package/dist/cjs/use-arrow-navigation/is-at-current-menu-level.js +87 -0
  16. package/dist/cjs/use-arrow-navigation/use-arrow-navigation.js +0 -82
  17. package/dist/es2019/entry-points/use-arrow-navigation.js +2 -1
  18. package/dist/es2019/internal/placement-to-position-area.js +40 -0
  19. package/dist/es2019/internal/placement-to-try-fallbacks.js +77 -0
  20. package/dist/es2019/internal/use-anchor-position.js +2 -116
  21. package/dist/es2019/popup/popup-content.js +2 -1
  22. package/dist/es2019/popup/popup-context.js +2 -36
  23. package/dist/es2019/popup/popup-provider.js +10 -0
  24. package/dist/es2019/popup/popup-trigger-function.js +1 -1
  25. package/dist/es2019/popup/popup-trigger.js +2 -1
  26. package/dist/es2019/popup/popup.js +1 -1
  27. package/dist/es2019/popup/use-maybe-popup-context.js +12 -0
  28. package/dist/es2019/popup/use-popup-context.js +15 -0
  29. package/dist/es2019/use-arrow-navigation/index.js +2 -1
  30. package/dist/es2019/use-arrow-navigation/is-at-current-menu-level.js +81 -0
  31. package/dist/es2019/use-arrow-navigation/use-arrow-navigation.js +0 -81
  32. package/dist/esm/entry-points/use-arrow-navigation.js +2 -1
  33. package/dist/esm/internal/placement-to-position-area.js +38 -0
  34. package/dist/esm/internal/placement-to-try-fallbacks.js +76 -0
  35. package/dist/esm/internal/use-anchor-position.js +16 -127
  36. package/dist/esm/popup/popup-content.js +2 -1
  37. package/dist/esm/popup/popup-context.js +2 -36
  38. package/dist/esm/popup/popup-provider.js +10 -0
  39. package/dist/esm/popup/popup-trigger-function.js +1 -1
  40. package/dist/esm/popup/popup-trigger.js +2 -1
  41. package/dist/esm/popup/popup.js +1 -1
  42. package/dist/esm/popup/use-maybe-popup-context.js +12 -0
  43. package/dist/esm/popup/use-popup-context.js +15 -0
  44. package/dist/esm/use-arrow-navigation/index.js +2 -1
  45. package/dist/esm/use-arrow-navigation/is-at-current-menu-level.js +81 -0
  46. package/dist/esm/use-arrow-navigation/use-arrow-navigation.js +0 -81
  47. package/dist/types/entry-points/use-arrow-navigation.d.ts +2 -1
  48. package/dist/types/internal/placement-to-position-area.d.ts +21 -0
  49. package/dist/types/internal/placement-to-try-fallbacks.d.ts +36 -0
  50. package/dist/types/internal/use-anchor-position.d.ts +0 -55
  51. package/dist/types/popup/popup-context.d.ts +1 -21
  52. package/dist/types/popup/popup-provider.d.ts +10 -0
  53. package/dist/types/popup/use-maybe-popup-context.d.ts +8 -0
  54. package/dist/types/popup/use-popup-context.d.ts +7 -0
  55. package/dist/types/use-arrow-navigation/index.d.ts +2 -1
  56. package/dist/types/use-arrow-navigation/is-at-current-menu-level.d.ts +48 -0
  57. package/dist/types/use-arrow-navigation/use-arrow-navigation.d.ts +0 -48
  58. package/dist/types-ts4.5/entry-points/use-arrow-navigation.d.ts +2 -1
  59. package/dist/types-ts4.5/internal/placement-to-position-area.d.ts +21 -0
  60. package/dist/types-ts4.5/internal/placement-to-try-fallbacks.d.ts +36 -0
  61. package/dist/types-ts4.5/internal/use-anchor-position.d.ts +0 -55
  62. package/dist/types-ts4.5/popup/popup-context.d.ts +1 -21
  63. package/dist/types-ts4.5/popup/popup-provider.d.ts +10 -0
  64. package/dist/types-ts4.5/popup/use-maybe-popup-context.d.ts +8 -0
  65. package/dist/types-ts4.5/popup/use-popup-context.d.ts +7 -0
  66. package/dist/types-ts4.5/use-arrow-navigation/index.d.ts +2 -1
  67. package/dist/types-ts4.5/use-arrow-navigation/is-at-current-menu-level.d.ts +48 -0
  68. package/dist/types-ts4.5/use-arrow-navigation/use-arrow-navigation.d.ts +0 -48
  69. package/package.json +2 -2
  70. package/dist/cjs/arrow/index.js +0 -131
  71. package/dist/cjs/arrow/types.js +0 -5
  72. package/dist/es2019/arrow/index.js +0 -269
  73. package/dist/es2019/arrow/types.js +0 -1
  74. package/dist/esm/arrow/index.js +0 -124
  75. package/dist/esm/arrow/types.js +0 -1
  76. package/dist/types/arrow/index.d.ts +0 -24
  77. package/dist/types/arrow/types.d.ts +0 -29
  78. package/dist/types-ts4.5/arrow/index.d.ts +0 -24
  79. package/dist/types-ts4.5/arrow/types.d.ts +0 -29
@@ -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 {};
@@ -1,124 +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
- 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";
24
-
25
- // ── Placement utilities ──
26
-
27
- /**
28
- * Converts a `position-area` value to a CSS rule name by replacing spaces with hyphens
29
- * and prepending `--ds-arrow-`.
30
- *
31
- * @example positionAreaToRuleName('block-end span-inline-start') → '--ds-arrow-block-end-span-inline-start'
32
- */
33
- function positionAreaToRuleName(_ref) {
34
- var positionArea = _ref.positionArea;
35
- return "--ds-arrow-".concat(positionArea.replace(/ /g, '-'));
36
- }
37
-
38
- /**
39
- * Returns `position-try-fallbacks` using named `@position-try` rules
40
- * that change both `position-area` and `margin` when flipping.
41
- *
42
- * This is required for the arrow technique because built-in keywords
43
- * (`flip-block`, `flip-inline`) only flip `position-area` - they do
44
- * not update the margin direction needed to reveal the correct arrow.
45
- */
46
- function getTryFallbacks(_ref2) {
47
- var placement = _ref2.placement;
48
- var _getPlacement = getPlacement({
49
- placement: placement
50
- }),
51
- axis = _getPlacement.axis,
52
- edge = _getPlacement.edge,
53
- align = _getPlacement.align;
54
- if (align === 'center') {
55
- // Single-axis: only flip the edge
56
- var _flippedEdge = edge === 'start' ? 'end' : 'start';
57
- return positionAreaToRuleName({
58
- positionArea: placementToPositionArea({
59
- placement: {
60
- axis: axis,
61
- edge: _flippedEdge
62
- }
63
- })
64
- });
65
- }
66
-
67
- // Compound placement: try flipping edge, alignment, and both
68
- var flippedEdge = edge === 'start' ? 'end' : 'start';
69
- var flippedAlign = align === 'start' ? 'end' : 'start';
70
- return [positionAreaToRuleName({
71
- positionArea: placementToPositionArea({
72
- placement: {
73
- axis: axis,
74
- edge: flippedEdge,
75
- align: align
76
- }
77
- })
78
- }), positionAreaToRuleName({
79
- positionArea: placementToPositionArea({
80
- placement: {
81
- axis: axis,
82
- edge: edge,
83
- align: flippedAlign
84
- }
85
- })
86
- }), positionAreaToRuleName({
87
- positionArea: placementToPositionArea({
88
- placement: {
89
- axis: axis,
90
- edge: flippedEdge,
91
- align: flippedAlign
92
- }
93
- })
94
- })].join(', ');
95
- }
96
-
97
- /**
98
- * Creates an arrow preset for popover content.
99
- *
100
- * The returned object is passed to `PopoverContent`'s `arrow` prop.
101
- * It carries the CSS string and fallback logic so that consumers who
102
- * do not use arrows pay no bundle cost.
103
- *
104
- * The arrows inherit their background from the popover element.
105
- * When `arrow` is active, `PopoverContent` does not reset `background`
106
- * to `transparent`, allowing the UA default (`canvas`) or a consumer-set
107
- * background to show through.
108
- *
109
- * @example
110
- * ```tsx
111
- * import { arrow } from '@atlaskit/top-layer/arrow';
112
- *
113
- * const myArrow = arrow();
114
- *
115
- * <Popup.Content arrow={myArrow} />
116
- * ```
117
- */
118
- export var arrow = once(function () {
119
- return {
120
- name: 'arrow',
121
- css: ARROW_CSS,
122
- getTryFallbacks: getTryFallbacks
123
- };
124
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,24 +0,0 @@
1
- import { type TArrowPreset } from './types';
2
- /**
3
- * Creates an arrow preset for popover content.
4
- *
5
- * The returned object is passed to `PopoverContent`'s `arrow` prop.
6
- * It carries the CSS string and fallback logic so that consumers who
7
- * do not use arrows pay no bundle cost.
8
- *
9
- * The arrows inherit their background from the popover element.
10
- * When `arrow` is active, `PopoverContent` does not reset `background`
11
- * to `transparent`, allowing the UA default (`canvas`) or a consumer-set
12
- * background to show through.
13
- *
14
- * @example
15
- * ```tsx
16
- * import { arrow } from '@atlaskit/top-layer/arrow';
17
- *
18
- * const myArrow = arrow();
19
- *
20
- * <Popup.Content arrow={myArrow} />
21
- * ```
22
- */
23
- export declare const arrow: () => TArrowPreset;
24
- export type { TArrowPreset } from './types';
@@ -1,29 +0,0 @@
1
- import type { TPlacementOptions } from '../popup/types';
2
- /**
3
- * A self-contained arrow preset for PopoverContent.
4
- *
5
- * Contains the CSS rules (injected once into `<head>`), a data-attribute name
6
- * for CSS targeting, and a function to compute `position-try-fallbacks` values
7
- * that change both `position-area` and `margin` when the popover flips.
8
- *
9
- * Imported from `@atlaskit/top-layer/arrow` so that consumers who do not use
10
- * arrows pay no bundle cost for the CSS string or fallback logic.
11
- */
12
- export type TArrowPreset = {
13
- /**
14
- * CSS to inject once into `document.head`, scoped to `[data-ds-popover-{name}]`.
15
- */
16
- css: string;
17
- /**
18
- * Data attribute suffix for CSS targeting (e.g. `'arrow'`).
19
- */
20
- name: string;
21
- /**
22
- * Returns the `position-try-fallbacks` value for a given placement.
23
- * Uses named `@position-try` rules that update both `position-area`
24
- * and `margin` so the correct arrow is revealed after a flip.
25
- */
26
- getTryFallbacks: (args: {
27
- placement: TPlacementOptions;
28
- }) => string;
29
- };
@@ -1,24 +0,0 @@
1
- import { type TArrowPreset } from './types';
2
- /**
3
- * Creates an arrow preset for popover content.
4
- *
5
- * The returned object is passed to `PopoverContent`'s `arrow` prop.
6
- * It carries the CSS string and fallback logic so that consumers who
7
- * do not use arrows pay no bundle cost.
8
- *
9
- * The arrows inherit their background from the popover element.
10
- * When `arrow` is active, `PopoverContent` does not reset `background`
11
- * to `transparent`, allowing the UA default (`canvas`) or a consumer-set
12
- * background to show through.
13
- *
14
- * @example
15
- * ```tsx
16
- * import { arrow } from '@atlaskit/top-layer/arrow';
17
- *
18
- * const myArrow = arrow();
19
- *
20
- * <Popup.Content arrow={myArrow} />
21
- * ```
22
- */
23
- export declare const arrow: () => TArrowPreset;
24
- export type { TArrowPreset } from './types';
@@ -1,29 +0,0 @@
1
- import type { TPlacementOptions } from '../popup/types';
2
- /**
3
- * A self-contained arrow preset for PopoverContent.
4
- *
5
- * Contains the CSS rules (injected once into `<head>`), a data-attribute name
6
- * for CSS targeting, and a function to compute `position-try-fallbacks` values
7
- * that change both `position-area` and `margin` when the popover flips.
8
- *
9
- * Imported from `@atlaskit/top-layer/arrow` so that consumers who do not use
10
- * arrows pay no bundle cost for the CSS string or fallback logic.
11
- */
12
- export type TArrowPreset = {
13
- /**
14
- * CSS to inject once into `document.head`, scoped to `[data-ds-popover-{name}]`.
15
- */
16
- css: string;
17
- /**
18
- * Data attribute suffix for CSS targeting (e.g. `'arrow'`).
19
- */
20
- name: string;
21
- /**
22
- * Returns the `position-try-fallbacks` value for a given placement.
23
- * Uses named `@position-try` rules that update both `position-area`
24
- * and `margin` so the correct arrow is revealed after a flip.
25
- */
26
- getTryFallbacks: (args: {
27
- placement: TPlacementOptions;
28
- }) => string;
29
- };