@atlaskit/top-layer 0.7.1 → 0.9.0

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 (59) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/cjs/animations/presets.js +4 -0
  3. package/dist/cjs/dialog/dialog-content.js +12 -0
  4. package/dist/cjs/focus/focus.js +2 -0
  5. package/dist/cjs/internal/ensure-preset-styles.js +1 -1
  6. package/dist/cjs/internal/use-anchor-position.js +6 -22
  7. package/dist/cjs/internal/use-preset-styles.js +1 -1
  8. package/dist/cjs/placement-map/index.js +2 -1
  9. package/dist/cjs/popover/popover.js +31 -0
  10. package/dist/cjs/popup/popup-content.js +1 -7
  11. package/dist/cjs/popup/popup-context.js +2 -0
  12. package/dist/cjs/use-arrow-navigation/use-arrow-navigation.js +1 -0
  13. package/dist/es2019/animations/presets.js +4 -0
  14. package/dist/es2019/dialog/dialog-content.js +12 -0
  15. package/dist/es2019/focus/focus.js +2 -0
  16. package/dist/es2019/internal/ensure-preset-styles.js +1 -1
  17. package/dist/es2019/internal/use-anchor-position.js +6 -20
  18. package/dist/es2019/internal/use-preset-styles.js +1 -1
  19. package/dist/es2019/placement-map/index.js +1 -0
  20. package/dist/es2019/popover/popover.js +31 -0
  21. package/dist/es2019/popup/popup-content.js +1 -7
  22. package/dist/es2019/popup/popup-context.js +2 -0
  23. package/dist/es2019/use-arrow-navigation/use-arrow-navigation.js +1 -0
  24. package/dist/esm/animations/presets.js +4 -0
  25. package/dist/esm/dialog/dialog-content.js +12 -0
  26. package/dist/esm/focus/focus.js +2 -0
  27. package/dist/esm/internal/ensure-preset-styles.js +1 -1
  28. package/dist/esm/internal/use-anchor-position.js +6 -22
  29. package/dist/esm/internal/use-preset-styles.js +1 -1
  30. package/dist/esm/placement-map/index.js +1 -0
  31. package/dist/esm/popover/popover.js +31 -0
  32. package/dist/esm/popup/popup-content.js +1 -7
  33. package/dist/esm/popup/popup-context.js +2 -0
  34. package/dist/esm/use-arrow-navigation/use-arrow-navigation.js +1 -0
  35. package/dist/types/internal/use-anchor-position.d.ts +1 -11
  36. package/dist/types/internal/use-preset-styles.d.ts +1 -1
  37. package/dist/types/popover/types.d.ts +4 -4
  38. package/dist/types/popup/types.d.ts +1 -28
  39. package/dist/types-ts4.5/internal/use-anchor-position.d.ts +1 -11
  40. package/dist/types-ts4.5/internal/use-preset-styles.d.ts +1 -1
  41. package/dist/types-ts4.5/popover/types.d.ts +4 -4
  42. package/dist/types-ts4.5/popup/types.d.ts +1 -28
  43. package/package.json +3 -1
  44. package/arrow/package.json +0 -17
  45. package/dist/cjs/arrow/index.js +0 -130
  46. package/dist/cjs/arrow/types.js +0 -5
  47. package/dist/cjs/entry-points/arrow.js +0 -12
  48. package/dist/es2019/arrow/index.js +0 -268
  49. package/dist/es2019/arrow/types.js +0 -1
  50. package/dist/es2019/entry-points/arrow.js +0 -1
  51. package/dist/esm/arrow/index.js +0 -123
  52. package/dist/esm/arrow/types.js +0 -1
  53. package/dist/esm/entry-points/arrow.js +0 -1
  54. package/dist/types/arrow/index.d.ts +0 -24
  55. package/dist/types/arrow/types.d.ts +0 -29
  56. package/dist/types/entry-points/arrow.d.ts +0 -2
  57. package/dist/types-ts4.5/arrow/index.d.ts +0 -24
  58. package/dist/types-ts4.5/arrow/types.d.ts +0 -29
  59. package/dist/types-ts4.5/entry-points/arrow.d.ts +0 -2
