@atlaskit/top-layer 0.12.0 → 0.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/cjs/animations/presets.js +5 -5
- package/dist/cjs/dialog/create-close-event.js +1 -1
- package/dist/cjs/dialog/dialog-content.js +5 -5
- package/dist/cjs/entry-points/use-arrow-navigation.js +3 -2
- package/dist/cjs/internal/ensure-preset-styles.js +1 -1
- package/dist/cjs/internal/placement-to-position-area.js +43 -0
- package/dist/cjs/internal/placement-to-try-fallbacks.js +82 -0
- package/dist/cjs/internal/reduced-motion.js +1 -1
- package/dist/cjs/internal/resolve-placement.js +2 -2
- package/dist/cjs/internal/role-types.js +1 -1
- package/dist/cjs/internal/slot.js +3 -3
- package/dist/cjs/internal/use-anchor-position.js +33 -161
- package/dist/cjs/internal/use-animated-visibility.js +10 -10
- package/dist/cjs/internal/use-animation-preset.js +1 -1
- package/dist/cjs/internal/use-preset-styles.js +1 -1
- package/dist/cjs/internal/use-width-from-anchor.js +4 -4
- package/dist/cjs/popover/create-close-event.js +1 -1
- package/dist/cjs/popover/popover.js +3 -3
- package/dist/cjs/popup/popup-content.js +6 -6
- package/dist/cjs/popup/popup-context.js +2 -38
- package/dist/cjs/popup/popup-provider.js +15 -0
- package/dist/cjs/popup/popup-trigger-function.js +2 -2
- package/dist/cjs/popup/popup-trigger.js +2 -2
- package/dist/cjs/popup/popup.js +2 -2
- package/dist/cjs/popup/use-maybe-popup-context.js +17 -0
- package/dist/cjs/popup/use-popup-context.js +20 -0
- package/dist/cjs/testing/polyfill.js +8 -8
- package/dist/cjs/testing/to-be-visible.js +5 -5
- package/dist/cjs/use-arrow-navigation/index.js +3 -2
- package/dist/cjs/use-arrow-navigation/is-at-current-menu-level.js +94 -0
- package/dist/cjs/use-arrow-navigation/use-arrow-navigation.js +0 -82
- package/dist/cjs/use-simple-light-dismiss/index.js +3 -3
- package/dist/es2019/animations/presets.js +5 -5
- package/dist/es2019/dialog/create-close-event.js +1 -1
- package/dist/es2019/dialog/dialog-content.js +5 -5
- package/dist/es2019/entry-points/use-arrow-navigation.js +2 -1
- package/dist/es2019/internal/ensure-preset-styles.js +1 -1
- package/dist/es2019/internal/placement-to-position-area.js +40 -0
- package/dist/es2019/internal/placement-to-try-fallbacks.js +77 -0
- package/dist/es2019/internal/reduced-motion.js +1 -1
- package/dist/es2019/internal/resolve-placement.js +2 -2
- package/dist/es2019/internal/role-types.js +1 -1
- package/dist/es2019/internal/slot.js +3 -3
- package/dist/es2019/internal/use-anchor-position.js +15 -132
- package/dist/es2019/internal/use-animated-visibility.js +10 -10
- package/dist/es2019/internal/use-animation-preset.js +1 -1
- package/dist/es2019/internal/use-preset-styles.js +1 -1
- package/dist/es2019/internal/use-width-from-anchor.js +4 -4
- package/dist/es2019/popover/create-close-event.js +1 -1
- package/dist/es2019/popover/popover.js +3 -3
- package/dist/es2019/popup/popup-content.js +6 -5
- package/dist/es2019/popup/popup-context.js +2 -36
- package/dist/es2019/popup/popup-provider.js +10 -0
- package/dist/es2019/popup/popup-trigger-function.js +1 -1
- package/dist/es2019/popup/popup-trigger.js +2 -1
- package/dist/es2019/popup/popup.js +1 -1
- package/dist/es2019/popup/use-maybe-popup-context.js +12 -0
- package/dist/es2019/popup/use-popup-context.js +15 -0
- package/dist/es2019/testing/polyfill.js +8 -8
- package/dist/es2019/testing/to-be-visible.js +5 -5
- package/dist/es2019/use-arrow-navigation/index.js +2 -1
- package/dist/es2019/use-arrow-navigation/is-at-current-menu-level.js +88 -0
- package/dist/es2019/use-arrow-navigation/use-arrow-navigation.js +0 -81
- package/dist/es2019/use-simple-light-dismiss/index.js +3 -3
- package/dist/esm/animations/presets.js +5 -5
- package/dist/esm/dialog/create-close-event.js +1 -1
- package/dist/esm/dialog/dialog-content.js +5 -5
- package/dist/esm/entry-points/use-arrow-navigation.js +2 -1
- package/dist/esm/internal/ensure-preset-styles.js +1 -1
- package/dist/esm/internal/placement-to-position-area.js +38 -0
- package/dist/esm/internal/placement-to-try-fallbacks.js +76 -0
- package/dist/esm/internal/reduced-motion.js +1 -1
- package/dist/esm/internal/resolve-placement.js +2 -2
- package/dist/esm/internal/role-types.js +1 -1
- package/dist/esm/internal/slot.js +3 -3
- package/dist/esm/internal/use-anchor-position.js +31 -157
- package/dist/esm/internal/use-animated-visibility.js +10 -10
- package/dist/esm/internal/use-animation-preset.js +1 -1
- package/dist/esm/internal/use-preset-styles.js +1 -1
- package/dist/esm/internal/use-width-from-anchor.js +4 -4
- package/dist/esm/popover/create-close-event.js +1 -1
- package/dist/esm/popover/popover.js +3 -3
- package/dist/esm/popup/popup-content.js +6 -5
- package/dist/esm/popup/popup-context.js +2 -36
- package/dist/esm/popup/popup-provider.js +10 -0
- package/dist/esm/popup/popup-trigger-function.js +1 -1
- package/dist/esm/popup/popup-trigger.js +2 -1
- package/dist/esm/popup/popup.js +1 -1
- package/dist/esm/popup/use-maybe-popup-context.js +12 -0
- package/dist/esm/popup/use-popup-context.js +15 -0
- package/dist/esm/testing/polyfill.js +8 -8
- package/dist/esm/testing/to-be-visible.js +5 -5
- package/dist/esm/use-arrow-navigation/index.js +2 -1
- package/dist/esm/use-arrow-navigation/is-at-current-menu-level.js +88 -0
- package/dist/esm/use-arrow-navigation/use-arrow-navigation.js +0 -81
- package/dist/esm/use-simple-light-dismiss/index.js +3 -3
- package/dist/types/dialog/create-close-event.d.ts +1 -1
- package/dist/types/dialog/types.d.ts +8 -0
- package/dist/types/entry-points/use-arrow-navigation.d.ts +2 -1
- package/dist/types/internal/placement-to-position-area.d.ts +21 -0
- package/dist/types/internal/placement-to-try-fallbacks.d.ts +36 -0
- package/dist/types/internal/reduced-motion.d.ts +1 -1
- package/dist/types/internal/resolve-placement.d.ts +2 -2
- package/dist/types/internal/slot.d.ts +4 -4
- package/dist/types/internal/use-anchor-position.d.ts +0 -55
- package/dist/types/internal/use-animated-visibility.d.ts +3 -3
- package/dist/types/internal/use-animation-preset.d.ts +1 -1
- package/dist/types/internal/use-preset-styles.d.ts +1 -1
- package/dist/types/internal/use-width-from-anchor.d.ts +2 -2
- package/dist/types/popover/create-close-event.d.ts +1 -1
- package/dist/types/popover/popover.d.ts +1 -1
- package/dist/types/popup/popup-context.d.ts +2 -22
- package/dist/types/popup/popup-provider.d.ts +10 -0
- package/dist/types/popup/use-maybe-popup-context.d.ts +8 -0
- package/dist/types/popup/use-popup-context.d.ts +7 -0
- package/dist/types/testing/to-be-visible.d.ts +3 -3
- package/dist/types/use-arrow-navigation/index.d.ts +2 -1
- package/dist/types/use-arrow-navigation/is-at-current-menu-level.d.ts +48 -0
- package/dist/types/use-arrow-navigation/use-arrow-navigation.d.ts +0 -48
- package/dist/types/use-simple-light-dismiss/index.d.ts +1 -1
- package/dist/types-ts4.5/dialog/create-close-event.d.ts +1 -1
- package/dist/types-ts4.5/dialog/types.d.ts +8 -0
- package/dist/types-ts4.5/entry-points/use-arrow-navigation.d.ts +2 -1
- package/dist/types-ts4.5/internal/placement-to-position-area.d.ts +21 -0
- package/dist/types-ts4.5/internal/placement-to-try-fallbacks.d.ts +36 -0
- package/dist/types-ts4.5/internal/reduced-motion.d.ts +1 -1
- package/dist/types-ts4.5/internal/resolve-placement.d.ts +2 -2
- package/dist/types-ts4.5/internal/slot.d.ts +4 -4
- package/dist/types-ts4.5/internal/use-anchor-position.d.ts +0 -55
- package/dist/types-ts4.5/internal/use-animated-visibility.d.ts +3 -3
- package/dist/types-ts4.5/internal/use-animation-preset.d.ts +1 -1
- package/dist/types-ts4.5/internal/use-preset-styles.d.ts +1 -1
- package/dist/types-ts4.5/internal/use-width-from-anchor.d.ts +2 -2
- package/dist/types-ts4.5/popover/create-close-event.d.ts +1 -1
- package/dist/types-ts4.5/popover/popover.d.ts +1 -1
- package/dist/types-ts4.5/popup/popup-context.d.ts +2 -22
- package/dist/types-ts4.5/popup/popup-provider.d.ts +10 -0
- package/dist/types-ts4.5/popup/use-maybe-popup-context.d.ts +8 -0
- package/dist/types-ts4.5/popup/use-popup-context.d.ts +7 -0
- package/dist/types-ts4.5/testing/to-be-visible.d.ts +3 -3
- package/dist/types-ts4.5/use-arrow-navigation/index.d.ts +2 -1
- package/dist/types-ts4.5/use-arrow-navigation/is-at-current-menu-level.d.ts +48 -0
- package/dist/types-ts4.5/use-arrow-navigation/use-arrow-navigation.d.ts +0 -48
- package/dist/types-ts4.5/use-simple-light-dismiss/index.d.ts +1 -1
- package/package.json +2 -2
- package/dist/cjs/arrow/index.js +0 -131
- package/dist/cjs/arrow/types.js +0 -5
- package/dist/es2019/arrow/index.js +0 -269
- package/dist/es2019/arrow/types.js +0 -1
- package/dist/esm/arrow/index.js +0 -124
- package/dist/esm/arrow/types.js +0 -1
- package/dist/types/arrow/index.d.ts +0 -24
- package/dist/types/arrow/types.d.ts +0 -29
- package/dist/types-ts4.5/arrow/index.d.ts +0 -24
- package/dist/types-ts4.5/arrow/types.d.ts +0 -29
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getPlacement } from '../internal/resolve-placement';
|
|
2
2
|
|
|
3
|
-
//
|
|
3
|
+
// slideAndFade
|
|
4
4
|
|
|
5
5
|
function getSlideAndFadeProperties(_ref) {
|
|
6
6
|
var placement = _ref.placement,
|
|
@@ -82,7 +82,7 @@ export function slideAndFade(options) {
|
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
//
|
|
85
|
+
// fade
|
|
86
86
|
|
|
87
87
|
var FADE_CSS = "\n[data-ds-popover-fade] {\n opacity: 0;\n transition:\n opacity 175ms cubic-bezier(0.15, 1, 0.3, 1),\n overlay 175ms allow-discrete,\n display 175ms allow-discrete;\n}\n\n[data-ds-popover-fade]:popover-open {\n opacity: 1;\n transition-duration: 350ms;\n}\n\n@starting-style {\n [data-ds-popover-fade]:popover-open {\n opacity: 0;\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n [data-ds-popover-fade],\n [data-ds-popover-fade]:popover-open {\n transition-duration: 0s;\n }\n}\n";
|
|
88
88
|
|
|
@@ -108,7 +108,7 @@ export function fade() {
|
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
//
|
|
111
|
+
// scaleAndFade
|
|
112
112
|
|
|
113
113
|
var SCALE_AND_FADE_CSS = "\n[data-ds-popover-scale-and-fade] {\n opacity: 0;\n transform: scale(0.95);\n transition:\n opacity 175ms cubic-bezier(0.15, 1, 0.3, 1),\n transform 175ms cubic-bezier(0.15, 1, 0.3, 1),\n overlay 175ms allow-discrete,\n display 175ms allow-discrete;\n}\n\n[data-ds-popover-scale-and-fade]:popover-open {\n opacity: 1;\n transform: none;\n transition-duration: 350ms;\n}\n\n@starting-style {\n [data-ds-popover-scale-and-fade]:popover-open {\n opacity: 0;\n transform: scale(0.95);\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n [data-ds-popover-scale-and-fade],\n [data-ds-popover-scale-and-fade]:popover-open {\n transition-duration: 0s;\n }\n}\n";
|
|
114
114
|
|
|
@@ -138,7 +138,7 @@ export function scaleAndFade() {
|
|
|
138
138
|
// Dialog presets
|
|
139
139
|
// ══════════════════════════════════════════════════════════════════════════════
|
|
140
140
|
|
|
141
|
-
//
|
|
141
|
+
// dialogSlideUpAndFade
|
|
142
142
|
|
|
143
143
|
var DIALOG_SLIDE_UP_AND_FADE_CSS = "\n[data-ds-dialog-slide-up-and-fade] {\n opacity: 0;\n transform: translateY(calc(-1 * var(--ds-dialog-ty, 12px)));\n transition:\n opacity 175ms cubic-bezier(0.15, 1, 0.3, 1),\n transform 175ms cubic-bezier(0.15, 1, 0.3, 1),\n overlay 175ms allow-discrete,\n display 175ms allow-discrete;\n}\n\n[data-ds-dialog-slide-up-and-fade][open] {\n opacity: 1;\n transform: none;\n transition-duration: 350ms;\n}\n\n@starting-style {\n [data-ds-dialog-slide-up-and-fade][open] {\n opacity: 0;\n transform: translateY(var(--ds-dialog-ty, 12px));\n }\n}\n\n[data-ds-dialog-slide-up-and-fade]::backdrop {\n background-color: transparent;\n transition:\n background-color 175ms cubic-bezier(0.15, 1, 0.3, 1),\n overlay 175ms allow-discrete,\n display 175ms allow-discrete;\n}\n\n[data-ds-dialog-slide-up-and-fade][open]::backdrop {\n background-color: var(--ds-blanket, #050C1F75);\n transition-duration: 350ms;\n}\n\n@starting-style {\n [data-ds-dialog-slide-up-and-fade][open]::backdrop {\n background-color: transparent;\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n [data-ds-dialog-slide-up-and-fade],\n [data-ds-dialog-slide-up-and-fade][open],\n [data-ds-dialog-slide-up-and-fade]::backdrop,\n [data-ds-dialog-slide-up-and-fade][open]::backdrop {\n transition-duration: 0s;\n }\n}\n";
|
|
144
144
|
|
|
@@ -174,7 +174,7 @@ export function dialogSlideUpAndFade(options) {
|
|
|
174
174
|
};
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
//
|
|
177
|
+
// dialogFade
|
|
178
178
|
|
|
179
179
|
var DIALOG_FADE_CSS = "\n[data-ds-dialog-fade] {\n opacity: 0;\n transition:\n opacity 175ms cubic-bezier(0.15, 1, 0.3, 1),\n overlay 175ms allow-discrete,\n display 175ms allow-discrete;\n}\n\n[data-ds-dialog-fade][open] {\n opacity: 1;\n transition-duration: 350ms;\n}\n\n@starting-style {\n [data-ds-dialog-fade][open] {\n opacity: 0;\n }\n}\n\n[data-ds-dialog-fade]::backdrop {\n background-color: transparent;\n transition:\n background-color 175ms cubic-bezier(0.15, 1, 0.3, 1),\n overlay 175ms allow-discrete,\n display 175ms allow-discrete;\n}\n\n[data-ds-dialog-fade][open]::backdrop {\n background-color: var(--ds-blanket, #050C1F75);\n transition-duration: 350ms;\n}\n\n@starting-style {\n [data-ds-dialog-fade][open]::backdrop {\n background-color: transparent;\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n [data-ds-dialog-fade],\n [data-ds-dialog-fade][open],\n [data-ds-dialog-fade]::backdrop,\n [data-ds-dialog-fade][open]::backdrop {\n transition-duration: 0s;\n }\n}\n";
|
|
180
180
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Creates a synthetic DOM event from a `TDialogCloseReason`.
|
|
3
3
|
*
|
|
4
4
|
* Useful when bridging the Dialog primitive's `onClose({ reason })` callback
|
|
5
|
-
* to a legacy API that expects a `KeyboardEvent` or `MouseEvent`
|
|
5
|
+
* to a legacy API that expects a `KeyboardEvent` or `MouseEvent` - for example,
|
|
6
6
|
* `@atlaskit/modal-dialog`'s `onClose(event, analyticsEvent)` contract.
|
|
7
7
|
*
|
|
8
8
|
* - `'escape'` → `KeyboardEvent('keydown', { key: 'Escape' })`
|
|
@@ -49,7 +49,7 @@ export var Dialog = /*#__PURE__*/forwardRef(function Dialog(_ref, ref) {
|
|
|
49
49
|
var ownRef = useRef(null);
|
|
50
50
|
var combinedRef = mergeRefs([ownRef, ref]);
|
|
51
51
|
|
|
52
|
-
//
|
|
52
|
+
// Animation lifecycle
|
|
53
53
|
var _useAnimatedVisibilit = useAnimatedVisibility({
|
|
54
54
|
isOpen: isOpen,
|
|
55
55
|
animate: animate,
|
|
@@ -59,7 +59,7 @@ export var Dialog = /*#__PURE__*/forwardRef(function Dialog(_ref, ref) {
|
|
|
59
59
|
showChildren = _useAnimatedVisibilit.showChildren,
|
|
60
60
|
preset = _useAnimatedVisibilit.preset;
|
|
61
61
|
|
|
62
|
-
//
|
|
62
|
+
// Focus wrap
|
|
63
63
|
// Native <dialog>.showModal() traps focus but wraps through <body> at
|
|
64
64
|
// the boundary (A → B → C → body → A). This hook intercepts Tab to
|
|
65
65
|
// wrap directly (A → B → C → A), matching the WAI-ARIA APG pattern.
|
|
@@ -68,7 +68,7 @@ export var Dialog = /*#__PURE__*/forwardRef(function Dialog(_ref, ref) {
|
|
|
68
68
|
role: 'dialog'
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
-
//
|
|
71
|
+
// Open layer observer registration
|
|
72
72
|
// Notifies the open layer observer so app-coordination features
|
|
73
73
|
// (open-count subscriptions) work with top-layer dialogs.
|
|
74
74
|
useNotifyOpenLayerObserver({
|
|
@@ -99,7 +99,7 @@ export var Dialog = /*#__PURE__*/forwardRef(function Dialog(_ref, ref) {
|
|
|
99
99
|
}
|
|
100
100
|
}, [isOpen]);
|
|
101
101
|
|
|
102
|
-
//
|
|
102
|
+
// Handle native Escape (cancel event)
|
|
103
103
|
var handleCancel = useCallback(function (event) {
|
|
104
104
|
event.preventDefault();
|
|
105
105
|
onClose({
|
|
@@ -107,7 +107,7 @@ export var Dialog = /*#__PURE__*/forwardRef(function Dialog(_ref, ref) {
|
|
|
107
107
|
});
|
|
108
108
|
}, [onClose]);
|
|
109
109
|
|
|
110
|
-
//
|
|
110
|
+
// Handle backdrop click
|
|
111
111
|
// Attached via bind-event-listener rather than a React prop so we avoid
|
|
112
112
|
// a11y lint suppressions on the <dialog> element.
|
|
113
113
|
// Keyboard dismiss is already handled natively (Escape → onCancel above).
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { useArrowNavigation
|
|
1
|
+
export { useArrowNavigation } from '../use-arrow-navigation';
|
|
2
|
+
export { isAtCurrentMenuLevel } from '../use-arrow-navigation/is-at-current-menu-level';
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Each preset's CSS is injected at most once into `<head>`.
|
|
5
5
|
* Shared by both PopoverContent and DialogContent.
|
|
6
6
|
*
|
|
7
|
-
* Note: injected `<style>` elements and the tracking Set are append-only
|
|
7
|
+
* Note: injected `<style>` elements and the tracking Set are append-only -
|
|
8
8
|
* they are never removed. This is intentional: the number of distinct
|
|
9
9
|
* presets is bounded (handful of animation presets), so the
|
|
10
10
|
* memory footprint is negligible. Removing styles would risk breaking
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { getPlacement } from './resolve-placement';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resolves placement options to CSS `position-area` syntax.
|
|
5
|
+
*
|
|
6
|
+
* The `align` field represents the *visual* alignment:
|
|
7
|
+
* - `align: 'start'` means "aligned to the trigger's start edge" (left in LTR for block axis)
|
|
8
|
+
* - `align: 'end'` means "aligned to the trigger's end edge"
|
|
9
|
+
* - `align: 'center'` means centered (single-axis position-area)
|
|
10
|
+
*
|
|
11
|
+
* CSS `position-area` uses `span-*` keywords which indicate the *expansion direction*.
|
|
12
|
+
* Visual start-alignment requires `span-{cross-axis}-end` (expand toward end = start-aligned).
|
|
13
|
+
* This function handles the inversion internally.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* placementToPositionArea({ placement: { axis: 'block', edge: 'end', align: 'center' } }) // → 'block-end'
|
|
17
|
+
* placementToPositionArea({ placement: { axis: 'block', edge: 'end', align: 'start' } }) // → 'block-end span-inline-end'
|
|
18
|
+
* placementToPositionArea({ placement: { axis: 'block', edge: 'end', align: 'end' } }) // → 'block-end span-inline-start'
|
|
19
|
+
*/
|
|
20
|
+
export function placementToPositionArea(_ref) {
|
|
21
|
+
var placement = _ref.placement;
|
|
22
|
+
var _getPlacement = getPlacement({
|
|
23
|
+
placement: placement
|
|
24
|
+
}),
|
|
25
|
+
axis = _getPlacement.axis,
|
|
26
|
+
edge = _getPlacement.edge,
|
|
27
|
+
align = _getPlacement.align;
|
|
28
|
+
var edgeValue = "".concat(axis, "-").concat(edge);
|
|
29
|
+
if (align === 'center') {
|
|
30
|
+
return edgeValue;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Cross-axis name: block ↔ inline
|
|
34
|
+
var crossAxis = axis === 'block' ? 'inline' : 'block';
|
|
35
|
+
// Invert align → CSS span direction: visual 'start' → span toward 'end'
|
|
36
|
+
var spanDir = align === 'start' ? 'end' : 'start';
|
|
37
|
+
return "".concat(edgeValue, " span-").concat(crossAxis, "-").concat(spanDir);
|
|
38
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import { getPlacement } from './resolve-placement';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns `position-try-fallbacks` value based on placement.
|
|
6
|
+
*
|
|
7
|
+
* For centered placements, includes cross-axis aligned position-area
|
|
8
|
+
* values so the browser can shift the popover along the cross-axis
|
|
9
|
+
* when the centered position would overflow the viewport edge.
|
|
10
|
+
*
|
|
11
|
+
* Fallback order for centered placements (e.g. `block-end`):
|
|
12
|
+
* 1. Same edge, start-aligned (shift for near-edge overflow)
|
|
13
|
+
* 2. Same edge, end-aligned (shift for far-edge overflow)
|
|
14
|
+
* 3. Flipped edge, centered
|
|
15
|
+
* 4. Flipped edge, start-aligned
|
|
16
|
+
* 5. Flipped edge, end-aligned
|
|
17
|
+
*
|
|
18
|
+
* For aligned placements (start/end), includes the same-edge centered
|
|
19
|
+
* position as fallbacks so the browser can try centering when the aligned
|
|
20
|
+
* position would overflow, before flipping to the opposite edge.
|
|
21
|
+
*
|
|
22
|
+
* **Why `flip-inline flip-block` (or `flip-block flip-inline`) is included:**
|
|
23
|
+
*
|
|
24
|
+
* When a popup is in a viewport corner (e.g. inline-end align-end at the
|
|
25
|
+
* top-right), flipping only the primary axis (`flip-inline`) moves the popup
|
|
26
|
+
* to the left but keeps the same cross-axis span direction (e.g. upward),
|
|
27
|
+
* which is still off-screen. The combined keyword `flip-inline flip-block`
|
|
28
|
+
* mirrors the popup diagonally. It flips BOTH the position-area AND both
|
|
29
|
+
* inline and block margins simultaneously, placing the popup at the
|
|
30
|
+
* diagonally opposite corner where there is always space.
|
|
31
|
+
*
|
|
32
|
+
* Named `position-area` entries (e.g. `inline-start span-block-end`) in
|
|
33
|
+
* `position-try-fallbacks` do NOT update margins, so only the `flip-*`
|
|
34
|
+
* tactic keywords correctly flip the gap margin along with the position.
|
|
35
|
+
*/
|
|
36
|
+
export function placementToTryFallbacks(_ref) {
|
|
37
|
+
var placement = _ref.placement;
|
|
38
|
+
var _getPlacement = getPlacement({
|
|
39
|
+
placement: placement
|
|
40
|
+
}),
|
|
41
|
+
axis = _getPlacement.axis,
|
|
42
|
+
edge = _getPlacement.edge,
|
|
43
|
+
align = _getPlacement.align;
|
|
44
|
+
var crossAxis = axis === 'block' ? 'inline' : 'block';
|
|
45
|
+
var flippedEdge = edge === 'start' ? 'end' : 'start';
|
|
46
|
+
var sameEdge = "".concat(axis, "-").concat(edge);
|
|
47
|
+
var oppositeEdge = "".concat(axis, "-").concat(flippedEdge);
|
|
48
|
+
var flipKeyword = axis === 'block' ? 'flip-block' : 'flip-inline';
|
|
49
|
+
var flipCrossKeyword = axis === 'block' ? 'flip-inline' : 'flip-block';
|
|
50
|
+
|
|
51
|
+
// Single algorithm: produce the shift list against any base alignment.
|
|
52
|
+
// For `align: 'start'` the "near" shift expands toward `end`; for
|
|
53
|
+
// `align: 'end'` it expands toward `start`; for `align: 'center'`
|
|
54
|
+
// either order is symmetric (we use end-then-start to match the
|
|
55
|
+
// historical fallback list).
|
|
56
|
+
function shifts(baseAlign, edgeKey) {
|
|
57
|
+
if (baseAlign === 'center') {
|
|
58
|
+
return ["".concat(edgeKey, " span-").concat(crossAxis, "-end"), "".concat(edgeKey, " span-").concat(crossAxis, "-start")];
|
|
59
|
+
}
|
|
60
|
+
var near = baseAlign === 'start' ? 'end' : 'start';
|
|
61
|
+
var far = baseAlign === 'start' ? 'start' : 'end';
|
|
62
|
+
return ["".concat(edgeKey, " span-").concat(crossAxis, "-").concat(near), edgeKey, "".concat(edgeKey, " span-").concat(crossAxis, "-").concat(far)];
|
|
63
|
+
}
|
|
64
|
+
if (align !== 'center') {
|
|
65
|
+
// Aligned (start/end): try same-edge shifts, then single-axis flip,
|
|
66
|
+
// then diagonal flip for corner overflow, then opposite-edge shifts.
|
|
67
|
+
// Legacy Popper fallback ordering for e.g. bottom-start:
|
|
68
|
+
// [bottom, bottom-end, top-start, top, top-end, auto].
|
|
69
|
+
return [].concat(_toConsumableArray(shifts(align, sameEdge)), [flipKeyword, "".concat(flipKeyword, " ").concat(flipCrossKeyword)], _toConsumableArray(shifts(align, oppositeEdge))).join(', ');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Centered: same-edge shifts, single-axis flip, opposite-edge shifts.
|
|
73
|
+
// Diagonal flip is unnecessary because centered placements expand
|
|
74
|
+
// equally in both cross-axis directions.
|
|
75
|
+
return [].concat(_toConsumableArray(shifts('center', sameEdge)), [flipKeyword], _toConsumableArray(shifts('center', oppositeEdge))).join(', ');
|
|
76
|
+
}
|
|
@@ -7,7 +7,7 @@ import once from '@atlaskit/ds-lib/once';
|
|
|
7
7
|
*
|
|
8
8
|
* The result is cached after the first call via `once`. This avoids
|
|
9
9
|
* calling `matchMedia` on every render. The trade-off is that if a user
|
|
10
|
-
* toggles the OS reduced-motion setting mid-session, the change
|
|
10
|
+
* toggles the OS reduced-motion setting mid-session, the change will not
|
|
11
11
|
* take effect until the next page load. This is acceptable because
|
|
12
12
|
* toggling this system-level preference mid-session is extremely rare,
|
|
13
13
|
* and a page refresh is a reasonable expectation for system accessibility
|
|
@@ -25,8 +25,8 @@ var DEFAULT_GAP = "var(--ds-space-100, 8px)";
|
|
|
25
25
|
* CSS length string (e.g. `token('space.100')`).
|
|
26
26
|
*
|
|
27
27
|
* The two offset axes are named for clarity at the call site:
|
|
28
|
-
* - `gap`
|
|
29
|
-
* - `crossAxisShift`
|
|
28
|
+
* - `gap` - distance away from the trigger along the placement axis
|
|
29
|
+
* - `crossAxisShift` - nudge along the trigger edge (perpendicular to the placement axis)
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
32
|
/**
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* (e.g. a combobox labels its listbox, tooltip content IS the accessible name).
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
//
|
|
25
|
+
// Shared ARIA role discrimination types
|
|
26
26
|
//
|
|
27
27
|
// These encode the WCAG 4.1.2 constraint: roles like `dialog`, `alertdialog`,
|
|
28
28
|
// and `menu` MUST have an accessible name (either `label` or `labelledBy`).
|
|
@@ -26,14 +26,14 @@ function isSlotChild(child) {
|
|
|
26
26
|
* Merges props (including ref) onto a single React element child.
|
|
27
27
|
*
|
|
28
28
|
* A safer alternative to raw `cloneElement` that:
|
|
29
|
-
* 1. Guards with `isValidElement`
|
|
29
|
+
* 1. Guards with `isValidElement` - non-element children (strings,
|
|
30
30
|
* fragments, null) are returned as-is instead of crashing.
|
|
31
31
|
* 2. Merges refs via `mergeRefs` so both the caller's ref and the
|
|
32
32
|
* child's existing ref are honoured.
|
|
33
33
|
* 3. Spreads any additional props (ARIA attributes, event handlers, etc.)
|
|
34
34
|
* onto the child element.
|
|
35
35
|
*
|
|
36
|
-
* Event handlers (e.g. `onClick`) are **not** auto-merged
|
|
36
|
+
* Event handlers (e.g. `onClick`) are **not** auto-merged - the caller's
|
|
37
37
|
* handler replaces the child's. Compose handlers before passing them in.
|
|
38
38
|
*
|
|
39
39
|
* @example
|
|
@@ -46,7 +46,7 @@ function isSlotChild(child) {
|
|
|
46
46
|
export var Slot = /*#__PURE__*/forwardRef(function Slot(slotProps, ref) {
|
|
47
47
|
var rawChildren = slotProps.children,
|
|
48
48
|
props = _objectWithoutProperties(slotProps, _excluded);
|
|
49
|
-
// `
|
|
49
|
+
// `TSlotProps` intersects `Record<string, unknown>`, so `children` is typed as `unknown`.
|
|
50
50
|
var children = rawChildren;
|
|
51
51
|
if (!isSlotChild(children)) {
|
|
52
52
|
return children;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
1
|
/**
|
|
5
2
|
* Anchor positioning for top-layer popovers. See
|
|
6
3
|
* `notes/architecture/positioning.md` for the full model.
|
|
@@ -21,6 +18,8 @@ import rafSchedule from 'raf-schd';
|
|
|
21
18
|
import once from '@atlaskit/ds-lib/once';
|
|
22
19
|
import { computeFallbackPosition } from './anchor-positioning-fallback';
|
|
23
20
|
import { combine } from './combine';
|
|
21
|
+
import { placementToPositionArea } from './placement-to-position-area';
|
|
22
|
+
import { placementToTryFallbacks } from './placement-to-try-fallbacks';
|
|
24
23
|
import { resolveCssLengthToPixels } from './resolve-css-length-to-pixels';
|
|
25
24
|
import { getPlacement } from './resolve-placement';
|
|
26
25
|
import { setStyle } from './set-style';
|
|
@@ -29,137 +28,15 @@ import { setStyle } from './set-style';
|
|
|
29
28
|
// from `./resolve-placement` so search-and-jump lands at the source of truth.
|
|
30
29
|
|
|
31
30
|
/**
|
|
32
|
-
* Module-scope no-op `ResizeObserver` used in non-DOM jest environments where
|
|
31
|
+
* Module-scope no-op `ResizeObserver` stub used in non-DOM jest environments where
|
|
33
32
|
* `ResizeObserver` is `undefined`. Hoisted out of the effect to avoid
|
|
34
|
-
* allocating
|
|
33
|
+
* re-allocating on every run.
|
|
35
34
|
*/
|
|
36
|
-
var
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
key: "observe",
|
|
42
|
-
value: function observe() {}
|
|
43
|
-
}, {
|
|
44
|
-
key: "unobserve",
|
|
45
|
-
value: function unobserve() {}
|
|
46
|
-
}, {
|
|
47
|
-
key: "disconnect",
|
|
48
|
-
value: function disconnect() {}
|
|
49
|
-
}]);
|
|
50
|
-
}();
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Resolves placement options to CSS `position-area` syntax.
|
|
54
|
-
*
|
|
55
|
-
* The `align` field represents the *visual* alignment:
|
|
56
|
-
* - `align: 'start'` means "aligned to the trigger's start edge" (left in LTR for block axis)
|
|
57
|
-
* - `align: 'end'` means "aligned to the trigger's end edge"
|
|
58
|
-
* - `align: 'center'` means centered (single-axis position-area)
|
|
59
|
-
*
|
|
60
|
-
* CSS `position-area` uses `span-*` keywords which indicate the *expansion direction*.
|
|
61
|
-
* Visual start-alignment requires `span-{cross-axis}-end` (expand toward end = start-aligned).
|
|
62
|
-
* This function handles the inversion internally.
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* placementToPositionArea({ placement: { axis: 'block', edge: 'end', align: 'center' } }) // → 'block-end'
|
|
66
|
-
* placementToPositionArea({ placement: { axis: 'block', edge: 'end', align: 'start' } }) // → 'block-end span-inline-end'
|
|
67
|
-
* placementToPositionArea({ placement: { axis: 'block', edge: 'end', align: 'end' } }) // → 'block-end span-inline-start'
|
|
68
|
-
*/
|
|
69
|
-
export function placementToPositionArea(_ref) {
|
|
70
|
-
var placement = _ref.placement;
|
|
71
|
-
var _getPlacement = getPlacement({
|
|
72
|
-
placement: placement
|
|
73
|
-
}),
|
|
74
|
-
axis = _getPlacement.axis,
|
|
75
|
-
edge = _getPlacement.edge,
|
|
76
|
-
align = _getPlacement.align;
|
|
77
|
-
var edgeValue = "".concat(axis, "-").concat(edge);
|
|
78
|
-
if (align === 'center') {
|
|
79
|
-
return edgeValue;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Cross-axis name: block ↔ inline
|
|
83
|
-
var crossAxis = axis === 'block' ? 'inline' : 'block';
|
|
84
|
-
// Invert align → CSS span direction: visual 'start' → span toward 'end'
|
|
85
|
-
var spanDir = align === 'start' ? 'end' : 'start';
|
|
86
|
-
return "".concat(edgeValue, " span-").concat(crossAxis, "-").concat(spanDir);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Returns `position-try-fallbacks` value based on placement.
|
|
91
|
-
*
|
|
92
|
-
* For centered placements, includes cross-axis aligned position-area
|
|
93
|
-
* values so the browser can shift the popover along the cross-axis
|
|
94
|
-
* when the centered position would overflow the viewport edge.
|
|
95
|
-
*
|
|
96
|
-
* Fallback order for centered placements (e.g. `block-end`):
|
|
97
|
-
* 1. Same edge, start-aligned (shift for near-edge overflow)
|
|
98
|
-
* 2. Same edge, end-aligned (shift for far-edge overflow)
|
|
99
|
-
* 3. Flipped edge, centered
|
|
100
|
-
* 4. Flipped edge, start-aligned
|
|
101
|
-
* 5. Flipped edge, end-aligned
|
|
102
|
-
*
|
|
103
|
-
* For aligned placements (start/end), includes the same-edge centered
|
|
104
|
-
* position as fallbacks so the browser can try centering when the aligned
|
|
105
|
-
* position would overflow, before flipping to the opposite edge.
|
|
106
|
-
*
|
|
107
|
-
* **Why `flip-inline flip-block` (or `flip-block flip-inline`) is included:**
|
|
108
|
-
*
|
|
109
|
-
* When a popup is in a viewport corner (e.g. inline-end align-end at the
|
|
110
|
-
* top-right), flipping only the primary axis (`flip-inline`) moves the popup
|
|
111
|
-
* to the left but keeps the same cross-axis span direction (e.g. upward),
|
|
112
|
-
* which is still off-screen. The combined keyword `flip-inline flip-block`
|
|
113
|
-
* mirrors the popup diagonally. It flips BOTH the position-area AND both
|
|
114
|
-
* inline and block margins simultaneously, placing the popup at the
|
|
115
|
-
* diagonally opposite corner where there is always space.
|
|
116
|
-
*
|
|
117
|
-
* Named `position-area` entries (e.g. `inline-start span-block-end`) in
|
|
118
|
-
* `position-try-fallbacks` do NOT update margins, so only the `flip-*`
|
|
119
|
-
* tactic keywords correctly flip the gap margin along with the position.
|
|
120
|
-
*/
|
|
121
|
-
// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
|
|
122
|
-
export function placementToTryFallbacks(_ref2) {
|
|
123
|
-
var placement = _ref2.placement;
|
|
124
|
-
var _getPlacement2 = getPlacement({
|
|
125
|
-
placement: placement
|
|
126
|
-
}),
|
|
127
|
-
axis = _getPlacement2.axis,
|
|
128
|
-
edge = _getPlacement2.edge,
|
|
129
|
-
align = _getPlacement2.align;
|
|
130
|
-
var crossAxis = axis === 'block' ? 'inline' : 'block';
|
|
131
|
-
var flippedEdge = edge === 'start' ? 'end' : 'start';
|
|
132
|
-
var sameEdge = "".concat(axis, "-").concat(edge);
|
|
133
|
-
var oppositeEdge = "".concat(axis, "-").concat(flippedEdge);
|
|
134
|
-
var flipKeyword = axis === 'block' ? 'flip-block' : 'flip-inline';
|
|
135
|
-
var flipCrossKeyword = axis === 'block' ? 'flip-inline' : 'flip-block';
|
|
136
|
-
|
|
137
|
-
// Single algorithm: produce the shift list against any base alignment.
|
|
138
|
-
// For `align: 'start'` the "near" shift expands toward `end`; for
|
|
139
|
-
// `align: 'end'` it expands toward `start`; for `align: 'center'`
|
|
140
|
-
// either order is symmetric (we use end-then-start to match the
|
|
141
|
-
// historical fallback list).
|
|
142
|
-
function shifts(baseAlign, edgeKey) {
|
|
143
|
-
if (baseAlign === 'center') {
|
|
144
|
-
return ["".concat(edgeKey, " span-").concat(crossAxis, "-end"), "".concat(edgeKey, " span-").concat(crossAxis, "-start")];
|
|
145
|
-
}
|
|
146
|
-
var near = baseAlign === 'start' ? 'end' : 'start';
|
|
147
|
-
var far = baseAlign === 'start' ? 'start' : 'end';
|
|
148
|
-
return ["".concat(edgeKey, " span-").concat(crossAxis, "-").concat(near), edgeKey, "".concat(edgeKey, " span-").concat(crossAxis, "-").concat(far)];
|
|
149
|
-
}
|
|
150
|
-
if (align !== 'center') {
|
|
151
|
-
// Aligned (start/end): try same-edge shifts, then single-axis flip,
|
|
152
|
-
// then diagonal flip for corner overflow, then opposite-edge shifts.
|
|
153
|
-
// Legacy Popper fallback ordering for e.g. bottom-start:
|
|
154
|
-
// [bottom, bottom-end, top-start, top, top-end, auto].
|
|
155
|
-
return [].concat(_toConsumableArray(shifts(align, sameEdge)), [flipKeyword, "".concat(flipKeyword, " ").concat(flipCrossKeyword)], _toConsumableArray(shifts(align, oppositeEdge))).join(', ');
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// Centered: same-edge shifts, single-axis flip, opposite-edge shifts.
|
|
159
|
-
// Diagonal flip is unnecessary because centered placements expand
|
|
160
|
-
// equally in both cross-axis directions.
|
|
161
|
-
return [].concat(_toConsumableArray(shifts('center', sameEdge)), [flipKeyword], _toConsumableArray(shifts('center', oppositeEdge))).join(', ');
|
|
162
|
-
}
|
|
35
|
+
var noopResizeObserver = {
|
|
36
|
+
observe: function observe() {},
|
|
37
|
+
unobserve: function unobserve() {},
|
|
38
|
+
disconnect: function disconnect() {}
|
|
39
|
+
};
|
|
163
40
|
|
|
164
41
|
/**
|
|
165
42
|
* Returns true when the popover is currently open. Wrapped because the
|
|
@@ -192,9 +69,9 @@ var supportsAnchorPositioning = once(function () {
|
|
|
192
69
|
* For example, a `block-end` placement (popover below) gets
|
|
193
70
|
* `margin-block-start: 8px` to push it away from the trigger's bottom edge.
|
|
194
71
|
*/
|
|
195
|
-
function edgeMargin(
|
|
196
|
-
var placement =
|
|
197
|
-
offset =
|
|
72
|
+
function edgeMargin(_ref) {
|
|
73
|
+
var placement = _ref.placement,
|
|
74
|
+
offset = _ref.offset;
|
|
198
75
|
var axis = placement.axis,
|
|
199
76
|
edge = placement.edge;
|
|
200
77
|
var value = offset;
|
|
@@ -235,10 +112,10 @@ function edgeMargin(_ref3) {
|
|
|
235
112
|
* positive), `align: 'center'` uses START. Margin on the un-anchored side
|
|
236
113
|
* has no effect under CSS Anchor Positioning.
|
|
237
114
|
*/
|
|
238
|
-
function crossAxisShiftMargin(
|
|
239
|
-
var placement =
|
|
240
|
-
crossAxisShiftCssValue =
|
|
241
|
-
direction =
|
|
115
|
+
function crossAxisShiftMargin(_ref2) {
|
|
116
|
+
var placement = _ref2.placement,
|
|
117
|
+
crossAxisShiftCssValue = _ref2.crossAxisShiftCssValue,
|
|
118
|
+
direction = _ref2.direction;
|
|
242
119
|
var axis = placement.axis,
|
|
243
120
|
align = placement.align;
|
|
244
121
|
var directionSign = direction === 'forwards' ? 1 : -1;
|
|
@@ -317,13 +194,13 @@ function useStablePlacement(placement) {
|
|
|
317
194
|
* placement shape is unchanged.
|
|
318
195
|
*/
|
|
319
196
|
// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
|
|
320
|
-
export function useAnchorPosition(
|
|
321
|
-
var anchorRef =
|
|
322
|
-
popoverRef =
|
|
323
|
-
|
|
324
|
-
placement =
|
|
325
|
-
|
|
326
|
-
forceFallbackPositioning =
|
|
197
|
+
export function useAnchorPosition(_ref3) {
|
|
198
|
+
var anchorRef = _ref3.anchorRef,
|
|
199
|
+
popoverRef = _ref3.popoverRef,
|
|
200
|
+
_ref3$placement = _ref3.placement,
|
|
201
|
+
placement = _ref3$placement === void 0 ? {} : _ref3$placement,
|
|
202
|
+
_ref3$forceFallbackPo = _ref3.forceFallbackPositioning,
|
|
203
|
+
forceFallbackPositioning = _ref3$forceFallbackPo === void 0 ? false : _ref3$forceFallbackPo;
|
|
327
204
|
var id = useId();
|
|
328
205
|
// Stabilize `placement` object so the same object literal
|
|
329
206
|
// value returns an object with the same reference
|
|
@@ -449,7 +326,7 @@ export function useAnchorPosition(_ref5) {
|
|
|
449
326
|
return _undoPositioning;
|
|
450
327
|
}
|
|
451
328
|
|
|
452
|
-
//
|
|
329
|
+
// JS fallback
|
|
453
330
|
// The popover is already in the browser's top layer via popover="auto",
|
|
454
331
|
// so it does not need position:fixed. We only reset the UA defaults
|
|
455
332
|
// (inset: 0; margin: auto) and set top/left based on measurements.
|
|
@@ -518,20 +395,17 @@ export function useAnchorPosition(_ref5) {
|
|
|
518
395
|
// Self-disconnects after one valid measurement; ongoing
|
|
519
396
|
// scroll/resize is handled by the window listeners below.
|
|
520
397
|
// `ResizeObserver` is missing in some non-DOM jest environments
|
|
521
|
-
// (e.g. post-office's `node` environment). Fall back to
|
|
522
|
-
//
|
|
523
|
-
// the popover positioned in the rare
|
|
524
|
-
// polyfilled `showPopover` but not
|
|
525
|
-
// browsers always have it.
|
|
526
|
-
|
|
527
|
-
// a new constructor on every effect run.
|
|
528
|
-
var ResizeObserverImpl = typeof ResizeObserver !== 'undefined' ? ResizeObserver : NoopResizeObserver;
|
|
529
|
-
var resizeObserver = new ResizeObserverImpl(function () {
|
|
398
|
+
// (e.g. post-office's `node` environment). Fall back to the
|
|
399
|
+
// module-scope `noopResizeObserver` stub there. The scroll/resize
|
|
400
|
+
// listeners below still keep the popover positioned in the rare
|
|
401
|
+
// case the consumer also polyfilled `showPopover` but not
|
|
402
|
+
// `ResizeObserver`. Real browsers always have it.
|
|
403
|
+
var resizeObserver = typeof ResizeObserver !== 'undefined' ? new ResizeObserver(function () {
|
|
530
404
|
if (popover.offsetWidth > 0 && popover.offsetHeight > 0) {
|
|
531
405
|
update();
|
|
532
406
|
resizeObserver.disconnect();
|
|
533
407
|
}
|
|
534
|
-
});
|
|
408
|
+
}) : noopResizeObserver;
|
|
535
409
|
|
|
536
410
|
// If the popover is already open by the time this effect runs (for
|
|
537
411
|
// example, the parent `useAnchorPosition` effect runs after the child
|
|
@@ -8,19 +8,19 @@ import { usePresetStyles } from './use-preset-styles';
|
|
|
8
8
|
*
|
|
9
9
|
* Used by both `Popover` and `Dialog` to share the same animation lifecycle
|
|
10
10
|
* logic. Those components own their own show/hide mechanisms (showPopover /
|
|
11
|
-
* hidePopover vs showModal / close) and event handling
|
|
11
|
+
* hidePopover vs showModal / close) and event handling - this hook only
|
|
12
12
|
* manages the relationship between `isOpen` and when children are rendered.
|
|
13
13
|
*
|
|
14
14
|
* ## Problem
|
|
15
15
|
*
|
|
16
16
|
* We want to delay the unmount of children until a CSS exit transition has
|
|
17
17
|
* finished playing. If we unmount children the moment `isOpen` becomes
|
|
18
|
-
* `false`, the exit animation is never visible
|
|
18
|
+
* `false`, the exit animation is never visible - the content just disappears.
|
|
19
19
|
*
|
|
20
20
|
* ## How it works
|
|
21
21
|
*
|
|
22
22
|
* `showChildren` tracks whether the consumer's children should be in the DOM.
|
|
23
|
-
* It does not mirror `isOpen` exactly
|
|
23
|
+
* It does not mirror `isOpen` exactly - it intentionally lags behind during
|
|
24
24
|
* exit animations:
|
|
25
25
|
*
|
|
26
26
|
* ```
|
|
@@ -56,12 +56,12 @@ export function useAnimatedVisibility(_ref) {
|
|
|
56
56
|
// or the user has enabled the "prefers reduced motion" OS setting.
|
|
57
57
|
var willAnimate = Boolean(animate) && !prefersReducedMotion();
|
|
58
58
|
|
|
59
|
-
//
|
|
59
|
+
// showChildren state
|
|
60
60
|
//
|
|
61
61
|
// This is the core of the hook. `showChildren` controls whether the
|
|
62
62
|
// consumer's children are in the DOM. The two `if` blocks below are
|
|
63
63
|
// intentionally written as synchronous state updates during render
|
|
64
|
-
// (React supports this pattern
|
|
64
|
+
// (React supports this pattern - setState during render is treated as
|
|
65
65
|
// a synchronous re-render before the browser paints).
|
|
66
66
|
//
|
|
67
67
|
// Mount path: isOpen went true but showChildren is still false → mount.
|
|
@@ -88,7 +88,7 @@ export function useAnimatedVisibility(_ref) {
|
|
|
88
88
|
var onExitFinishRef = useRef(onExitFinish);
|
|
89
89
|
onExitFinishRef.current = onExitFinish;
|
|
90
90
|
|
|
91
|
-
//
|
|
91
|
+
// Animated entry effect
|
|
92
92
|
//
|
|
93
93
|
// Fires `onEnterFinish` after the entry transition completes.
|
|
94
94
|
// When there is no animation, fires it immediately via a separate effect.
|
|
@@ -137,7 +137,7 @@ export function useAnimatedVisibility(_ref) {
|
|
|
137
137
|
};
|
|
138
138
|
}, [isOpen, showChildren, willAnimate, preset === null || preset === void 0 ? void 0 : preset.enterDurationMs, elementRef]);
|
|
139
139
|
|
|
140
|
-
//
|
|
140
|
+
// Non-animated entry callback
|
|
141
141
|
//
|
|
142
142
|
// When there is no animation, fire `onEnterFinish` immediately on mount and after `isOpen` goes false->true.
|
|
143
143
|
// The initial value is false to make sure it fires on mount if the current `isOpen` is true.
|
|
@@ -151,7 +151,7 @@ export function useAnimatedVisibility(_ref) {
|
|
|
151
151
|
}
|
|
152
152
|
}, [isOpen, willAnimate]);
|
|
153
153
|
|
|
154
|
-
//
|
|
154
|
+
// Animated exit effect
|
|
155
155
|
//
|
|
156
156
|
// Runs when all three conditions are true:
|
|
157
157
|
// • `isOpen` is false (consumer wants to close)
|
|
@@ -214,10 +214,10 @@ export function useAnimatedVisibility(_ref) {
|
|
|
214
214
|
};
|
|
215
215
|
}, [isOpen, showChildren, willAnimate, preset === null || preset === void 0 ? void 0 : preset.exitDurationMs, elementRef]);
|
|
216
216
|
|
|
217
|
-
//
|
|
217
|
+
// Non-animated exit callback
|
|
218
218
|
//
|
|
219
219
|
// When there is no animation, children unmount synchronously (handled
|
|
220
|
-
// by the `if` block above). But `onExitFinish` still needs to fire
|
|
220
|
+
// by the `if` block above). But `onExitFinish` still needs to fire -
|
|
221
221
|
// we do that in a follow-up effect so the consumer can react to it.
|
|
222
222
|
//
|
|
223
223
|
// Uses a previous-value ref (`wasOpenRef`) to detect the exact
|
|
@@ -3,7 +3,7 @@ import { ensurePresetStyles } from './ensure-preset-styles';
|
|
|
3
3
|
/**
|
|
4
4
|
* Normalizes the `animate` prop to a preset (or null) and ensures its CSS
|
|
5
5
|
* is injected once into document.head. Used by PopupContent, Popover, and
|
|
6
|
-
* DialogContent so they
|
|
6
|
+
* DialogContent so they do not duplicate this logic.
|
|
7
7
|
*/
|
|
8
8
|
export function useAnimationPreset(animate) {
|
|
9
9
|
var preset = animate != null && animate !== false ? animate : null;
|
|
@@ -4,7 +4,7 @@ import { ensurePresetStyles } from './ensure-preset-styles';
|
|
|
4
4
|
* Normalizes a preset prop to a value (or null) and ensures its CSS
|
|
5
5
|
* is injected once into `document.head`.
|
|
6
6
|
*
|
|
7
|
-
* Works with any preset that has `{ css, name }`
|
|
7
|
+
* Works with any preset that has `{ css, name }` - animation presets
|
|
8
8
|
* (TAnimationPreset) satisfies this shape.
|
|
9
9
|
*/
|
|
10
10
|
export function usePresetStyles(_ref) {
|