@atlaskit/top-layer 2.0.0 → 3.1.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.
- package/CHANGELOG.md +24 -0
- package/dist/cjs/dialog/dialog-content.js +1 -1
- package/dist/cjs/internal/placement-to-position-area.js +5 -5
- package/dist/cjs/internal/placement-to-try-fallbacks.js +1 -1
- package/dist/cjs/internal/resolve-css-length-to-pixels.js +1 -1
- package/dist/cjs/internal/resolve-placement.js +3 -3
- package/dist/cjs/internal/use-anchor-position.js +2 -2
- package/dist/cjs/popover/popover.js +43 -34
- package/dist/cjs/popover-surface/popover-surface.js +1 -1
- package/dist/es2019/dialog/dialog-content.js +1 -1
- package/dist/es2019/internal/placement-to-position-area.js +2 -2
- package/dist/es2019/internal/placement-to-try-fallbacks.js +2 -2
- package/dist/es2019/internal/resolve-css-length-to-pixels.js +1 -1
- package/dist/es2019/internal/resolve-placement.js +2 -2
- package/dist/es2019/internal/use-anchor-position.js +3 -3
- package/dist/es2019/popover/popover.js +45 -35
- package/dist/es2019/popover-surface/popover-surface.js +1 -1
- package/dist/esm/dialog/dialog-content.js +1 -1
- package/dist/esm/internal/placement-to-position-area.js +5 -5
- package/dist/esm/internal/placement-to-try-fallbacks.js +2 -2
- package/dist/esm/internal/resolve-css-length-to-pixels.js +1 -1
- package/dist/esm/internal/resolve-placement.js +2 -2
- package/dist/esm/internal/use-anchor-position.js +3 -3
- package/dist/esm/popover/popover.js +44 -35
- package/dist/esm/popover-surface/popover-surface.js +1 -1
- package/dist/types/dialog/types.d.ts +1 -1
- package/dist/types/internal/resolve-placement.d.ts +6 -4
- package/dist/types/popover/types.d.ts +2 -24
- package/package.json +5 -5
- package/dist/cjs/popover/animations.js +0 -50
- package/dist/es2019/popover/animations.js +0 -46
- package/dist/esm/popover/animations.js +0 -44
- package/dist/types/popover/animations.d.ts +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @atlaskit/top-layer
|
|
2
2
|
|
|
3
|
+
## 3.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`a50c282feb7d3`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a50c282feb7d3) -
|
|
8
|
+
Widens the `xcss` types accepted by Dialog to include `scrollbarGutter` and `overflow` properties.
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
|
|
14
|
+
## 3.0.0
|
|
15
|
+
|
|
16
|
+
### Major Changes
|
|
17
|
+
|
|
18
|
+
- [`30abd36d3c8d6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/30abd36d3c8d6) -
|
|
19
|
+
Removes the `onOpenChange` prop from Popover. This prop was not being relied on, and created a
|
|
20
|
+
divergence between the Dialog and Popover APIs.
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- [`c0874b1b13309`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c0874b1b13309) -
|
|
25
|
+
Refactor popover motion styles and rename `getPlacement` to `resolvePlacement`.
|
|
26
|
+
|
|
3
27
|
## 2.0.0
|
|
4
28
|
|
|
5
29
|
### Major Changes
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.placementToPositionArea = placementToPositionArea;
|
|
7
|
-
var
|
|
7
|
+
var _resolvePlacement2 = require("./resolve-placement");
|
|
8
8
|
/**
|
|
9
9
|
* Resolves placement options to CSS `position-area` syntax.
|
|
10
10
|
*
|
|
@@ -24,12 +24,12 @@ var _resolvePlacement = require("./resolve-placement");
|
|
|
24
24
|
*/
|
|
25
25
|
function placementToPositionArea(_ref) {
|
|
26
26
|
var placement = _ref.placement;
|
|
27
|
-
var
|
|
27
|
+
var _resolvePlacement = (0, _resolvePlacement2.resolvePlacement)({
|
|
28
28
|
placement: placement
|
|
29
29
|
}),
|
|
30
|
-
axis =
|
|
31
|
-
edge =
|
|
32
|
-
align =
|
|
30
|
+
axis = _resolvePlacement.axis,
|
|
31
|
+
edge = _resolvePlacement.edge,
|
|
32
|
+
align = _resolvePlacement.align;
|
|
33
33
|
var edgeValue = "".concat(axis, "-").concat(edge);
|
|
34
34
|
if (align === 'center') {
|
|
35
35
|
return edgeValue;
|
|
@@ -49,7 +49,7 @@ function placementToTryFallbacks(_ref3) {
|
|
|
49
49
|
* The browser tries them _in order_ and uses the _first_ one that fits.
|
|
50
50
|
*/
|
|
51
51
|
|
|
52
|
-
var resolved = (0, _resolvePlacement.
|
|
52
|
+
var resolved = (0, _resolvePlacement.resolvePlacement)({
|
|
53
53
|
placement: placement
|
|
54
54
|
});
|
|
55
55
|
var axis = resolved.axis,
|
|
@@ -64,7 +64,7 @@ function resolveCssLengthToPixels(_ref3) {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
// Fast path: bare `${n}px` strings come from the consumer normalisation
|
|
67
|
-
// in `
|
|
67
|
+
// in `resolvePlacement`. Avoid a reflow when we can.
|
|
68
68
|
var pxMatch = value.match(/^(-?\d+(?:\.\d+)?)px$/);
|
|
69
69
|
if (pxMatch) {
|
|
70
70
|
return Number(pxMatch[1]);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.resolvePlacement = resolvePlacement;
|
|
7
7
|
var _resolveCssLength = require("./resolve-css-length");
|
|
8
8
|
/**
|
|
9
9
|
* Default gap between trigger and popover. Resolves to a design
|
|
@@ -19,7 +19,7 @@ var DEFAULT_GAP = "var(--ds-space-100, 8px)";
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* Fully-resolved placement (internal). Use `
|
|
22
|
+
* Fully-resolved placement (internal). Use `resolvePlacement` for partial input.
|
|
23
23
|
* `offset.gap` and `offset.crossAxisShift.value` are always CSS
|
|
24
24
|
* length strings.
|
|
25
25
|
*/
|
|
@@ -42,7 +42,7 @@ var DEFAULT_GAP = "var(--ds-space-100, 8px)";
|
|
|
42
42
|
* `offset.gap: token('space.100', '8px')`,
|
|
43
43
|
* `offset.crossAxisShift: { value: '0px', direction: 'forwards' }`.
|
|
44
44
|
*/
|
|
45
|
-
function
|
|
45
|
+
function resolvePlacement(_ref) {
|
|
46
46
|
var _placement$offset, _placement$axis, _placement$edge, _placement$align, _placement$offset$cro, _placement$offset2, _placement$offset$cro2, _placement$offset3;
|
|
47
47
|
var placement = _ref.placement;
|
|
48
48
|
var consumerGap = (_placement$offset = placement.offset) === null || _placement$offset === void 0 ? void 0 : _placement$offset.gap;
|
|
@@ -33,7 +33,7 @@ var _setStyle = require("./set-style");
|
|
|
33
33
|
* is never painted at the wrong location.
|
|
34
34
|
*/
|
|
35
35
|
|
|
36
|
-
// `
|
|
36
|
+
// `resolvePlacement` is intentionally NOT re-exported here - import it directly
|
|
37
37
|
// from `./resolve-placement` so search-and-jump lands at the source of truth.
|
|
38
38
|
|
|
39
39
|
/**
|
|
@@ -157,7 +157,7 @@ function crossAxisShiftMargin(_ref2) {
|
|
|
157
157
|
* (or undefined fields vs explicit defaults) does not produce a fresh result.
|
|
158
158
|
*/
|
|
159
159
|
function useStablePlacement(placement) {
|
|
160
|
-
var resolved = (0, _resolvePlacement.
|
|
160
|
+
var resolved = (0, _resolvePlacement.resolvePlacement)({
|
|
161
161
|
placement: placement
|
|
162
162
|
});
|
|
163
163
|
var axis = resolved.axis;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* popover.tsx generated by @compiled/babel-plugin
|
|
1
|
+
/* popover.tsx generated by @compiled/babel-plugin v2.0.0 */
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
4
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
@@ -15,12 +15,11 @@ var _bindEventListener = require("bind-event-listener");
|
|
|
15
15
|
var _mergeRefs = _interopRequireDefault(require("@atlaskit/ds-lib/merge-refs"));
|
|
16
16
|
var _once = _interopRequireDefault(require("@atlaskit/ds-lib/once"));
|
|
17
17
|
var _useNotifyOpenLayerObserver = require("@atlaskit/layering/use-notify-open-layer-observer");
|
|
18
|
+
var _resolvePlacement2 = require("../internal/resolve-placement");
|
|
18
19
|
var _roleTypes = require("../internal/role-types");
|
|
19
|
-
var _setStyle = require("../internal/set-style");
|
|
20
20
|
var _useAnimatedVisibility = require("../internal/use-animated-visibility");
|
|
21
21
|
var _useFocusWrap = require("../internal/use-focus-wrap");
|
|
22
22
|
var _useInitialFocus = require("../internal/use-initial-focus");
|
|
23
|
-
var _animations = require("./animations");
|
|
24
23
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
25
24
|
/**
|
|
26
25
|
* Detects `popover="hint"` support via DOM reflection. SSR-safe, cached.
|
|
@@ -55,6 +54,31 @@ var styles = {
|
|
|
55
54
|
enter: "_y44v179n",
|
|
56
55
|
exit: "_y44vof1f"
|
|
57
56
|
};
|
|
57
|
+
|
|
58
|
+
// Intentionally using `Record<string, string>` instead of `React.CSSProperties`
|
|
59
|
+
// to avoid type errors about the CSS variables not being valid property names
|
|
60
|
+
var popupMotionStyles = {
|
|
61
|
+
block: {
|
|
62
|
+
start: {
|
|
63
|
+
'--ds-popover-motion-enter': "var(--ds-popup-enter-top, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInTop8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)",
|
|
64
|
+
'--ds-popover-motion-exit': "var(--ds-popup-exit-top, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutTop8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
65
|
+
},
|
|
66
|
+
end: {
|
|
67
|
+
'--ds-popover-motion-enter': "var(--ds-popup-enter-bottom, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInBottom8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)",
|
|
68
|
+
'--ds-popover-motion-exit': "var(--ds-popup-exit-bottom, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutBottom8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
inline: {
|
|
72
|
+
start: {
|
|
73
|
+
'--ds-popover-motion-enter': "var(--ds-popup-enter-left, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInLeft8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)",
|
|
74
|
+
'--ds-popover-motion-exit': "var(--ds-popup-exit-left, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutLeft8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
75
|
+
},
|
|
76
|
+
end: {
|
|
77
|
+
'--ds-popover-motion-enter': "var(--ds-popup-enter-right, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInRight8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)",
|
|
78
|
+
'--ds-popover-motion-exit': "var(--ds-popup-exit-right, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutRight8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
58
82
|
/**
|
|
59
83
|
* Roles registered with the open layer observer as `popup`, so `closeLayers()`
|
|
60
84
|
* dismisses them. `modal` comes from Dialog only; other layer types are unused.
|
|
@@ -98,7 +122,6 @@ var Popover = exports.Popover = /*#__PURE__*/(0, _react.forwardRef)(function Pop
|
|
|
98
122
|
_ref$mode = _ref.mode,
|
|
99
123
|
modeProp = _ref$mode === void 0 ? 'auto' : _ref$mode,
|
|
100
124
|
onClose = _ref.onClose,
|
|
101
|
-
onOpenChange = _ref.onOpenChange,
|
|
102
125
|
onEnterFinish = _ref.onEnterFinish,
|
|
103
126
|
onExitFinish = _ref.onExitFinish,
|
|
104
127
|
_ref$shouldAnimate = _ref.shouldAnimate,
|
|
@@ -166,6 +189,17 @@ var Popover = exports.Popover = /*#__PURE__*/(0, _react.forwardRef)(function Pop
|
|
|
166
189
|
// will close other `auto` popovers when opened. Acceptable trade-off given
|
|
167
190
|
// shrinking browser set without `hint` support.
|
|
168
191
|
var mode = modeProp === 'hint' && !supportsPopoverHint() ? 'auto' : modeProp;
|
|
192
|
+
var popupMotionStyle = (0, _react.useMemo)(function () {
|
|
193
|
+
if (!placement || !shouldAnimate) {
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
var _resolvePlacement = (0, _resolvePlacement2.resolvePlacement)({
|
|
197
|
+
placement: placement
|
|
198
|
+
}),
|
|
199
|
+
axis = _resolvePlacement.axis,
|
|
200
|
+
edge = _resolvePlacement.edge;
|
|
201
|
+
return popupMotionStyles[axis][edge];
|
|
202
|
+
}, [placement, shouldAnimate]);
|
|
169
203
|
|
|
170
204
|
// Prevents toggle handler from calling onClose for our own hidePopover() calls.
|
|
171
205
|
var programmaticCloseRef = (0, _react.useRef)(false);
|
|
@@ -187,21 +221,10 @@ var Popover = exports.Popover = /*#__PURE__*/(0, _react.forwardRef)(function Pop
|
|
|
187
221
|
var handleToggle = (0, _react.useCallback)(function (event) {
|
|
188
222
|
var element = ownRef.current;
|
|
189
223
|
if (event.newState === 'open') {
|
|
190
|
-
if (element) {
|
|
191
|
-
onOpenChange === null || onOpenChange === void 0 || onOpenChange({
|
|
192
|
-
isOpen: true,
|
|
193
|
-
element: element
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
224
|
return;
|
|
197
225
|
}
|
|
198
226
|
if (event.newState === 'closed') {
|
|
199
227
|
if (element) {
|
|
200
|
-
onOpenChange === null || onOpenChange === void 0 || onOpenChange({
|
|
201
|
-
isOpen: false,
|
|
202
|
-
element: element
|
|
203
|
-
});
|
|
204
|
-
|
|
205
228
|
// Nested-popover focus restoration fallback (browser only
|
|
206
229
|
// restores outermost; Firefox skips nested entirely).
|
|
207
230
|
// Restore only when the role moved focus in on open AND the
|
|
@@ -238,7 +261,7 @@ var Popover = exports.Popover = /*#__PURE__*/(0, _react.forwardRef)(function Pop
|
|
|
238
261
|
reason: reason
|
|
239
262
|
});
|
|
240
263
|
}
|
|
241
|
-
}, [onClose,
|
|
264
|
+
}, [onClose, role]);
|
|
242
265
|
|
|
243
266
|
// Bind via `useLayoutEffect`, and BEFORE the show/hide layout effect
|
|
244
267
|
// below, so listeners are attached when `showPopover()` synchronously
|
|
@@ -280,23 +303,6 @@ var Popover = exports.Popover = /*#__PURE__*/(0, _react.forwardRef)(function Pop
|
|
|
280
303
|
};
|
|
281
304
|
}, [handleToggle, handleBeforeToggle, isVisible]);
|
|
282
305
|
|
|
283
|
-
// Placement-dependent animation CSS vars. Kept separate from show/hide
|
|
284
|
-
// so preset reference changes do not re-trigger visibility. The cleanup
|
|
285
|
-
// restores the previous inline values so a preset change does not leave
|
|
286
|
-
// stale custom properties on the element.
|
|
287
|
-
(0, _react.useLayoutEffect)(function () {
|
|
288
|
-
var element = ownRef.current;
|
|
289
|
-
if (!element || !placement) {
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
return (0, _setStyle.setStyle)({
|
|
293
|
-
element: element,
|
|
294
|
-
styles: (0, _animations.getPopupMotionStyles)({
|
|
295
|
-
placement: placement
|
|
296
|
-
})
|
|
297
|
-
});
|
|
298
|
-
}, [placement, isVisible]);
|
|
299
|
-
|
|
300
306
|
// Show/hide based on isOpen. `showPopover`/`hidePopover` are no-ops when
|
|
301
307
|
// already in the target state. Try/catch guards `InvalidStateError` on
|
|
302
308
|
// disconnected elements (StrictMode/concurrent/unmount edge cases).
|
|
@@ -343,7 +349,10 @@ var Popover = exports.Popover = /*#__PURE__*/(0, _react.forwardRef)(function Pop
|
|
|
343
349
|
role: role,
|
|
344
350
|
"aria-label": label,
|
|
345
351
|
"aria-labelledby": labelledBy,
|
|
346
|
-
"data-testid": testId
|
|
352
|
+
"data-testid": testId
|
|
353
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Motion styles are selected at runtime from the placement.
|
|
354
|
+
,
|
|
355
|
+
style: popupMotionStyle,
|
|
347
356
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop, @atlaskit/ui-styling-standard/local-cx-xcss, @compiled/local-cx-xcss
|
|
348
357
|
className: (0, _runtime.ax)([styles.root, surfaceResetStyles.root, shouldAnimate && phase === 'entering' && styles.enter, shouldAnimate && phase === 'exiting' && styles.exit, shouldAnimate && styles.motion, (0, _react2.cx)(shouldAnimate && phase === 'entering' && enteringAnimationXcss, shouldAnimate && phase === 'exiting' && exitingAnimationXcss)])
|
|
349
358
|
}, children);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* dialog-content.tsx generated by @compiled/babel-plugin
|
|
1
|
+
/* dialog-content.tsx generated by @compiled/babel-plugin v2.0.0 */
|
|
2
2
|
import "./dialog-content.compiled.css";
|
|
3
3
|
import { ax, ix } from "@compiled/react/runtime";
|
|
4
4
|
import React, { forwardRef, useCallback, useEffect, useId, useLayoutEffect, useRef } from 'react';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolvePlacement } from './resolve-placement';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Resolves placement options to CSS `position-area` syntax.
|
|
@@ -24,7 +24,7 @@ export function placementToPositionArea({
|
|
|
24
24
|
axis,
|
|
25
25
|
edge,
|
|
26
26
|
align
|
|
27
|
-
} =
|
|
27
|
+
} = resolvePlacement({
|
|
28
28
|
placement
|
|
29
29
|
});
|
|
30
30
|
const edgeValue = `${axis}-${edge}`;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolvePlacement } from './resolve-placement';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A `position-area` primary edge — the placement axis joined to its edge, e.g.
|
|
@@ -47,7 +47,7 @@ export function placementToTryFallbacks({
|
|
|
47
47
|
* The browser tries them _in order_ and uses the _first_ one that fits.
|
|
48
48
|
*/
|
|
49
49
|
|
|
50
|
-
const resolved =
|
|
50
|
+
const resolved = resolvePlacement({
|
|
51
51
|
placement
|
|
52
52
|
});
|
|
53
53
|
const {
|
|
@@ -61,7 +61,7 @@ export function resolveCssLengthToPixels({
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
// Fast path: bare `${n}px` strings come from the consumer normalisation
|
|
64
|
-
// in `
|
|
64
|
+
// in `resolvePlacement`. Avoid a reflow when we can.
|
|
65
65
|
const pxMatch = value.match(/^(-?\d+(?:\.\d+)?)px$/);
|
|
66
66
|
if (pxMatch) {
|
|
67
67
|
return Number(pxMatch[1]);
|
|
@@ -14,7 +14,7 @@ const DEFAULT_GAP = "var(--ds-space-100, 8px)";
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* Fully-resolved placement (internal). Use `
|
|
17
|
+
* Fully-resolved placement (internal). Use `resolvePlacement` for partial input.
|
|
18
18
|
* `offset.gap` and `offset.crossAxisShift.value` are always CSS
|
|
19
19
|
* length strings.
|
|
20
20
|
*/
|
|
@@ -37,7 +37,7 @@ const DEFAULT_GAP = "var(--ds-space-100, 8px)";
|
|
|
37
37
|
* `offset.gap: token('space.100', '8px')`,
|
|
38
38
|
* `offset.crossAxisShift: { value: '0px', direction: 'forwards' }`.
|
|
39
39
|
*/
|
|
40
|
-
export function
|
|
40
|
+
export function resolvePlacement({
|
|
41
41
|
placement
|
|
42
42
|
}) {
|
|
43
43
|
var _placement$offset, _placement$axis, _placement$edge, _placement$align, _placement$offset$cro, _placement$offset2, _placement$offset2$cr, _placement$offset$cro2, _placement$offset3, _placement$offset3$cr;
|
|
@@ -21,10 +21,10 @@ import { combine } from './combine';
|
|
|
21
21
|
import { placementToPositionArea } from './placement-to-position-area';
|
|
22
22
|
import { placementToTryFallbacks } from './placement-to-try-fallbacks';
|
|
23
23
|
import { resolveCssLengthToPixels } from './resolve-css-length-to-pixels';
|
|
24
|
-
import {
|
|
24
|
+
import { resolvePlacement } from './resolve-placement';
|
|
25
25
|
import { setStyle } from './set-style';
|
|
26
26
|
|
|
27
|
-
// `
|
|
27
|
+
// `resolvePlacement` is intentionally NOT re-exported here - import it directly
|
|
28
28
|
// from `./resolve-placement` so search-and-jump lands at the source of truth.
|
|
29
29
|
|
|
30
30
|
/**
|
|
@@ -144,7 +144,7 @@ function crossAxisShiftMargin({
|
|
|
144
144
|
* (or undefined fields vs explicit defaults) does not produce a fresh result.
|
|
145
145
|
*/
|
|
146
146
|
function useStablePlacement(placement) {
|
|
147
|
-
const resolved =
|
|
147
|
+
const resolved = resolvePlacement({
|
|
148
148
|
placement
|
|
149
149
|
});
|
|
150
150
|
const axis = resolved.axis;
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
/* popover.tsx generated by @compiled/babel-plugin
|
|
1
|
+
/* popover.tsx generated by @compiled/babel-plugin v2.0.0 */
|
|
2
2
|
import "./popover.compiled.css";
|
|
3
3
|
import { ax, ix } from "@compiled/react/runtime";
|
|
4
|
-
import React, { forwardRef, useCallback, useId, useLayoutEffect, useRef } from 'react';
|
|
4
|
+
import React, { forwardRef, useCallback, useId, useLayoutEffect, useMemo, useRef } from 'react';
|
|
5
5
|
import { cx } from '@compiled/react';
|
|
6
6
|
import { bind } from 'bind-event-listener';
|
|
7
7
|
import mergeRefs from '@atlaskit/ds-lib/merge-refs';
|
|
8
8
|
import once from '@atlaskit/ds-lib/once';
|
|
9
9
|
import { useNotifyOpenLayerObserver } from '@atlaskit/layering/use-notify-open-layer-observer';
|
|
10
|
+
import { resolvePlacement } from '../internal/resolve-placement';
|
|
10
11
|
import { shouldFocusIntoPopover } from '../internal/role-types';
|
|
11
|
-
import { setStyle } from '../internal/set-style';
|
|
12
12
|
import { useAnimatedVisibility } from '../internal/use-animated-visibility';
|
|
13
13
|
import { useFocusWrap } from '../internal/use-focus-wrap';
|
|
14
14
|
import { useInitialFocus } from '../internal/use-initial-focus';
|
|
15
|
-
import { getPopupMotionStyles } from './animations';
|
|
16
15
|
/**
|
|
17
16
|
* Detects `popover="hint"` support via DOM reflection. SSR-safe, cached.
|
|
18
17
|
*/
|
|
@@ -46,6 +45,31 @@ const styles = {
|
|
|
46
45
|
enter: "_y44v179n",
|
|
47
46
|
exit: "_y44vof1f"
|
|
48
47
|
};
|
|
48
|
+
|
|
49
|
+
// Intentionally using `Record<string, string>` instead of `React.CSSProperties`
|
|
50
|
+
// to avoid type errors about the CSS variables not being valid property names
|
|
51
|
+
const popupMotionStyles = {
|
|
52
|
+
block: {
|
|
53
|
+
start: {
|
|
54
|
+
'--ds-popover-motion-enter': "var(--ds-popup-enter-top, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInTop8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)",
|
|
55
|
+
'--ds-popover-motion-exit': "var(--ds-popup-exit-top, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutTop8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
56
|
+
},
|
|
57
|
+
end: {
|
|
58
|
+
'--ds-popover-motion-enter': "var(--ds-popup-enter-bottom, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInBottom8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)",
|
|
59
|
+
'--ds-popover-motion-exit': "var(--ds-popup-exit-bottom, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutBottom8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
inline: {
|
|
63
|
+
start: {
|
|
64
|
+
'--ds-popover-motion-enter': "var(--ds-popup-enter-left, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInLeft8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)",
|
|
65
|
+
'--ds-popover-motion-exit': "var(--ds-popup-exit-left, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutLeft8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
66
|
+
},
|
|
67
|
+
end: {
|
|
68
|
+
'--ds-popover-motion-enter': "var(--ds-popup-enter-right, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInRight8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)",
|
|
69
|
+
'--ds-popover-motion-exit': "var(--ds-popup-exit-right, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutRight8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
49
73
|
/**
|
|
50
74
|
* Roles registered with the open layer observer as `popup`, so `closeLayers()`
|
|
51
75
|
* dismisses them. `modal` comes from Dialog only; other layer types are unused.
|
|
@@ -88,7 +112,6 @@ export const Popover = /*#__PURE__*/forwardRef(function Popover({
|
|
|
88
112
|
children,
|
|
89
113
|
mode: modeProp = 'auto',
|
|
90
114
|
onClose,
|
|
91
|
-
onOpenChange,
|
|
92
115
|
onEnterFinish,
|
|
93
116
|
onExitFinish,
|
|
94
117
|
shouldAnimate = false,
|
|
@@ -158,6 +181,18 @@ export const Popover = /*#__PURE__*/forwardRef(function Popover({
|
|
|
158
181
|
// will close other `auto` popovers when opened. Acceptable trade-off given
|
|
159
182
|
// shrinking browser set without `hint` support.
|
|
160
183
|
const mode = modeProp === 'hint' && !supportsPopoverHint() ? 'auto' : modeProp;
|
|
184
|
+
const popupMotionStyle = useMemo(() => {
|
|
185
|
+
if (!placement || !shouldAnimate) {
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
188
|
+
const {
|
|
189
|
+
axis,
|
|
190
|
+
edge
|
|
191
|
+
} = resolvePlacement({
|
|
192
|
+
placement
|
|
193
|
+
});
|
|
194
|
+
return popupMotionStyles[axis][edge];
|
|
195
|
+
}, [placement, shouldAnimate]);
|
|
161
196
|
|
|
162
197
|
// Prevents toggle handler from calling onClose for our own hidePopover() calls.
|
|
163
198
|
const programmaticCloseRef = useRef(false);
|
|
@@ -179,21 +214,10 @@ export const Popover = /*#__PURE__*/forwardRef(function Popover({
|
|
|
179
214
|
const handleToggle = useCallback(event => {
|
|
180
215
|
const element = ownRef.current;
|
|
181
216
|
if (event.newState === 'open') {
|
|
182
|
-
if (element) {
|
|
183
|
-
onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange({
|
|
184
|
-
isOpen: true,
|
|
185
|
-
element: element
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
217
|
return;
|
|
189
218
|
}
|
|
190
219
|
if (event.newState === 'closed') {
|
|
191
220
|
if (element) {
|
|
192
|
-
onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange({
|
|
193
|
-
isOpen: false,
|
|
194
|
-
element: element
|
|
195
|
-
});
|
|
196
|
-
|
|
197
221
|
// Nested-popover focus restoration fallback (browser only
|
|
198
222
|
// restores outermost; Firefox skips nested entirely).
|
|
199
223
|
// Restore only when the role moved focus in on open AND the
|
|
@@ -230,7 +254,7 @@ export const Popover = /*#__PURE__*/forwardRef(function Popover({
|
|
|
230
254
|
reason
|
|
231
255
|
});
|
|
232
256
|
}
|
|
233
|
-
}, [onClose,
|
|
257
|
+
}, [onClose, role]);
|
|
234
258
|
|
|
235
259
|
// Bind via `useLayoutEffect`, and BEFORE the show/hide layout effect
|
|
236
260
|
// below, so listeners are attached when `showPopover()` synchronously
|
|
@@ -272,23 +296,6 @@ export const Popover = /*#__PURE__*/forwardRef(function Popover({
|
|
|
272
296
|
};
|
|
273
297
|
}, [handleToggle, handleBeforeToggle, isVisible]);
|
|
274
298
|
|
|
275
|
-
// Placement-dependent animation CSS vars. Kept separate from show/hide
|
|
276
|
-
// so preset reference changes do not re-trigger visibility. The cleanup
|
|
277
|
-
// restores the previous inline values so a preset change does not leave
|
|
278
|
-
// stale custom properties on the element.
|
|
279
|
-
useLayoutEffect(() => {
|
|
280
|
-
const element = ownRef.current;
|
|
281
|
-
if (!element || !placement) {
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
return setStyle({
|
|
285
|
-
element,
|
|
286
|
-
styles: getPopupMotionStyles({
|
|
287
|
-
placement
|
|
288
|
-
})
|
|
289
|
-
});
|
|
290
|
-
}, [placement, isVisible]);
|
|
291
|
-
|
|
292
299
|
// Show/hide based on isOpen. `showPopover`/`hidePopover` are no-ops when
|
|
293
300
|
// already in the target state. Try/catch guards `InvalidStateError` on
|
|
294
301
|
// disconnected elements (StrictMode/concurrent/unmount edge cases).
|
|
@@ -335,7 +342,10 @@ export const Popover = /*#__PURE__*/forwardRef(function Popover({
|
|
|
335
342
|
role: role,
|
|
336
343
|
"aria-label": label,
|
|
337
344
|
"aria-labelledby": labelledBy,
|
|
338
|
-
"data-testid": testId
|
|
345
|
+
"data-testid": testId
|
|
346
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Motion styles are selected at runtime from the placement.
|
|
347
|
+
,
|
|
348
|
+
style: popupMotionStyle,
|
|
339
349
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop, @atlaskit/ui-styling-standard/local-cx-xcss, @compiled/local-cx-xcss
|
|
340
350
|
className: ax([styles.root, surfaceResetStyles.root, shouldAnimate && phase === 'entering' && styles.enter, shouldAnimate && phase === 'exiting' && styles.exit, shouldAnimate && styles.motion, cx(shouldAnimate && phase === 'entering' && enteringAnimationXcss, shouldAnimate && phase === 'exiting' && exitingAnimationXcss)])
|
|
341
351
|
}, children);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* dialog-content.tsx generated by @compiled/babel-plugin
|
|
1
|
+
/* dialog-content.tsx generated by @compiled/babel-plugin v2.0.0 */
|
|
2
2
|
import "./dialog-content.compiled.css";
|
|
3
3
|
import { ax, ix } from "@compiled/react/runtime";
|
|
4
4
|
import React, { forwardRef, useCallback, useEffect, useId, useLayoutEffect, useRef } from 'react';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolvePlacement } from './resolve-placement';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Resolves placement options to CSS `position-area` syntax.
|
|
@@ -19,12 +19,12 @@ import { getPlacement } from './resolve-placement';
|
|
|
19
19
|
*/
|
|
20
20
|
export function placementToPositionArea(_ref) {
|
|
21
21
|
var placement = _ref.placement;
|
|
22
|
-
var
|
|
22
|
+
var _resolvePlacement = resolvePlacement({
|
|
23
23
|
placement: placement
|
|
24
24
|
}),
|
|
25
|
-
axis =
|
|
26
|
-
edge =
|
|
27
|
-
align =
|
|
25
|
+
axis = _resolvePlacement.axis,
|
|
26
|
+
edge = _resolvePlacement.edge,
|
|
27
|
+
align = _resolvePlacement.align;
|
|
28
28
|
var edgeValue = "".concat(axis, "-").concat(edge);
|
|
29
29
|
if (align === 'center') {
|
|
30
30
|
return edgeValue;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolvePlacement } from './resolve-placement';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A `position-area` primary edge — the placement axis joined to its edge, e.g.
|
|
@@ -44,7 +44,7 @@ export function placementToTryFallbacks(_ref3) {
|
|
|
44
44
|
* The browser tries them _in order_ and uses the _first_ one that fits.
|
|
45
45
|
*/
|
|
46
46
|
|
|
47
|
-
var resolved =
|
|
47
|
+
var resolved = resolvePlacement({
|
|
48
48
|
placement: placement
|
|
49
49
|
});
|
|
50
50
|
var axis = resolved.axis,
|
|
@@ -58,7 +58,7 @@ export function resolveCssLengthToPixels(_ref3) {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
// Fast path: bare `${n}px` strings come from the consumer normalisation
|
|
61
|
-
// in `
|
|
61
|
+
// in `resolvePlacement`. Avoid a reflow when we can.
|
|
62
62
|
var pxMatch = value.match(/^(-?\d+(?:\.\d+)?)px$/);
|
|
63
63
|
if (pxMatch) {
|
|
64
64
|
return Number(pxMatch[1]);
|
|
@@ -14,7 +14,7 @@ var DEFAULT_GAP = "var(--ds-space-100, 8px)";
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* Fully-resolved placement (internal). Use `
|
|
17
|
+
* Fully-resolved placement (internal). Use `resolvePlacement` for partial input.
|
|
18
18
|
* `offset.gap` and `offset.crossAxisShift.value` are always CSS
|
|
19
19
|
* length strings.
|
|
20
20
|
*/
|
|
@@ -37,7 +37,7 @@ var DEFAULT_GAP = "var(--ds-space-100, 8px)";
|
|
|
37
37
|
* `offset.gap: token('space.100', '8px')`,
|
|
38
38
|
* `offset.crossAxisShift: { value: '0px', direction: 'forwards' }`.
|
|
39
39
|
*/
|
|
40
|
-
export function
|
|
40
|
+
export function resolvePlacement(_ref) {
|
|
41
41
|
var _placement$offset, _placement$axis, _placement$edge, _placement$align, _placement$offset$cro, _placement$offset2, _placement$offset$cro2, _placement$offset3;
|
|
42
42
|
var placement = _ref.placement;
|
|
43
43
|
var consumerGap = (_placement$offset = placement.offset) === null || _placement$offset === void 0 ? void 0 : _placement$offset.gap;
|
|
@@ -23,10 +23,10 @@ import { combine } from './combine';
|
|
|
23
23
|
import { placementToPositionArea } from './placement-to-position-area';
|
|
24
24
|
import { placementToTryFallbacks } from './placement-to-try-fallbacks';
|
|
25
25
|
import { resolveCssLengthToPixels } from './resolve-css-length-to-pixels';
|
|
26
|
-
import {
|
|
26
|
+
import { resolvePlacement } from './resolve-placement';
|
|
27
27
|
import { setStyle } from './set-style';
|
|
28
28
|
|
|
29
|
-
// `
|
|
29
|
+
// `resolvePlacement` is intentionally NOT re-exported here - import it directly
|
|
30
30
|
// from `./resolve-placement` so search-and-jump lands at the source of truth.
|
|
31
31
|
|
|
32
32
|
/**
|
|
@@ -150,7 +150,7 @@ function crossAxisShiftMargin(_ref2) {
|
|
|
150
150
|
* (or undefined fields vs explicit defaults) does not produce a fresh result.
|
|
151
151
|
*/
|
|
152
152
|
function useStablePlacement(placement) {
|
|
153
|
-
var resolved =
|
|
153
|
+
var resolved = resolvePlacement({
|
|
154
154
|
placement: placement
|
|
155
155
|
});
|
|
156
156
|
var axis = resolved.axis;
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
/* popover.tsx generated by @compiled/babel-plugin
|
|
1
|
+
/* popover.tsx generated by @compiled/babel-plugin v2.0.0 */
|
|
2
2
|
import "./popover.compiled.css";
|
|
3
3
|
import { ax, ix } from "@compiled/react/runtime";
|
|
4
|
-
import React, { forwardRef, useCallback, useId, useLayoutEffect, useRef } from 'react';
|
|
4
|
+
import React, { forwardRef, useCallback, useId, useLayoutEffect, useMemo, useRef } from 'react';
|
|
5
5
|
import { cx } from '@compiled/react';
|
|
6
6
|
import { bind } from 'bind-event-listener';
|
|
7
7
|
import mergeRefs from '@atlaskit/ds-lib/merge-refs';
|
|
8
8
|
import once from '@atlaskit/ds-lib/once';
|
|
9
9
|
import { useNotifyOpenLayerObserver } from '@atlaskit/layering/use-notify-open-layer-observer';
|
|
10
|
+
import { resolvePlacement } from '../internal/resolve-placement';
|
|
10
11
|
import { shouldFocusIntoPopover } from '../internal/role-types';
|
|
11
|
-
import { setStyle } from '../internal/set-style';
|
|
12
12
|
import { useAnimatedVisibility } from '../internal/use-animated-visibility';
|
|
13
13
|
import { useFocusWrap } from '../internal/use-focus-wrap';
|
|
14
14
|
import { useInitialFocus } from '../internal/use-initial-focus';
|
|
15
|
-
import { getPopupMotionStyles } from './animations';
|
|
16
15
|
/**
|
|
17
16
|
* Detects `popover="hint"` support via DOM reflection. SSR-safe, cached.
|
|
18
17
|
*/
|
|
@@ -46,6 +45,31 @@ var styles = {
|
|
|
46
45
|
enter: "_y44v179n",
|
|
47
46
|
exit: "_y44vof1f"
|
|
48
47
|
};
|
|
48
|
+
|
|
49
|
+
// Intentionally using `Record<string, string>` instead of `React.CSSProperties`
|
|
50
|
+
// to avoid type errors about the CSS variables not being valid property names
|
|
51
|
+
var popupMotionStyles = {
|
|
52
|
+
block: {
|
|
53
|
+
start: {
|
|
54
|
+
'--ds-popover-motion-enter': "var(--ds-popup-enter-top, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInTop8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)",
|
|
55
|
+
'--ds-popover-motion-exit': "var(--ds-popup-exit-top, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutTop8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
56
|
+
},
|
|
57
|
+
end: {
|
|
58
|
+
'--ds-popover-motion-enter': "var(--ds-popup-enter-bottom, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInBottom8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)",
|
|
59
|
+
'--ds-popover-motion-exit': "var(--ds-popup-exit-bottom, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutBottom8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
inline: {
|
|
63
|
+
start: {
|
|
64
|
+
'--ds-popover-motion-enter': "var(--ds-popup-enter-left, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInLeft8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)",
|
|
65
|
+
'--ds-popover-motion-exit': "var(--ds-popup-exit-left, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutLeft8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
66
|
+
},
|
|
67
|
+
end: {
|
|
68
|
+
'--ds-popover-motion-enter': "var(--ds-popup-enter-right, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInRight8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)",
|
|
69
|
+
'--ds-popover-motion-exit': "var(--ds-popup-exit-right, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutRight8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
49
73
|
/**
|
|
50
74
|
* Roles registered with the open layer observer as `popup`, so `closeLayers()`
|
|
51
75
|
* dismisses them. `modal` comes from Dialog only; other layer types are unused.
|
|
@@ -89,7 +113,6 @@ export var Popover = /*#__PURE__*/forwardRef(function Popover(_ref, ref) {
|
|
|
89
113
|
_ref$mode = _ref.mode,
|
|
90
114
|
modeProp = _ref$mode === void 0 ? 'auto' : _ref$mode,
|
|
91
115
|
onClose = _ref.onClose,
|
|
92
|
-
onOpenChange = _ref.onOpenChange,
|
|
93
116
|
onEnterFinish = _ref.onEnterFinish,
|
|
94
117
|
onExitFinish = _ref.onExitFinish,
|
|
95
118
|
_ref$shouldAnimate = _ref.shouldAnimate,
|
|
@@ -157,6 +180,17 @@ export var Popover = /*#__PURE__*/forwardRef(function Popover(_ref, ref) {
|
|
|
157
180
|
// will close other `auto` popovers when opened. Acceptable trade-off given
|
|
158
181
|
// shrinking browser set without `hint` support.
|
|
159
182
|
var mode = modeProp === 'hint' && !supportsPopoverHint() ? 'auto' : modeProp;
|
|
183
|
+
var popupMotionStyle = useMemo(function () {
|
|
184
|
+
if (!placement || !shouldAnimate) {
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
var _resolvePlacement = resolvePlacement({
|
|
188
|
+
placement: placement
|
|
189
|
+
}),
|
|
190
|
+
axis = _resolvePlacement.axis,
|
|
191
|
+
edge = _resolvePlacement.edge;
|
|
192
|
+
return popupMotionStyles[axis][edge];
|
|
193
|
+
}, [placement, shouldAnimate]);
|
|
160
194
|
|
|
161
195
|
// Prevents toggle handler from calling onClose for our own hidePopover() calls.
|
|
162
196
|
var programmaticCloseRef = useRef(false);
|
|
@@ -178,21 +212,10 @@ export var Popover = /*#__PURE__*/forwardRef(function Popover(_ref, ref) {
|
|
|
178
212
|
var handleToggle = useCallback(function (event) {
|
|
179
213
|
var element = ownRef.current;
|
|
180
214
|
if (event.newState === 'open') {
|
|
181
|
-
if (element) {
|
|
182
|
-
onOpenChange === null || onOpenChange === void 0 || onOpenChange({
|
|
183
|
-
isOpen: true,
|
|
184
|
-
element: element
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
215
|
return;
|
|
188
216
|
}
|
|
189
217
|
if (event.newState === 'closed') {
|
|
190
218
|
if (element) {
|
|
191
|
-
onOpenChange === null || onOpenChange === void 0 || onOpenChange({
|
|
192
|
-
isOpen: false,
|
|
193
|
-
element: element
|
|
194
|
-
});
|
|
195
|
-
|
|
196
219
|
// Nested-popover focus restoration fallback (browser only
|
|
197
220
|
// restores outermost; Firefox skips nested entirely).
|
|
198
221
|
// Restore only when the role moved focus in on open AND the
|
|
@@ -229,7 +252,7 @@ export var Popover = /*#__PURE__*/forwardRef(function Popover(_ref, ref) {
|
|
|
229
252
|
reason: reason
|
|
230
253
|
});
|
|
231
254
|
}
|
|
232
|
-
}, [onClose,
|
|
255
|
+
}, [onClose, role]);
|
|
233
256
|
|
|
234
257
|
// Bind via `useLayoutEffect`, and BEFORE the show/hide layout effect
|
|
235
258
|
// below, so listeners are attached when `showPopover()` synchronously
|
|
@@ -271,23 +294,6 @@ export var Popover = /*#__PURE__*/forwardRef(function Popover(_ref, ref) {
|
|
|
271
294
|
};
|
|
272
295
|
}, [handleToggle, handleBeforeToggle, isVisible]);
|
|
273
296
|
|
|
274
|
-
// Placement-dependent animation CSS vars. Kept separate from show/hide
|
|
275
|
-
// so preset reference changes do not re-trigger visibility. The cleanup
|
|
276
|
-
// restores the previous inline values so a preset change does not leave
|
|
277
|
-
// stale custom properties on the element.
|
|
278
|
-
useLayoutEffect(function () {
|
|
279
|
-
var element = ownRef.current;
|
|
280
|
-
if (!element || !placement) {
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
return setStyle({
|
|
284
|
-
element: element,
|
|
285
|
-
styles: getPopupMotionStyles({
|
|
286
|
-
placement: placement
|
|
287
|
-
})
|
|
288
|
-
});
|
|
289
|
-
}, [placement, isVisible]);
|
|
290
|
-
|
|
291
297
|
// Show/hide based on isOpen. `showPopover`/`hidePopover` are no-ops when
|
|
292
298
|
// already in the target state. Try/catch guards `InvalidStateError` on
|
|
293
299
|
// disconnected elements (StrictMode/concurrent/unmount edge cases).
|
|
@@ -334,7 +340,10 @@ export var Popover = /*#__PURE__*/forwardRef(function Popover(_ref, ref) {
|
|
|
334
340
|
role: role,
|
|
335
341
|
"aria-label": label,
|
|
336
342
|
"aria-labelledby": labelledBy,
|
|
337
|
-
"data-testid": testId
|
|
343
|
+
"data-testid": testId
|
|
344
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Motion styles are selected at runtime from the placement.
|
|
345
|
+
,
|
|
346
|
+
style: popupMotionStyle,
|
|
338
347
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop, @atlaskit/ui-styling-standard/local-cx-xcss, @compiled/local-cx-xcss
|
|
339
348
|
className: ax([styles.root, surfaceResetStyles.root, shouldAnimate && phase === 'entering' && styles.enter, shouldAnimate && phase === 'exiting' && styles.exit, shouldAnimate && styles.motion, cx(shouldAnimate && phase === 'entering' && enteringAnimationXcss, shouldAnimate && phase === 'exiting' && exitingAnimationXcss)])
|
|
340
349
|
}, children);
|
|
@@ -61,7 +61,7 @@ type TDialogBaseProps = {
|
|
|
61
61
|
* Applied after built-in dialog and animation styles so consumers can own
|
|
62
62
|
* static styling that must live in their package.
|
|
63
63
|
*/
|
|
64
|
-
xcss?: XCSSProp<'margin' | 'height' | 'width' | 'maxWidth' | 'insetBlockStart' | 'insetInlineStart' | 'insetInlineEnd', never>;
|
|
64
|
+
xcss?: XCSSProp<'margin' | 'height' | 'width' | 'maxWidth' | 'insetBlockStart' | 'insetInlineStart' | 'insetInlineEnd' | 'overflow' | 'scrollbarGutter', never>;
|
|
65
65
|
/**
|
|
66
66
|
* Animation styles applied while the dialog is entering.
|
|
67
67
|
*
|
|
@@ -7,14 +7,16 @@ export type TCrossAxisShiftOffset = {
|
|
|
7
7
|
value: string;
|
|
8
8
|
direction: 'forwards' | 'backwards';
|
|
9
9
|
};
|
|
10
|
+
export type TPlacementAxis = 'block' | 'inline';
|
|
11
|
+
export type TPlacementEdge = 'start' | 'end';
|
|
10
12
|
/**
|
|
11
|
-
* Fully-resolved placement (internal). Use `
|
|
13
|
+
* Fully-resolved placement (internal). Use `resolvePlacement` for partial input.
|
|
12
14
|
* `offset.gap` and `offset.crossAxisShift.value` are always CSS
|
|
13
15
|
* length strings.
|
|
14
16
|
*/
|
|
15
17
|
export type TPlacement = {
|
|
16
|
-
axis:
|
|
17
|
-
edge:
|
|
18
|
+
axis: TPlacementAxis;
|
|
19
|
+
edge: TPlacementEdge;
|
|
18
20
|
align: 'start' | 'center' | 'end';
|
|
19
21
|
offset: {
|
|
20
22
|
gap: string;
|
|
@@ -53,6 +55,6 @@ export type TPlacementOptions = {
|
|
|
53
55
|
* `offset.gap: token('space.100', '8px')`,
|
|
54
56
|
* `offset.crossAxisShift: { value: '0px', direction: 'forwards' }`.
|
|
55
57
|
*/
|
|
56
|
-
export declare function
|
|
58
|
+
export declare function resolvePlacement({ placement }: {
|
|
57
59
|
placement: TPlacementOptions;
|
|
58
60
|
}): TPlacement;
|
|
@@ -81,8 +81,8 @@ type TPopoverBaseProps = {
|
|
|
81
81
|
* The exact unmount timing is private and may change.
|
|
82
82
|
* - The `id` (supplied or generated via `usePopoverId()`) is stable across opens.
|
|
83
83
|
* - The `ref` is populated only while the host element is rendered. Consumers
|
|
84
|
-
* that read from the ref outside of `
|
|
85
|
-
*
|
|
84
|
+
* that read from the ref outside of `onEnterFinish` should gate the read on
|
|
85
|
+
* `isOpen` being `true`.
|
|
86
86
|
*
|
|
87
87
|
* **Important:** For `mode="auto"` popovers, the browser can dismiss the popover
|
|
88
88
|
* via light dismiss (Escape, click outside) independently of this prop. When that
|
|
@@ -91,28 +91,6 @@ type TPopoverBaseProps = {
|
|
|
91
91
|
* React state will be out of sync (the popover will be hidden despite `isOpen={true}`).
|
|
92
92
|
*/
|
|
93
93
|
isOpen: boolean;
|
|
94
|
-
/**
|
|
95
|
-
* Called when the popover's open state changes via browser toggle events.
|
|
96
|
-
*
|
|
97
|
-
* Receives the new open state and a reference to the popover element,
|
|
98
|
-
* which is useful for focus management (e.g. focusing the first interactive
|
|
99
|
-
* child on open via `getFirstFocusable` from `@atlaskit/top-layer/focus`).
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```tsx
|
|
103
|
-
* <Popover
|
|
104
|
-
* onOpenChange={({ isOpen, element }) => {
|
|
105
|
-
* if (isOpen) {
|
|
106
|
-
* getFirstFocusable({ container: element })?.focus();
|
|
107
|
-
* }
|
|
108
|
-
* }}
|
|
109
|
-
* />
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
onOpenChange?: (args: {
|
|
113
|
-
isOpen: boolean;
|
|
114
|
-
element: HTMLDivElement;
|
|
115
|
-
}) => void;
|
|
116
94
|
/**
|
|
117
95
|
* Placement hint for directional animations (e.g. `slideAndFade`).
|
|
118
96
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/top-layer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
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",
|
|
@@ -53,12 +53,12 @@
|
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@af/integration-testing": "workspace:^",
|
|
55
55
|
"@af/visual-regression": "workspace:^",
|
|
56
|
-
"@atlaskit/button": "^
|
|
57
|
-
"@atlaskit/heading": "^
|
|
58
|
-
"@atlaskit/lozenge": "^
|
|
56
|
+
"@atlaskit/button": "^25.0.0",
|
|
57
|
+
"@atlaskit/heading": "^7.0.0",
|
|
58
|
+
"@atlaskit/lozenge": "^15.0.0",
|
|
59
59
|
"@atlaskit/primitives": "^22.2.0",
|
|
60
60
|
"@atlaskit/ssr": "workspace:^",
|
|
61
|
-
"@atlaskit/textfield": "^
|
|
61
|
+
"@atlaskit/textfield": "^10.0.0",
|
|
62
62
|
"@atlassian/ssr-tests": "workspace:^",
|
|
63
63
|
"@atlassian/testing-library": "^0.11.0",
|
|
64
64
|
"@testing-library/jest-dom": "^6.4.5",
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getPopupMotionStyles = getPopupMotionStyles;
|
|
7
|
-
var _resolvePlacement = require("../internal/resolve-placement");
|
|
8
|
-
function getPopupMotionStyles(_ref) {
|
|
9
|
-
var placement = _ref.placement;
|
|
10
|
-
var _getPlacement = (0, _resolvePlacement.getPlacement)({
|
|
11
|
-
placement: placement
|
|
12
|
-
}),
|
|
13
|
-
axis = _getPlacement.axis,
|
|
14
|
-
edge = _getPlacement.edge;
|
|
15
|
-
if (axis === 'block' && edge === 'start') {
|
|
16
|
-
return [{
|
|
17
|
-
property: '--ds-popover-motion-enter',
|
|
18
|
-
value: "var(--ds-popup-enter-top, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInTop8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)"
|
|
19
|
-
}, {
|
|
20
|
-
property: '--ds-popover-motion-exit',
|
|
21
|
-
value: "var(--ds-popup-exit-top, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutTop8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
22
|
-
}];
|
|
23
|
-
}
|
|
24
|
-
if (axis === 'inline' && edge === 'start') {
|
|
25
|
-
return [{
|
|
26
|
-
property: '--ds-popover-motion-enter',
|
|
27
|
-
value: "var(--ds-popup-enter-left, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInLeft8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)"
|
|
28
|
-
}, {
|
|
29
|
-
property: '--ds-popover-motion-exit',
|
|
30
|
-
value: "var(--ds-popup-exit-left, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutLeft8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
31
|
-
}];
|
|
32
|
-
}
|
|
33
|
-
if (axis === 'inline' && edge === 'end') {
|
|
34
|
-
return [{
|
|
35
|
-
property: '--ds-popover-motion-enter',
|
|
36
|
-
value: "var(--ds-popup-enter-right, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInRight8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)"
|
|
37
|
-
}, {
|
|
38
|
-
property: '--ds-popover-motion-exit',
|
|
39
|
-
value: "var(--ds-popup-exit-right, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutRight8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
40
|
-
}];
|
|
41
|
-
}
|
|
42
|
-
// Default: block/end (popover below trigger)
|
|
43
|
-
return [{
|
|
44
|
-
property: '--ds-popover-motion-enter',
|
|
45
|
-
value: "var(--ds-popup-enter-bottom, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInBottom8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)"
|
|
46
|
-
}, {
|
|
47
|
-
property: '--ds-popover-motion-exit',
|
|
48
|
-
value: "var(--ds-popup-exit-bottom, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutBottom8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
49
|
-
}];
|
|
50
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { getPlacement } from '../internal/resolve-placement';
|
|
2
|
-
export function getPopupMotionStyles({
|
|
3
|
-
placement
|
|
4
|
-
}) {
|
|
5
|
-
const {
|
|
6
|
-
axis,
|
|
7
|
-
edge
|
|
8
|
-
} = getPlacement({
|
|
9
|
-
placement
|
|
10
|
-
});
|
|
11
|
-
if (axis === 'block' && edge === 'start') {
|
|
12
|
-
return [{
|
|
13
|
-
property: '--ds-popover-motion-enter',
|
|
14
|
-
value: "var(--ds-popup-enter-top, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInTop8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)"
|
|
15
|
-
}, {
|
|
16
|
-
property: '--ds-popover-motion-exit',
|
|
17
|
-
value: "var(--ds-popup-exit-top, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutTop8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
18
|
-
}];
|
|
19
|
-
}
|
|
20
|
-
if (axis === 'inline' && edge === 'start') {
|
|
21
|
-
return [{
|
|
22
|
-
property: '--ds-popover-motion-enter',
|
|
23
|
-
value: "var(--ds-popup-enter-left, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInLeft8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)"
|
|
24
|
-
}, {
|
|
25
|
-
property: '--ds-popover-motion-exit',
|
|
26
|
-
value: "var(--ds-popup-exit-left, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutLeft8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
27
|
-
}];
|
|
28
|
-
}
|
|
29
|
-
if (axis === 'inline' && edge === 'end') {
|
|
30
|
-
return [{
|
|
31
|
-
property: '--ds-popover-motion-enter',
|
|
32
|
-
value: "var(--ds-popup-enter-right, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInRight8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)"
|
|
33
|
-
}, {
|
|
34
|
-
property: '--ds-popover-motion-exit',
|
|
35
|
-
value: "var(--ds-popup-exit-right, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutRight8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
36
|
-
}];
|
|
37
|
-
}
|
|
38
|
-
// Default: block/end (popover below trigger)
|
|
39
|
-
return [{
|
|
40
|
-
property: '--ds-popover-motion-enter',
|
|
41
|
-
value: "var(--ds-popup-enter-bottom, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInBottom8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)"
|
|
42
|
-
}, {
|
|
43
|
-
property: '--ds-popover-motion-exit',
|
|
44
|
-
value: "var(--ds-popup-exit-bottom, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutBottom8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
45
|
-
}];
|
|
46
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { getPlacement } from '../internal/resolve-placement';
|
|
2
|
-
export function getPopupMotionStyles(_ref) {
|
|
3
|
-
var placement = _ref.placement;
|
|
4
|
-
var _getPlacement = getPlacement({
|
|
5
|
-
placement: placement
|
|
6
|
-
}),
|
|
7
|
-
axis = _getPlacement.axis,
|
|
8
|
-
edge = _getPlacement.edge;
|
|
9
|
-
if (axis === 'block' && edge === 'start') {
|
|
10
|
-
return [{
|
|
11
|
-
property: '--ds-popover-motion-enter',
|
|
12
|
-
value: "var(--ds-popup-enter-top, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInTop8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)"
|
|
13
|
-
}, {
|
|
14
|
-
property: '--ds-popover-motion-exit',
|
|
15
|
-
value: "var(--ds-popup-exit-top, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutTop8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
16
|
-
}];
|
|
17
|
-
}
|
|
18
|
-
if (axis === 'inline' && edge === 'start') {
|
|
19
|
-
return [{
|
|
20
|
-
property: '--ds-popover-motion-enter',
|
|
21
|
-
value: "var(--ds-popup-enter-left, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInLeft8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)"
|
|
22
|
-
}, {
|
|
23
|
-
property: '--ds-popover-motion-exit',
|
|
24
|
-
value: "var(--ds-popup-exit-left, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutLeft8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
25
|
-
}];
|
|
26
|
-
}
|
|
27
|
-
if (axis === 'inline' && edge === 'end') {
|
|
28
|
-
return [{
|
|
29
|
-
property: '--ds-popover-motion-enter',
|
|
30
|
-
value: "var(--ds-popup-enter-right, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInRight8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)"
|
|
31
|
-
}, {
|
|
32
|
-
property: '--ds-popover-motion-exit',
|
|
33
|
-
value: "var(--ds-popup-exit-right, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutRight8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
34
|
-
}];
|
|
35
|
-
}
|
|
36
|
-
// Default: block/end (popover below trigger)
|
|
37
|
-
return [{
|
|
38
|
-
property: '--ds-popover-motion-enter',
|
|
39
|
-
value: "var(--ds-popup-enter-bottom, 150ms cubic-bezier(0.4, 1, 0.6, 1) SlideInBottom8px, 150ms cubic-bezier(0.4, 1, 0.6, 1) FadeIn0to100)"
|
|
40
|
-
}, {
|
|
41
|
-
property: '--ds-popover-motion-exit',
|
|
42
|
-
value: "var(--ds-popup-exit-bottom, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) SlideOutBottom8px, 100ms cubic-bezier(0.6, 0, 0.8, 0.6) FadeOut100to0)"
|
|
43
|
-
}];
|
|
44
|
-
}
|