@atlaskit/drawer 7.14.2 → 8.0.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 +17 -0
- package/dist/cjs/components/index.js +125 -180
- package/dist/cjs/components/primitives/focus-lock.js +44 -73
- package/dist/es2019/components/index.js +114 -158
- package/dist/es2019/components/primitives/focus-lock.js +37 -52
- package/dist/esm/components/index.js +123 -181
- package/dist/esm/components/primitives/focus-lock.js +44 -74
- package/dist/types/components/index.d.ts +3 -30
- package/dist/types/components/primitives/focus-lock.d.ts +9 -12
- package/dist/types/components/types.d.ts +3 -4
- package/dist/types-ts4.5/components/index.d.ts +3 -30
- package/dist/types-ts4.5/components/primitives/focus-lock.d.ts +9 -12
- package/dist/types-ts4.5/components/types.d.ts +3 -4
- package/package.json +5 -9
|
@@ -1,189 +1,24 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
-
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
4
|
-
import _inherits from "@babel/runtime/helpers/inherits";
|
|
5
|
-
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
6
|
-
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
7
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
8
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
9
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
11
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
12
1
|
/* eslint-disable @repo/internal/dom-events/no-unsafe-event-listeners */
|
|
13
|
-
import React, {
|
|
2
|
+
import React, { useCallback, useEffect } from 'react';
|
|
14
3
|
import { canUseDOM } from 'exenv';
|
|
15
|
-
import {
|
|
4
|
+
import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next';
|
|
16
5
|
import { UNSAFE_LAYERING, useCloseOnEscapePress } from '@atlaskit/layering';
|
|
17
6
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
18
7
|
import Portal from '@atlaskit/portal';
|
|
19
|
-
import { defaultFocusLockSettings } from '../constants';
|
|
20
8
|
import Blanket from './blanket';
|
|
21
9
|
import DrawerPrimitive from './primitives';
|
|
22
|
-
var packageName = "@atlaskit/drawer";
|
|
23
|
-
var packageVersion = "7.14.2";
|
|
24
|
-
var createAndFireEventOnAtlaskit = createAndFireEvent('atlaskit');
|
|
25
|
-
var createAndFireOnClick = function createAndFireOnClick(createAnalyticsEvent, trigger) {
|
|
26
|
-
return createAndFireEventOnAtlaskit({
|
|
27
|
-
action: 'dismissed',
|
|
28
|
-
actionSubject: 'drawer',
|
|
29
|
-
attributes: {
|
|
30
|
-
componentName: 'drawer',
|
|
31
|
-
packageName: packageName,
|
|
32
|
-
packageVersion: packageVersion,
|
|
33
|
-
trigger: trigger
|
|
34
|
-
}
|
|
35
|
-
})(createAnalyticsEvent);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
10
|
// escape close manager for layering
|
|
39
11
|
var EscapeCloseManager = function EscapeCloseManager(_ref) {
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
handleClose(event, _analyticsEvent);
|
|
46
|
-
}
|
|
47
|
-
}, [handleClose, createAnalyticsEvent]);
|
|
12
|
+
var onClose = _ref.onClose;
|
|
13
|
+
// wrap so that we can cast the event to a React.KeyboardEvent
|
|
14
|
+
var handleClose = useCallback(function (evt) {
|
|
15
|
+
onClose && onClose(evt);
|
|
16
|
+
}, [onClose]);
|
|
48
17
|
useCloseOnEscapePress({
|
|
49
|
-
onClose:
|
|
18
|
+
onClose: handleClose
|
|
50
19
|
});
|
|
51
|
-
// only create a dummy component for using ths hook in class component
|
|
52
20
|
return /*#__PURE__*/React.createElement("span", null);
|
|
53
21
|
};
|
|
54
|
-
export var DrawerBase = /*#__PURE__*/function (_Component) {
|
|
55
|
-
_inherits(DrawerBase, _Component);
|
|
56
|
-
var _super = _createSuper(DrawerBase);
|
|
57
|
-
function DrawerBase() {
|
|
58
|
-
var _this;
|
|
59
|
-
_classCallCheck(this, DrawerBase);
|
|
60
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
61
|
-
args[_key] = arguments[_key];
|
|
62
|
-
}
|
|
63
|
-
_this = _super.call.apply(_super, [this].concat(args));
|
|
64
|
-
_defineProperty(_assertThisInitialized(_this), "state", {
|
|
65
|
-
renderPortal: false
|
|
66
|
-
});
|
|
67
|
-
_defineProperty(_assertThisInitialized(_this), "body", canUseDOM ? document.querySelector('body') : undefined);
|
|
68
|
-
_defineProperty(_assertThisInitialized(_this), "handleBlanketClick", function (event) {
|
|
69
|
-
_this.handleClose(event, 'blanket');
|
|
70
|
-
});
|
|
71
|
-
_defineProperty(_assertThisInitialized(_this), "handleBackButtonClick", function (event) {
|
|
72
|
-
_this.handleClose(event, 'backButton');
|
|
73
|
-
});
|
|
74
|
-
_defineProperty(_assertThisInitialized(_this), "handleClose", function (event, trigger) {
|
|
75
|
-
var _this$props = _this.props,
|
|
76
|
-
createAnalyticsEvent = _this$props.createAnalyticsEvent,
|
|
77
|
-
onClose = _this$props.onClose;
|
|
78
|
-
var analyticsEvent = createAnalyticsEvent && createAndFireOnClick(createAnalyticsEvent, trigger);
|
|
79
|
-
if (onClose) {
|
|
80
|
-
onClose(event, analyticsEvent);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
_defineProperty(_assertThisInitialized(_this), "handleKeyDown", function (event) {
|
|
84
|
-
var _this$props2 = _this.props,
|
|
85
|
-
isOpen = _this$props2.isOpen,
|
|
86
|
-
onKeyDown = _this$props2.onKeyDown;
|
|
87
|
-
if (!fg('platform.design-system-team.inline-message-layering_wfp1p')) {
|
|
88
|
-
// when feature flag on, we will use the EscapeCloseManager instead
|
|
89
|
-
if (event.key === 'Escape' && isOpen) {
|
|
90
|
-
_this.handleClose(event, 'escKey');
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (onKeyDown) {
|
|
94
|
-
onKeyDown(event);
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
return _this;
|
|
98
|
-
}
|
|
99
|
-
_createClass(DrawerBase, [{
|
|
100
|
-
key: "componentDidMount",
|
|
101
|
-
value: function componentDidMount() {
|
|
102
|
-
var isOpen = this.props.isOpen;
|
|
103
|
-
if (isOpen) {
|
|
104
|
-
window.addEventListener('keydown', this.handleKeyDown);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}, {
|
|
108
|
-
key: "componentWillUnmount",
|
|
109
|
-
value: function componentWillUnmount() {
|
|
110
|
-
window.removeEventListener('keydown', this.handleKeyDown);
|
|
111
|
-
}
|
|
112
|
-
}, {
|
|
113
|
-
key: "componentDidUpdate",
|
|
114
|
-
value: function componentDidUpdate(prevProps) {
|
|
115
|
-
var isOpen = this.props.isOpen;
|
|
116
|
-
if (isOpen !== prevProps.isOpen) {
|
|
117
|
-
if (isOpen) {
|
|
118
|
-
window.addEventListener('keydown', this.handleKeyDown);
|
|
119
|
-
} else {
|
|
120
|
-
window.removeEventListener('keydown', this.handleKeyDown);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}, {
|
|
125
|
-
key: "render",
|
|
126
|
-
value: function render() {
|
|
127
|
-
if (!this.body) {
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
var _this$props3 = this.props,
|
|
131
|
-
testId = _this$props3.testId,
|
|
132
|
-
isOpen = _this$props3.isOpen,
|
|
133
|
-
children = _this$props3.children,
|
|
134
|
-
icon = _this$props3.icon,
|
|
135
|
-
closeLabel = _this$props3.closeLabel,
|
|
136
|
-
scrollContentLabel = _this$props3.scrollContentLabel,
|
|
137
|
-
width = _this$props3.width,
|
|
138
|
-
shouldUnmountOnExit = _this$props3.shouldUnmountOnExit,
|
|
139
|
-
onCloseComplete = _this$props3.onCloseComplete,
|
|
140
|
-
onOpenComplete = _this$props3.onOpenComplete,
|
|
141
|
-
autoFocusFirstElem = _this$props3.autoFocusFirstElem,
|
|
142
|
-
isFocusLockEnabled = _this$props3.isFocusLockEnabled,
|
|
143
|
-
shouldReturnFocus = _this$props3.shouldReturnFocus,
|
|
144
|
-
overrides = _this$props3.overrides,
|
|
145
|
-
_this$props3$zIndex = _this$props3.zIndex,
|
|
146
|
-
zIndex = _this$props3$zIndex === void 0 ? 'unset' : _this$props3$zIndex,
|
|
147
|
-
label = _this$props3.label,
|
|
148
|
-
titleId = _this$props3.titleId,
|
|
149
|
-
enterFrom = _this$props3.enterFrom;
|
|
150
|
-
var shouldHaveLayeringEnabled = fg('platform.design-system-team.inline-message-layering_wfp1p') && isOpen;
|
|
151
|
-
return /*#__PURE__*/React.createElement(Portal, {
|
|
152
|
-
zIndex: zIndex
|
|
153
|
-
}, /*#__PURE__*/React.createElement(Blanket, {
|
|
154
|
-
isOpen: isOpen,
|
|
155
|
-
onBlanketClicked: this.handleBlanketClick,
|
|
156
|
-
testId: testId && "".concat(testId, "--blanket")
|
|
157
|
-
}), /*#__PURE__*/React.createElement(DrawerPrimitive, {
|
|
158
|
-
testId: testId,
|
|
159
|
-
icon: icon,
|
|
160
|
-
closeLabel: closeLabel,
|
|
161
|
-
in: isOpen,
|
|
162
|
-
onClose: this.handleBackButtonClick,
|
|
163
|
-
onCloseComplete: onCloseComplete,
|
|
164
|
-
onOpenComplete: onOpenComplete,
|
|
165
|
-
width: width,
|
|
166
|
-
enterFrom: enterFrom,
|
|
167
|
-
label: label,
|
|
168
|
-
titleId: titleId,
|
|
169
|
-
shouldUnmountOnExit: shouldUnmountOnExit
|
|
170
|
-
// eslint-disable-next-line @repo/internal/react/no-unsafe-overrides
|
|
171
|
-
,
|
|
172
|
-
overrides: overrides,
|
|
173
|
-
autoFocusFirstElem: autoFocusFirstElem,
|
|
174
|
-
isFocusLockEnabled: isFocusLockEnabled,
|
|
175
|
-
shouldReturnFocus: shouldReturnFocus,
|
|
176
|
-
scrollContentLabel: scrollContentLabel
|
|
177
|
-
}, shouldHaveLayeringEnabled ? /*#__PURE__*/React.createElement(UNSAFE_LAYERING, {
|
|
178
|
-
isDisabled: false
|
|
179
|
-
}, children, /*#__PURE__*/React.createElement(EscapeCloseManager, {
|
|
180
|
-
createAnalyticsEvent: this.props.createAnalyticsEvent,
|
|
181
|
-
handleClose: this.handleClose
|
|
182
|
-
})) : children));
|
|
183
|
-
}
|
|
184
|
-
}]);
|
|
185
|
-
return DrawerBase;
|
|
186
|
-
}(Component);
|
|
187
22
|
|
|
188
23
|
/**
|
|
189
24
|
* __Drawer__
|
|
@@ -194,12 +29,119 @@ export var DrawerBase = /*#__PURE__*/function (_Component) {
|
|
|
194
29
|
* - [Code](https://atlassian.design/components/drawer/code)
|
|
195
30
|
* - [Usage](https://atlassian.design/components/drawer/usage)
|
|
196
31
|
*/
|
|
197
|
-
|
|
198
|
-
width
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
32
|
+
export var Drawer = function Drawer(_ref2) {
|
|
33
|
+
var _ref2$width = _ref2.width,
|
|
34
|
+
width = _ref2$width === void 0 ? 'narrow' : _ref2$width,
|
|
35
|
+
isOpen = _ref2.isOpen,
|
|
36
|
+
_ref2$isFocusLockEnab = _ref2.isFocusLockEnabled,
|
|
37
|
+
isFocusLockEnabled = _ref2$isFocusLockEnab === void 0 ? true : _ref2$isFocusLockEnab,
|
|
38
|
+
_ref2$shouldReturnFoc = _ref2.shouldReturnFocus,
|
|
39
|
+
shouldReturnFocus = _ref2$shouldReturnFoc === void 0 ? true : _ref2$shouldReturnFoc,
|
|
40
|
+
_ref2$autoFocusFirstE = _ref2.autoFocusFirstElem,
|
|
41
|
+
autoFocusFirstElem = _ref2$autoFocusFirstE === void 0 ? true : _ref2$autoFocusFirstE,
|
|
42
|
+
onKeyDown = _ref2.onKeyDown,
|
|
43
|
+
onClose = _ref2.onClose,
|
|
44
|
+
testId = _ref2.testId,
|
|
45
|
+
children = _ref2.children,
|
|
46
|
+
icon = _ref2.icon,
|
|
47
|
+
closeLabel = _ref2.closeLabel,
|
|
48
|
+
scrollContentLabel = _ref2.scrollContentLabel,
|
|
49
|
+
shouldUnmountOnExit = _ref2.shouldUnmountOnExit,
|
|
50
|
+
onCloseComplete = _ref2.onCloseComplete,
|
|
51
|
+
onOpenComplete = _ref2.onOpenComplete,
|
|
52
|
+
overrides = _ref2.overrides,
|
|
53
|
+
_ref2$zIndex = _ref2.zIndex,
|
|
54
|
+
zIndex = _ref2$zIndex === void 0 ? 'unset' : _ref2$zIndex,
|
|
55
|
+
label = _ref2.label,
|
|
56
|
+
titleId = _ref2.titleId,
|
|
57
|
+
enterFrom = _ref2.enterFrom;
|
|
58
|
+
var body = canUseDOM ? document.querySelector('body') : undefined;
|
|
59
|
+
var handleClose = usePlatformLeafEventHandler({
|
|
60
|
+
fn: function fn(evt, analyticsEvent) {
|
|
61
|
+
return onClose && onClose(evt, analyticsEvent);
|
|
62
|
+
},
|
|
63
|
+
action: 'dismissed',
|
|
64
|
+
componentName: 'drawer',
|
|
65
|
+
packageName: "@atlaskit/drawer",
|
|
66
|
+
packageVersion: "8.0.0",
|
|
67
|
+
analyticsData: {
|
|
68
|
+
trigger: 'escKey'
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
var handleKeyDown = useCallback(function (evt) {
|
|
72
|
+
onKeyDown && onKeyDown(evt);
|
|
73
|
+
if (!fg('platform.design-system-team.inline-message-layering_wfp1p')) {
|
|
74
|
+
// when feature flag on, we will use the EscapeCloseManager instead
|
|
75
|
+
if (evt.key === 'Escape' && isOpen && onClose) {
|
|
76
|
+
handleClose(evt);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}, [handleClose, isOpen, onClose, onKeyDown]);
|
|
80
|
+
useEffect(function () {
|
|
81
|
+
if (isOpen) {
|
|
82
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
83
|
+
}
|
|
84
|
+
return function () {
|
|
85
|
+
window.removeEventListener('keydown', handleKeyDown);
|
|
86
|
+
};
|
|
87
|
+
}, [handleKeyDown, isOpen]);
|
|
88
|
+
var handleBlanketClick = usePlatformLeafEventHandler({
|
|
89
|
+
fn: function fn(evt, analyticsEvent) {
|
|
90
|
+
return onClose && onClose(evt, analyticsEvent);
|
|
91
|
+
},
|
|
92
|
+
action: 'dismissed',
|
|
93
|
+
componentName: 'drawer',
|
|
94
|
+
packageName: "@atlaskit/drawer",
|
|
95
|
+
packageVersion: "8.0.0",
|
|
96
|
+
analyticsData: {
|
|
97
|
+
trigger: 'blanket'
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
var handleBackButtonClick = usePlatformLeafEventHandler({
|
|
101
|
+
fn: function fn(evt, analyticsEvent) {
|
|
102
|
+
return onClose && onClose(evt, analyticsEvent);
|
|
103
|
+
},
|
|
104
|
+
action: 'dismissed',
|
|
105
|
+
componentName: 'drawer',
|
|
106
|
+
packageName: "@atlaskit/drawer",
|
|
107
|
+
packageVersion: "8.0.0",
|
|
108
|
+
analyticsData: {
|
|
109
|
+
trigger: 'backButton'
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
if (!body) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
return /*#__PURE__*/React.createElement(Portal, {
|
|
116
|
+
zIndex: zIndex
|
|
117
|
+
}, /*#__PURE__*/React.createElement(Blanket, {
|
|
118
|
+
isOpen: isOpen,
|
|
119
|
+
onBlanketClicked: handleBlanketClick,
|
|
120
|
+
testId: testId && "".concat(testId, "--blanket")
|
|
121
|
+
}), /*#__PURE__*/React.createElement(DrawerPrimitive, {
|
|
122
|
+
testId: testId,
|
|
123
|
+
icon: icon,
|
|
124
|
+
closeLabel: closeLabel,
|
|
125
|
+
in: isOpen,
|
|
126
|
+
onClose: handleBackButtonClick,
|
|
127
|
+
onCloseComplete: onCloseComplete,
|
|
128
|
+
onOpenComplete: onOpenComplete,
|
|
129
|
+
width: width,
|
|
130
|
+
enterFrom: enterFrom,
|
|
131
|
+
label: label,
|
|
132
|
+
titleId: titleId,
|
|
133
|
+
shouldUnmountOnExit: shouldUnmountOnExit
|
|
134
|
+
// eslint-disable-next-line @repo/internal/react/no-unsafe-overrides
|
|
135
|
+
,
|
|
136
|
+
overrides: overrides,
|
|
137
|
+
autoFocusFirstElem: autoFocusFirstElem,
|
|
138
|
+
isFocusLockEnabled: isFocusLockEnabled,
|
|
139
|
+
shouldReturnFocus: shouldReturnFocus,
|
|
140
|
+
scrollContentLabel: scrollContentLabel
|
|
141
|
+
}, isOpen && fg('platform.design-system-team.inline-message-layering_wfp1p') ? /*#__PURE__*/React.createElement(UNSAFE_LAYERING, {
|
|
142
|
+
isDisabled: false
|
|
143
|
+
}, children, /*#__PURE__*/React.createElement(EscapeCloseManager, {
|
|
144
|
+
onClose: handleClose
|
|
145
|
+
})) : children));
|
|
146
|
+
};
|
|
205
147
|
export default Drawer;
|
|
@@ -1,81 +1,51 @@
|
|
|
1
|
-
import
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
-
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
4
|
-
import _inherits from "@babel/runtime/helpers/inherits";
|
|
5
|
-
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
6
|
-
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
7
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
8
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
9
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
11
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
12
|
-
import React, { Component } from 'react';
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
13
2
|
import ReactFocusLock from 'react-focus-lock';
|
|
14
3
|
import ScrollLock from 'react-scrolllock';
|
|
15
4
|
import invariant from 'tiny-invariant';
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
5
|
+
/**
|
|
6
|
+
* __Focus lock__
|
|
7
|
+
*
|
|
8
|
+
* Thin wrapper over react-focus-lock. This wrapper only exists to ensure API compatibility.
|
|
9
|
+
* This component should be deleted during https://ecosystem.atlassian.net/browse/AK-5658
|
|
10
|
+
*/
|
|
11
|
+
var FocusLock = function FocusLock(_ref) {
|
|
12
|
+
var _ref$isFocusLockEnabl = _ref.isFocusLockEnabled,
|
|
13
|
+
isFocusLockEnabled = _ref$isFocusLockEnabl === void 0 ? true : _ref$isFocusLockEnabl,
|
|
14
|
+
_ref$autoFocusFirstEl = _ref.autoFocusFirstElem,
|
|
15
|
+
autoFocusFirstElem = _ref$autoFocusFirstEl === void 0 ? true : _ref$autoFocusFirstEl,
|
|
16
|
+
_ref$shouldReturnFocu = _ref.shouldReturnFocus,
|
|
17
|
+
shouldReturnFocus = _ref$shouldReturnFocu === void 0 ? true : _ref$shouldReturnFocu,
|
|
18
|
+
children = _ref.children;
|
|
19
|
+
useEffect(function () {
|
|
20
|
+
if (typeof process !== 'undefined' && process.env.NODE_ENV !== 'production' && !process.env.CI) {
|
|
21
|
+
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.');
|
|
27
22
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return shouldReturnFocus;
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
});
|
|
36
|
-
_defineProperty(_assertThisInitialized(_this), "onDeactivation", function () {
|
|
37
|
-
var shouldReturnFocus = _this.props.shouldReturnFocus;
|
|
38
|
-
if (typeof shouldReturnFocus !== 'boolean') {
|
|
39
|
-
window.setTimeout(function () {
|
|
40
|
-
var _shouldReturnFocus$cu;
|
|
41
|
-
shouldReturnFocus === null || shouldReturnFocus === void 0 || (_shouldReturnFocus$cu = shouldReturnFocus.current) === null || _shouldReturnFocus$cu === void 0 || _shouldReturnFocus$cu.focus();
|
|
42
|
-
}, 0);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
return _this;
|
|
46
|
-
}
|
|
47
|
-
_createClass(FocusLock, [{
|
|
48
|
-
key: "componentDidMount",
|
|
49
|
-
value: function componentDidMount() {
|
|
50
|
-
var _this$props = this.props,
|
|
51
|
-
isFocusLockEnabled = _this$props.isFocusLockEnabled,
|
|
52
|
-
autoFocusFirstElem = _this$props.autoFocusFirstElem;
|
|
53
|
-
if (typeof process !== 'undefined' && process.env.NODE_ENV !== 'production' && !process.env.CI) {
|
|
54
|
-
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.');
|
|
55
|
-
}
|
|
56
|
-
if (typeof autoFocusFirstElem === 'function' && isFocusLockEnabled) {
|
|
57
|
-
var elem = autoFocusFirstElem();
|
|
58
|
-
if (elem && elem.focus) {
|
|
59
|
-
elem.focus();
|
|
60
|
-
}
|
|
23
|
+
if (typeof autoFocusFirstElem === 'function' && isFocusLockEnabled) {
|
|
24
|
+
var elem = autoFocusFirstElem();
|
|
25
|
+
if (elem && elem.focus) {
|
|
26
|
+
elem.focus();
|
|
61
27
|
}
|
|
62
28
|
}
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
},
|
|
29
|
+
}, [autoFocusFirstElem, isFocusLockEnabled]);
|
|
30
|
+
var getFocusTarget = function getFocusTarget() {
|
|
31
|
+
if (typeof shouldReturnFocus === 'boolean') {
|
|
32
|
+
return shouldReturnFocus;
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
};
|
|
36
|
+
var onDeactivation = function onDeactivation() {
|
|
37
|
+
if (typeof shouldReturnFocus !== 'boolean') {
|
|
38
|
+
window.setTimeout(function () {
|
|
39
|
+
var _shouldReturnFocus$cu;
|
|
40
|
+
shouldReturnFocus === null || shouldReturnFocus === void 0 || (_shouldReturnFocus$cu = shouldReturnFocus.current) === null || _shouldReturnFocus$cu === void 0 || _shouldReturnFocus$cu.focus();
|
|
41
|
+
}, 0);
|
|
76
42
|
}
|
|
77
|
-
}
|
|
78
|
-
return
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
43
|
+
};
|
|
44
|
+
return /*#__PURE__*/React.createElement(ReactFocusLock, {
|
|
45
|
+
disabled: !isFocusLockEnabled,
|
|
46
|
+
autoFocus: !!autoFocusFirstElem,
|
|
47
|
+
returnFocus: getFocusTarget(),
|
|
48
|
+
onDeactivation: onDeactivation
|
|
49
|
+
}, /*#__PURE__*/React.createElement(ScrollLock, null, children));
|
|
50
|
+
};
|
|
51
|
+
export default FocusLock;
|
|
@@ -1,27 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import { type DrawerProps
|
|
3
|
-
export declare class DrawerBase extends Component<DrawerProps, {
|
|
4
|
-
renderPortal: boolean;
|
|
5
|
-
}> {
|
|
6
|
-
static defaultProps: {
|
|
7
|
-
autoFocusFirstElem?: boolean | (() => HTMLElement | null) | undefined;
|
|
8
|
-
isFocusLockEnabled?: boolean | undefined;
|
|
9
|
-
shouldReturnFocus?: boolean | React.RefObject<HTMLElement> | undefined;
|
|
10
|
-
width: DrawerWidth;
|
|
11
|
-
};
|
|
12
|
-
state: {
|
|
13
|
-
renderPortal: boolean;
|
|
14
|
-
};
|
|
15
|
-
body: HTMLBodyElement | null | undefined;
|
|
16
|
-
componentDidMount(): void;
|
|
17
|
-
componentWillUnmount(): void;
|
|
18
|
-
componentDidUpdate(prevProps: DrawerProps): void;
|
|
19
|
-
private handleBlanketClick;
|
|
20
|
-
private handleBackButtonClick;
|
|
21
|
-
private handleClose;
|
|
22
|
-
handleKeyDown: (event: KeyboardEvent) => void;
|
|
23
|
-
render(): JSX.Element | null;
|
|
24
|
-
}
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { type DrawerProps } from './types';
|
|
25
3
|
/**
|
|
26
4
|
* __Drawer__
|
|
27
5
|
*
|
|
@@ -31,10 +9,5 @@ export declare class DrawerBase extends Component<DrawerProps, {
|
|
|
31
9
|
* - [Code](https://atlassian.design/components/drawer/code)
|
|
32
10
|
* - [Usage](https://atlassian.design/components/drawer/usage)
|
|
33
11
|
*/
|
|
34
|
-
declare const Drawer:
|
|
35
|
-
autoFocusFirstElem?: boolean | (() => HTMLElement | null) | undefined;
|
|
36
|
-
isFocusLockEnabled?: boolean | undefined;
|
|
37
|
-
shouldReturnFocus?: boolean | React.RefObject<HTMLElement> | undefined;
|
|
38
|
-
width: DrawerWidth;
|
|
39
|
-
}, never>> & React.RefAttributes<any> & import("@atlaskit/analytics-next").WithContextProps, "scrollContentLabel" | "width" | "children" | "onKeyDown" | "key" | "onClose" | "testId" | "icon" | "closeLabel" | "enterFrom" | "onOpenComplete" | "onCloseComplete" | "shouldUnmountOnExit" | "overrides" | "zIndex" | "isOpen" | "analyticsContext" | keyof import("./types").FocusLockSettings | keyof import("./types").DrawerLabel> & React.RefAttributes<any>>;
|
|
12
|
+
export declare const Drawer: ({ width, isOpen, isFocusLockEnabled, shouldReturnFocus, autoFocusFirstElem, onKeyDown, onClose, testId, children, icon, closeLabel, scrollContentLabel, shouldUnmountOnExit, onCloseComplete, onOpenComplete, overrides, zIndex, label, titleId, enterFrom, }: DrawerProps) => JSX.Element | null;
|
|
40
13
|
export default Drawer;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import { type FocusLockProps } from '../types';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
onDeactivation: () => void;
|
|
12
|
-
render(): JSX.Element;
|
|
13
|
-
}
|
|
3
|
+
/**
|
|
4
|
+
* __Focus lock__
|
|
5
|
+
*
|
|
6
|
+
* Thin wrapper over react-focus-lock. This wrapper only exists to ensure API compatibility.
|
|
7
|
+
* This component should be deleted during https://ecosystem.atlassian.net/browse/AK-5658
|
|
8
|
+
*/
|
|
9
|
+
declare const FocusLock: ({ isFocusLockEnabled, autoFocusFirstElem, shouldReturnFocus, children, }: FocusLockProps) => JSX.Element;
|
|
10
|
+
export default FocusLock;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type ComponentType, type ReactElement, type ReactNode, type RefObject, type SyntheticEvent } from 'react';
|
|
2
2
|
import { type CSSObject } from '@emotion/react';
|
|
3
|
-
import { type WithAnalyticsEventsProps } from '@atlaskit/analytics-next';
|
|
4
3
|
import { type Direction } from '@atlaskit/motion';
|
|
5
4
|
export type Widths = {
|
|
6
5
|
extended: {
|
|
@@ -129,7 +128,7 @@ export interface DrawerPrimitiveProps extends BaseProps, FocusLockSettings, Draw
|
|
|
129
128
|
in: boolean;
|
|
130
129
|
onClose: (event: SyntheticEvent<HTMLElement>) => void;
|
|
131
130
|
}
|
|
132
|
-
export type DrawerProps = BaseProps & FocusLockSettings &
|
|
131
|
+
export type DrawerProps = BaseProps & FocusLockSettings & DrawerLabel & {
|
|
133
132
|
/**
|
|
134
133
|
* Callback function called while the drawer is displayed and `keydown` event is triggered.
|
|
135
134
|
*/
|
|
@@ -137,7 +136,7 @@ export type DrawerProps = BaseProps & FocusLockSettings & WithAnalyticsEventsPro
|
|
|
137
136
|
/**
|
|
138
137
|
* Callback function called when the drawer is closed.
|
|
139
138
|
*/
|
|
140
|
-
onClose?: (event: SyntheticEvent<HTMLElement>, analyticsEvent
|
|
139
|
+
onClose?: (event: SyntheticEvent<HTMLElement>, analyticsEvent?: any) => void;
|
|
141
140
|
/**
|
|
142
141
|
* Controls if the drawer is open or closed.
|
|
143
142
|
*/
|
|
@@ -147,7 +146,7 @@ export type DrawerProps = BaseProps & FocusLockSettings & WithAnalyticsEventsPro
|
|
|
147
146
|
* This is passed to the portal component.
|
|
148
147
|
* Defaults to `unset`.
|
|
149
148
|
*/
|
|
150
|
-
zIndex?: number;
|
|
149
|
+
zIndex?: number | 'unset';
|
|
151
150
|
};
|
|
152
151
|
export interface FocusLockSettings {
|
|
153
152
|
/**
|
|
@@ -1,27 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import { type DrawerProps
|
|
3
|
-
export declare class DrawerBase extends Component<DrawerProps, {
|
|
4
|
-
renderPortal: boolean;
|
|
5
|
-
}> {
|
|
6
|
-
static defaultProps: {
|
|
7
|
-
autoFocusFirstElem?: boolean | (() => HTMLElement | null) | undefined;
|
|
8
|
-
isFocusLockEnabled?: boolean | undefined;
|
|
9
|
-
shouldReturnFocus?: boolean | React.RefObject<HTMLElement> | undefined;
|
|
10
|
-
width: DrawerWidth;
|
|
11
|
-
};
|
|
12
|
-
state: {
|
|
13
|
-
renderPortal: boolean;
|
|
14
|
-
};
|
|
15
|
-
body: HTMLBodyElement | null | undefined;
|
|
16
|
-
componentDidMount(): void;
|
|
17
|
-
componentWillUnmount(): void;
|
|
18
|
-
componentDidUpdate(prevProps: DrawerProps): void;
|
|
19
|
-
private handleBlanketClick;
|
|
20
|
-
private handleBackButtonClick;
|
|
21
|
-
private handleClose;
|
|
22
|
-
handleKeyDown: (event: KeyboardEvent) => void;
|
|
23
|
-
render(): JSX.Element | null;
|
|
24
|
-
}
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { type DrawerProps } from './types';
|
|
25
3
|
/**
|
|
26
4
|
* __Drawer__
|
|
27
5
|
*
|
|
@@ -31,10 +9,5 @@ export declare class DrawerBase extends Component<DrawerProps, {
|
|
|
31
9
|
* - [Code](https://atlassian.design/components/drawer/code)
|
|
32
10
|
* - [Usage](https://atlassian.design/components/drawer/usage)
|
|
33
11
|
*/
|
|
34
|
-
declare const Drawer:
|
|
35
|
-
autoFocusFirstElem?: boolean | (() => HTMLElement | null) | undefined;
|
|
36
|
-
isFocusLockEnabled?: boolean | undefined;
|
|
37
|
-
shouldReturnFocus?: boolean | React.RefObject<HTMLElement> | undefined;
|
|
38
|
-
width: DrawerWidth;
|
|
39
|
-
}, never>> & React.RefAttributes<any> & import("@atlaskit/analytics-next").WithContextProps, "scrollContentLabel" | "width" | "children" | "onKeyDown" | "key" | "onClose" | "testId" | "icon" | "closeLabel" | "enterFrom" | "onOpenComplete" | "onCloseComplete" | "shouldUnmountOnExit" | "overrides" | "zIndex" | "isOpen" | "analyticsContext" | keyof import("./types").FocusLockSettings | keyof import("./types").DrawerLabel> & React.RefAttributes<any>>;
|
|
12
|
+
export declare const Drawer: ({ width, isOpen, isFocusLockEnabled, shouldReturnFocus, autoFocusFirstElem, onKeyDown, onClose, testId, children, icon, closeLabel, scrollContentLabel, shouldUnmountOnExit, onCloseComplete, onOpenComplete, overrides, zIndex, label, titleId, enterFrom, }: DrawerProps) => JSX.Element | null;
|
|
40
13
|
export default Drawer;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import { type FocusLockProps } from '../types';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
onDeactivation: () => void;
|
|
12
|
-
render(): JSX.Element;
|
|
13
|
-
}
|
|
3
|
+
/**
|
|
4
|
+
* __Focus lock__
|
|
5
|
+
*
|
|
6
|
+
* Thin wrapper over react-focus-lock. This wrapper only exists to ensure API compatibility.
|
|
7
|
+
* This component should be deleted during https://ecosystem.atlassian.net/browse/AK-5658
|
|
8
|
+
*/
|
|
9
|
+
declare const FocusLock: ({ isFocusLockEnabled, autoFocusFirstElem, shouldReturnFocus, children, }: FocusLockProps) => JSX.Element;
|
|
10
|
+
export default FocusLock;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type ComponentType, type ReactElement, type ReactNode, type RefObject, type SyntheticEvent } from 'react';
|
|
2
2
|
import { type CSSObject } from '@emotion/react';
|
|
3
|
-
import { type WithAnalyticsEventsProps } from '@atlaskit/analytics-next';
|
|
4
3
|
import { type Direction } from '@atlaskit/motion';
|
|
5
4
|
export type Widths = {
|
|
6
5
|
extended: {
|
|
@@ -129,7 +128,7 @@ export interface DrawerPrimitiveProps extends BaseProps, FocusLockSettings, Draw
|
|
|
129
128
|
in: boolean;
|
|
130
129
|
onClose: (event: SyntheticEvent<HTMLElement>) => void;
|
|
131
130
|
}
|
|
132
|
-
export type DrawerProps = BaseProps & FocusLockSettings &
|
|
131
|
+
export type DrawerProps = BaseProps & FocusLockSettings & DrawerLabel & {
|
|
133
132
|
/**
|
|
134
133
|
* Callback function called while the drawer is displayed and `keydown` event is triggered.
|
|
135
134
|
*/
|
|
@@ -137,7 +136,7 @@ export type DrawerProps = BaseProps & FocusLockSettings & WithAnalyticsEventsPro
|
|
|
137
136
|
/**
|
|
138
137
|
* Callback function called when the drawer is closed.
|
|
139
138
|
*/
|
|
140
|
-
onClose?: (event: SyntheticEvent<HTMLElement>, analyticsEvent
|
|
139
|
+
onClose?: (event: SyntheticEvent<HTMLElement>, analyticsEvent?: any) => void;
|
|
141
140
|
/**
|
|
142
141
|
* Controls if the drawer is open or closed.
|
|
143
142
|
*/
|
|
@@ -147,7 +146,7 @@ export type DrawerProps = BaseProps & FocusLockSettings & WithAnalyticsEventsPro
|
|
|
147
146
|
* This is passed to the portal component.
|
|
148
147
|
* Defaults to `unset`.
|
|
149
148
|
*/
|
|
150
|
-
zIndex?: number;
|
|
149
|
+
zIndex?: number | 'unset';
|
|
151
150
|
};
|
|
152
151
|
export interface FocusLockSettings {
|
|
153
152
|
/**
|