@@ -1,130 +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 _useAnchorPosition = require("../internal/use-anchor-position");
10
- /**
11
- * CSS for popover arrows using the `clip-path: inset() margin-box` technique.
12
- *
13
- * How it works:
14
- * 1. Four arrow shapes exist simultaneously as `::before` (top/bottom) and
15
- * `::after` (left/right) hexagonal pseudo-elements.
16
- * 2. `clip-path: inset(0) margin-box` clips the popover to its margin-box.
17
- * 3. Margin on the anchor-facing side pushes the popover away, creating space
18
- * where one arrow "escapes" the clip boundary and becomes visible.
19
- * 4. `@position-try` rules change both `position-area` and `margin` when
20
- * flipping, ensuring the correct arrow is always shown.
21
- *
22
- * Constraints:
23
- * - `box-shadow` must be `none` (interferes with `clip-path: inset() margin-box`)
24
- * - `::before` and `::after` are consumed - consumers cannot use them
25
- * - Arrow pseudo-elements use `background: inherit` from the popover element
26
- *
27
- * @see https://goulet.dev/posts/tooltip-with-popover-and-anchor-positioning/
28
- */
29
- 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";
30
-
31
- // ── Placement utilities ──
32
-
33
- /**
34
- * Converts a `position-area` value to a CSS rule name by replacing spaces with hyphens
35
- * and prepending `--ds-arrow-`.
36
- *
37
- * @example positionAreaToRuleName('block-end span-inline-start') → '--ds-arrow-block-end-span-inline-start'
38
- */
39
- function positionAreaToRuleName(_ref) {
40
- var positionArea = _ref.positionArea;
41
- return "--ds-arrow-".concat(positionArea.replace(/ /g, '-'));
42
- }
43
-
44
- /**
45
- * Returns `position-try-fallbacks` using named `@position-try` rules
46
- * that change both `position-area` and `margin` when flipping.
47
- *
48
- * This is required for the arrow technique because built-in keywords
49
- * (`flip-block`, `flip-inline`) only flip `position-area` - they do
50
- * not update the margin direction needed to reveal the correct arrow.
51
- */
52
- function getTryFallbacks(_ref2) {
53
- var placement = _ref2.placement;
54
- var _getPlacement = (0, _useAnchorPosition.getPlacement)({
55
- placement: placement
56
- }),
57
- axis = _getPlacement.axis,
58
- edge = _getPlacement.edge,
59
- align = _getPlacement.align;
60
- if (align === 'center') {
61
- // Single-axis: only flip the edge
62
- var _flippedEdge = edge === 'start' ? 'end' : 'start';
63
- return positionAreaToRuleName({
64
- positionArea: (0, _useAnchorPosition.placementToPositionArea)({
65
- placement: {
66
- axis: axis,
67
- edge: _flippedEdge
68
- }
69
- })
70
- });
71
- }
72
-
73
- // Compound placement: try flipping edge, alignment, and both
74
- var flippedEdge = edge === 'start' ? 'end' : 'start';
75
- var flippedAlign = align === 'start' ? 'end' : 'start';
76
- return [positionAreaToRuleName({
77
- positionArea: (0, _useAnchorPosition.placementToPositionArea)({
78
- placement: {
79
- axis: axis,
80
- edge: flippedEdge,
81
- align: align
82
- }
83
- })
84
- }), positionAreaToRuleName({
85
- positionArea: (0, _useAnchorPosition.placementToPositionArea)({
86
- placement: {
87
- axis: axis,
88
- edge: edge,
89
- align: flippedAlign
90
- }
91
- })
92
- }), positionAreaToRuleName({
93
- positionArea: (0, _useAnchorPosition.placementToPositionArea)({
94
- placement: {
95
- axis: axis,
96
- edge: flippedEdge,
97
- align: flippedAlign
98
- }
99
- })
100
- })].join(', ');
101
- }
102
-
103
- /**
104
- * Creates an arrow preset for popover content.
105
- *
106
- * The returned object is passed to `PopoverContent`'s `arrow` prop.
107
- * It carries the CSS string and fallback logic so that consumers who
108
- * don't use arrows pay no bundle cost.
109
- *
110
- * The arrows inherit their background from the popover element.
111
- * When `arrow` is active, `PopoverContent` does not reset `background`
112
- * to `transparent`, allowing the UA default (`canvas`) or a consumer-set
113
- * background to show through.
114
- *
115
- * @example
116
- * ```tsx
117
- * import { arrow } from '@atlaskit/top-layer/arrow';
118
- *
119
- * const myArrow = arrow();
120
- *
121
- * <Popup.Content arrow={myArrow} />
122
- * ```
123
- */
124
- var arrow = exports.arrow = (0, _once.default)(function () {
125
- return {
126
- name: 'arrow',
127
- css: ARROW_CSS,
128
- getTryFallbacks: getTryFallbacks
129
- };
130
- });
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "arrow", {
7
- enumerable: true,
8
- get: function get() {
9
- return _arrow.arrow;
10
- }
11
- });
12
- var _arrow = require("../arrow");
@@ -1,268 +0,0 @@
1
- import once from '@atlaskit/ds-lib/once';
2
- import { getPlacement, placementToPositionArea } from '../internal/use-anchor-position';
3
- /**
4
- * CSS for popover arrows using the `clip-path: inset() margin-box` technique.
5
- *
6
- * How it works:
7
- * 1. Four arrow shapes exist simultaneously as `::before` (top/bottom) and
8
- * `::after` (left/right) hexagonal pseudo-elements.
9
- * 2. `clip-path: inset(0) margin-box` clips the popover to its margin-box.
10
- * 3. Margin on the anchor-facing side pushes the popover away, creating space
11
- * where one arrow "escapes" the clip boundary and becomes visible.
12
- * 4. `@position-try` rules change both `position-area` and `margin` when
13
- * flipping, ensuring the correct arrow is always shown.
14
- *
15
- * Constraints:
16
- * - `box-shadow` must be `none` (interferes with `clip-path: inset() margin-box`)
17
- * - `::before` and `::after` are consumed - consumers cannot use them
18
- * - Arrow pseudo-elements use `background: inherit` from the popover element
19
- *
20
- * @see https://goulet.dev/posts/tooltip-with-popover-and-anchor-positioning/
21
- */
22
- const ARROW_CSS = `
23
- [data-ds-popover-arrow] {
24
- clip-path: inset(var(--ds-arrow-offset, 0px)) margin-box;
25
- box-shadow: none;
26
- }
27
-
28
- /* Top and Bottom arrows (vertical hexagon) */
29
- [data-ds-popover-arrow]::before {
30
- content: "";
31
- position: absolute;
32
- z-index: -1;
33
- background: inherit;
34
- left: 50%;
35
- transform: translateX(-50%);
36
- width: calc(var(--ds-arrow-size, 8px) * 2);
37
- height: calc(100% + var(--ds-arrow-size, 8px) * 2);
38
- top: calc(var(--ds-arrow-size, 8px) * -1);
39
- clip-path: polygon(
40
- 0 var(--ds-arrow-size, 8px),
41
- 50% 0,
42
- 100% var(--ds-arrow-size, 8px),
43
- 100% calc(100% - var(--ds-arrow-size, 8px)),
44
- 50% 100%,
45
- 0 calc(100% - var(--ds-arrow-size, 8px))
46
- );
47
- }
48
-
49
- /* Left and Right arrows (horizontal hexagon) */
50
- [data-ds-popover-arrow]::after {
51
- content: "";
52
- position: absolute;
53
- z-index: -1;
54
- background: inherit;
55
- top: 50%;
56
- transform: translateY(-50%);
57
- height: calc(var(--ds-arrow-size, 8px) * 2);
58
- width: calc(100% + var(--ds-arrow-size, 8px) * 2);
59
- left: calc(var(--ds-arrow-size, 8px) * -1);
60
- clip-path: polygon(
61
- var(--ds-arrow-size, 8px) 0,
62
- calc(100% - var(--ds-arrow-size, 8px)) 0,
63
- 100% 50%,
64
- calc(100% - var(--ds-arrow-size, 8px)) 100%,
65
- var(--ds-arrow-size, 8px) 100%,
66
- 0 50%
67
- );
68
- }
69
-
70
- /* ── @position-try rules ──
71
- * One rule per possible position-area value.
72
- * Each sets the position-area and the correct margin direction
73
- * so the arrow on the anchor-facing side is revealed.
74
- *
75
- * Margin direction per edge:
76
- * block-start (above anchor) → margin-block-end (bottom, facing anchor)
77
- * block-end (below anchor) → margin-block-start (top, facing anchor)
78
- * inline-start (left of anchor) → margin-inline-end (right, facing anchor)
79
- * inline-end (right of anchor) → margin-inline-start (left, facing anchor)
80
- */
81
-
82
- /* Each rule sets two margins: the anchor-facing margin for the gap
83
- (via --ds-arrow-size) and one cross-axis margin for the shift
84
- (via one of --ds-cross-axis-shift-margin-start, --ds-cross-axis-shift-margin-end,
85
- --ds-cross-axis-shift-margin-block-start, or --ds-cross-axis-shift-margin-block-end). The
86
- side matches the popover's anchored cross-axis edge per align. Only
87
- one of the four properties is non-zero at a time; useAnchorPosition
88
- picks it. See notes/architecture/positioning.md for details. */
89
- /* Single-axis centered (align: center) */
90
- @position-try --ds-arrow-block-start {
91
- position-area: block-start;
92
- margin: 0;
93
- margin-block-end: var(--ds-arrow-size, 8px);
94
- margin-inline-start: var(--ds-cross-axis-shift-margin-start, 0px);
95
- }
96
- @position-try --ds-arrow-block-end {
97
- position-area: block-end;
98
- margin: 0;
99
- margin-block-start: var(--ds-arrow-size, 8px);
100
- margin-inline-start: var(--ds-cross-axis-shift-margin-start, 0px);
101
- }
102
- @position-try --ds-arrow-inline-start {
103
- position-area: inline-start;
104
- margin: 0;
105
- margin-inline-end: var(--ds-arrow-size, 8px);
106
- margin-block-start: var(--ds-cross-axis-shift-margin-block-start, 0px);
107
- }
108
- @position-try --ds-arrow-inline-end {
109
- position-area: inline-end;
110
- margin: 0;
111
- margin-inline-start: var(--ds-arrow-size, 8px);
112
- margin-block-start: var(--ds-cross-axis-shift-margin-block-start, 0px);
113
- }
114
-
115
- /* Block edge + inline span (align: start uses span-inline-end; align: end uses span-inline-start) */
116
- @position-try --ds-arrow-block-start-span-inline-start {
117
- position-area: block-start span-inline-start;
118
- margin: 0;
119
- margin-block-end: var(--ds-arrow-size, 8px);
120
- margin-inline-end: var(--ds-cross-axis-shift-margin-end, 0px);
121
- }
122
- @position-try --ds-arrow-block-start-span-inline-end {
123
- position-area: block-start span-inline-end;
124
- margin: 0;
125
- margin-block-end: var(--ds-arrow-size, 8px);
126
- margin-inline-start: var(--ds-cross-axis-shift-margin-start, 0px);
127
- }
128
- @position-try --ds-arrow-block-end-span-inline-start {
129
- position-area: block-end span-inline-start;
130
- margin: 0;
131
- margin-block-start: var(--ds-arrow-size, 8px);
132
- margin-inline-end: var(--ds-cross-axis-shift-margin-end, 0px);
133
- }
134
- @position-try --ds-arrow-block-end-span-inline-end {
135
- position-area: block-end span-inline-end;
136
- margin: 0;
137
- margin-block-start: var(--ds-arrow-size, 8px);
138
- margin-inline-start: var(--ds-cross-axis-shift-margin-start, 0px);
139
- }
140
-
141
- /* Inline edge + block span (align: start uses span-block-end; align: end uses span-block-start) */
142
- @position-try --ds-arrow-inline-start-span-block-start {
143
- position-area: inline-start span-block-start;
144
- margin: 0;
145
- margin-inline-end: var(--ds-arrow-size, 8px);
146
- margin-block-end: var(--ds-cross-axis-shift-margin-block-end, 0px);
147
- }
148
- @position-try --ds-arrow-inline-start-span-block-end {
149
- position-area: inline-start span-block-end;
150
- margin: 0;
151
- margin-inline-end: var(--ds-arrow-size, 8px);
152
- margin-block-start: var(--ds-cross-axis-shift-margin-block-start, 0px);
153
- }
154
- @position-try --ds-arrow-inline-end-span-block-start {
155
- position-area: inline-end span-block-start;
156
- margin: 0;
157
- margin-inline-start: var(--ds-arrow-size, 8px);
158
- margin-block-end: var(--ds-cross-axis-shift-margin-block-end, 0px);
159
- }
160
- @position-try --ds-arrow-inline-end-span-block-end {
161
- position-area: inline-end span-block-end;
162
- margin: 0;
163
- margin-inline-start: var(--ds-arrow-size, 8px);
164
- margin-block-start: var(--ds-cross-axis-shift-margin-block-start, 0px);
165
- }
166
- `;
167
-
168
- // ── Placement utilities ──
169
-
170
- /**
171
- * Converts a `position-area` value to a CSS rule name by replacing spaces with hyphens
172
- * and prepending `--ds-arrow-`.
173
- *
174
- * @example positionAreaToRuleName('block-end span-inline-start') → '--ds-arrow-block-end-span-inline-start'
175
- */
176
- function positionAreaToRuleName({
177
- positionArea
178
- }) {
179
- return `--ds-arrow-${positionArea.replace(/ /g, '-')}`;
180
- }
181
-
182
- /**
183
- * Returns `position-try-fallbacks` using named `@position-try` rules
184
- * that change both `position-area` and `margin` when flipping.
185
- *
186
- * This is required for the arrow technique because built-in keywords
187
- * (`flip-block`, `flip-inline`) only flip `position-area` - they do
188
- * not update the margin direction needed to reveal the correct arrow.
189
- */
190
- function getTryFallbacks({
191
- placement
192
- }) {
193
- const {
194
- axis,
195
- edge,
196
- align
197
- } = getPlacement({
198
- placement
199
- });
200
- if (align === 'center') {
201
- // Single-axis: only flip the edge
202
- const flippedEdge = edge === 'start' ? 'end' : 'start';
203
- return positionAreaToRuleName({
204
- positionArea: placementToPositionArea({
205
- placement: {
206
- axis,
207
- edge: flippedEdge
208
- }
209
- })
210
- });
211
- }
212
-
213
- // Compound placement: try flipping edge, alignment, and both
214
- const flippedEdge = edge === 'start' ? 'end' : 'start';
215
- const flippedAlign = align === 'start' ? 'end' : 'start';
216
- return [positionAreaToRuleName({
217
- positionArea: placementToPositionArea({
218
- placement: {
219
- axis,
220
- edge: flippedEdge,
221
- align
222
- }
223
- })
224
- }), positionAreaToRuleName({
225
- positionArea: placementToPositionArea({
226
- placement: {
227
- axis,
228
- edge,
229
- align: flippedAlign
230
- }
231
- })
232
- }), positionAreaToRuleName({
233
- positionArea: placementToPositionArea({
234
- placement: {
235
- axis,
236
- edge: flippedEdge,
237
- align: flippedAlign
238
- }
239
- })
240
- })].join(', ');
241
- }
242
-
243
- /**
244
- * Creates an arrow preset for popover content.
245
- *
246
- * The returned object is passed to `PopoverContent`'s `arrow` prop.
247
- * It carries the CSS string and fallback logic so that consumers who
248
- * don't use arrows pay no bundle cost.
249
- *
250
- * The arrows inherit their background from the popover element.
251
- * When `arrow` is active, `PopoverContent` does not reset `background`
252
- * to `transparent`, allowing the UA default (`canvas`) or a consumer-set
253
- * background to show through.
254
- *
255
- * @example
256
- * ```tsx
257
- * import { arrow } from '@atlaskit/top-layer/arrow';
258
- *
259
- * const myArrow = arrow();
260
- *
261
- * <Popup.Content arrow={myArrow} />
262
- * ```
263
- */
264
- export const arrow = once(() => ({
265
- name: 'arrow',
266
- css: ARROW_CSS,
267
- getTryFallbacks
268
- }));
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export { arrow } from '../arrow';
@@ -1,123 +0,0 @@
1
- import once from '@atlaskit/ds-lib/once';
2
- import { getPlacement, placementToPositionArea } from '../internal/use-anchor-position';
3
- /**
4
- * CSS for popover arrows using the `clip-path: inset() margin-box` technique.
5
- *
6
- * How it works:
7
- * 1. Four arrow shapes exist simultaneously as `::before` (top/bottom) and
8
- * `::after` (left/right) hexagonal pseudo-elements.
9
- * 2. `clip-path: inset(0) margin-box` clips the popover to its margin-box.
10
- * 3. Margin on the anchor-facing side pushes the popover away, creating space
11
- * where one arrow "escapes" the clip boundary and becomes visible.
12
- * 4. `@position-try` rules change both `position-area` and `margin` when
13
- * flipping, ensuring the correct arrow is always shown.
14
- *
15
- * Constraints:
16
- * - `box-shadow` must be `none` (interferes with `clip-path: inset() margin-box`)
17
- * - `::before` and `::after` are consumed - consumers cannot use them
18
- * - Arrow pseudo-elements use `background: inherit` from the popover element
19
- *
20
- * @see https://goulet.dev/posts/tooltip-with-popover-and-anchor-positioning/
21
- */
22
- 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";
23
-
24
- // ── Placement utilities ──
25
-
26
- /**
27
- * Converts a `position-area` value to a CSS rule name by replacing spaces with hyphens
28
- * and prepending `--ds-arrow-`.
29
- *
30
- * @example positionAreaToRuleName('block-end span-inline-start') → '--ds-arrow-block-end-span-inline-start'
31
- */
32
- function positionAreaToRuleName(_ref) {
33
- var positionArea = _ref.positionArea;
34
- return "--ds-arrow-".concat(positionArea.replace(/ /g, '-'));
35
- }
36
-
37
- /**
38
- * Returns `position-try-fallbacks` using named `@position-try` rules
39
- * that change both `position-area` and `margin` when flipping.
40
- *
41
- * This is required for the arrow technique because built-in keywords
42
- * (`flip-block`, `flip-inline`) only flip `position-area` - they do
43
- * not update the margin direction needed to reveal the correct arrow.
44
- */
45
- function getTryFallbacks(_ref2) {
46
- var placement = _ref2.placement;
47
- var _getPlacement = getPlacement({
48
- placement: placement
49
- }),
50
- axis = _getPlacement.axis,
51
- edge = _getPlacement.edge,
52
- align = _getPlacement.align;
53
- if (align === 'center') {
54
- // Single-axis: only flip the edge
55
- var _flippedEdge = edge === 'start' ? 'end' : 'start';
56
- return positionAreaToRuleName({
57
- positionArea: placementToPositionArea({
58
- placement: {
59
- axis: axis,
60
- edge: _flippedEdge
61
- }
62
- })
63
- });
64
- }
65
-
66
- // Compound placement: try flipping edge, alignment, and both
67
- var flippedEdge = edge === 'start' ? 'end' : 'start';
68
- var flippedAlign = align === 'start' ? 'end' : 'start';
69
- return [positionAreaToRuleName({
70
- positionArea: placementToPositionArea({
71
- placement: {
72
- axis: axis,
73
- edge: flippedEdge,
74
- align: align
75
- }
76
- })
77
- }), positionAreaToRuleName({
78
- positionArea: placementToPositionArea({
79
- placement: {
80
- axis: axis,
81
- edge: edge,
82
- align: flippedAlign
83
- }
84
- })
85
- }), positionAreaToRuleName({
86
- positionArea: placementToPositionArea({
87
- placement: {
88
- axis: axis,
89
- edge: flippedEdge,
90
- align: flippedAlign
91
- }
92
- })
93
- })].join(', ');
94
- }
95
-
96
- /**
97
- * Creates an arrow preset for popover content.
98
- *
99
- * The returned object is passed to `PopoverContent`'s `arrow` prop.
100
- * It carries the CSS string and fallback logic so that consumers who
101
- * don't use arrows pay no bundle cost.
102
- *
103
- * The arrows inherit their background from the popover element.
104
- * When `arrow` is active, `PopoverContent` does not reset `background`
105
- * to `transparent`, allowing the UA default (`canvas`) or a consumer-set
106
- * background to show through.
107
- *
108
- * @example
109
- * ```tsx
110
- * import { arrow } from '@atlaskit/top-layer/arrow';
111
- *
112
- * const myArrow = arrow();
113
- *
114
- * <Popup.Content arrow={myArrow} />
115
- * ```
116
- */
117
- export var arrow = once(function () {
118
- return {
119
- name: 'arrow',
120
- css: ARROW_CSS,
121
- getTryFallbacks: getTryFallbacks
122
- };
123
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export { arrow } from '../arrow';
@@ -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
- * don't 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 don't 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,2 +0,0 @@
1
- export { arrow } from '../arrow';
2
- export type { TArrowPreset } from '../arrow/types';
@@ -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
- * don't 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';