@atlaskit/drawer 13.1.0 → 13.2.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 +20 -0
- package/__tests__/playwright/top-layer-focus.spec.tsx +148 -0
- package/compass.yml +38 -0
- package/dist/cjs/drawer-panel/drawer-content.js +11 -2
- package/dist/cjs/drawer-panel/drawer-slide-in.js +67 -0
- package/dist/cjs/drawer-panel/drawer-top-layer.compiled.css +8 -0
- package/dist/cjs/drawer-panel/drawer-top-layer.js +256 -0
- package/dist/cjs/drawer-panel/hooks/use-prevent-programmatic-scroll.js +6 -0
- package/dist/cjs/drawer.js +25 -14
- package/dist/cjs/use-drawer-stack.js +88 -0
- package/dist/es2019/drawer-panel/drawer-content.js +11 -2
- package/dist/es2019/drawer-panel/drawer-slide-in.js +107 -0
- package/dist/es2019/drawer-panel/drawer-top-layer.compiled.css +8 -0
- package/dist/es2019/drawer-panel/drawer-top-layer.js +238 -0
- package/dist/es2019/drawer-panel/hooks/use-prevent-programmatic-scroll.js +6 -0
- package/dist/es2019/drawer.js +25 -14
- package/dist/es2019/use-drawer-stack.js +75 -0
- package/dist/esm/drawer-panel/drawer-content.js +11 -2
- package/dist/esm/drawer-panel/drawer-slide-in.js +61 -0
- package/dist/esm/drawer-panel/drawer-top-layer.compiled.css +8 -0
- package/dist/esm/drawer-panel/drawer-top-layer.js +247 -0
- package/dist/esm/drawer-panel/hooks/use-prevent-programmatic-scroll.js +6 -0
- package/dist/esm/drawer.js +25 -14
- package/dist/esm/use-drawer-stack.js +82 -0
- package/dist/types/drawer-panel/drawer-slide-in.d.ts +23 -0
- package/dist/types/drawer-panel/drawer-top-layer.d.ts +24 -0
- package/dist/types/drawer.d.ts +1 -1
- package/dist/types/use-drawer-stack.d.ts +17 -0
- package/package.json +14 -6
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = useDrawerStack;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
var _useLazyCallback = _interopRequireDefault(require("@atlaskit/ds-lib/use-lazy-callback"));
|
|
11
|
+
var _usePreviousValue = _interopRequireDefault(require("@atlaskit/ds-lib/use-previous-value"));
|
|
12
|
+
var _useStateRef3 = _interopRequireDefault(require("@atlaskit/ds-lib/use-state-ref"));
|
|
13
|
+
/**
|
|
14
|
+
* **Major versions will not know about each other**
|
|
15
|
+
*
|
|
16
|
+
* An array holding references to all currently open drawers. This only works
|
|
17
|
+
* for drawers of the same major version, because the reference differs between
|
|
18
|
+
* majors (for example V13 will not know about any from V14).
|
|
19
|
+
*
|
|
20
|
+
* Adapted from `useModalStack` in `@atlaskit/modal-dialog`. The top-layer drawer
|
|
21
|
+
* path uses this to know its position in the stack so that only the foreground
|
|
22
|
+
* drawer renders a visible `::backdrop` (this avoids cumulative darkening for
|
|
23
|
+
* nested or stacked drawers). Unlike the modal version, the register is timed
|
|
24
|
+
* off `isOpen` rather than `@atlaskit/motion`'s `useExitingPersistence`: the
|
|
25
|
+
* `Dialog` primitive owns its own exit lifecycle, so the top-layer drawer needs
|
|
26
|
+
* no `ExitingPersistence` wrapper.
|
|
27
|
+
*/
|
|
28
|
+
var drawerStackRegister = [];
|
|
29
|
+
/**
|
|
30
|
+
* Returns the position of the calling drawer in the drawer stack. A stack index
|
|
31
|
+
* of `0` is the foreground (top of the stack); higher numbers are further back.
|
|
32
|
+
*/
|
|
33
|
+
function useDrawerStack(_ref) {
|
|
34
|
+
var isOpen = _ref.isOpen,
|
|
35
|
+
onStackChange = _ref.onStackChange;
|
|
36
|
+
var _useStateRef = (0, _useStateRef3.default)(0),
|
|
37
|
+
_useStateRef2 = (0, _slicedToArray2.default)(_useStateRef, 2),
|
|
38
|
+
stackIndexRef = _useStateRef2[0],
|
|
39
|
+
setStackIndex = _useStateRef2[1];
|
|
40
|
+
var currentStackIndex = stackIndexRef.current;
|
|
41
|
+
var previousStackIndex = (0, _usePreviousValue.default)(stackIndexRef.current);
|
|
42
|
+
|
|
43
|
+
// Kept stable for the lifetime of the component so it can be the identity in
|
|
44
|
+
// the shared register. This is why it is a lazy callback and not a
|
|
45
|
+
// useMemo/useCallback value.
|
|
46
|
+
var updateStack = (0, _useLazyCallback.default)(function () {
|
|
47
|
+
var newStackIndex = drawerStackRegister.indexOf(updateStack);
|
|
48
|
+
// Read from the ref rather than state: this closure only ever sees the
|
|
49
|
+
// initial state value.
|
|
50
|
+
if (stackIndexRef.current !== newStackIndex) {
|
|
51
|
+
setStackIndex(newStackIndex);
|
|
52
|
+
stackIndexRef.current = newStackIndex;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
(0, _react.useEffect)(function () {
|
|
56
|
+
if (!isOpen) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
// Opening: join the front of the register (the newest open drawer is the
|
|
60
|
+
// foreground at index 0), then notify every open drawer to recompute.
|
|
61
|
+
if (drawerStackRegister.indexOf(updateStack) === -1) {
|
|
62
|
+
drawerStackRegister.unshift(updateStack);
|
|
63
|
+
}
|
|
64
|
+
drawerStackRegister.forEach(function (callback) {
|
|
65
|
+
return callback();
|
|
66
|
+
});
|
|
67
|
+
return function () {
|
|
68
|
+
// Closing or unmounting: leave the register and notify the rest.
|
|
69
|
+
var index = drawerStackRegister.indexOf(updateStack);
|
|
70
|
+
if (index !== -1) {
|
|
71
|
+
drawerStackRegister.splice(index, 1);
|
|
72
|
+
}
|
|
73
|
+
drawerStackRegister.forEach(function (callback) {
|
|
74
|
+
return callback();
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
}, [isOpen, updateStack]);
|
|
78
|
+
(0, _react.useEffect)(function () {
|
|
79
|
+
if (previousStackIndex === undefined) {
|
|
80
|
+
// Initial render: nothing to notify about.
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (previousStackIndex !== currentStackIndex) {
|
|
84
|
+
onStackChange === null || onStackChange === void 0 || onStackChange(currentStackIndex);
|
|
85
|
+
}
|
|
86
|
+
}, [onStackChange, previousStackIndex, currentStackIndex]);
|
|
87
|
+
return currentStackIndex;
|
|
88
|
+
}
|
|
@@ -5,6 +5,7 @@ import { ax, ix } from "@compiled/react/runtime";
|
|
|
5
5
|
import { forwardRef, useEffect, useRef, useState } from 'react';
|
|
6
6
|
import ScrollLock from 'react-scrolllock';
|
|
7
7
|
import { mergeRefs } from 'use-callback-ref';
|
|
8
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
8
9
|
import { useEnsureIsInsideDrawer } from '../use-ensure-is-inside-drawer';
|
|
9
10
|
import usePreventProgrammaticScroll from './hooks/use-prevent-programmatic-scroll';
|
|
10
11
|
const styles = {
|
|
@@ -48,8 +49,16 @@ export const DrawerContent = ({
|
|
|
48
49
|
}) => {
|
|
49
50
|
useEnsureIsInsideDrawer();
|
|
50
51
|
usePreventProgrammaticScroll();
|
|
51
|
-
|
|
52
|
+
const content = /*#__PURE__*/React.createElement(DrawerContentBase, {
|
|
52
53
|
scrollContentLabel: scrollContentLabel,
|
|
53
54
|
xcss: xcss
|
|
54
|
-
}, children)
|
|
55
|
+
}, children);
|
|
56
|
+
|
|
57
|
+
// Under the top-layer flag, background scroll is handled by `DialogScrollLock`
|
|
58
|
+
// (rendered by `DrawerTopLayer`), so we skip `react-scrolllock` here to avoid
|
|
59
|
+
// double-locking the body. See the top-layer migration scroll decision.
|
|
60
|
+
if (fg('platform-dst-top-layer')) {
|
|
61
|
+
return content;
|
|
62
|
+
}
|
|
63
|
+
return /*#__PURE__*/React.createElement(ScrollLock, null, content);
|
|
55
64
|
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Off-screen transform per entry edge. A drawer slides in from the edge it is
|
|
3
|
+
* pinned to and exits back to the same edge (legacy `SlideIn` used
|
|
4
|
+
* `exitTo={enterFrom}`), so enter and exit are symmetric.
|
|
5
|
+
*/
|
|
6
|
+
const HIDDEN_TRANSFORM = {
|
|
7
|
+
left: 'translateX(-100%)',
|
|
8
|
+
right: 'translateX(100%)',
|
|
9
|
+
top: 'translateY(-100%)',
|
|
10
|
+
bottom: 'translateY(100%)'
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// Match the legacy `CustomSlideIn`: `duration="small"` (100ms) on enter,
|
|
14
|
+
// `small * 0.5` (50ms) on exit, `ease-out` timing. Drawer slides with no panel
|
|
15
|
+
// fade (`fade="none"`); only the backdrop fades.
|
|
16
|
+
const ENTER_MS = 100;
|
|
17
|
+
const EXIT_MS = 50;
|
|
18
|
+
const EASE = 'cubic-bezier(0.2,0,0,1)'; // @atlaskit/motion `easeOut`
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Builds the slide CSS for a single entry edge, scoped to
|
|
22
|
+
* `[data-ds-dialog-drawer-slide-{from}]` (the `Dialog` primitive stamps
|
|
23
|
+
* `data-ds-dialog-{name}` on the `<dialog>` element).
|
|
24
|
+
*
|
|
25
|
+
* - base selector → hidden/exit state + exit duration
|
|
26
|
+
* - `[open]` → visible state + enter duration
|
|
27
|
+
* - `@starting-style` → initial (pre-paint) state so the entry transition runs
|
|
28
|
+
*
|
|
29
|
+
* The `::backdrop` fades its blanket colour in step with the panel. Stacked
|
|
30
|
+
* drawers hide their backdrop via the `Dialog` `shouldHideBackdrop` prop (an
|
|
31
|
+
* ID-scoped `<style>` whose specificity beats this rule).
|
|
32
|
+
*/
|
|
33
|
+
function buildCss(name, hidden) {
|
|
34
|
+
const sel = `[data-ds-dialog-${name}]`;
|
|
35
|
+
return `
|
|
36
|
+
${sel} {
|
|
37
|
+
transform: ${hidden};
|
|
38
|
+
transition:
|
|
39
|
+
transform ${EXIT_MS}ms ${EASE},
|
|
40
|
+
overlay ${EXIT_MS}ms allow-discrete,
|
|
41
|
+
display ${EXIT_MS}ms allow-discrete;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
${sel}[open] {
|
|
45
|
+
transform: none;
|
|
46
|
+
transition-duration: ${ENTER_MS}ms;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@starting-style {
|
|
50
|
+
${sel}[open] {
|
|
51
|
+
transform: ${hidden};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
${sel}::backdrop {
|
|
56
|
+
background-color: transparent;
|
|
57
|
+
transition:
|
|
58
|
+
background-color ${EXIT_MS}ms ${EASE},
|
|
59
|
+
overlay ${EXIT_MS}ms allow-discrete,
|
|
60
|
+
display ${EXIT_MS}ms allow-discrete;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
${sel}[open]::backdrop {
|
|
64
|
+
background-color: var(--ds-blanket, #050C1F75);
|
|
65
|
+
transition-duration: ${ENTER_MS}ms;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@starting-style {
|
|
69
|
+
${sel}[open]::backdrop {
|
|
70
|
+
background-color: transparent;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@media (prefers-reduced-motion: reduce) {
|
|
75
|
+
${sel},
|
|
76
|
+
${sel}[open],
|
|
77
|
+
${sel}::backdrop,
|
|
78
|
+
${sel}[open]::backdrop {
|
|
79
|
+
transition-duration: 0s;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
`;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Directional slide animation for the top-layer `Drawer`, passed to the
|
|
86
|
+
* `Dialog` primitive's `animate` prop. Local to `@atlaskit/drawer` (not a
|
|
87
|
+
* shared top-layer preset). The panel slides in from its pinned viewport edge
|
|
88
|
+
* while the `::backdrop` fades.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```tsx
|
|
92
|
+
* <Dialog animate={drawerSlideIn({ from: 'left' })} isOpen={isOpen} onClose={onClose} label="...">
|
|
93
|
+
* ...
|
|
94
|
+
* </Dialog>
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export function drawerSlideIn({
|
|
98
|
+
from = 'left'
|
|
99
|
+
} = {}) {
|
|
100
|
+
const name = `drawer-slide-${from}`;
|
|
101
|
+
return {
|
|
102
|
+
name,
|
|
103
|
+
css: buildCss(name, HIDDEN_TRANSFORM[from]),
|
|
104
|
+
enterDurationMs: ENTER_MS,
|
|
105
|
+
exitDurationMs: EXIT_MS
|
|
106
|
+
};
|
|
107
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
._18m915vq{overflow-y:hidden}
|
|
2
|
+
._1bsb1osq{width:100%}
|
|
3
|
+
._1e0c1txw{display:flex}
|
|
4
|
+
._1q1l1bhr{--ds-elevation-surface-current:var(--ds-surface-overlay,#fff)}
|
|
5
|
+
._1reo15vq{overflow-x:hidden}
|
|
6
|
+
._4t3i1osq{height:100%}
|
|
7
|
+
._bfhk1bhr{background-color:var(--ds-surface-overlay,#fff)}
|
|
8
|
+
._ect4ttxp{font-family:var(--ds-font-family-body,"Atlassian Sans",ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/* drawer-top-layer.tsx generated by @compiled/babel-plugin v0.39.1 */
|
|
2
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
3
|
+
import "./drawer-top-layer.compiled.css";
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { ax, ix } from "@compiled/react/runtime";
|
|
6
|
+
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
7
|
+
import { bind } from 'bind-event-listener';
|
|
8
|
+
import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next/usePlatformLeafEventHandler';
|
|
9
|
+
import { createCloseEvent, Dialog } from '@atlaskit/top-layer/dialog';
|
|
10
|
+
import { DialogScrollLock } from '@atlaskit/top-layer/dialog-scroll-lock';
|
|
11
|
+
import { EnsureIsInsideDrawerContext } from '../ensure-is-inside-drawer-context';
|
|
12
|
+
import { OnCloseContext } from '../on-close-context';
|
|
13
|
+
import useDrawerStack from '../use-drawer-stack';
|
|
14
|
+
import { drawerSlideIn } from './drawer-slide-in';
|
|
15
|
+
const LOCAL_CURRENT_SURFACE_CSS_VAR = '--ds-elevation-surface-current';
|
|
16
|
+
const styles = {
|
|
17
|
+
surface: "_1reo15vq _18m915vq _1e0c1txw _1bsb1osq _4t3i1osq _bfhk1bhr _1q1l1bhr _ect4ttxp"
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Width presets mirror the legacy `DrawerPanel`. Applied to the `<dialog>` (the
|
|
21
|
+
// sized, edge-pinned element) and clamped to the viewport for mobile safety.
|
|
22
|
+
const WIDTH_MAP = {
|
|
23
|
+
narrow: '360px',
|
|
24
|
+
medium: '480px',
|
|
25
|
+
wide: '600px',
|
|
26
|
+
extended: '95vw',
|
|
27
|
+
full: '100vw'
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Resolve the native `<dialog>` accessible name props. Prefer the consumer's
|
|
32
|
+
* `label`, then their `titleId`. If neither is supplied (legacy allowed this),
|
|
33
|
+
* fall back to a generic name so the dialog is never unlabelled. Note:
|
|
34
|
+
* `@atlaskit/drawer` has no i18n setup, so this fallback is English only;
|
|
35
|
+
* consumers should pass a localised `label` or `titleId`.
|
|
36
|
+
*/
|
|
37
|
+
function getAccessibleName({
|
|
38
|
+
label,
|
|
39
|
+
titleId
|
|
40
|
+
}) {
|
|
41
|
+
if (label) {
|
|
42
|
+
return {
|
|
43
|
+
label
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (titleId) {
|
|
47
|
+
return {
|
|
48
|
+
labelledBy: titleId
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
label: 'Drawer'
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* **DrawerTopLayer**
|
|
58
|
+
*
|
|
59
|
+
* Top-layer (`platform-dst-top-layer`) implementation of `Drawer`. Renders a
|
|
60
|
+
* native `<dialog>` via `@atlaskit/top-layer`, replacing Portal, Blanket,
|
|
61
|
+
* react-focus-lock, react-scrolllock and `@atlaskit/layering` with native
|
|
62
|
+
* modality, `::backdrop`, focus trap and return, and `DialogScrollLock`.
|
|
63
|
+
*
|
|
64
|
+
* The `Dialog` primitive owns the entry and exit animation lifecycle (it keeps
|
|
65
|
+
* the host element mounted through the exit transition, then fires
|
|
66
|
+
* `onExitFinish`), so no `ExitingPersistence` wrapper is needed: the drawer
|
|
67
|
+
* renders `<Dialog isOpen={isOpen}>` directly. `useDrawerStack` tracks stack
|
|
68
|
+
* depth so only the foreground drawer shows a `::backdrop`.
|
|
69
|
+
*
|
|
70
|
+
* `isFocusLockEnabled` is intentionally unsupported: a native modal `<dialog>`
|
|
71
|
+
* always traps focus, so `isFocusLockEnabled={false}` is a no-op under this gate.
|
|
72
|
+
*/
|
|
73
|
+
export function DrawerTopLayer({
|
|
74
|
+
width = 'narrow',
|
|
75
|
+
isOpen,
|
|
76
|
+
shouldReturnFocus = true,
|
|
77
|
+
onKeyDown,
|
|
78
|
+
testId,
|
|
79
|
+
children,
|
|
80
|
+
onClose,
|
|
81
|
+
onCloseComplete,
|
|
82
|
+
onOpenComplete,
|
|
83
|
+
label,
|
|
84
|
+
titleId,
|
|
85
|
+
enterFrom = 'left'
|
|
86
|
+
}) {
|
|
87
|
+
const stackIndex = useDrawerStack({
|
|
88
|
+
isOpen
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Points to the panel surface. Passed to `onOpenComplete` / `onCloseComplete`.
|
|
93
|
+
*/
|
|
94
|
+
const contentRef = useRef(null);
|
|
95
|
+
// Cache the last content element so `onCloseComplete` still receives a node
|
|
96
|
+
// after children unmount (with reduced motion `contentRef` can clear before
|
|
97
|
+
// `onExitFinish` fires).
|
|
98
|
+
const lastContentElRef = useRef(null);
|
|
99
|
+
// Callback ref runs at commit (not during render), so both refs stay
|
|
100
|
+
// populated without a render-time side effect. `lastContentElRef` only
|
|
101
|
+
// overwrites with a non-null node, preserving it across the unmount.
|
|
102
|
+
const setContentEl = useCallback(el => {
|
|
103
|
+
contentRef.current = el;
|
|
104
|
+
if (el) {
|
|
105
|
+
lastContentElRef.current = el;
|
|
106
|
+
}
|
|
107
|
+
}, []);
|
|
108
|
+
|
|
109
|
+
// Analytics-wrapped close handlers, one per legacy trigger.
|
|
110
|
+
const handleEscapeClose = usePlatformLeafEventHandler({
|
|
111
|
+
fn: (evt, analyticsEvent) => onClose === null || onClose === void 0 ? void 0 : onClose(evt, analyticsEvent),
|
|
112
|
+
action: 'dismissed',
|
|
113
|
+
componentName: 'drawer',
|
|
114
|
+
packageName: "@atlaskit/drawer",
|
|
115
|
+
packageVersion: "13.1.1",
|
|
116
|
+
analyticsData: {
|
|
117
|
+
trigger: 'escKey'
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
const handleBlanketClose = usePlatformLeafEventHandler({
|
|
121
|
+
fn: (evt, analyticsEvent) => onClose === null || onClose === void 0 ? void 0 : onClose(evt, analyticsEvent),
|
|
122
|
+
action: 'dismissed',
|
|
123
|
+
componentName: 'drawer',
|
|
124
|
+
packageName: "@atlaskit/drawer",
|
|
125
|
+
packageVersion: "13.1.1",
|
|
126
|
+
analyticsData: {
|
|
127
|
+
trigger: 'blanket'
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
const handleBackButtonClose = usePlatformLeafEventHandler({
|
|
131
|
+
fn: (evt, analyticsEvent) => onClose === null || onClose === void 0 ? void 0 : onClose(evt, analyticsEvent),
|
|
132
|
+
action: 'dismissed',
|
|
133
|
+
componentName: 'drawer',
|
|
134
|
+
packageName: "@atlaskit/drawer",
|
|
135
|
+
packageVersion: "13.1.1",
|
|
136
|
+
analyticsData: {
|
|
137
|
+
trigger: 'backButton'
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// Bridge the Dialog primitive's `onClose({ reason })` to the legacy
|
|
142
|
+
// `onClose(event, analyticsEvent)` contract via a synthetic event. Drawer
|
|
143
|
+
// has no `shouldCloseOn*` props, so both reasons always forward.
|
|
144
|
+
const handleDialogClose = useCallback(({
|
|
145
|
+
reason
|
|
146
|
+
}) => {
|
|
147
|
+
const event = createCloseEvent({
|
|
148
|
+
reason
|
|
149
|
+
});
|
|
150
|
+
if (reason === 'escape') {
|
|
151
|
+
handleEscapeClose(event);
|
|
152
|
+
} else {
|
|
153
|
+
handleBlanketClose(event);
|
|
154
|
+
}
|
|
155
|
+
}, [handleEscapeClose, handleBlanketClose]);
|
|
156
|
+
|
|
157
|
+
// Mirror the legacy window `keydown` listener so `onKeyDown` still fires
|
|
158
|
+
// while the drawer is open.
|
|
159
|
+
const handleKeyDown = useCallback(evt => {
|
|
160
|
+
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(evt);
|
|
161
|
+
}, [onKeyDown]);
|
|
162
|
+
useEffect(() => {
|
|
163
|
+
if (!isOpen) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
return bind(window, {
|
|
167
|
+
type: 'keydown',
|
|
168
|
+
listener: handleKeyDown
|
|
169
|
+
});
|
|
170
|
+
}, [isOpen, handleKeyDown]);
|
|
171
|
+
|
|
172
|
+
// `onOpenComplete` once the entry animation settles (via `Dialog`'s
|
|
173
|
+
// `onEnterFinish`, which the underlying hook fires for animated,
|
|
174
|
+
// non-animated and reduced-motion paths).
|
|
175
|
+
const handleEnterFinish = useCallback(() => {
|
|
176
|
+
onOpenComplete === null || onOpenComplete === void 0 ? void 0 : onOpenComplete(contentRef.current);
|
|
177
|
+
}, [onOpenComplete]);
|
|
178
|
+
|
|
179
|
+
// `onCloseComplete` once the exit animation settles (via `Dialog`'s
|
|
180
|
+
// `onExitFinish`). This is also where a custom `shouldReturnFocus={ref}` is
|
|
181
|
+
// honoured: native `<dialog>` restores focus to the trigger at the start of
|
|
182
|
+
// close, so the consumer's ref is focused now that the exit is done.
|
|
183
|
+
// `shouldReturnFocus={false}` is a documented best-effort limitation; native
|
|
184
|
+
// always restores focus to the trigger.
|
|
185
|
+
const handleExitFinish = useCallback(() => {
|
|
186
|
+
var _contentRef$current;
|
|
187
|
+
onCloseComplete === null || onCloseComplete === void 0 ? void 0 : onCloseComplete((_contentRef$current = contentRef.current) !== null && _contentRef$current !== void 0 ? _contentRef$current : lastContentElRef.current);
|
|
188
|
+
lastContentElRef.current = null;
|
|
189
|
+
if (typeof shouldReturnFocus === 'object' && shouldReturnFocus !== null && shouldReturnFocus !== void 0 && shouldReturnFocus.current) {
|
|
190
|
+
shouldReturnFocus.current.focus();
|
|
191
|
+
}
|
|
192
|
+
}, [onCloseComplete, shouldReturnFocus]);
|
|
193
|
+
|
|
194
|
+
// Pin the `<dialog>` full-height to the inline-start edge (overriding the
|
|
195
|
+
// primitive's centred `margin: auto`); width from the preset, clamped to the
|
|
196
|
+
// viewport. `enterFrom` only drives the slide animation, not the pin edge;
|
|
197
|
+
// it matches the legacy panel, which always pins `inset-inline-start`.
|
|
198
|
+
const dialogStyle = {
|
|
199
|
+
margin: 0,
|
|
200
|
+
insetBlockStart: 0,
|
|
201
|
+
insetInlineStart: 0,
|
|
202
|
+
insetInlineEnd: 'auto',
|
|
203
|
+
height: '100dvh',
|
|
204
|
+
maxHeight: '100dvh',
|
|
205
|
+
width: `min(${WIDTH_MAP[width]}, 100vw)`
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// Memoized so the preset object (and its CSS string) is rebuilt only when
|
|
209
|
+
// `enterFrom` changes, not on every render.
|
|
210
|
+
const animate = useMemo(() => drawerSlideIn({
|
|
211
|
+
from: enterFrom
|
|
212
|
+
}), [enterFrom]);
|
|
213
|
+
const accessibleName = getAccessibleName({
|
|
214
|
+
label,
|
|
215
|
+
titleId
|
|
216
|
+
});
|
|
217
|
+
return /*#__PURE__*/React.createElement(Dialog, _extends({
|
|
218
|
+
isOpen: isOpen,
|
|
219
|
+
onClose: handleDialogClose,
|
|
220
|
+
onEnterFinish: handleEnterFinish,
|
|
221
|
+
onExitFinish: handleExitFinish,
|
|
222
|
+
animate: animate,
|
|
223
|
+
shouldHideBackdrop: stackIndex > 0,
|
|
224
|
+
testId: testId
|
|
225
|
+
}, accessibleName, {
|
|
226
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
|
|
227
|
+
style: dialogStyle
|
|
228
|
+
}), /*#__PURE__*/React.createElement(DialogScrollLock, {
|
|
229
|
+
isOpen: true
|
|
230
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
231
|
+
ref: setContentEl,
|
|
232
|
+
className: ax([styles.surface])
|
|
233
|
+
}, /*#__PURE__*/React.createElement(EnsureIsInsideDrawerContext.Provider, {
|
|
234
|
+
value: true
|
|
235
|
+
}, /*#__PURE__*/React.createElement(OnCloseContext.Provider, {
|
|
236
|
+
value: handleBackButtonClose
|
|
237
|
+
}, children))));
|
|
238
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useCallback, useEffect, useLayoutEffect, useState } from 'react';
|
|
2
2
|
import { bind } from 'bind-event-listener';
|
|
3
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Returns how far the body is scrolled from the top of the viewport.
|
|
@@ -37,6 +38,11 @@ export default function usePreventProgrammaticScroll() {
|
|
|
37
38
|
}
|
|
38
39
|
}, [scrollTopOffset]);
|
|
39
40
|
useEffect(() => {
|
|
41
|
+
// The top-layer drawer relies on native modality + `DialogScrollLock`; the
|
|
42
|
+
// programmatic-scroll guard is intentionally dropped under the flag.
|
|
43
|
+
if (fg('platform-dst-top-layer')) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
40
46
|
return bind(window, {
|
|
41
47
|
type: 'scroll',
|
|
42
48
|
listener: onWindowScroll
|
package/dist/es2019/drawer.js
CHANGED
|
@@ -4,9 +4,11 @@ import React, { useCallback, useEffect } from 'react';
|
|
|
4
4
|
import { canUseDOM } from 'exenv';
|
|
5
5
|
import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next';
|
|
6
6
|
import { Layering, useCloseOnEscapePress } from '@atlaskit/layering';
|
|
7
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
7
8
|
import Portal from '@atlaskit/portal';
|
|
8
9
|
import Blanket from './blanket';
|
|
9
10
|
import { DrawerPanel } from './drawer-panel/drawer-panel';
|
|
11
|
+
import { DrawerTopLayer } from './drawer-panel/drawer-top-layer';
|
|
10
12
|
// escape close manager for layering
|
|
11
13
|
const EscapeCloseManager = ({
|
|
12
14
|
onClose
|
|
@@ -20,17 +22,7 @@ const EscapeCloseManager = ({
|
|
|
20
22
|
});
|
|
21
23
|
return /*#__PURE__*/React.createElement("span", null);
|
|
22
24
|
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* __Drawer__
|
|
26
|
-
*
|
|
27
|
-
* A drawer is a panel that slides in from the left side of the screen.
|
|
28
|
-
*
|
|
29
|
-
* - [Examples](https://atlassian.design/components/drawer/examples)
|
|
30
|
-
* - [Code](https://atlassian.design/components/drawer/code)
|
|
31
|
-
* - [Usage](https://atlassian.design/components/drawer/usage)
|
|
32
|
-
*/
|
|
33
|
-
export const Drawer = ({
|
|
25
|
+
const DrawerBase = ({
|
|
34
26
|
width = 'narrow',
|
|
35
27
|
isOpen,
|
|
36
28
|
isFocusLockEnabled = true,
|
|
@@ -52,7 +44,7 @@ export const Drawer = ({
|
|
|
52
44
|
action: 'dismissed',
|
|
53
45
|
componentName: 'drawer',
|
|
54
46
|
packageName: "@atlaskit/drawer",
|
|
55
|
-
packageVersion: "13.
|
|
47
|
+
packageVersion: "13.1.1",
|
|
56
48
|
analyticsData: {
|
|
57
49
|
trigger: 'escKey'
|
|
58
50
|
}
|
|
@@ -73,7 +65,7 @@ export const Drawer = ({
|
|
|
73
65
|
action: 'dismissed',
|
|
74
66
|
componentName: 'drawer',
|
|
75
67
|
packageName: "@atlaskit/drawer",
|
|
76
|
-
packageVersion: "13.
|
|
68
|
+
packageVersion: "13.1.1",
|
|
77
69
|
analyticsData: {
|
|
78
70
|
trigger: 'blanket'
|
|
79
71
|
}
|
|
@@ -83,7 +75,7 @@ export const Drawer = ({
|
|
|
83
75
|
action: 'dismissed',
|
|
84
76
|
componentName: 'drawer',
|
|
85
77
|
packageName: "@atlaskit/drawer",
|
|
86
|
-
packageVersion: "13.
|
|
78
|
+
packageVersion: "13.1.1",
|
|
87
79
|
analyticsData: {
|
|
88
80
|
trigger: 'backButton'
|
|
89
81
|
}
|
|
@@ -116,4 +108,23 @@ export const Drawer = ({
|
|
|
116
108
|
}, children, /*#__PURE__*/React.createElement(EscapeCloseManager, {
|
|
117
109
|
onClose: handleClose
|
|
118
110
|
})) : children));
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* __Drawer__
|
|
115
|
+
*
|
|
116
|
+
* A drawer is a panel that slides in from the left side of the screen.
|
|
117
|
+
*
|
|
118
|
+
* - [Examples](https://atlassian.design/components/drawer/examples)
|
|
119
|
+
* - [Code](https://atlassian.design/components/drawer/code)
|
|
120
|
+
* - [Usage](https://atlassian.design/components/drawer/usage)
|
|
121
|
+
*/
|
|
122
|
+
export const Drawer = props => {
|
|
123
|
+
if (fg('platform-dst-top-layer')) {
|
|
124
|
+
// eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props -- internal implementation component takes the same DrawerProps
|
|
125
|
+
return /*#__PURE__*/React.createElement(DrawerTopLayer, props);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props -- internal implementation component takes the same DrawerProps
|
|
129
|
+
return /*#__PURE__*/React.createElement(DrawerBase, props);
|
|
119
130
|
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import useLazyCallback from '@atlaskit/ds-lib/use-lazy-callback';
|
|
3
|
+
import usePreviousValue from '@atlaskit/ds-lib/use-previous-value';
|
|
4
|
+
import useStateRef from '@atlaskit/ds-lib/use-state-ref';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* **Major versions will not know about each other**
|
|
8
|
+
*
|
|
9
|
+
* An array holding references to all currently open drawers. This only works
|
|
10
|
+
* for drawers of the same major version, because the reference differs between
|
|
11
|
+
* majors (for example V13 will not know about any from V14).
|
|
12
|
+
*
|
|
13
|
+
* Adapted from `useModalStack` in `@atlaskit/modal-dialog`. The top-layer drawer
|
|
14
|
+
* path uses this to know its position in the stack so that only the foreground
|
|
15
|
+
* drawer renders a visible `::backdrop` (this avoids cumulative darkening for
|
|
16
|
+
* nested or stacked drawers). Unlike the modal version, the register is timed
|
|
17
|
+
* off `isOpen` rather than `@atlaskit/motion`'s `useExitingPersistence`: the
|
|
18
|
+
* `Dialog` primitive owns its own exit lifecycle, so the top-layer drawer needs
|
|
19
|
+
* no `ExitingPersistence` wrapper.
|
|
20
|
+
*/
|
|
21
|
+
const drawerStackRegister = [];
|
|
22
|
+
/**
|
|
23
|
+
* Returns the position of the calling drawer in the drawer stack. A stack index
|
|
24
|
+
* of `0` is the foreground (top of the stack); higher numbers are further back.
|
|
25
|
+
*/
|
|
26
|
+
export default function useDrawerStack({
|
|
27
|
+
isOpen,
|
|
28
|
+
onStackChange
|
|
29
|
+
}) {
|
|
30
|
+
const [stackIndexRef, setStackIndex] = useStateRef(0);
|
|
31
|
+
const currentStackIndex = stackIndexRef.current;
|
|
32
|
+
const previousStackIndex = usePreviousValue(stackIndexRef.current);
|
|
33
|
+
|
|
34
|
+
// Kept stable for the lifetime of the component so it can be the identity in
|
|
35
|
+
// the shared register. This is why it is a lazy callback and not a
|
|
36
|
+
// useMemo/useCallback value.
|
|
37
|
+
const updateStack = useLazyCallback(() => {
|
|
38
|
+
const newStackIndex = drawerStackRegister.indexOf(updateStack);
|
|
39
|
+
// Read from the ref rather than state: this closure only ever sees the
|
|
40
|
+
// initial state value.
|
|
41
|
+
if (stackIndexRef.current !== newStackIndex) {
|
|
42
|
+
setStackIndex(newStackIndex);
|
|
43
|
+
stackIndexRef.current = newStackIndex;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (!isOpen) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
// Opening: join the front of the register (the newest open drawer is the
|
|
51
|
+
// foreground at index 0), then notify every open drawer to recompute.
|
|
52
|
+
if (drawerStackRegister.indexOf(updateStack) === -1) {
|
|
53
|
+
drawerStackRegister.unshift(updateStack);
|
|
54
|
+
}
|
|
55
|
+
drawerStackRegister.forEach(callback => callback());
|
|
56
|
+
return () => {
|
|
57
|
+
// Closing or unmounting: leave the register and notify the rest.
|
|
58
|
+
const index = drawerStackRegister.indexOf(updateStack);
|
|
59
|
+
if (index !== -1) {
|
|
60
|
+
drawerStackRegister.splice(index, 1);
|
|
61
|
+
}
|
|
62
|
+
drawerStackRegister.forEach(callback => callback());
|
|
63
|
+
};
|
|
64
|
+
}, [isOpen, updateStack]);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (previousStackIndex === undefined) {
|
|
67
|
+
// Initial render: nothing to notify about.
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (previousStackIndex !== currentStackIndex) {
|
|
71
|
+
onStackChange === null || onStackChange === void 0 ? void 0 : onStackChange(currentStackIndex);
|
|
72
|
+
}
|
|
73
|
+
}, [onStackChange, previousStackIndex, currentStackIndex]);
|
|
74
|
+
return currentStackIndex;
|
|
75
|
+
}
|
|
@@ -6,6 +6,7 @@ import { ax, ix } from "@compiled/react/runtime";
|
|
|
6
6
|
import { forwardRef, useEffect, useRef, useState } from 'react';
|
|
7
7
|
import ScrollLock from 'react-scrolllock';
|
|
8
8
|
import { mergeRefs } from 'use-callback-ref';
|
|
9
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
9
10
|
import { useEnsureIsInsideDrawer } from '../use-ensure-is-inside-drawer';
|
|
10
11
|
import usePreventProgrammaticScroll from './hooks/use-prevent-programmatic-scroll';
|
|
11
12
|
var styles = {
|
|
@@ -51,8 +52,16 @@ export var DrawerContent = function DrawerContent(_ref2) {
|
|
|
51
52
|
xcss = _ref2.xcss;
|
|
52
53
|
useEnsureIsInsideDrawer();
|
|
53
54
|
usePreventProgrammaticScroll();
|
|
54
|
-
|
|
55
|
+
var content = /*#__PURE__*/React.createElement(DrawerContentBase, {
|
|
55
56
|
scrollContentLabel: scrollContentLabel,
|
|
56
57
|
xcss: xcss
|
|
57
|
-
}, children)
|
|
58
|
+
}, children);
|
|
59
|
+
|
|
60
|
+
// Under the top-layer flag, background scroll is handled by `DialogScrollLock`
|
|
61
|
+
// (rendered by `DrawerTopLayer`), so we skip `react-scrolllock` here to avoid
|
|
62
|
+
// double-locking the body. See the top-layer migration scroll decision.
|
|
63
|
+
if (fg('platform-dst-top-layer')) {
|
|
64
|
+
return content;
|
|
65
|
+
}
|
|
66
|
+
return /*#__PURE__*/React.createElement(ScrollLock, null, content);
|
|
58
67
|
};
|