@atlaskit/drawer 7.3.2 → 7.4.1
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 +16 -0
- package/dist/cjs/components/index.js +16 -16
- package/dist/cjs/components/primitives/drawer-wrapper.js +79 -0
- package/dist/cjs/components/{focus-lock.js → primitives/focus-lock.js} +16 -4
- package/dist/cjs/components/primitives/hooks/use-prevent-programmatic-scroll.js +64 -0
- package/dist/cjs/components/primitives/index.js +31 -43
- package/dist/cjs/constants.js +8 -2
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/components/index.js +9 -12
- package/dist/es2019/components/primitives/drawer-wrapper.js +63 -0
- package/dist/es2019/components/{focus-lock.js → primitives/focus-lock.js} +11 -4
- package/dist/es2019/components/primitives/hooks/use-prevent-programmatic-scroll.js +48 -0
- package/dist/es2019/components/primitives/index.js +31 -44
- package/dist/es2019/constants.js +6 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/components/index.js +15 -15
- package/dist/esm/components/primitives/drawer-wrapper.js +63 -0
- package/dist/esm/components/{focus-lock.js → primitives/focus-lock.js} +13 -3
- package/dist/esm/components/primitives/hooks/use-prevent-programmatic-scroll.js +53 -0
- package/dist/esm/components/primitives/index.js +27 -40
- package/dist/esm/constants.js +5 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/components/index.d.ts +8 -8
- package/dist/types/components/primitives/drawer-wrapper.d.ts +22 -0
- package/dist/types/components/primitives/focus-lock.d.ts +11 -0
- package/dist/types/components/primitives/hooks/use-prevent-programmatic-scroll.d.ts +9 -0
- package/dist/types/components/primitives/index.d.ts +1 -1
- package/dist/types/components/types.d.ts +12 -9
- package/dist/types/constants.d.ts +2 -1
- package/package.json +10 -15
- package/report.api.md +49 -98
- package/dist/types/components/focus-lock.d.ts +0 -6
- package/dist/types-ts4.0/components/blanket.d.ts +0 -11
- package/dist/types-ts4.0/components/focus-lock.d.ts +0 -6
- package/dist/types-ts4.0/components/index.d.ts +0 -31
- package/dist/types-ts4.0/components/primitives/content.d.ts +0 -8
- package/dist/types-ts4.0/components/primitives/icon-button.d.ts +0 -8
- package/dist/types-ts4.0/components/primitives/index.d.ts +0 -5
- package/dist/types-ts4.0/components/primitives/sidebar.d.ts +0 -9
- package/dist/types-ts4.0/components/types.d.ts +0 -134
- package/dist/types-ts4.0/components/utils.d.ts +0 -7
- package/dist/types-ts4.0/constants.d.ts +0 -6
- package/dist/types-ts4.0/index.d.ts +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/drawer
|
|
2
2
|
|
|
3
|
+
## 7.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 7.4.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [`3d5675d420e`](https://bitbucket.org/atlassian/atlassian-frontend/commits/3d5675d420e) - [ux] Prevents the background from being scrollable while a drawer is open.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
3
19
|
## 7.3.2
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -31,9 +31,9 @@ var _analyticsNext = require("@atlaskit/analytics-next");
|
|
|
31
31
|
|
|
32
32
|
var _portal = _interopRequireDefault(require("@atlaskit/portal"));
|
|
33
33
|
|
|
34
|
-
var
|
|
34
|
+
var _constants = require("../constants");
|
|
35
35
|
|
|
36
|
-
var
|
|
36
|
+
var _blanket = _interopRequireDefault(require("./blanket"));
|
|
37
37
|
|
|
38
38
|
var _primitives = _interopRequireDefault(require("./primitives"));
|
|
39
39
|
|
|
@@ -41,12 +41,16 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
41
41
|
|
|
42
42
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
43
43
|
|
|
44
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
45
|
+
|
|
46
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
47
|
+
|
|
44
48
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
45
49
|
|
|
46
50
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
47
51
|
|
|
48
52
|
var packageName = "@atlaskit/drawer";
|
|
49
|
-
var packageVersion = "7.
|
|
53
|
+
var packageVersion = "7.4.1";
|
|
50
54
|
var createAndFireEventOnAtlaskit = (0, _analyticsNext.createAndFireEvent)('atlaskit');
|
|
51
55
|
|
|
52
56
|
var createAndFireOnClick = function createAndFireOnClick(createAnalyticsEvent, trigger) {
|
|
@@ -168,11 +172,7 @@ var DrawerBase = /*#__PURE__*/function (_Component) {
|
|
|
168
172
|
isOpen: isOpen,
|
|
169
173
|
onBlanketClicked: this.handleBlanketClick,
|
|
170
174
|
testId: testId && "".concat(testId, "--blanket")
|
|
171
|
-
}), /*#__PURE__*/_react.default.createElement(
|
|
172
|
-
autoFocusFirstElem: autoFocusFirstElem,
|
|
173
|
-
isFocusLockEnabled: isFocusLockEnabled,
|
|
174
|
-
shouldReturnFocus: shouldReturnFocus
|
|
175
|
-
}, /*#__PURE__*/_react.default.createElement(_primitives.default, {
|
|
175
|
+
}), /*#__PURE__*/_react.default.createElement(_primitives.default, {
|
|
176
176
|
testId: testId,
|
|
177
177
|
icon: icon,
|
|
178
178
|
in: isOpen,
|
|
@@ -182,20 +182,20 @@ var DrawerBase = /*#__PURE__*/function (_Component) {
|
|
|
182
182
|
width: width,
|
|
183
183
|
shouldUnmountOnExit: shouldUnmountOnExit // eslint-disable-next-line @repo/internal/react/no-unsafe-overrides
|
|
184
184
|
,
|
|
185
|
-
overrides: overrides
|
|
186
|
-
|
|
185
|
+
overrides: overrides,
|
|
186
|
+
autoFocusFirstElem: autoFocusFirstElem,
|
|
187
|
+
isFocusLockEnabled: isFocusLockEnabled,
|
|
188
|
+
shouldReturnFocus: shouldReturnFocus
|
|
189
|
+
}, children));
|
|
187
190
|
}
|
|
188
191
|
}]);
|
|
189
192
|
return DrawerBase;
|
|
190
193
|
}(_react.Component);
|
|
191
194
|
|
|
192
195
|
exports.DrawerBase = DrawerBase;
|
|
193
|
-
(0, _defineProperty2.default)(DrawerBase, "defaultProps", {
|
|
194
|
-
width: 'narrow'
|
|
195
|
-
|
|
196
|
-
shouldReturnFocus: true,
|
|
197
|
-
autoFocusFirstElem: false
|
|
198
|
-
});
|
|
196
|
+
(0, _defineProperty2.default)(DrawerBase, "defaultProps", _objectSpread({
|
|
197
|
+
width: 'narrow'
|
|
198
|
+
}, _constants.defaultFocusLockSettings));
|
|
199
199
|
|
|
200
200
|
var _default = (0, _analyticsNext.withAnalyticsContext)({
|
|
201
201
|
componentName: 'drawer',
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _react = require("react");
|
|
11
|
+
|
|
12
|
+
var _react2 = require("@emotion/react");
|
|
13
|
+
|
|
14
|
+
var _useCallbackRef = require("use-callback-ref");
|
|
15
|
+
|
|
16
|
+
var _colors = require("@atlaskit/theme/colors");
|
|
17
|
+
|
|
18
|
+
var _constants = require("@atlaskit/theme/constants");
|
|
19
|
+
|
|
20
|
+
var _usePreventProgrammaticScroll = _interopRequireDefault(require("./hooks/use-prevent-programmatic-scroll"));
|
|
21
|
+
|
|
22
|
+
/** @jsx jsx */
|
|
23
|
+
var widths = {
|
|
24
|
+
full: '100vw',
|
|
25
|
+
extended: '95vw',
|
|
26
|
+
narrow: 45 * (0, _constants.gridSize)(),
|
|
27
|
+
medium: 60 * (0, _constants.gridSize)(),
|
|
28
|
+
wide: 75 * (0, _constants.gridSize)()
|
|
29
|
+
};
|
|
30
|
+
var wrapperStyles = (0, _react2.css)({
|
|
31
|
+
display: 'flex',
|
|
32
|
+
height: '100vh',
|
|
33
|
+
position: 'fixed',
|
|
34
|
+
zIndex: _constants.layers.blanket() + 1,
|
|
35
|
+
top: 0,
|
|
36
|
+
left: 0,
|
|
37
|
+
backgroundColor: "var(--ds-surface-overlay, ".concat(_colors.N0, ")"),
|
|
38
|
+
overflow: 'hidden'
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A wrapper that controls the styling of the drawer with a few hacks with refs to get our Touch±Scroll locks working.
|
|
43
|
+
*/
|
|
44
|
+
var DrawerWrapper = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, scrollRef) {
|
|
45
|
+
var children = _ref.children,
|
|
46
|
+
className = _ref.className,
|
|
47
|
+
width = _ref.width,
|
|
48
|
+
testId = _ref.testId,
|
|
49
|
+
drawerRef = _ref.drawerRef;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* We use a callback ref to assign the `<Content />` component to the forwarded `scrollRef`.
|
|
53
|
+
* This ref comes from `react-scrolllock` to allow touch scrolling, eg.: `<ScrollLock><TouchScrollable>{children}</TouchScrollable><ScrollLock>`
|
|
54
|
+
*
|
|
55
|
+
* This is because we do not control the `<Content />` component in order to forward a ref to it (given it can be overriden via `DrawerPrimitiveProps['overrides']['Content']['component']`).
|
|
56
|
+
* Additionally, we target the last child because with `props.overrides.Sidebar.component = () => null` you only have one child.
|
|
57
|
+
* If both `Sidebar.component` and `Content.component` return null you will have no children and this will throw an error, but that doesn't seem valid.
|
|
58
|
+
*/
|
|
59
|
+
var assignSecondChildRef = (0, _react.useCallback)(function (node) {
|
|
60
|
+
var _node$children;
|
|
61
|
+
|
|
62
|
+
if (node !== null && node !== void 0 && (_node$children = node.children) !== null && _node$children !== void 0 && _node$children.length && typeof scrollRef === 'function') {
|
|
63
|
+
scrollRef(node.children[node.children.length - 1]);
|
|
64
|
+
}
|
|
65
|
+
}, [scrollRef]);
|
|
66
|
+
var ref = (0, _useCallbackRef.useMergeRefs)([drawerRef, assignSecondChildRef]);
|
|
67
|
+
(0, _usePreventProgrammaticScroll.default)();
|
|
68
|
+
return (0, _react2.jsx)("div", {
|
|
69
|
+
className: className,
|
|
70
|
+
css: wrapperStyles,
|
|
71
|
+
style: {
|
|
72
|
+
width: widths[width !== null && width !== void 0 ? width : 'narrow']
|
|
73
|
+
},
|
|
74
|
+
"data-testid": testId,
|
|
75
|
+
ref: ref
|
|
76
|
+
}, children);
|
|
77
|
+
});
|
|
78
|
+
var _default = DrawerWrapper;
|
|
79
|
+
exports.default = _default;
|
|
@@ -19,16 +19,26 @@ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime
|
|
|
19
19
|
|
|
20
20
|
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
21
21
|
|
|
22
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
23
|
+
|
|
22
24
|
var _react = _interopRequireWildcard(require("react"));
|
|
23
25
|
|
|
24
26
|
var _reactFocusLock = _interopRequireDefault(require("react-focus-lock"));
|
|
25
27
|
|
|
28
|
+
var _reactScrolllock = _interopRequireDefault(require("react-scrolllock"));
|
|
29
|
+
|
|
26
30
|
var _tinyInvariant = _interopRequireDefault(require("tiny-invariant"));
|
|
27
31
|
|
|
32
|
+
var _constants = require("../../constants");
|
|
33
|
+
|
|
28
34
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
29
35
|
|
|
30
36
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
31
37
|
|
|
38
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
39
|
+
|
|
40
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
41
|
+
|
|
32
42
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
33
43
|
|
|
34
44
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
@@ -53,7 +63,7 @@ var FocusLock = /*#__PURE__*/function (_Component) {
|
|
|
53
63
|
autoFocusFirstElem = _this$props.autoFocusFirstElem;
|
|
54
64
|
|
|
55
65
|
if (process.env.NODE_ENV !== 'production' && !process.env.CI) {
|
|
56
|
-
(0, _tinyInvariant.default)(typeof autoFocusFirstElem === 'boolean', '@atlaskit/
|
|
66
|
+
(0, _tinyInvariant.default)(typeof autoFocusFirstElem === 'boolean', '@atlaskit/drawer: Passing a function as autoFocus is deprecated. Instead call focus on the element ref or use the autofocus property.');
|
|
57
67
|
}
|
|
58
68
|
|
|
59
69
|
if (typeof autoFocusFirstElem === 'function' && isFocusLockEnabled) {
|
|
@@ -70,15 +80,17 @@ var FocusLock = /*#__PURE__*/function (_Component) {
|
|
|
70
80
|
var _this$props2 = this.props,
|
|
71
81
|
isFocusLockEnabled = _this$props2.isFocusLockEnabled,
|
|
72
82
|
autoFocusFirstElem = _this$props2.autoFocusFirstElem,
|
|
73
|
-
shouldReturnFocus = _this$props2.shouldReturnFocus
|
|
83
|
+
shouldReturnFocus = _this$props2.shouldReturnFocus,
|
|
84
|
+
children = _this$props2.children;
|
|
74
85
|
return /*#__PURE__*/_react.default.createElement(_reactFocusLock.default, {
|
|
75
86
|
disabled: !isFocusLockEnabled,
|
|
76
87
|
autoFocus: !!autoFocusFirstElem,
|
|
77
88
|
returnFocus: shouldReturnFocus
|
|
78
|
-
},
|
|
89
|
+
}, /*#__PURE__*/_react.default.createElement(_reactScrolllock.default, null, children));
|
|
79
90
|
}
|
|
80
91
|
}]);
|
|
81
92
|
return FocusLock;
|
|
82
93
|
}(_react.Component);
|
|
83
94
|
|
|
84
|
-
exports.default = FocusLock;
|
|
95
|
+
exports.default = FocusLock;
|
|
96
|
+
(0, _defineProperty2.default)(FocusLock, "defaultProps", _objectSpread({}, _constants.defaultFocusLockSettings));
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = usePreventProgrammaticScroll;
|
|
9
|
+
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
+
|
|
12
|
+
var _react = require("react");
|
|
13
|
+
|
|
14
|
+
var _bindEventListener = require("bind-event-listener");
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Returns how far the body is scrolled from the top of the viewport.
|
|
18
|
+
*
|
|
19
|
+
* ⚠️ This is copied from `packages/design-system/modal-dialog/src/internal/hooks/use-prevent-programmatic-scroll.tsx`
|
|
20
|
+
*
|
|
21
|
+
* ____
|
|
22
|
+
* ||____|| <-- overflow
|
|
23
|
+
* | | <-- viewport
|
|
24
|
+
* |____|
|
|
25
|
+
*
|
|
26
|
+
* Scroll distance is the height of overflow outside the viewport.
|
|
27
|
+
*/
|
|
28
|
+
function getScrollDistance() {
|
|
29
|
+
var _document$documentEle, _document$body;
|
|
30
|
+
|
|
31
|
+
return window.pageYOffset || ((_document$documentEle = document.documentElement) === null || _document$documentEle === void 0 ? void 0 : _document$documentEle.scrollTop) || ((_document$body = document.body) === null || _document$body === void 0 ? void 0 : _document$body.scrollTop) || 0;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Prevents programmatic scrolling of the viewport with `scrollIntoView`.
|
|
35
|
+
* Should be used in conjunction with a scroll lock to prevent a user from scrolling.
|
|
36
|
+
*
|
|
37
|
+
* ⚠️ This is copied from `packages/design-system/modal-dialog/src/internal/hooks/use-prevent-programmatic-scroll.tsx`
|
|
38
|
+
*
|
|
39
|
+
* @returns scroll top offset of the viewport
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
function usePreventProgrammaticScroll() {
|
|
44
|
+
var _useState = (0, _react.useState)(0),
|
|
45
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
46
|
+
scrollTopOffset = _useState2[0],
|
|
47
|
+
setScrollTopOffset = _useState2[1];
|
|
48
|
+
|
|
49
|
+
(0, _react.useLayoutEffect)(function () {
|
|
50
|
+
setScrollTopOffset(getScrollDistance());
|
|
51
|
+
}, []);
|
|
52
|
+
var onWindowScroll = (0, _react.useCallback)(function () {
|
|
53
|
+
if (getScrollDistance() !== scrollTopOffset) {
|
|
54
|
+
window.scrollTo(window.pageXOffset, scrollTopOffset);
|
|
55
|
+
}
|
|
56
|
+
}, [scrollTopOffset]);
|
|
57
|
+
(0, _react.useEffect)(function () {
|
|
58
|
+
return (0, _bindEventListener.bind)(window, {
|
|
59
|
+
type: 'scroll',
|
|
60
|
+
listener: onWindowScroll
|
|
61
|
+
});
|
|
62
|
+
}, [onWindowScroll]);
|
|
63
|
+
return scrollTopOffset;
|
|
64
|
+
}
|
|
@@ -17,42 +17,24 @@ var _arrowLeft = _interopRequireDefault(require("@atlaskit/icon/glyph/arrow-left
|
|
|
17
17
|
|
|
18
18
|
var _motion = require("@atlaskit/motion");
|
|
19
19
|
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
var _constants = require("@atlaskit/theme/constants");
|
|
23
|
-
|
|
24
|
-
var _constants2 = require("../../constants");
|
|
20
|
+
var _constants = require("../../constants");
|
|
25
21
|
|
|
26
22
|
var _utils = require("../utils");
|
|
27
23
|
|
|
28
24
|
var _content = _interopRequireDefault(require("./content"));
|
|
29
25
|
|
|
26
|
+
var _drawerWrapper = _interopRequireDefault(require("./drawer-wrapper"));
|
|
27
|
+
|
|
28
|
+
var _focusLock = _interopRequireDefault(require("./focus-lock"));
|
|
29
|
+
|
|
30
30
|
var _iconButton = _interopRequireDefault(require("./icon-button"));
|
|
31
31
|
|
|
32
32
|
var _sidebar = _interopRequireDefault(require("./sidebar"));
|
|
33
33
|
|
|
34
|
-
var _excluded = ["
|
|
35
|
-
_excluded2 = ["component"]
|
|
36
|
-
_excluded3 = ["component"];
|
|
34
|
+
var _excluded = ["component"],
|
|
35
|
+
_excluded2 = ["component"];
|
|
37
36
|
// Misc.
|
|
38
37
|
// ------------------------------
|
|
39
|
-
var widths = {
|
|
40
|
-
full: '100vw',
|
|
41
|
-
extended: '95vw',
|
|
42
|
-
narrow: 45 * (0, _constants.gridSize)(),
|
|
43
|
-
medium: 60 * (0, _constants.gridSize)(),
|
|
44
|
-
wide: 75 * (0, _constants.gridSize)()
|
|
45
|
-
};
|
|
46
|
-
var wrapperStyles = (0, _react2.css)({
|
|
47
|
-
display: 'flex',
|
|
48
|
-
height: '100vh',
|
|
49
|
-
position: 'fixed',
|
|
50
|
-
zIndex: _constants.layers.blanket() + 1,
|
|
51
|
-
top: 0,
|
|
52
|
-
left: 0,
|
|
53
|
-
backgroundColor: "var(--ds-surface-overlay, ".concat(_colors.N0, ")"),
|
|
54
|
-
overflow: 'hidden'
|
|
55
|
-
});
|
|
56
38
|
var defaults = {
|
|
57
39
|
Sidebar: _sidebar.default,
|
|
58
40
|
Content: _content.default
|
|
@@ -74,9 +56,9 @@ var CustomSlideIn = function CustomSlideIn(_ref) {
|
|
|
74
56
|
*/
|
|
75
57
|
|
|
76
58
|
|
|
77
|
-
var duration = isExiting ?
|
|
59
|
+
var duration = isExiting ? _constants.transitionDurationMs * 2 : _constants.transitionDurationMs;
|
|
78
60
|
return (0, _react2.jsx)(_motion.SlideIn, {
|
|
79
|
-
animationTimingFunction:
|
|
61
|
+
animationTimingFunction: _constants.animationTimingFunction,
|
|
80
62
|
duration: duration,
|
|
81
63
|
enterFrom: "left",
|
|
82
64
|
exitTo: "left",
|
|
@@ -94,23 +76,30 @@ var DrawerPrimitive = function DrawerPrimitive(_ref2) {
|
|
|
94
76
|
overrides = _ref2.overrides,
|
|
95
77
|
testId = _ref2.testId,
|
|
96
78
|
isOpen = _ref2.in,
|
|
97
|
-
|
|
79
|
+
shouldReturnFocus = _ref2.shouldReturnFocus,
|
|
80
|
+
autoFocusFirstElem = _ref2.autoFocusFirstElem,
|
|
81
|
+
isFocusLockEnabled = _ref2.isFocusLockEnabled,
|
|
82
|
+
width = _ref2.width;
|
|
98
83
|
var getOverrides = (0, _utils.createExtender)(defaults, overrides);
|
|
99
84
|
|
|
100
85
|
var _getOverrides = getOverrides('Sidebar'),
|
|
101
86
|
Sidebar = _getOverrides.component,
|
|
102
|
-
sideBarOverrides = (0, _objectWithoutProperties2.default)(_getOverrides,
|
|
87
|
+
sideBarOverrides = (0, _objectWithoutProperties2.default)(_getOverrides, _excluded);
|
|
103
88
|
|
|
104
89
|
var _getOverrides2 = getOverrides('Content'),
|
|
105
90
|
Content = _getOverrides2.component,
|
|
106
|
-
contentOverrides = (0, _objectWithoutProperties2.default)(_getOverrides2,
|
|
91
|
+
contentOverrides = (0, _objectWithoutProperties2.default)(_getOverrides2, _excluded2);
|
|
92
|
+
/**
|
|
93
|
+
* A ref to point to our wrapper, passed to `onCloseComplete` and `onOpenComplete` callbacks.
|
|
94
|
+
*/
|
|
107
95
|
|
|
108
|
-
|
|
96
|
+
|
|
97
|
+
var drawerRef = (0, _react.useRef)(null);
|
|
109
98
|
var onFinish = (0, _react.useCallback)(function (state) {
|
|
110
99
|
if (state === 'entering') {
|
|
111
|
-
onOpenComplete === null || onOpenComplete === void 0 ? void 0 : onOpenComplete(
|
|
100
|
+
onOpenComplete === null || onOpenComplete === void 0 ? void 0 : onOpenComplete(drawerRef.current);
|
|
112
101
|
} else if (state === 'exiting') {
|
|
113
|
-
onCloseComplete === null || onCloseComplete === void 0 ? void 0 : onCloseComplete(
|
|
102
|
+
onCloseComplete === null || onCloseComplete === void 0 ? void 0 : onCloseComplete(drawerRef.current);
|
|
114
103
|
}
|
|
115
104
|
}, [onCloseComplete, onOpenComplete]);
|
|
116
105
|
return (0, _react2.jsx)(_motion.ExitingPersistence, {
|
|
@@ -118,17 +107,16 @@ var DrawerPrimitive = function DrawerPrimitive(_ref2) {
|
|
|
118
107
|
}, isOpen && (0, _react2.jsx)(CustomSlideIn, {
|
|
119
108
|
onFinish: onFinish
|
|
120
109
|
}, function (_ref3) {
|
|
121
|
-
var _props$width;
|
|
122
|
-
|
|
123
110
|
var className = _ref3.className;
|
|
124
|
-
return (0, _react2.jsx)(
|
|
111
|
+
return (0, _react2.jsx)(_focusLock.default, {
|
|
112
|
+
autoFocusFirstElem: autoFocusFirstElem,
|
|
113
|
+
isFocusLockEnabled: isFocusLockEnabled,
|
|
114
|
+
shouldReturnFocus: shouldReturnFocus
|
|
115
|
+
}, (0, _react2.jsx)(_drawerWrapper.default, {
|
|
125
116
|
className: className,
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
},
|
|
130
|
-
"data-testid": testId,
|
|
131
|
-
ref: ref
|
|
117
|
+
width: width,
|
|
118
|
+
testId: testId,
|
|
119
|
+
drawerRef: drawerRef
|
|
132
120
|
}, (0, _react2.jsx)(Sidebar, sideBarOverrides, (0, _react2.jsx)(_iconButton.default, {
|
|
133
121
|
onClick: onClose,
|
|
134
122
|
testId: testId && 'DrawerPrimitiveSidebarCloseButton'
|
|
@@ -136,7 +124,7 @@ var DrawerPrimitive = function DrawerPrimitive(_ref2) {
|
|
|
136
124
|
size: "large"
|
|
137
125
|
}) : (0, _react2.jsx)(_arrowLeft.default, {
|
|
138
126
|
label: "Close drawer"
|
|
139
|
-
}))), (0, _react2.jsx)(Content, contentOverrides, children));
|
|
127
|
+
}))), (0, _react2.jsx)(Content, contentOverrides, children)));
|
|
140
128
|
}));
|
|
141
129
|
}; // eslint-disable-next-line @repo/internal/react/require-jsdoc
|
|
142
130
|
|
package/dist/cjs/constants.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.widths = exports.transitionTimingFunction = exports.transitionDurationMs = exports.transitionDuration = exports.animationTimingFunction = void 0;
|
|
6
|
+
exports.widths = exports.transitionTimingFunction = exports.transitionDurationMs = exports.transitionDuration = exports.defaultFocusLockSettings = exports.animationTimingFunction = void 0;
|
|
7
7
|
|
|
8
8
|
var _curves = require("@atlaskit/motion/curves");
|
|
9
9
|
|
|
@@ -20,4 +20,10 @@ var animationTimingFunction = function animationTimingFunction() {
|
|
|
20
20
|
return _curves.easeOut;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
exports.animationTimingFunction = animationTimingFunction;
|
|
23
|
+
exports.animationTimingFunction = animationTimingFunction;
|
|
24
|
+
var defaultFocusLockSettings = {
|
|
25
|
+
isFocusLockEnabled: true,
|
|
26
|
+
shouldReturnFocus: true,
|
|
27
|
+
autoFocusFirstElem: false
|
|
28
|
+
};
|
|
29
|
+
exports.defaultFocusLockSettings = defaultFocusLockSettings;
|
package/dist/cjs/version.json
CHANGED
|
@@ -5,11 +5,11 @@ import React, { Component } from 'react';
|
|
|
5
5
|
import { canUseDOM } from 'exenv';
|
|
6
6
|
import { createAndFireEvent, withAnalyticsContext, withAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
7
7
|
import Portal from '@atlaskit/portal';
|
|
8
|
+
import { defaultFocusLockSettings } from '../constants';
|
|
8
9
|
import Blanket from './blanket';
|
|
9
|
-
import FocusLock from './focus-lock';
|
|
10
10
|
import DrawerPrimitive from './primitives';
|
|
11
11
|
const packageName = "@atlaskit/drawer";
|
|
12
|
-
const packageVersion = "7.
|
|
12
|
+
const packageVersion = "7.4.1";
|
|
13
13
|
const createAndFireEventOnAtlaskit = createAndFireEvent('atlaskit');
|
|
14
14
|
|
|
15
15
|
const createAndFireOnClick = (createAnalyticsEvent, trigger) => createAndFireEventOnAtlaskit({
|
|
@@ -123,11 +123,7 @@ export class DrawerBase extends Component {
|
|
|
123
123
|
isOpen: isOpen,
|
|
124
124
|
onBlanketClicked: this.handleBlanketClick,
|
|
125
125
|
testId: testId && `${testId}--blanket`
|
|
126
|
-
}), /*#__PURE__*/React.createElement(
|
|
127
|
-
autoFocusFirstElem: autoFocusFirstElem,
|
|
128
|
-
isFocusLockEnabled: isFocusLockEnabled,
|
|
129
|
-
shouldReturnFocus: shouldReturnFocus
|
|
130
|
-
}, /*#__PURE__*/React.createElement(DrawerPrimitive, {
|
|
126
|
+
}), /*#__PURE__*/React.createElement(DrawerPrimitive, {
|
|
131
127
|
testId: testId,
|
|
132
128
|
icon: icon,
|
|
133
129
|
in: isOpen,
|
|
@@ -137,17 +133,18 @@ export class DrawerBase extends Component {
|
|
|
137
133
|
width: width,
|
|
138
134
|
shouldUnmountOnExit: shouldUnmountOnExit // eslint-disable-next-line @repo/internal/react/no-unsafe-overrides
|
|
139
135
|
,
|
|
140
|
-
overrides: overrides
|
|
141
|
-
|
|
136
|
+
overrides: overrides,
|
|
137
|
+
autoFocusFirstElem: autoFocusFirstElem,
|
|
138
|
+
isFocusLockEnabled: isFocusLockEnabled,
|
|
139
|
+
shouldReturnFocus: shouldReturnFocus
|
|
140
|
+
}, children));
|
|
142
141
|
}
|
|
143
142
|
|
|
144
143
|
}
|
|
145
144
|
|
|
146
145
|
_defineProperty(DrawerBase, "defaultProps", {
|
|
147
146
|
width: 'narrow',
|
|
148
|
-
|
|
149
|
-
shouldReturnFocus: true,
|
|
150
|
-
autoFocusFirstElem: false
|
|
147
|
+
...defaultFocusLockSettings
|
|
151
148
|
});
|
|
152
149
|
|
|
153
150
|
export default withAnalyticsContext({
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { forwardRef, useCallback } from 'react';
|
|
3
|
+
import { css, jsx } from '@emotion/react';
|
|
4
|
+
import { useMergeRefs } from 'use-callback-ref';
|
|
5
|
+
import { N0 } from '@atlaskit/theme/colors';
|
|
6
|
+
import { gridSize, layers } from '@atlaskit/theme/constants';
|
|
7
|
+
import usePreventProgrammaticScroll from './hooks/use-prevent-programmatic-scroll';
|
|
8
|
+
const widths = {
|
|
9
|
+
full: '100vw',
|
|
10
|
+
extended: '95vw',
|
|
11
|
+
narrow: 45 * gridSize(),
|
|
12
|
+
medium: 60 * gridSize(),
|
|
13
|
+
wide: 75 * gridSize()
|
|
14
|
+
};
|
|
15
|
+
const wrapperStyles = css({
|
|
16
|
+
display: 'flex',
|
|
17
|
+
height: '100vh',
|
|
18
|
+
position: 'fixed',
|
|
19
|
+
zIndex: layers.blanket() + 1,
|
|
20
|
+
top: 0,
|
|
21
|
+
left: 0,
|
|
22
|
+
backgroundColor: `var(--ds-surface-overlay, ${N0})`,
|
|
23
|
+
overflow: 'hidden'
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A wrapper that controls the styling of the drawer with a few hacks with refs to get our Touch±Scroll locks working.
|
|
28
|
+
*/
|
|
29
|
+
const DrawerWrapper = /*#__PURE__*/forwardRef(({
|
|
30
|
+
children,
|
|
31
|
+
className,
|
|
32
|
+
width,
|
|
33
|
+
testId,
|
|
34
|
+
drawerRef
|
|
35
|
+
}, scrollRef) => {
|
|
36
|
+
/**
|
|
37
|
+
* We use a callback ref to assign the `<Content />` component to the forwarded `scrollRef`.
|
|
38
|
+
* This ref comes from `react-scrolllock` to allow touch scrolling, eg.: `<ScrollLock><TouchScrollable>{children}</TouchScrollable><ScrollLock>`
|
|
39
|
+
*
|
|
40
|
+
* This is because we do not control the `<Content />` component in order to forward a ref to it (given it can be overriden via `DrawerPrimitiveProps['overrides']['Content']['component']`).
|
|
41
|
+
* Additionally, we target the last child because with `props.overrides.Sidebar.component = () => null` you only have one child.
|
|
42
|
+
* If both `Sidebar.component` and `Content.component` return null you will have no children and this will throw an error, but that doesn't seem valid.
|
|
43
|
+
*/
|
|
44
|
+
const assignSecondChildRef = useCallback(node => {
|
|
45
|
+
var _node$children;
|
|
46
|
+
|
|
47
|
+
if (node !== null && node !== void 0 && (_node$children = node.children) !== null && _node$children !== void 0 && _node$children.length && typeof scrollRef === 'function') {
|
|
48
|
+
scrollRef(node.children[node.children.length - 1]);
|
|
49
|
+
}
|
|
50
|
+
}, [scrollRef]);
|
|
51
|
+
const ref = useMergeRefs([drawerRef, assignSecondChildRef]);
|
|
52
|
+
usePreventProgrammaticScroll();
|
|
53
|
+
return jsx("div", {
|
|
54
|
+
className: className,
|
|
55
|
+
css: wrapperStyles,
|
|
56
|
+
style: {
|
|
57
|
+
width: widths[width !== null && width !== void 0 ? width : 'narrow']
|
|
58
|
+
},
|
|
59
|
+
"data-testid": testId,
|
|
60
|
+
ref: ref
|
|
61
|
+
}, children);
|
|
62
|
+
});
|
|
63
|
+
export default DrawerWrapper;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
1
2
|
import React, { Component } from 'react';
|
|
2
3
|
import ReactFocusLock from 'react-focus-lock';
|
|
4
|
+
import ScrollLock from 'react-scrolllock';
|
|
3
5
|
import invariant from 'tiny-invariant';
|
|
6
|
+
import { defaultFocusLockSettings } from '../../constants';
|
|
4
7
|
// Thin wrapper over react-focus-lock. This wrapper only exists to ensure API compatibility.
|
|
5
8
|
// This component should be deleted during https://ecosystem.atlassian.net/browse/AK-5658
|
|
6
9
|
export default class FocusLock extends Component {
|
|
@@ -11,7 +14,7 @@ export default class FocusLock extends Component {
|
|
|
11
14
|
} = this.props;
|
|
12
15
|
|
|
13
16
|
if (process.env.NODE_ENV !== 'production' && !process.env.CI) {
|
|
14
|
-
invariant(typeof autoFocusFirstElem === 'boolean', '@atlaskit/
|
|
17
|
+
invariant(typeof autoFocusFirstElem === 'boolean', '@atlaskit/drawer: Passing a function as autoFocus is deprecated. Instead call focus on the element ref or use the autofocus property.');
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
if (typeof autoFocusFirstElem === 'function' && isFocusLockEnabled) {
|
|
@@ -27,13 +30,17 @@ export default class FocusLock extends Component {
|
|
|
27
30
|
const {
|
|
28
31
|
isFocusLockEnabled,
|
|
29
32
|
autoFocusFirstElem,
|
|
30
|
-
shouldReturnFocus
|
|
33
|
+
shouldReturnFocus,
|
|
34
|
+
children
|
|
31
35
|
} = this.props;
|
|
32
36
|
return /*#__PURE__*/React.createElement(ReactFocusLock, {
|
|
33
37
|
disabled: !isFocusLockEnabled,
|
|
34
38
|
autoFocus: !!autoFocusFirstElem,
|
|
35
39
|
returnFocus: shouldReturnFocus
|
|
36
|
-
},
|
|
40
|
+
}, /*#__PURE__*/React.createElement(ScrollLock, null, children));
|
|
37
41
|
}
|
|
38
42
|
|
|
39
|
-
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
_defineProperty(FocusLock, "defaultProps", { ...defaultFocusLockSettings
|
|
46
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useCallback, useEffect, useLayoutEffect, useState } from 'react';
|
|
2
|
+
import { bind } from 'bind-event-listener';
|
|
3
|
+
/**
|
|
4
|
+
* Returns how far the body is scrolled from the top of the viewport.
|
|
5
|
+
*
|
|
6
|
+
* ⚠️ This is copied from `packages/design-system/modal-dialog/src/internal/hooks/use-prevent-programmatic-scroll.tsx`
|
|
7
|
+
*
|
|
8
|
+
* ____
|
|
9
|
+
* ||____|| <-- overflow
|
|
10
|
+
* | | <-- viewport
|
|
11
|
+
* |____|
|
|
12
|
+
*
|
|
13
|
+
* Scroll distance is the height of overflow outside the viewport.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
function getScrollDistance() {
|
|
17
|
+
var _document$documentEle, _document$body;
|
|
18
|
+
|
|
19
|
+
return window.pageYOffset || ((_document$documentEle = document.documentElement) === null || _document$documentEle === void 0 ? void 0 : _document$documentEle.scrollTop) || ((_document$body = document.body) === null || _document$body === void 0 ? void 0 : _document$body.scrollTop) || 0;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Prevents programmatic scrolling of the viewport with `scrollIntoView`.
|
|
23
|
+
* Should be used in conjunction with a scroll lock to prevent a user from scrolling.
|
|
24
|
+
*
|
|
25
|
+
* ⚠️ This is copied from `packages/design-system/modal-dialog/src/internal/hooks/use-prevent-programmatic-scroll.tsx`
|
|
26
|
+
*
|
|
27
|
+
* @returns scroll top offset of the viewport
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
export default function usePreventProgrammaticScroll() {
|
|
32
|
+
const [scrollTopOffset, setScrollTopOffset] = useState(0);
|
|
33
|
+
useLayoutEffect(() => {
|
|
34
|
+
setScrollTopOffset(getScrollDistance());
|
|
35
|
+
}, []);
|
|
36
|
+
const onWindowScroll = useCallback(() => {
|
|
37
|
+
if (getScrollDistance() !== scrollTopOffset) {
|
|
38
|
+
window.scrollTo(window.pageXOffset, scrollTopOffset);
|
|
39
|
+
}
|
|
40
|
+
}, [scrollTopOffset]);
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
return bind(window, {
|
|
43
|
+
type: 'scroll',
|
|
44
|
+
listener: onWindowScroll
|
|
45
|
+
});
|
|
46
|
+
}, [onWindowScroll]);
|
|
47
|
+
return scrollTopOffset;
|
|
48
|
+
}
|