@atlaskit/top-layer 1.4.0 → 1.6.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 +19 -0
- package/dist/cjs/dialog/animations.js +90 -0
- package/dist/cjs/dialog/dialog-content.compiled.css +17 -25
- package/dist/cjs/dialog/dialog-content.js +29 -41
- package/dist/cjs/entry-points/animations.js +9 -8
- package/dist/cjs/internal/use-animated-visibility.js +40 -8
- package/dist/cjs/popover/animations.js +196 -0
- package/dist/cjs/popover/popover.compiled.css +17 -14
- package/dist/cjs/popover/popover.js +21 -30
- package/dist/es2019/dialog/animations.js +80 -0
- package/dist/es2019/dialog/dialog-content.compiled.css +17 -25
- package/dist/es2019/dialog/dialog-content.js +29 -38
- package/dist/es2019/entry-points/animations.js +2 -1
- package/dist/es2019/internal/use-animated-visibility.js +41 -8
- package/dist/es2019/popover/animations.js +190 -0
- package/dist/es2019/popover/popover.compiled.css +17 -14
- package/dist/es2019/popover/popover.js +21 -27
- package/dist/esm/dialog/animations.js +82 -0
- package/dist/esm/dialog/dialog-content.compiled.css +17 -25
- package/dist/esm/dialog/dialog-content.js +29 -41
- package/dist/esm/entry-points/animations.js +2 -1
- package/dist/esm/internal/use-animated-visibility.js +41 -8
- package/dist/esm/popover/animations.js +187 -0
- package/dist/esm/popover/popover.compiled.css +17 -14
- package/dist/esm/popover/popover.js +21 -30
- package/dist/types/dialog/animations.d.ts +57 -0
- package/dist/types/dialog/types.d.ts +2 -2
- package/dist/types/entry-points/animations.d.ts +2 -2
- package/dist/types/internal/use-animated-visibility.d.ts +35 -6
- package/dist/types/popover/animations.d.ts +52 -0
- package/dist/types/popover/types.d.ts +3 -3
- package/package.json +30 -12
- package/dist/cjs/animations/presets.js +0 -298
- package/dist/cjs/animations/types.js +0 -5
- package/dist/es2019/animations/presets.js +0 -285
- package/dist/es2019/animations/types.js +0 -1
- package/dist/esm/animations/presets.js +0 -285
- package/dist/esm/animations/types.js +0 -1
- package/dist/types/animations/presets.d.ts +0 -128
- package/dist/types/animations/types.d.ts +0 -34
|
@@ -2,6 +2,41 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
2
2
|
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
3
3
|
import { bind, bindAll } from 'bind-event-listener';
|
|
4
4
|
import { prefersReducedMotion } from './reduced-motion';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A self-contained animation preset for top-layer elements.
|
|
8
|
+
*
|
|
9
|
+
* Contains a stable preset name used by the host component to select its
|
|
10
|
+
* component-local Compiled style entry, plus optional per-placement inline
|
|
11
|
+
* styles.
|
|
12
|
+
*
|
|
13
|
+
* The actual Compiled styles are kept static and component-local so the
|
|
14
|
+
* Compiled transform can extract them at build time.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Using the recommended motion timings for safety net.
|
|
19
|
+
*
|
|
20
|
+
* Not setting these timings on the preset config because they're defined in the CSS,
|
|
21
|
+
* so configuring it in the preset doesn't achieve anything except introduce a potential
|
|
22
|
+
* source of drift.
|
|
23
|
+
*
|
|
24
|
+
* TODO: figure out a way to not need to redeclare these in the future,
|
|
25
|
+
* and keep CSS and JS timings in sync always.
|
|
26
|
+
*/
|
|
27
|
+
var safetyNetMsMap = {
|
|
28
|
+
dialog: {
|
|
29
|
+
enter: 250,
|
|
30
|
+
// Corresponds to `motion.duration.long`
|
|
31
|
+
exit: 200 // Corresponds to `motion.duration.medium`
|
|
32
|
+
},
|
|
33
|
+
popover: {
|
|
34
|
+
enter: 150,
|
|
35
|
+
// Corresponds to `motion.duration.short`
|
|
36
|
+
exit: 100 // Corresponds to `motion.duration.xshort`
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
5
40
|
/**
|
|
6
41
|
* Fires `onSettled` once when `transitionend` fires on `element`, or after
|
|
7
42
|
* `safetyNetMs` if the event is swallowed (mid-transition unmount, CSS
|
|
@@ -153,8 +188,7 @@ export function useAnimatedVisibility(_ref2) {
|
|
|
153
188
|
// move to `open`. The fallback guarantees settle on swallowed events
|
|
154
189
|
// (zero-duration, browser quirk, mid-transition unmount).
|
|
155
190
|
useEffect(function () {
|
|
156
|
-
|
|
157
|
-
if (phase !== 'entering') {
|
|
191
|
+
if (phase !== 'entering' || !(preset !== null && preset !== void 0 && preset.kind)) {
|
|
158
192
|
return;
|
|
159
193
|
}
|
|
160
194
|
var element = elementRef.current;
|
|
@@ -163,7 +197,7 @@ export function useAnimatedVisibility(_ref2) {
|
|
|
163
197
|
}
|
|
164
198
|
return runOnTransitionEndOrTimeout({
|
|
165
199
|
element: element,
|
|
166
|
-
safetyNetMs:
|
|
200
|
+
safetyNetMs: safetyNetMsMap[preset.kind].enter + 50,
|
|
167
201
|
onSettled: function onSettled() {
|
|
168
202
|
var _onEnterFinishRef$cur;
|
|
169
203
|
// Fire the consumer callback before transitioning phase so any
|
|
@@ -176,7 +210,7 @@ export function useAnimatedVisibility(_ref2) {
|
|
|
176
210
|
});
|
|
177
211
|
}
|
|
178
212
|
});
|
|
179
|
-
}, [phase, preset === null || preset === void 0 ? void 0 : preset.
|
|
213
|
+
}, [phase, preset === null || preset === void 0 ? void 0 : preset.kind, elementRef]);
|
|
180
214
|
|
|
181
215
|
// Non-animated entry callback. The lifecycle goes `closed → open`
|
|
182
216
|
// directly with no `entering` phase; fire `onEnterFinish` on that jump.
|
|
@@ -197,8 +231,7 @@ export function useAnimatedVisibility(_ref2) {
|
|
|
197
231
|
// Animated exit: wait for `transitionend` (or a safety-net timeout),
|
|
198
232
|
// fire `onExitFinish`, then move to `closed` to unmount the host.
|
|
199
233
|
useEffect(function () {
|
|
200
|
-
|
|
201
|
-
if (phase !== 'exiting' || !willAnimate) {
|
|
234
|
+
if (phase !== 'exiting' || !willAnimate || !(preset !== null && preset !== void 0 && preset.kind)) {
|
|
202
235
|
return;
|
|
203
236
|
}
|
|
204
237
|
var element = elementRef.current;
|
|
@@ -207,7 +240,7 @@ export function useAnimatedVisibility(_ref2) {
|
|
|
207
240
|
}
|
|
208
241
|
return runOnTransitionEndOrTimeout({
|
|
209
242
|
element: element,
|
|
210
|
-
safetyNetMs:
|
|
243
|
+
safetyNetMs: safetyNetMsMap[preset.kind].exit + 50,
|
|
211
244
|
onSettled: function onSettled() {
|
|
212
245
|
var _onExitFinishRef$curr;
|
|
213
246
|
// Fire the consumer callback before transitioning phase to
|
|
@@ -222,7 +255,7 @@ export function useAnimatedVisibility(_ref2) {
|
|
|
222
255
|
});
|
|
223
256
|
}
|
|
224
257
|
});
|
|
225
|
-
}, [phase, willAnimate, preset === null || preset === void 0 ? void 0 : preset.
|
|
258
|
+
}, [phase, willAnimate, preset === null || preset === void 0 ? void 0 : preset.kind, elementRef]);
|
|
226
259
|
|
|
227
260
|
// Non-animated exit: wait for the browser's `toggle` (closed) or
|
|
228
261
|
// `close` event before unmounting, so the consumer's listener (close
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { getPlacement } from '../internal/resolve-placement';
|
|
2
|
+
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
|
+
}
|
|
45
|
+
|
|
46
|
+
// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
|
|
47
|
+
export function popupMotion() {
|
|
48
|
+
return {
|
|
49
|
+
kind: 'popover',
|
|
50
|
+
name: 'motion',
|
|
51
|
+
getStyles: getPopupMotionStyles
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function getSlideAndFadeStyles(_ref2) {
|
|
55
|
+
var placement = _ref2.placement,
|
|
56
|
+
distance = _ref2.distance;
|
|
57
|
+
var pos = "".concat(distance, "px");
|
|
58
|
+
var neg = "-".concat(distance, "px");
|
|
59
|
+
var _getPlacement2 = getPlacement({
|
|
60
|
+
placement: placement
|
|
61
|
+
}),
|
|
62
|
+
axis = _getPlacement2.axis,
|
|
63
|
+
edge = _getPlacement2.edge;
|
|
64
|
+
if (axis === 'block' && edge === 'start') {
|
|
65
|
+
return [{
|
|
66
|
+
property: '--ds-popover-tx',
|
|
67
|
+
value: '0'
|
|
68
|
+
}, {
|
|
69
|
+
property: '--ds-popover-ty',
|
|
70
|
+
value: pos
|
|
71
|
+
}];
|
|
72
|
+
}
|
|
73
|
+
if (axis === 'block' && edge === 'end') {
|
|
74
|
+
return [{
|
|
75
|
+
property: '--ds-popover-tx',
|
|
76
|
+
value: '0'
|
|
77
|
+
}, {
|
|
78
|
+
property: '--ds-popover-ty',
|
|
79
|
+
value: neg
|
|
80
|
+
}];
|
|
81
|
+
}
|
|
82
|
+
if (axis === 'inline' && edge === 'start') {
|
|
83
|
+
return [{
|
|
84
|
+
property: '--ds-popover-tx',
|
|
85
|
+
value: pos
|
|
86
|
+
}, {
|
|
87
|
+
property: '--ds-popover-ty',
|
|
88
|
+
value: '0'
|
|
89
|
+
}];
|
|
90
|
+
}
|
|
91
|
+
if (axis === 'inline' && edge === 'end') {
|
|
92
|
+
return [{
|
|
93
|
+
property: '--ds-popover-tx',
|
|
94
|
+
value: neg
|
|
95
|
+
}, {
|
|
96
|
+
property: '--ds-popover-ty',
|
|
97
|
+
value: '0'
|
|
98
|
+
}];
|
|
99
|
+
}
|
|
100
|
+
return [{
|
|
101
|
+
property: '--ds-popover-tx',
|
|
102
|
+
value: '0'
|
|
103
|
+
}, {
|
|
104
|
+
property: '--ds-popover-ty',
|
|
105
|
+
value: neg
|
|
106
|
+
}];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Directional slide + opacity animation.
|
|
111
|
+
*
|
|
112
|
+
* The popover slides in from the direction opposite its placement edge
|
|
113
|
+
* (e.g. a `block-end` popover slides down from above).
|
|
114
|
+
*
|
|
115
|
+
* @param options.distance - Slide distance in pixels. Defaults to `4`.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```tsx
|
|
119
|
+
* import { slideAndFade } from '@atlaskit/top-layer/animations';
|
|
120
|
+
*
|
|
121
|
+
* // Default 4px slide (tooltip)
|
|
122
|
+
* <Popover animate={slideAndFade()} />
|
|
123
|
+
*
|
|
124
|
+
* // Custom 8px slide (popup / dropdown)
|
|
125
|
+
* <Popover animate={slideAndFade({ distance: 8 })} />
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
|
|
129
|
+
export function slideAndFade(options) {
|
|
130
|
+
var _options$distance;
|
|
131
|
+
var distance = (_options$distance = options === null || options === void 0 ? void 0 : options.distance) !== null && _options$distance !== void 0 ? _options$distance : 4;
|
|
132
|
+
return {
|
|
133
|
+
kind: 'popover',
|
|
134
|
+
name: 'slide-and-fade',
|
|
135
|
+
getStyles: function getStyles(_ref3) {
|
|
136
|
+
var placement = _ref3.placement;
|
|
137
|
+
return getSlideAndFadeStyles({
|
|
138
|
+
placement: placement,
|
|
139
|
+
distance: distance
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// fade
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Simple opacity transition, no transform.
|
|
149
|
+
*
|
|
150
|
+
* Suitable for popup dialogs or content that does not need directional motion.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```tsx
|
|
154
|
+
* import { fade } from '@atlaskit/top-layer/animations';
|
|
155
|
+
*
|
|
156
|
+
* <Popover animate={fade()} />
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
|
|
160
|
+
export function fade() {
|
|
161
|
+
return {
|
|
162
|
+
kind: 'popover',
|
|
163
|
+
name: 'fade'
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// scaleAndFade
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Scale from 0.95 + opacity transition.
|
|
171
|
+
*
|
|
172
|
+
* Suitable for menus, dropdowns, and select options.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```tsx
|
|
176
|
+
* import { scaleAndFade } from '@atlaskit/top-layer/animations';
|
|
177
|
+
*
|
|
178
|
+
* <Popover animate={scaleAndFade()} />
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
|
|
182
|
+
export function scaleAndFade() {
|
|
183
|
+
return {
|
|
184
|
+
kind: 'popover',
|
|
185
|
+
name: 'scale-and-fade'
|
|
186
|
+
};
|
|
187
|
+
}
|
|
@@ -2,32 +2,35 @@
|
|
|
2
2
|
._15ns179n:popover-open{animation:var(--ds-popover-motion-enter)}
|
|
3
3
|
._19itglyw{border:none}
|
|
4
4
|
._1r041wug{inset:auto}
|
|
5
|
-
._y44vof1f{animation:var(--ds-popover-motion-exit)}.
|
|
6
|
-
._162xglyw:popover-open{transform:none}
|
|
5
|
+
._y44vof1f{animation:var(--ds-popover-motion-exit)}._12t71ign:popover-open{transition-duration:var(--ds-duration-short,.15s)}
|
|
7
6
|
._18m9ewfl{overflow-y:visible}
|
|
8
7
|
._18u0idpf{margin-left:0}
|
|
9
8
|
._19bvidpf{padding-left:0}
|
|
10
9
|
._19pkidpf{margin-top:0}
|
|
11
|
-
.
|
|
10
|
+
._1a5xt94y{--dir:1px}
|
|
12
11
|
._1o51q7pw{animation-fill-mode:forwards}
|
|
13
|
-
.
|
|
14
|
-
.
|
|
12
|
+
._1oecdn4k{transition-duration:var(--ds-duration-xshort,.1s)}
|
|
13
|
+
._1pgl1lbj{animation-timing-function:var(--ds-easing-in-practical,cubic-bezier(.6,0,.8,.6))}
|
|
14
|
+
._1psg1ign:popover-open{animation-duration:var(--ds-duration-short,.15s)}
|
|
15
15
|
._1reoewfl{overflow-x:visible}
|
|
16
16
|
._1s9z1a5r{transition-behavior:allow-discrete}
|
|
17
17
|
._2hwxidpf{margin-right:0}
|
|
18
|
-
.
|
|
18
|
+
._5sagdn4k{animation-duration:var(--ds-duration-xshort,.1s)}
|
|
19
|
+
._71re1bym:popover-open{animation-name:var(--ds-keyframe-fade-in,FadeIn0to100)}
|
|
20
|
+
._71re1v6b:popover-open{animation-name:var(--ds-keyframe-fade-in,FadeIn0to100),var(--ds-keyframe-scale-in-small,ScaleIn95to100)}
|
|
21
|
+
._71rervlo:popover-open{animation-name:k1ut9kob,var(--ds-keyframe-fade-in,FadeIn0to100)}
|
|
19
22
|
._bfhk1j28{background-color:transparent}
|
|
20
23
|
._ca0qidpf{padding-top:0}
|
|
24
|
+
._j7hq1a5s{animation-name:var(--ds-keyframe-fade-out,FadeOut100to0)}
|
|
25
|
+
._j7hq1l2h{animation-name:k1e4c1ew,var(--ds-keyframe-fade-out,FadeOut100to0)}
|
|
26
|
+
._j7hqneez{animation-name:var(--ds-keyframe-fade-out,FadeOut100to0),var(--ds-keyframe-scale-out-small,ScaleOut100to95)}
|
|
21
27
|
._k8m011k7{transition-property:overlay,display}
|
|
22
|
-
._k8m01slm{transition-property:opacity,overlay,display}
|
|
23
|
-
._k8m0rv36{transition-property:opacity,transform,overlay,display}
|
|
24
28
|
._n3tdidpf{padding-bottom:0}
|
|
25
29
|
._n70peoah:popover-open{animation-fill-mode:backwards}
|
|
30
|
+
._o8i7indk:popover-open{animation-timing-function:var(--ds-easing-out-practical,cubic-bezier(.4,1,.6,1))}
|
|
26
31
|
._otyridpf{margin-bottom:0}
|
|
27
|
-
._t9ecgt2x{transform:scale(.95)}
|
|
28
|
-
._t9ecxauz{transform:translate(var(--ds-popover-tx,0),var(--ds-popover-ty,0))}
|
|
29
|
-
._tzy4idpf{opacity:0}
|
|
30
32
|
._u5f3idpf{padding-right:0}
|
|
31
|
-
[dir=rtl] .
|
|
32
|
-
@
|
|
33
|
-
@
|
|
33
|
+
[dir=rtl] ._34bx1n1a{--dir:-1px}
|
|
34
|
+
@keyframes k1e4c1ew{0%{transform:none}to{transform:translate(calc(var(--dir)*var(--ds-popover-tx, 0)),var(--ds-popover-ty,0))}}
|
|
35
|
+
@keyframes k1ut9kob{0%{transform:translate(calc(var(--dir)*var(--ds-popover-tx, 0)),var(--ds-popover-ty,0))}to{transform:none}}
|
|
36
|
+
@media (prefers-reduced-motion:reduce){._bl8aglyw{animation-name:none}._156yru3m{transition-duration:0s}._8rmvglyw:popover-open{animation-name:none}._2qm2ru3m:popover-open{transition-duration:0s}}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
/* popover.tsx generated by @compiled/babel-plugin v0.39.1 */
|
|
2
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
3
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
5
2
|
import "./popover.compiled.css";
|
|
6
3
|
import { ax, ix } from "@compiled/react/runtime";
|
|
7
4
|
import React, { forwardRef, useCallback, useId, useLayoutEffect, useRef } from 'react';
|
|
@@ -10,6 +7,7 @@ import mergeRefs from '@atlaskit/ds-lib/merge-refs';
|
|
|
10
7
|
import once from '@atlaskit/ds-lib/once';
|
|
11
8
|
import { useNotifyOpenLayerObserver } from '@atlaskit/layering/experimental/open-layer-observer';
|
|
12
9
|
import { shouldFocusIntoPopover } from '../internal/role-types';
|
|
10
|
+
import { setStyle } from '../internal/set-style';
|
|
13
11
|
import { useAnimatedVisibility } from '../internal/use-animated-visibility';
|
|
14
12
|
import { useFocusWrap } from '../internal/use-focus-wrap';
|
|
15
13
|
import { useInitialFocus } from '../internal/use-initial-focus';
|
|
@@ -25,16 +23,19 @@ var supportsPopoverHint = once(function () {
|
|
|
25
23
|
element.setAttribute('popover', 'hint');
|
|
26
24
|
return element.popover === 'hint';
|
|
27
25
|
});
|
|
26
|
+
var slideInKeyframes = null;
|
|
27
|
+
var slideOutKeyframes = null;
|
|
28
28
|
|
|
29
29
|
// These animation styles use the non-strict Compiled cssMap because they rely
|
|
30
30
|
// on `@starting-style`, `:popover-open`, `[dir='rtl']`, and `allow-discrete`.
|
|
31
31
|
// Keep them in this component so the Compiled transform can statically extract
|
|
32
32
|
// every referenced style.
|
|
33
33
|
var popoverAnimationStyles = {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
fade: "
|
|
37
|
-
|
|
34
|
+
root: "_k8m011k7 _1oecdn4k _1s9z1a5r _1a5xt94y _12t71ign _34bx1n1a _bl8aglyw _156yru3m _8rmvglyw _2qm2ru3m",
|
|
35
|
+
motion: "_y44vof1f _1o51q7pw _15ns179n _n70peoah",
|
|
36
|
+
'slide-and-fade': "_j7hq1l2h _5sagdn4k _1pgl1lbj _71rervlo _1psg1ign _o8i7indk",
|
|
37
|
+
fade: "_j7hq1a5s _5sagdn4k _1pgl1lbj _71re1bym _1psg1ign _o8i7indk",
|
|
38
|
+
'scale-and-fade': "_j7hqneez _5sagdn4k _1pgl1lbj _71re1v6b _1psg1ign _o8i7indk"
|
|
38
39
|
};
|
|
39
40
|
var styles = {
|
|
40
41
|
root: "_19itglyw _ca0qidpf _u5f3idpf _n3tdidpf _19bvidpf _19pkidpf _2hwxidpf _otyridpf _18u0idpf _1r041wug _1reoewfl _18m9ewfl _bfhk1j28"
|
|
@@ -89,7 +90,7 @@ export var Popover = /*#__PURE__*/forwardRef(function Popover(_ref, ref) {
|
|
|
89
90
|
placement = _ref.placement,
|
|
90
91
|
testId = _ref.testId,
|
|
91
92
|
isOpen = _ref.isOpen,
|
|
92
|
-
|
|
93
|
+
consumerXcss = _ref.xcss,
|
|
93
94
|
role = _ref.role,
|
|
94
95
|
label = _ref.label,
|
|
95
96
|
labelledBy = _ref.labelledBy,
|
|
@@ -264,27 +265,19 @@ export var Popover = /*#__PURE__*/forwardRef(function Popover(_ref, ref) {
|
|
|
264
265
|
|
|
265
266
|
// Placement-dependent animation CSS vars. Kept separate from show/hide
|
|
266
267
|
// so preset reference changes do not re-trigger visibility. The cleanup
|
|
267
|
-
//
|
|
268
|
-
// properties on the element.
|
|
268
|
+
// restores the previous inline values so a preset change does not leave
|
|
269
|
+
// stale custom properties on the element.
|
|
269
270
|
useLayoutEffect(function () {
|
|
270
271
|
var element = ownRef.current;
|
|
271
|
-
if (!element || !(preset !== null && preset !== void 0 && preset.
|
|
272
|
+
if (!element || !(preset !== null && preset !== void 0 && preset.getStyles) || !placement) {
|
|
272
273
|
return;
|
|
273
274
|
}
|
|
274
|
-
|
|
275
|
-
|
|
275
|
+
return setStyle({
|
|
276
|
+
element: element,
|
|
277
|
+
styles: preset.getStyles({
|
|
278
|
+
placement: placement
|
|
279
|
+
})
|
|
276
280
|
});
|
|
277
|
-
Object.entries(props).forEach(function (_ref2) {
|
|
278
|
-
var _ref3 = _slicedToArray(_ref2, 2),
|
|
279
|
-
key = _ref3[0],
|
|
280
|
-
value = _ref3[1];
|
|
281
|
-
element.style.setProperty(key, String(value));
|
|
282
|
-
});
|
|
283
|
-
return function () {
|
|
284
|
-
Object.keys(props).forEach(function (key) {
|
|
285
|
-
element.style.removeProperty(key);
|
|
286
|
-
});
|
|
287
|
-
};
|
|
288
281
|
}, [preset, placement, isVisible]);
|
|
289
282
|
|
|
290
283
|
// Show/hide based on isOpen. `showPopover`/`hidePopover` are no-ops when
|
|
@@ -323,7 +316,7 @@ export var Popover = /*#__PURE__*/forwardRef(function Popover(_ref, ref) {
|
|
|
323
316
|
if (!isVisible) {
|
|
324
317
|
return null;
|
|
325
318
|
}
|
|
326
|
-
return /*#__PURE__*/React.createElement("div",
|
|
319
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
327
320
|
ref: combinedRef,
|
|
328
321
|
id: popoverId
|
|
329
322
|
// @ts-expect-error -- popover attribute not yet in React types
|
|
@@ -333,9 +326,7 @@ export var Popover = /*#__PURE__*/forwardRef(function Popover(_ref, ref) {
|
|
|
333
326
|
role: role,
|
|
334
327
|
"aria-label": label,
|
|
335
328
|
"aria-labelledby": labelledBy,
|
|
336
|
-
"data-testid": testId
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
className: ax([styles.root, (preset === null || preset === void 0 ? void 0 : preset.name) === 'popup-motion' && popoverAnimationStyles.popupMotion, (preset === null || preset === void 0 ? void 0 : preset.name) === 'slide-and-fade' && popoverAnimationStyles.slideAndFade, (preset === null || preset === void 0 ? void 0 : preset.name) === 'fade' && popoverAnimationStyles.fade, (preset === null || preset === void 0 ? void 0 : preset.name) === 'scale-and-fade' && popoverAnimationStyles.scaleAndFade, xcssFromProps])
|
|
340
|
-
}), children);
|
|
329
|
+
"data-testid": testId,
|
|
330
|
+
className: ax([styles.root, preset && popoverAnimationStyles.root, preset && popoverAnimationStyles[preset.name], consumerXcss])
|
|
331
|
+
}, children);
|
|
341
332
|
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { TAnimationPreset } from '../internal/use-animated-visibility';
|
|
2
|
+
export type TDialogAnimationPresetName = 'motion' | 'slide-up-and-fade' | 'fade' | 'custom';
|
|
3
|
+
export type TDialogAnimationPreset = TAnimationPreset<'dialog', TDialogAnimationPresetName>;
|
|
4
|
+
/**
|
|
5
|
+
* Dialog motion animation.
|
|
6
|
+
*
|
|
7
|
+
* Includes backdrop fade animation.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* import { dialogMotion } from '@atlaskit/top-layer/animations';
|
|
12
|
+
*
|
|
13
|
+
* <Dialog animate={dialogMotion()} isOpen={isOpen} onClose={handleClose} label="...">
|
|
14
|
+
* ...
|
|
15
|
+
* </Dialog>
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function dialogMotion(): TDialogAnimationPreset;
|
|
19
|
+
/**
|
|
20
|
+
* Slide up + opacity animation for dialogs.
|
|
21
|
+
*
|
|
22
|
+
* Entry slides up from below; exit slides up and out (asymmetric).
|
|
23
|
+
* Includes backdrop fade animation.
|
|
24
|
+
*
|
|
25
|
+
* @param options.distance - Slide distance in pixels. Defaults to `12`.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* import { dialogSlideUpAndFade } from '@atlaskit/top-layer/animations';
|
|
30
|
+
*
|
|
31
|
+
* const animation = dialogSlideUpAndFade();
|
|
32
|
+
* <Dialog animate={animation} isOpen={isOpen} onClose={handleClose} label="...">
|
|
33
|
+
* ...
|
|
34
|
+
* </Dialog>
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function dialogSlideUpAndFade(options?: {
|
|
38
|
+
/**
|
|
39
|
+
* Slide distance in pixels. Defaults to `12`.
|
|
40
|
+
*/
|
|
41
|
+
distance?: number;
|
|
42
|
+
}): TDialogAnimationPreset;
|
|
43
|
+
/**
|
|
44
|
+
* Simple opacity transition for dialogs, no transform.
|
|
45
|
+
*
|
|
46
|
+
* Includes backdrop fade animation.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```tsx
|
|
50
|
+
* import { dialogFade } from '@atlaskit/top-layer/animations';
|
|
51
|
+
*
|
|
52
|
+
* <Dialog animate={dialogFade()} isOpen={isOpen} onClose={handleClose} label="...">
|
|
53
|
+
* ...
|
|
54
|
+
* </Dialog>
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function dialogFade(): TDialogAnimationPreset;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
2
|
import { type CompiledStyles } from '@compiled/react';
|
|
3
|
-
import {
|
|
3
|
+
import type { TDialogAnimationPreset } from './animations';
|
|
4
4
|
/**
|
|
5
5
|
* Close reasons produced by the Dialog primitive.
|
|
6
6
|
*
|
|
@@ -53,7 +53,7 @@ type TDialogBaseProps = {
|
|
|
53
53
|
* Pass a `TAnimationPreset` (e.g. `dialogSlideUpAndFade()`) to enable
|
|
54
54
|
* CSS-based entry and exit animation. Pass `false` (or omit) to disable.
|
|
55
55
|
*/
|
|
56
|
-
animate?:
|
|
56
|
+
animate?: TDialogAnimationPreset | false;
|
|
57
57
|
/**
|
|
58
58
|
* Additional Compiled styles applied to the `<dialog>` element.
|
|
59
59
|
*
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { dialogMotion,
|
|
2
|
-
export type
|
|
1
|
+
export { dialogMotion, dialogSlideUpAndFade, dialogFade, type TDialogAnimationPreset, } from '../dialog/animations';
|
|
2
|
+
export { popupMotion, slideAndFade, fade, scaleAndFade, type TPopoverAnimationPreset, } from '../popover/animations';
|
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
import { type RefObject } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
type
|
|
2
|
+
import type { TPlacementOptions } from './resolve-placement';
|
|
3
|
+
type TAnimationPresetKind = 'dialog' | 'popover';
|
|
4
|
+
/**
|
|
5
|
+
* A self-contained animation preset for top-layer elements.
|
|
6
|
+
*
|
|
7
|
+
* Contains a stable preset name used by the host component to select its
|
|
8
|
+
* component-local Compiled style entry, plus optional per-placement inline
|
|
9
|
+
* styles.
|
|
10
|
+
*
|
|
11
|
+
* The actual Compiled styles are kept static and component-local so the
|
|
12
|
+
* Compiled transform can extract them at build time.
|
|
13
|
+
*/
|
|
14
|
+
export type TAnimationPreset<Kind extends TAnimationPresetKind, Name = string> = {
|
|
15
|
+
kind: Kind;
|
|
16
|
+
/**
|
|
17
|
+
* Stable preset name used to select a component-local Compiled style entry.
|
|
18
|
+
*/
|
|
19
|
+
name: Name;
|
|
20
|
+
/**
|
|
21
|
+
* Per-placement inline styles (e.g. directional offset custom properties for
|
|
22
|
+
* `slideAndFade`). Only used by presets that vary by placement or by a
|
|
23
|
+
* configurable distance.
|
|
24
|
+
*/
|
|
25
|
+
getStyles?: (args: {
|
|
26
|
+
placement: TPlacementOptions;
|
|
27
|
+
}) => Array<{
|
|
28
|
+
property: string;
|
|
29
|
+
value: string;
|
|
30
|
+
}>;
|
|
31
|
+
};
|
|
32
|
+
type TUseAnimatedVisibilityArgs<Kind extends TAnimationPresetKind, Name> = {
|
|
4
33
|
/**
|
|
5
34
|
* Whether the element is logically open.
|
|
6
35
|
*/
|
|
@@ -9,7 +38,7 @@ type TUseAnimatedVisibilityArgs = {
|
|
|
9
38
|
* Animation preset for entry/exit transitions.
|
|
10
39
|
* Pass `false` or `undefined` to disable animation.
|
|
11
40
|
*/
|
|
12
|
-
animate: TAnimationPreset | false | undefined;
|
|
41
|
+
animate: TAnimationPreset<Kind, Name> | false | undefined;
|
|
13
42
|
/**
|
|
14
43
|
* Ref to the DOM element that plays the entry/exit transitions.
|
|
15
44
|
* Used to listen for `transitionend`.
|
|
@@ -27,7 +56,7 @@ type TUseAnimatedVisibilityArgs = {
|
|
|
27
56
|
*/
|
|
28
57
|
onExitFinish?: () => void;
|
|
29
58
|
};
|
|
30
|
-
type TUseAnimatedVisibilityResult = {
|
|
59
|
+
type TUseAnimatedVisibilityResult<Kind extends TAnimationPresetKind, Name> = {
|
|
31
60
|
/**
|
|
32
61
|
* Current visibility phase. See `TPhase` for the full lifecycle.
|
|
33
62
|
*
|
|
@@ -42,7 +71,7 @@ type TUseAnimatedVisibilityResult = {
|
|
|
42
71
|
* Resolved animation preset (styles applied via the host element's `css`
|
|
43
72
|
* prop), or `null` if animation is disabled.
|
|
44
73
|
*/
|
|
45
|
-
preset: TAnimationPreset | null;
|
|
74
|
+
preset: TAnimationPreset<Kind, Name> | null;
|
|
46
75
|
};
|
|
47
76
|
/**
|
|
48
77
|
* Visibility lifecycle phase shared between `useAnimatedVisibility`,
|
|
@@ -105,5 +134,5 @@ export type TPhase = 'closed' | 'entering' | 'open' | 'exiting';
|
|
|
105
134
|
* Every effect dispatches on the single `phase` value instead of a
|
|
106
135
|
* cross-product of booleans.
|
|
107
136
|
*/
|
|
108
|
-
export declare function useAnimatedVisibility({ isOpen, animate, elementRef, onEnterFinish, onExitFinish, }: TUseAnimatedVisibilityArgs): TUseAnimatedVisibilityResult
|
|
137
|
+
export declare function useAnimatedVisibility<Kind extends TAnimationPresetKind, Name>({ isOpen, animate, elementRef, onEnterFinish, onExitFinish, }: TUseAnimatedVisibilityArgs<Kind, Name>): TUseAnimatedVisibilityResult<Kind, Name>;
|
|
109
138
|
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { TAnimationPreset } from '../internal/use-animated-visibility';
|
|
2
|
+
export type TPopoverAnimationPresetName = 'motion' | 'slide-and-fade' | 'scale-and-fade' | 'fade';
|
|
3
|
+
export type TPopoverAnimationPreset = TAnimationPreset<'popover', TPopoverAnimationPresetName>;
|
|
4
|
+
export declare function popupMotion(): TPopoverAnimationPreset;
|
|
5
|
+
/**
|
|
6
|
+
* Directional slide + opacity animation.
|
|
7
|
+
*
|
|
8
|
+
* The popover slides in from the direction opposite its placement edge
|
|
9
|
+
* (e.g. a `block-end` popover slides down from above).
|
|
10
|
+
*
|
|
11
|
+
* @param options.distance - Slide distance in pixels. Defaults to `4`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* import { slideAndFade } from '@atlaskit/top-layer/animations';
|
|
16
|
+
*
|
|
17
|
+
* // Default 4px slide (tooltip)
|
|
18
|
+
* <Popover animate={slideAndFade()} />
|
|
19
|
+
*
|
|
20
|
+
* // Custom 8px slide (popup / dropdown)
|
|
21
|
+
* <Popover animate={slideAndFade({ distance: 8 })} />
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function slideAndFade(options?: {
|
|
25
|
+
distance?: number;
|
|
26
|
+
}): TPopoverAnimationPreset;
|
|
27
|
+
/**
|
|
28
|
+
* Simple opacity transition, no transform.
|
|
29
|
+
*
|
|
30
|
+
* Suitable for popup dialogs or content that does not need directional motion.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* import { fade } from '@atlaskit/top-layer/animations';
|
|
35
|
+
*
|
|
36
|
+
* <Popover animate={fade()} />
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function fade(): TPopoverAnimationPreset;
|
|
40
|
+
/**
|
|
41
|
+
* Scale from 0.95 + opacity transition.
|
|
42
|
+
*
|
|
43
|
+
* Suitable for menus, dropdowns, and select options.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```tsx
|
|
47
|
+
* import { scaleAndFade } from '@atlaskit/top-layer/animations';
|
|
48
|
+
*
|
|
49
|
+
* <Popover animate={scaleAndFade()} />
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function scaleAndFade(): TPopoverAnimationPreset;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import { type StrictXCSSProp } from '@atlaskit/css';
|
|
3
|
-
import { type TAnimationPreset } from '../animations/types';
|
|
4
3
|
import { type TPlacementOptions } from '../internal/resolve-placement';
|
|
5
4
|
import { type TAriaRoleRequired, type TRoleRequiringAccessibleName, type TRoleWithImplicitName } from '../internal/role-types';
|
|
5
|
+
import { type TPopoverAnimationPreset } from './animations';
|
|
6
6
|
/**
|
|
7
7
|
* The reason a popover was closed.
|
|
8
8
|
*
|
|
@@ -43,7 +43,7 @@ type TPopoverBaseProps = {
|
|
|
43
43
|
* Animations use `@starting-style` and `allow-discrete` for progressive
|
|
44
44
|
* enhancement: browsers without support show/hide instantly.
|
|
45
45
|
*/
|
|
46
|
-
animate?: false |
|
|
46
|
+
animate?: false | TPopoverAnimationPreset;
|
|
47
47
|
/**
|
|
48
48
|
* Test ID applied to the popover element.
|
|
49
49
|
*/
|
|
@@ -109,7 +109,7 @@ type TPopoverBaseProps = {
|
|
|
109
109
|
/**
|
|
110
110
|
* Placement hint for directional animations (e.g. `slideAndFade`).
|
|
111
111
|
*
|
|
112
|
-
* When `animate` is provided, the preset's `
|
|
112
|
+
* When `animate` is provided, the preset's `getStyles(placement)` is
|
|
113
113
|
* called to set CSS custom properties (like `--ds-popover-tx`, `--ds-popover-ty`)
|
|
114
114
|
* that control the slide direction. Has no effect without `animate`.
|
|
115
115
|
*
|