@semcore/side-panel 1.0.3 → 1.3.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 +27 -0
- package/lib/cjs/SidePanel.js +63 -99
- package/lib/cjs/SidePanel.js.map +1 -1
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/style/side-panel.shadow.css +1 -1
- package/lib/es6/SidePanel.js +70 -101
- package/lib/es6/SidePanel.js.map +1 -1
- package/lib/es6/index.js.map +1 -1
- package/lib/es6/style/side-panel.shadow.css +1 -1
- package/lib/types/index.d.ts +60 -2
- package/package.json +6 -5
- package/src/{SidePanel.tsx → SidePanel.js} +19 -113
- package/src/index.d.ts +60 -0
- package/src/{index.tsx → index.js} +0 -0
- package/src/style/side-panel.shadow.css +1 -1
- package/lib/types/SidePanel.d.ts +0 -110
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
CHANGELOG.md standards are inspired by [keepachangelog.com](https://keepachangelog.com/en/1.0.0/).
|
|
4
4
|
|
|
5
|
+
## [1.3.0] - 2022-01-18
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- Up version icons and use new icon.
|
|
10
|
+
|
|
11
|
+
## [1.2.1] - 2021-8-26
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- Add 'sideEffect=false' for more optimal build via webpack
|
|
16
|
+
|
|
17
|
+
## [1.2.0] - 2021-07-05
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- Version of dependence `@semcore/core` has been changed to `1.11`.
|
|
22
|
+
- Improved performance. Removed one component wrapper.
|
|
23
|
+
- The style processing system has been changed.
|
|
24
|
+
- Removed the ability to apply media styles via a plugin `babel-plugin-react-semcore`.
|
|
25
|
+
|
|
26
|
+
## [1.1.0] - 2020-12-17
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
|
|
30
|
+
- Added supported react@17.
|
|
31
|
+
|
|
5
32
|
## [1.0.3] - 2020-10-29
|
|
6
33
|
|
|
7
34
|
### Fixed
|
package/lib/cjs/SidePanel.js
CHANGED
|
@@ -9,6 +9,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
9
9
|
});
|
|
10
10
|
exports["default"] = void 0;
|
|
11
11
|
|
|
12
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
+
|
|
12
14
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
15
|
|
|
14
16
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
@@ -25,14 +27,12 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/ge
|
|
|
25
27
|
|
|
26
28
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
27
29
|
|
|
28
|
-
var
|
|
30
|
+
var _core = _interopRequireWildcard(require("@semcore/core"));
|
|
29
31
|
|
|
30
32
|
var _react = _interopRequireWildcard(require("react"));
|
|
31
33
|
|
|
32
34
|
var _reactFocusLock = _interopRequireDefault(require("react-focus-lock"));
|
|
33
35
|
|
|
34
|
-
var _core = _interopRequireWildcard(require("@semcore/core"));
|
|
35
|
-
|
|
36
36
|
var _flexBox = require("@semcore/flex-box");
|
|
37
37
|
|
|
38
38
|
var _animation = require("@semcore/animation");
|
|
@@ -41,7 +41,7 @@ var _portal = _interopRequireWildcard(require("@semcore/portal"));
|
|
|
41
41
|
|
|
42
42
|
var _outsideClick = _interopRequireDefault(require("@semcore/outside-click"));
|
|
43
43
|
|
|
44
|
-
var
|
|
44
|
+
var _l = _interopRequireDefault(require("@semcore/icon/Close/l"));
|
|
45
45
|
|
|
46
46
|
var _fire = _interopRequireDefault(require("@semcore/utils/lib/fire"));
|
|
47
47
|
|
|
@@ -51,55 +51,33 @@ var _keyboardFocusEnhance = _interopRequireDefault(require("@semcore/utils/lib/e
|
|
|
51
51
|
|
|
52
52
|
var _usePreventScroll = _interopRequireDefault(require("@semcore/utils/lib/use/usePreventScroll"));
|
|
53
53
|
|
|
54
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
55
|
+
|
|
56
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
57
|
+
|
|
54
58
|
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); }; }
|
|
55
59
|
|
|
56
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try {
|
|
60
|
+
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; } }
|
|
57
61
|
|
|
58
62
|
/*__reshadow-styles__:"./style/side-panel.shadow.css"*/
|
|
59
|
-
var
|
|
63
|
+
var style = (
|
|
60
64
|
/*__reshadow_css_start__*/
|
|
61
|
-
|
|
65
|
+
_core.sstyled.insert(
|
|
62
66
|
/*__inner_css_start__*/
|
|
63
|
-
".
|
|
67
|
+
".___SOverlay_tjy0q_gg_{position:fixed;top:0;bottom:0;left:0;right:0;margin:0;display:flex;overflow:hidden;z-index:10005;background:rgba(0,0,0,.8);-webkit-overflow-scrolling:touch}.___SPanel_tjy0q_gg_{padding:24px;width:256px;outline:none;position:fixed;box-sizing:border-box;will-change:transform;background:#fff;z-index:1}.___SPanel_tjy0q_gg_._placement_top_tjy0q_gg_{box-shadow:3px 0 8px rgba(0,0,0,.2);width:100%;margin-bottom:auto;top:0;left:0}.___SPanel_tjy0q_gg_._placement_right_tjy0q_gg_{box-shadow:0 3px 8px rgba(0,0,0,.2);height:100vh;margin-left:auto;top:0;right:0}.___SPanel_tjy0q_gg_._placement_bottom_tjy0q_gg_{box-shadow:3px 0 8px rgba(0,0,0,.2);width:100%;margin-top:auto;bottom:0;left:0}.___SPanel_tjy0q_gg_._placement_left_tjy0q_gg_{box-shadow:0 3px 8px rgba(0,0,0,.2);height:100vh;margin-right:auto;top:0;left:0}.panel-right--enter{transform:translate(100%)}.panel-left--enter{transform:translate(-100%)}.panel-bottom--enter{transform:translateY(100%)}.panel-bottom--enter-active,.panel-bottom--exit,.panel-left--enter-active,.panel-left--exit,.panel-right--enter-active,.panel-right--exit{transform:translate(0)}.panel-right--exit-active{transform:translate(100%)}.panel-left--exit-active{transform:translate(-100%)}.panel-bottom--exit-active{transform:translateY(100%)}.___SClose_tjy0q_gg_{display:inline-flex;position:absolute;right:0;top:0;padding:12px;color:#a6b0b3;cursor:pointer;z-index:1;border:none;background:none;outline:none}.___SClose_tjy0q_gg_:hover{color:#929b9e}.___SClose_tjy0q_gg_.__keyboardFocused_tjy0q_gg_{box-shadow:0 0 0 3px rgba(43,148,225,.3)}"
|
|
64
68
|
/*__inner_css_end__*/
|
|
65
|
-
, "
|
|
69
|
+
, "1ohwmsk_gg_")
|
|
66
70
|
/*__reshadow_css_end__*/
|
|
67
71
|
, {
|
|
68
|
-
"__SOverlay": "
|
|
69
|
-
"__SPanel": "
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
|
|
77
|
-
"panel-bottom--enter": "_panel-bottom--enter_1ywi1_gg_",
|
|
78
|
-
"panel-right--enter-active": "_panel-right--enter-active_1i10l_gg_",
|
|
79
|
-
"panel-left--enter-active": "_panel-left--enter-active_1idlf_gg_",
|
|
80
|
-
"panel-bottom--enter-active": "_panel-bottom--enter-active_oe720_gg_",
|
|
81
|
-
"panel-right--exit": "_panel-right--exit_19stu_gg_",
|
|
82
|
-
"panel-left--exit": "_panel-left--exit_bet5q_gg_",
|
|
83
|
-
"panel-bottom--exit": "_panel-bottom--exit_39ak4_gg_",
|
|
84
|
-
"panel-right--exit-active": "_panel-right--exit-active_vbmch_gg_",
|
|
85
|
-
"panel-left--exit-active": "_panel-left--exit-active_1lu84_gg_",
|
|
86
|
-
"panel-bottom--exit-active": "_panel-bottom--exit-active_snwxm_gg_",
|
|
87
|
-
"__SClose": "___SClose_k3ylz_gg_",
|
|
88
|
-
"_keyboardFocused": "__keyboardFocused_k3ylz_gg_"
|
|
89
|
-
}),
|
|
90
|
-
style = (0, _extends2["default"])({}, _ref);
|
|
91
|
-
|
|
92
|
-
if (false) {
|
|
93
|
-
/*__reshadow_css_start__*/
|
|
94
|
-
(0, _core.__css__)(
|
|
95
|
-
/*__inner_css_start__*/
|
|
96
|
-
"@media (max-width: 768px) {\n\n.___SClose_k3ylz_gg_ {\n padding: 15.6px\n}}"
|
|
97
|
-
/*__inner_css_end__*/
|
|
98
|
-
, "1yl1vcn_gg_")
|
|
99
|
-
/*__reshadow_css_end__*/
|
|
100
|
-
;
|
|
101
|
-
}
|
|
102
|
-
|
|
72
|
+
"__SOverlay": "___SOverlay_tjy0q_gg_",
|
|
73
|
+
"__SPanel": "___SPanel_tjy0q_gg_",
|
|
74
|
+
"_placement_top": "_placement_top_tjy0q_gg_",
|
|
75
|
+
"_placement_right": "_placement_right_tjy0q_gg_",
|
|
76
|
+
"_placement_bottom": "_placement_bottom_tjy0q_gg_",
|
|
77
|
+
"_placement_left": "_placement_left_tjy0q_gg_",
|
|
78
|
+
"__SClose": "___SClose_tjy0q_gg_",
|
|
79
|
+
"_keyboardFocused": "__keyboardFocused_tjy0q_gg_"
|
|
80
|
+
});
|
|
103
81
|
var placementTransformMap = {
|
|
104
82
|
top: ['translate(0, -100%)', 'translate(0, 0)'],
|
|
105
83
|
right: ['translate(100%, 0)', 'translate(0, 0)'],
|
|
@@ -199,15 +177,14 @@ var RootSidePanel = /*#__PURE__*/function (_Component) {
|
|
|
199
177
|
}, {
|
|
200
178
|
key: "render",
|
|
201
179
|
value: function render() {
|
|
202
|
-
var
|
|
180
|
+
var _ref = this ? this.asProps : arguments[0];
|
|
181
|
+
|
|
203
182
|
var _this$asProps3 = this.asProps,
|
|
204
183
|
Children = _this$asProps3.Children,
|
|
205
184
|
disablePortal = _this$asProps3.disablePortal;
|
|
206
185
|
return /*#__PURE__*/_react["default"].createElement(_portal["default"], {
|
|
207
186
|
disablePortal: disablePortal
|
|
208
|
-
}, this.isAdvanceMode() ? /*#__PURE__*/_react["default"].createElement(Children, null) : /*#__PURE__*/_react["default"].createElement(SidePanel.Overlay, null, /*#__PURE__*/_react["default"].createElement(
|
|
209
|
-
render: SidePanel.Panel
|
|
210
|
-
})));
|
|
187
|
+
}, this.isAdvanceMode() ? /*#__PURE__*/_react["default"].createElement(Children, null) : /*#__PURE__*/_react["default"].createElement(SidePanel.Overlay, null, /*#__PURE__*/_react["default"].createElement(SidePanel.Panel, (0, _core.assignProps)({}, _ref))));
|
|
211
188
|
}
|
|
212
189
|
}]);
|
|
213
190
|
return RootSidePanel;
|
|
@@ -220,22 +197,19 @@ var RootSidePanel = /*#__PURE__*/function (_Component) {
|
|
|
220
197
|
duration: 350,
|
|
221
198
|
closable: true
|
|
222
199
|
});
|
|
223
|
-
var styled_c8 = (0, _core.create)([]);
|
|
224
200
|
|
|
225
201
|
function Overlay(props) {
|
|
226
|
-
var
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
visible: visible
|
|
233
|
-
}))));
|
|
202
|
+
var _ref2 = this ? this.asProps : arguments[0],
|
|
203
|
+
_ref5;
|
|
204
|
+
|
|
205
|
+
var SOverlay = _animation.FadeInOut;
|
|
206
|
+
(0, _usePreventScroll["default"])(props.visible);
|
|
207
|
+
return _ref5 = (0, _core.sstyled)(props.styles), /*#__PURE__*/_react["default"].createElement(SOverlay, _ref5.cn("SOverlay", _objectSpread({}, (0, _core.assignProps)({}, _ref2))));
|
|
234
208
|
}
|
|
235
209
|
|
|
236
|
-
var FocusLockWrapper = /*#__PURE__*/_react["default"].forwardRef(function (
|
|
237
|
-
var disableEnforceFocus =
|
|
238
|
-
other = (0, _objectWithoutProperties2["default"])(
|
|
210
|
+
var FocusLockWrapper = /*#__PURE__*/_react["default"].forwardRef(function (_ref8, ref) {
|
|
211
|
+
var disableEnforceFocus = _ref8.disableEnforceFocus,
|
|
212
|
+
other = (0, _objectWithoutProperties2["default"])(_ref8, ["disableEnforceFocus"]);
|
|
239
213
|
return /*#__PURE__*/_react["default"].createElement(_reactFocusLock["default"], (0, _extends2["default"])({
|
|
240
214
|
ref: ref,
|
|
241
215
|
lockProps: other,
|
|
@@ -243,9 +217,9 @@ var FocusLockWrapper = /*#__PURE__*/_react["default"].forwardRef(function (_ref2
|
|
|
243
217
|
}, other));
|
|
244
218
|
});
|
|
245
219
|
|
|
246
|
-
var TransformWrapper = /*#__PURE__*/_react["default"].forwardRef(function (
|
|
247
|
-
var tag =
|
|
248
|
-
other = (0, _objectWithoutProperties2["default"])(
|
|
220
|
+
var TransformWrapper = /*#__PURE__*/_react["default"].forwardRef(function (_ref9, ref) {
|
|
221
|
+
var tag = _ref9.tag,
|
|
222
|
+
other = (0, _objectWithoutProperties2["default"])(_ref9, ["tag"]);
|
|
249
223
|
return /*#__PURE__*/_react["default"].createElement(_animation.Transform, (0, _extends2["default"])({
|
|
250
224
|
tag: FocusLockWrapper,
|
|
251
225
|
ref: ref,
|
|
@@ -253,55 +227,45 @@ var TransformWrapper = /*#__PURE__*/_react["default"].forwardRef(function (_ref3
|
|
|
253
227
|
}, other));
|
|
254
228
|
});
|
|
255
229
|
|
|
256
|
-
var styled_12c = (0, _core.create)([]);
|
|
257
|
-
|
|
258
230
|
function Panel(props) {
|
|
259
|
-
var
|
|
260
|
-
|
|
231
|
+
var _ref3 = this ? this.asProps : arguments[0],
|
|
232
|
+
_ref6;
|
|
233
|
+
|
|
234
|
+
var SPanel = TransformWrapper;
|
|
235
|
+
var Children = props.Children,
|
|
261
236
|
styles = props.styles,
|
|
262
237
|
visible = props.visible,
|
|
263
238
|
closable = props.closable,
|
|
264
239
|
placement = props.placement,
|
|
265
240
|
onOutsideClick = props.onOutsideClick;
|
|
266
241
|
var sidebarRef = (0, _react.useRef)(null);
|
|
267
|
-
return
|
|
268
|
-
onOutsideClick: onOutsideClick,
|
|
269
|
-
excludeRefs: [sidebarRef]
|
|
270
|
-
})), /*#__PURE__*/_react["default"].createElement(SPanel, (0, _core.
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
}), /*#__PURE__*/_react["default"].createElement(_portal.PortalProvider, (0, _core.map)("PortalProvider", {
|
|
281
|
-
value: sidebarRef
|
|
282
|
-
}), closable && /*#__PURE__*/_react["default"].createElement(SidePanel.Close, {
|
|
283
|
-
className: _core.styled.styles["__SidePanel.Close"]
|
|
284
|
-
}), /*#__PURE__*/_react["default"].createElement(Children, {
|
|
285
|
-
className: _core.styled.styles["__Children"]
|
|
286
|
-
}))))));
|
|
242
|
+
return _ref6 = (0, _core.sstyled)(styles), /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, visible && /*#__PURE__*/_react["default"].createElement(_outsideClick["default"], _ref6.cn("OutsideClick", {
|
|
243
|
+
"onOutsideClick": onOutsideClick,
|
|
244
|
+
"excludeRefs": [sidebarRef]
|
|
245
|
+
})), /*#__PURE__*/_react["default"].createElement(SPanel, _ref6.cn("SPanel", _objectSpread({}, (0, _core.assignProps)({
|
|
246
|
+
"tag": _flexBox.Box,
|
|
247
|
+
"ref": sidebarRef,
|
|
248
|
+
"tabIndex": -1,
|
|
249
|
+
"returnFocus": true,
|
|
250
|
+
"autoFocus": true,
|
|
251
|
+
"transform": placementTransformMap[placement]
|
|
252
|
+
}, _ref3))), /*#__PURE__*/_react["default"].createElement(_portal.PortalProvider, _ref6.cn("PortalProvider", {
|
|
253
|
+
"value": sidebarRef
|
|
254
|
+
}), closable && /*#__PURE__*/_react["default"].createElement(SidePanel.Close, null), /*#__PURE__*/_react["default"].createElement(Children, _ref6.cn("Children", {})))));
|
|
287
255
|
}
|
|
288
256
|
|
|
289
|
-
var styled_190 = (0, _core.create)([]);
|
|
290
|
-
|
|
291
257
|
function Close(props) {
|
|
292
|
-
var
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
tag: "button"
|
|
298
|
-
|
|
299
|
-
keyboardFocused: keyboardFocused
|
|
300
|
-
}))));
|
|
258
|
+
var _ref4 = this ? this.asProps : arguments[0],
|
|
259
|
+
_ref7;
|
|
260
|
+
|
|
261
|
+
var SClose = _flexBox.Box;
|
|
262
|
+
return _ref7 = (0, _core.sstyled)(props.styles), /*#__PURE__*/_react["default"].createElement(SClose, _ref7.cn("SClose", _objectSpread({}, (0, _core.assignProps)({
|
|
263
|
+
"tag": "button"
|
|
264
|
+
}, _ref4))));
|
|
301
265
|
}
|
|
302
266
|
|
|
303
267
|
Close.defaultProps = {
|
|
304
|
-
children: /*#__PURE__*/_react["default"].createElement(
|
|
268
|
+
children: /*#__PURE__*/_react["default"].createElement(_l["default"], {
|
|
305
269
|
title: "Close"
|
|
306
270
|
})
|
|
307
271
|
};
|
package/lib/cjs/SidePanel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/SidePanel.tsx"],"names":["placementTransformMap","top","right","bottom","left","RootSidePanel","React","createRef","e","key","stopPropagation","asProps","Children","SidePanel","Overlay","displayName","Panel","isAdvanceMode","name","delay","duration","usedOverlay","isUsedOverlay","overlay","panel","visible","calculateDelayAnimation","placement","closable","disableEnforceFocus","onOutsideClick","handleOutsideClick","onKeyDown","handleSidebarKeyDown","onClick","handleIconCloseClick","Root","disablePortal","Component","style","props","SOverlay","styles","FadeInOut","FocusLockWrapper","forwardRef","ref","other","TransformWrapper","tag","SPanel","sidebarRef","Box","Close","SClose","keyboardFocused","defaultProps","children","enhance"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAOA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA,IAAMA,qBAAqB,GAAG;AAC5BC,EAAAA,GAAG,EAAE,CAAC,qBAAD,EAAwB,iBAAxB,CADuB;AAE5BC,EAAAA,KAAK,EAAE,CAAC,oBAAD,EAAuB,iBAAvB,CAFqB;AAG5BC,EAAAA,MAAM,EAAE,CAAC,oBAAD,EAAuB,iBAAvB,CAHoB;AAI5BC,EAAAA,IAAI,EAAE,CAAC,qBAAD,EAAwB,iBAAxB;AAJsB,CAA9B;;IAOMC,a;;;;;;;;;;;;;;;gHASSC,kBAAMC,SAAN,E;6GAEU,UAACC,CAAD,EAAO;AAC5B,UAAIA,CAAC,CAACC,GAAF,KAAU,QAAd,EAAwB;AACtBD,QAAAA,CAAC,CAACE,eAAF;AACA,8EAAW,SAAX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,gCAAC,wBAAD;AAAA,oBAA8BK,cAA9B;AAAA,iBAA2D,CAACqB,UAAD;AAA3D,KADd,eAEE,gCAAC,MAAD;AAAA,YACUH,gBADV;AAAA,SAEOI,YAFP;AAAA,SAGOD,UAHP;AAAA,eAIaxB,SAJb;AAAA,aAKWF,OALX;AAAA,cAMY,CAAC,CANb;AAAA,iBAOe,IAPf;AAAA,eAQa,IARb;AAAA,eASazB,qBAAqB,CAAC2B,SAAD;AATlC,mBAWE,gCAAC,sBAAD;AAAA,WAAuBwB;AAAvB,MACGvB,QAAQ,iBAAI,gCAAC,SAAD,CAAW,KAAX;AAAA;AAAA,IADf,eAEE,gCAAC,QAAD;AAAA;AAAA,IAFF,CAXF,CAFF,CADK,EAAP;AAqBD;;;;AAED,SAASyB,KAAT,CAAeb,KAAf,EAAsB;AAAA,MACNc,MADM,GAC8Bd,KAD9B,CACZJ,IADY;AAAA,MACEM,MADF,GAC8BF,KAD9B,CACEE,MADF;AAAA,MACUa,eADV,GAC8Bf,KAD9B,CACUe,eADV;AAEpB,SAAO,+CAAOb,MAAP,iBACL,gCAAC,MAAD;AAAA,YAAgBU,YAAhB;AAAA,SAAyB,QAAzB;AAAA,cAA4C,CAA5C;AAAA,qBAAgEG;AAAhE,KADK,EAAP;AAGD;;AAEDF,KAAK,CAACG,YAAN,GAAqB;AACnBC,EAAAA,QAAQ,eAAE,gCAAC,aAAD;AAAQ,IAAA,KAAK,EAAC;AAAd;AADS,CAArB;AAGAJ,KAAK,CAACK,OAAN,GAAgB,CAAC,uCAAD,CAAhB;AAEA,IAAM7C,SAAS,GAAG,sBAQhBR,aARgB,EAQD;AACfS,EAAAA,OAAO,EAAPA,OADe;AAEfE,EAAAA,KAAK,EAALA,KAFe;AAGfqC,EAAAA,KAAK,EAALA;AAHe,CARC,CAAlB;eAcexC,S","sourcesContent":["import React, { ComponentProps, useRef } from 'react';\nimport FocusLock from 'react-focus-lock';\nimport createComponent, {\n Component,\n IFunctionProps,\n Merge,\n PropGetter,\n styled,\n} from '@semcore/core';\nimport { Box } from '@semcore/flex-box';\nimport { FadeInOut, IFadeInOutProps, ITransformProps, Transform } from '@semcore/animation';\nimport Portal, { IPortalProps, PortalProvider } from '@semcore/portal';\nimport OutsideClick from '@semcore/outside-click';\nimport CloseS from '@semcore/icon/lib/Close/s';\nimport fire from '@semcore/utils/lib/fire';\nimport findComponent from '@semcore/utils/lib/findComponent';\nimport keyboardFocusEnhance from '@semcore/utils/lib/enhances/keyboardFocusEnhance';\nimport usePreventScroll from '@semcore/utils/lib/use/usePreventScroll';\n\nimport style from './style/side-panel.shadow.css';\n\nexport type OnCloseTriggerType = 'onOutsideClick' | 'onEscape' | 'onCloseClick';\nexport type OnCloseType = (\n trigger: OnCloseTriggerType,\n e?: React.MouseEvent | React.KeyboardEvent,\n) => void;\n\nexport type SidePanelPlacement = 'top' | 'left' | 'right' | 'bottom';\n\nexport interface ISidePanelProps extends IPortalProps {\n /** Animation display duration in ms\n * @default 350\n */\n duration?: number;\n /**\n * The property responsible for the visibility of the component\n */\n visible?: boolean;\n /**\n * Callback for the component closure\n */\n onClose?: OnCloseType;\n /**\n * Property for displaying the close button\n * @default true\n */\n closable?: boolean;\n /**\n * Position of a dropdown window\n * @default right\n */\n placement?: SidePanelPlacement;\n}\n\nexport interface ISidePanelOverlayProps extends IFadeInOutProps {\n /**\n * @link ISidePanelProps.visible\n */\n visible?: ISidePanelProps['visible'];\n}\n\nexport interface ISidePanelPanelProps extends ITransformProps {\n /**\n * @link ISidePanelProps.visible\n */\n visible?: ISidePanelProps['visible'];\n /**\n * @link ISidePanelProps.placement\n */\n placement?: ISidePanelProps['placement'];\n /**\n * @link ISidePanelProps.closable\n */\n closable?: ISidePanelProps['closable'];\n\n onOutsideClick?: (e?: React.SyntheticEvent) => void;\n}\n\nexport interface ISidePanelContext extends ISidePanelProps {\n /**\n * The method that encapsulates the props needed to run SidePanel.Overlay\n */\n getOverlayProps?: PropGetter<RootSidePanel['getOverlayProps']>;\n /**\n * The method that encapsulates the props needed to run SidePanel.Panel\n */\n getPanelProps?: PropGetter<RootSidePanel['getPanelProps']>;\n /**\n * The method that encapsulates the props needed to run SidePanel.Close\n */\n getCloseProps?: PropGetter<RootSidePanel['getCloseProps']>;\n}\n\nconst placementTransformMap = {\n top: ['translate(0, -100%)', 'translate(0, 0)'],\n right: ['translate(100%, 0)', 'translate(0, 0)'],\n bottom: ['translate(0, 100%)', 'translate(0, 0)'],\n left: ['translate(-100%, 0)', 'translate(0, 0)'],\n};\n\nclass RootSidePanel extends Component<ISidePanelProps> {\n static displayName = 'SidePanel';\n static style = style;\n static defaultProps = {\n placement: 'right',\n duration: 350,\n closable: true,\n };\n\n sidebarRef = React.createRef<HTMLElement>();\n\n handleSidebarKeyDown = (e) => {\n if (e.key === 'Escape') {\n e.stopPropagation();\n fire(this, 'onClose', 'onEscape', e);\n }\n };\n\n handleIconCloseClick = (e) => {\n fire(this, 'onClose', 'onCloseClick', e);\n };\n\n handleOutsideClick = (e) => {\n fire(this, 'onClose', 'onOutsideClick', e);\n };\n\n isAdvanceMode() {\n return !!findComponent(this.asProps.Children, [\n SidePanel.Overlay.displayName,\n SidePanel.Panel.displayName,\n ]);\n }\n\n isUsedOverlay() {\n return (\n !this.isAdvanceMode() ||\n !!findComponent(this.asProps.Children, [SidePanel.Overlay.displayName])\n );\n }\n\n calculateDelayAnimation(name) {\n const delay = this.asProps.duration / 2;\n const usedOverlay = this.isUsedOverlay();\n\n return {\n overlay: usedOverlay ? [0, delay] : 0,\n panel: usedOverlay ? [delay, 0] : 0,\n }[name];\n }\n\n getOverlayProps() {\n const { visible, duration } = this.asProps;\n return {\n visible,\n duration,\n delay: this.calculateDelayAnimation('overlay'),\n };\n }\n\n getPanelProps() {\n const { placement, visible, closable, duration } = this.asProps;\n\n return {\n visible,\n placement,\n closable,\n duration,\n disableEnforceFocus: !this.isUsedOverlay(),\n delay: this.calculateDelayAnimation('panel'),\n onOutsideClick: this.handleOutsideClick,\n onKeyDown: this.handleSidebarKeyDown,\n };\n }\n\n getCloseProps() {\n return {\n onClick: this.handleIconCloseClick,\n };\n }\n\n render() {\n const Root = this.Root;\n const { Children, disablePortal } = this.asProps;\n\n return (\n <Portal disablePortal={disablePortal}>\n {this.isAdvanceMode() ? (\n <Children />\n ) : (\n <SidePanel.Overlay>\n <Root render={SidePanel.Panel} />\n </SidePanel.Overlay>\n )}\n </Portal>\n );\n }\n}\n\nfunction Overlay(props: IFunctionProps<ISidePanelOverlayProps>) {\n const { Root: SOverlay, styles, visible } = props;\n usePreventScroll(visible);\n\n return styled(styles)(<SOverlay render={FadeInOut} visible={visible} />);\n}\n\nconst FocusLockWrapper = React.forwardRef<HTMLElement, any>(function (\n { disableEnforceFocus, ...other },\n ref,\n) {\n return <FocusLock ref={ref} lockProps={other} disabled={disableEnforceFocus} {...other} />;\n});\n\nconst TransformWrapper = React.forwardRef<HTMLElement, any>(function ({ tag, ...other }, ref) {\n return <Transform tag={FocusLockWrapper} ref={ref} as={tag} {...other} />;\n});\n\nfunction Panel(props: IFunctionProps<ISidePanelPanelProps>) {\n const { Root: SPanel, Children, styles, visible, closable, placement, onOutsideClick } = props;\n\n const sidebarRef = useRef<HTMLElement>(null);\n\n return styled(styles)(\n <>\n {visible && <OutsideClick onOutsideClick={onOutsideClick} excludeRefs={[sidebarRef]} />}\n <SPanel\n render={TransformWrapper}\n tag={Box}\n ref={sidebarRef}\n placement={placement}\n visible={visible}\n tabIndex={-1}\n returnFocus={true}\n autoFocus={true}\n transform={placementTransformMap[placement]}\n >\n <PortalProvider value={sidebarRef}>\n {closable && <SidePanel.Close />}\n <Children />\n </PortalProvider>\n </SPanel>\n </>,\n );\n}\n\nfunction Close(props) {\n const { Root: SClose, styles, keyboardFocused } = props;\n return styled(styles)(\n <SClose render={Box} tag=\"button\" tabIndex={0} keyboardFocused={keyboardFocused} />,\n );\n}\n\nClose.defaultProps = {\n children: <CloseS title=\"Close\" />,\n};\nClose.enhance = [keyboardFocusEnhance()];\n\nconst SidePanel = createComponent<\n ISidePanelProps,\n {\n Overlay: Merge<ISidePanelOverlayProps, ComponentProps<typeof Box>>;\n Panel: Merge<ISidePanelPanelProps, ComponentProps<typeof Box>>;\n Close: ComponentProps<typeof Box>;\n },\n ISidePanelContext\n>(RootSidePanel, {\n Overlay,\n Panel,\n Close,\n});\n\nexport default SidePanel;\n"],"file":"SidePanel.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/SidePanel.js"],"names":["placementTransformMap","top","right","bottom","left","RootSidePanel","React","createRef","e","key","stopPropagation","asProps","Children","SidePanel","Overlay","displayName","Panel","isAdvanceMode","name","delay","duration","usedOverlay","isUsedOverlay","overlay","panel","visible","calculateDelayAnimation","placement","closable","disableEnforceFocus","onOutsideClick","handleOutsideClick","onKeyDown","handleSidebarKeyDown","onClick","handleIconCloseClick","disablePortal","Component","style","props","SOverlay","FadeInOut","styles","FocusLockWrapper","forwardRef","ref","other","TransformWrapper","tag","SPanel","sidebarRef","Box","Close","SClose","defaultProps","children","enhance"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;AAFA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,IAAMA,qBAAqB,GAAG;AAC5BC,EAAAA,GAAG,EAAE,CAAC,qBAAD,EAAwB,iBAAxB,CADuB;AAE5BC,EAAAA,KAAK,EAAE,CAAC,oBAAD,EAAuB,iBAAvB,CAFqB;AAG5BC,EAAAA,MAAM,EAAE,CAAC,oBAAD,EAAuB,iBAAvB,CAHoB;AAI5BC,EAAAA,IAAI,EAAE,CAAC,qBAAD,EAAwB,iBAAxB;AAJsB,CAA9B;;IAOMC,a;;;;;;;;;;;;;;;gHASSC,kBAAMC,SAAN,E;6GAEU,UAACC,CAAD,EAAO;AAC5B,UAAIA,CAAC,CAACC,GAAF,KAAU,QAAd,EAAwB;AACtBD,QAAAA,CAAC,CAACE,eAAF;AACA,8EA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AA,WAGOD,UAHP;AAAA,gBAIY,CAAC,CAJb;AAAA,mBAKe,IALf;AAAA,iBAMa,IANb;AAAA,iBAOalD,qBAAqB,CAAC2B,SAAD;AAPlC,4BASE,gCAAC,sBAAD;AAAA,aAAuBuB;AAAvB,MACGtB,QAAQ,iBAAI,gCAAC,SAAD,CAAW,KAAX,OADf,eAEE,gCAAC,QAAD,2BAFF,CATF,CAFF,CADF;AAmBD;;AAED,SAASwB,KAAT,CAAeb,KAAf,EAAsB;AAAA;AAAA;;AACpB,MAAMc,MAAM,GACiCF,YAD7C;AACA,iBAAO,mBAAQZ,KAAK,CAACG,MAAd,CAAP,eAA6B,gCAAC,MAAD;AAAA,WAAyB;AAAzB,cAA7B;AACD;;AAEDU,KAAK,CAACE,YAAN,GAAqB;AACnBC,EAAAA,QAAQ,eAAE,gCAAC,aAAD;AAAW,IAAA,KAAK,EAAC;AAAjB;AADS,CAArB;AAGAH,KAAK,CAACI,OAAN,GAAgB,CAAC,uCAAD,CAAhB;AAEA,IAAM3C,SAAS,GAAG,sBAAgBR,aAAhB,EAA+B;AAC/CS,EAAAA,OAAO,EAAPA,OAD+C;AAE/CE,EAAAA,KAAK,EAALA,KAF+C;AAG/CoC,EAAAA,KAAK,EAALA;AAH+C,CAA/B,CAAlB;eAMevC,S","sourcesContent":["import React, { ComponentProps, useRef } from 'react';\nimport FocusLock from 'react-focus-lock';\nimport createComponent, { Component, Root, sstyled } from '@semcore/core';\nimport { Box } from '@semcore/flex-box';\nimport { FadeInOut, IFadeInOutProps, ITransformProps, Transform } from '@semcore/animation';\nimport Portal, { IPortalProps, PortalProvider } from '@semcore/portal';\nimport OutsideClick from '@semcore/outside-click';\nimport CloseIcon from '@semcore/icon/Close/l';\nimport fire from '@semcore/utils/lib/fire';\nimport findComponent from '@semcore/utils/lib/findComponent';\nimport keyboardFocusEnhance from '@semcore/utils/lib/enhances/keyboardFocusEnhance';\nimport usePreventScroll from '@semcore/utils/lib/use/usePreventScroll';\n\nimport style from './style/side-panel.shadow.css';\n\nconst placementTransformMap = {\n top: ['translate(0, -100%)', 'translate(0, 0)'],\n right: ['translate(100%, 0)', 'translate(0, 0)'],\n bottom: ['translate(0, 100%)', 'translate(0, 0)'],\n left: ['translate(-100%, 0)', 'translate(0, 0)'],\n};\n\nclass RootSidePanel extends Component {\n static displayName = 'SidePanel';\n static style = style;\n static defaultProps = {\n placement: 'right',\n duration: 350,\n closable: true,\n };\n\n sidebarRef = React.createRef();\n\n handleSidebarKeyDown = (e) => {\n if (e.key === 'Escape') {\n e.stopPropagation();\n fire(this, 'onClose', 'onEscape', e);\n }\n };\n\n handleIconCloseClick = (e) => {\n fire(this, 'onClose', 'onCloseClick', e);\n };\n\n handleOutsideClick = (e) => {\n fire(this, 'onClose', 'onOutsideClick', e);\n };\n\n isAdvanceMode() {\n return !!findComponent(this.asProps.Children, [\n SidePanel.Overlay.displayName,\n SidePanel.Panel.displayName,\n ]);\n }\n\n isUsedOverlay() {\n return (\n !this.isAdvanceMode() ||\n !!findComponent(this.asProps.Children, [SidePanel.Overlay.displayName])\n );\n }\n\n calculateDelayAnimation(name) {\n const delay = this.asProps.duration / 2;\n const usedOverlay = this.isUsedOverlay();\n\n return {\n overlay: usedOverlay ? [0, delay] : 0,\n panel: usedOverlay ? [delay, 0] : 0,\n }[name];\n }\n\n getOverlayProps() {\n const { visible, duration } = this.asProps;\n return {\n visible,\n duration,\n delay: this.calculateDelayAnimation('overlay'),\n };\n }\n\n getPanelProps() {\n const { placement, visible, closable, duration } = this.asProps;\n\n return {\n visible,\n placement,\n closable,\n duration,\n disableEnforceFocus: !this.isUsedOverlay(),\n delay: this.calculateDelayAnimation('panel'),\n onOutsideClick: this.handleOutsideClick,\n onKeyDown: this.handleSidebarKeyDown,\n };\n }\n\n getCloseProps() {\n return {\n onClick: this.handleIconCloseClick,\n };\n }\n\n render() {\n const { Children, disablePortal } = this.asProps;\n\n return (\n <Portal disablePortal={disablePortal}>\n {this.isAdvanceMode() ? (\n <Children />\n ) : (\n <SidePanel.Overlay>\n <Root render={SidePanel.Panel} />\n </SidePanel.Overlay>\n )}\n </Portal>\n );\n }\n}\n\nfunction Overlay(props) {\n const SOverlay = Root;\n usePreventScroll(props.visible);\n return sstyled(props.styles)(<SOverlay render={FadeInOut} />);\n}\n\nconst FocusLockWrapper = React.forwardRef(function({ disableEnforceFocus, ...other }, ref) {\n return <FocusLock ref={ref} lockProps={other} disabled={disableEnforceFocus} {...other} />;\n});\n\nconst TransformWrapper = React.forwardRef(function({ tag, ...other }, ref) {\n return <Transform tag={FocusLockWrapper} ref={ref} as={tag} {...other} />;\n});\n\nfunction Panel(props) {\n const SPanel = Root;\n const { Children, styles, visible, closable, placement, onOutsideClick } = props;\n\n const sidebarRef = useRef(null);\n\n return sstyled(styles)(\n <>\n {visible && <OutsideClick onOutsideClick={onOutsideClick} excludeRefs={[sidebarRef]} />}\n <SPanel\n render={TransformWrapper}\n tag={Box}\n ref={sidebarRef}\n tabIndex={-1}\n returnFocus={true}\n autoFocus={true}\n transform={placementTransformMap[placement]}\n >\n <PortalProvider value={sidebarRef}>\n {closable && <SidePanel.Close />}\n <Children />\n </PortalProvider>\n </SPanel>\n </>,\n );\n}\n\nfunction Close(props) {\n const SClose = Root;\n return sstyled(props.styles)(<SClose render={Box} tag=\"button\" />);\n}\n\nClose.defaultProps = {\n children: <CloseIcon title=\"Close\" />,\n};\nClose.enhance = [keyboardFocusEnhance()];\n\nconst SidePanel = createComponent(RootSidePanel, {\n Overlay,\n Panel,\n Close,\n});\n\nexport default SidePanel;\n"],"file":"SidePanel.js"}
|
package/lib/cjs/index.js
CHANGED
|
@@ -18,6 +18,7 @@ var _SidePanel = _interopRequireWildcard(require("./SidePanel"));
|
|
|
18
18
|
Object.keys(_SidePanel).forEach(function (key) {
|
|
19
19
|
if (key === "default" || key === "__esModule") return;
|
|
20
20
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
21
|
+
if (key in exports && exports[key] === _SidePanel[key]) return;
|
|
21
22
|
Object.defineProperty(exports, key, {
|
|
22
23
|
enumerable: true,
|
|
23
24
|
get: function get() {
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.
|
|
1
|
+
{"version":3,"sources":["../../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export { default } from './SidePanel';\nexport * from './SidePanel';\n"],"file":"index.js"}
|
package/lib/es6/SidePanel.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
1
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
3
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
4
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
@@ -6,70 +7,52 @@ import _inherits from "@babel/runtime/helpers/inherits";
|
|
|
6
7
|
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
7
8
|
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
8
9
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
9
|
-
import
|
|
10
|
+
import { sstyled as _sstyled } from "@semcore/core";
|
|
11
|
+
import { assignProps as _assignProps4 } from "@semcore/core";
|
|
12
|
+
import { assignProps as _assignProps3 } from "@semcore/core";
|
|
13
|
+
import { assignProps as _assignProps2 } from "@semcore/core";
|
|
14
|
+
import { assignProps as _assignProps } from "@semcore/core";
|
|
15
|
+
|
|
16
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
17
|
+
|
|
18
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
10
19
|
|
|
11
20
|
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); }; }
|
|
12
21
|
|
|
13
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try {
|
|
22
|
+
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; } }
|
|
14
23
|
|
|
15
|
-
import React, { useRef } from 'react';
|
|
24
|
+
import React, { ComponentProps, useRef } from 'react';
|
|
16
25
|
import FocusLock from 'react-focus-lock';
|
|
17
|
-
import createComponent, { Component,
|
|
26
|
+
import createComponent, { Component, Root, sstyled } from '@semcore/core';
|
|
18
27
|
import { Box } from '@semcore/flex-box';
|
|
19
|
-
import { FadeInOut, Transform } from '@semcore/animation';
|
|
20
|
-
import Portal, { PortalProvider } from '@semcore/portal';
|
|
28
|
+
import { FadeInOut, IFadeInOutProps, ITransformProps, Transform } from '@semcore/animation';
|
|
29
|
+
import Portal, { IPortalProps, PortalProvider } from '@semcore/portal';
|
|
21
30
|
import OutsideClick from '@semcore/outside-click';
|
|
22
|
-
import
|
|
31
|
+
import CloseIcon from '@semcore/icon/Close/l';
|
|
23
32
|
import fire from '@semcore/utils/lib/fire';
|
|
24
33
|
import findComponent from '@semcore/utils/lib/findComponent';
|
|
25
34
|
import keyboardFocusEnhance from '@semcore/utils/lib/enhances/keyboardFocusEnhance';
|
|
26
35
|
import usePreventScroll from '@semcore/utils/lib/use/usePreventScroll';
|
|
27
36
|
|
|
28
37
|
/*__reshadow-styles__:"./style/side-panel.shadow.css"*/
|
|
29
|
-
var
|
|
38
|
+
var style = (
|
|
30
39
|
/*__reshadow_css_start__*/
|
|
31
|
-
|
|
40
|
+
_sstyled.insert(
|
|
32
41
|
/*__inner_css_start__*/
|
|
33
|
-
".
|
|
42
|
+
".___SOverlay_tjy0q_gg_{position:fixed;top:0;bottom:0;left:0;right:0;margin:0;display:flex;overflow:hidden;z-index:10005;background:rgba(0,0,0,.8);-webkit-overflow-scrolling:touch}.___SPanel_tjy0q_gg_{padding:24px;width:256px;outline:none;position:fixed;box-sizing:border-box;will-change:transform;background:#fff;z-index:1}.___SPanel_tjy0q_gg_._placement_top_tjy0q_gg_{box-shadow:3px 0 8px rgba(0,0,0,.2);width:100%;margin-bottom:auto;top:0;left:0}.___SPanel_tjy0q_gg_._placement_right_tjy0q_gg_{box-shadow:0 3px 8px rgba(0,0,0,.2);height:100vh;margin-left:auto;top:0;right:0}.___SPanel_tjy0q_gg_._placement_bottom_tjy0q_gg_{box-shadow:3px 0 8px rgba(0,0,0,.2);width:100%;margin-top:auto;bottom:0;left:0}.___SPanel_tjy0q_gg_._placement_left_tjy0q_gg_{box-shadow:0 3px 8px rgba(0,0,0,.2);height:100vh;margin-right:auto;top:0;left:0}.panel-right--enter{transform:translate(100%)}.panel-left--enter{transform:translate(-100%)}.panel-bottom--enter{transform:translateY(100%)}.panel-bottom--enter-active,.panel-bottom--exit,.panel-left--enter-active,.panel-left--exit,.panel-right--enter-active,.panel-right--exit{transform:translate(0)}.panel-right--exit-active{transform:translate(100%)}.panel-left--exit-active{transform:translate(-100%)}.panel-bottom--exit-active{transform:translateY(100%)}.___SClose_tjy0q_gg_{display:inline-flex;position:absolute;right:0;top:0;padding:12px;color:#a6b0b3;cursor:pointer;z-index:1;border:none;background:none;outline:none}.___SClose_tjy0q_gg_:hover{color:#929b9e}.___SClose_tjy0q_gg_.__keyboardFocused_tjy0q_gg_{box-shadow:0 0 0 3px rgba(43,148,225,.3)}"
|
|
34
43
|
/*__inner_css_end__*/
|
|
35
|
-
, "
|
|
44
|
+
, "1ohwmsk_gg_")
|
|
36
45
|
/*__reshadow_css_end__*/
|
|
37
46
|
, {
|
|
38
|
-
"__SOverlay": "
|
|
39
|
-
"__SPanel": "
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
"panel-bottom--enter": "_panel-bottom--enter_1ywi1_gg_",
|
|
48
|
-
"panel-right--enter-active": "_panel-right--enter-active_1i10l_gg_",
|
|
49
|
-
"panel-left--enter-active": "_panel-left--enter-active_1idlf_gg_",
|
|
50
|
-
"panel-bottom--enter-active": "_panel-bottom--enter-active_oe720_gg_",
|
|
51
|
-
"panel-right--exit": "_panel-right--exit_19stu_gg_",
|
|
52
|
-
"panel-left--exit": "_panel-left--exit_bet5q_gg_",
|
|
53
|
-
"panel-bottom--exit": "_panel-bottom--exit_39ak4_gg_",
|
|
54
|
-
"panel-right--exit-active": "_panel-right--exit-active_vbmch_gg_",
|
|
55
|
-
"panel-left--exit-active": "_panel-left--exit-active_1lu84_gg_",
|
|
56
|
-
"panel-bottom--exit-active": "_panel-bottom--exit-active_snwxm_gg_",
|
|
57
|
-
"__SClose": "___SClose_k3ylz_gg_",
|
|
58
|
-
"_keyboardFocused": "__keyboardFocused_k3ylz_gg_"
|
|
59
|
-
}),
|
|
60
|
-
style = _extends({}, _ref);
|
|
61
|
-
|
|
62
|
-
if (false) {
|
|
63
|
-
/*__reshadow_css_start__*/
|
|
64
|
-
__css__(
|
|
65
|
-
/*__inner_css_start__*/
|
|
66
|
-
"@media (max-width: 768px) {\n\n.___SClose_k3ylz_gg_ {\n padding: 15.6px\n}}"
|
|
67
|
-
/*__inner_css_end__*/
|
|
68
|
-
, "1yl1vcn_gg_")
|
|
69
|
-
/*__reshadow_css_end__*/
|
|
70
|
-
;
|
|
71
|
-
}
|
|
72
|
-
|
|
47
|
+
"__SOverlay": "___SOverlay_tjy0q_gg_",
|
|
48
|
+
"__SPanel": "___SPanel_tjy0q_gg_",
|
|
49
|
+
"_placement_top": "_placement_top_tjy0q_gg_",
|
|
50
|
+
"_placement_right": "_placement_right_tjy0q_gg_",
|
|
51
|
+
"_placement_bottom": "_placement_bottom_tjy0q_gg_",
|
|
52
|
+
"_placement_left": "_placement_left_tjy0q_gg_",
|
|
53
|
+
"__SClose": "___SClose_tjy0q_gg_",
|
|
54
|
+
"_keyboardFocused": "__keyboardFocused_tjy0q_gg_"
|
|
55
|
+
});
|
|
73
56
|
var placementTransformMap = {
|
|
74
57
|
top: ['translate(0, -100%)', 'translate(0, 0)'],
|
|
75
58
|
right: ['translate(100%, 0)', 'translate(0, 0)'],
|
|
@@ -174,15 +157,14 @@ var RootSidePanel = /*#__PURE__*/function (_Component) {
|
|
|
174
157
|
}, {
|
|
175
158
|
key: "render",
|
|
176
159
|
value: function render() {
|
|
177
|
-
var
|
|
160
|
+
var _ref = this ? this.asProps : arguments[0];
|
|
161
|
+
|
|
178
162
|
var _this$asProps3 = this.asProps,
|
|
179
163
|
Children = _this$asProps3.Children,
|
|
180
164
|
disablePortal = _this$asProps3.disablePortal;
|
|
181
165
|
return /*#__PURE__*/React.createElement(Portal, {
|
|
182
166
|
disablePortal: disablePortal
|
|
183
|
-
}, this.isAdvanceMode() ? /*#__PURE__*/React.createElement(Children, null) : /*#__PURE__*/React.createElement(SidePanel.Overlay, null, /*#__PURE__*/React.createElement(
|
|
184
|
-
render: SidePanel.Panel
|
|
185
|
-
})));
|
|
167
|
+
}, this.isAdvanceMode() ? /*#__PURE__*/React.createElement(Children, null) : /*#__PURE__*/React.createElement(SidePanel.Overlay, null, /*#__PURE__*/React.createElement(SidePanel.Panel, _assignProps({}, _ref))));
|
|
186
168
|
}
|
|
187
169
|
}]);
|
|
188
170
|
|
|
@@ -199,22 +181,18 @@ _defineProperty(RootSidePanel, "defaultProps", {
|
|
|
199
181
|
closable: true
|
|
200
182
|
});
|
|
201
183
|
|
|
202
|
-
var styled_c8 = create([]);
|
|
203
|
-
|
|
204
184
|
function Overlay(props) {
|
|
205
|
-
var
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
visible: visible
|
|
212
|
-
}))));
|
|
185
|
+
var _ref2 = this ? this.asProps : arguments[0],
|
|
186
|
+
_ref5;
|
|
187
|
+
|
|
188
|
+
var SOverlay = FadeInOut;
|
|
189
|
+
usePreventScroll(props.visible);
|
|
190
|
+
return _ref5 = sstyled(props.styles), /*#__PURE__*/React.createElement(SOverlay, _ref5.cn("SOverlay", _objectSpread({}, _assignProps2({}, _ref2))));
|
|
213
191
|
}
|
|
214
192
|
|
|
215
|
-
var FocusLockWrapper = /*#__PURE__*/React.forwardRef(function (
|
|
216
|
-
var disableEnforceFocus =
|
|
217
|
-
other = _objectWithoutProperties(
|
|
193
|
+
var FocusLockWrapper = /*#__PURE__*/React.forwardRef(function (_ref8, ref) {
|
|
194
|
+
var disableEnforceFocus = _ref8.disableEnforceFocus,
|
|
195
|
+
other = _objectWithoutProperties(_ref8, ["disableEnforceFocus"]);
|
|
218
196
|
|
|
219
197
|
return /*#__PURE__*/React.createElement(FocusLock, _extends({
|
|
220
198
|
ref: ref,
|
|
@@ -222,9 +200,9 @@ var FocusLockWrapper = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
|
|
|
222
200
|
disabled: disableEnforceFocus
|
|
223
201
|
}, other));
|
|
224
202
|
});
|
|
225
|
-
var TransformWrapper = /*#__PURE__*/React.forwardRef(function (
|
|
226
|
-
var tag =
|
|
227
|
-
other = _objectWithoutProperties(
|
|
203
|
+
var TransformWrapper = /*#__PURE__*/React.forwardRef(function (_ref9, ref) {
|
|
204
|
+
var tag = _ref9.tag,
|
|
205
|
+
other = _objectWithoutProperties(_ref9, ["tag"]);
|
|
228
206
|
|
|
229
207
|
return /*#__PURE__*/React.createElement(Transform, _extends({
|
|
230
208
|
tag: FocusLockWrapper,
|
|
@@ -232,55 +210,46 @@ var TransformWrapper = /*#__PURE__*/React.forwardRef(function (_ref3, ref) {
|
|
|
232
210
|
as: tag
|
|
233
211
|
}, other));
|
|
234
212
|
});
|
|
235
|
-
var styled_12c = create([]);
|
|
236
213
|
|
|
237
214
|
function Panel(props) {
|
|
238
|
-
var
|
|
239
|
-
|
|
215
|
+
var _ref3 = this ? this.asProps : arguments[0],
|
|
216
|
+
_ref6;
|
|
217
|
+
|
|
218
|
+
var SPanel = TransformWrapper;
|
|
219
|
+
var Children = props.Children,
|
|
240
220
|
styles = props.styles,
|
|
241
221
|
visible = props.visible,
|
|
242
222
|
closable = props.closable,
|
|
243
223
|
placement = props.placement,
|
|
244
224
|
onOutsideClick = props.onOutsideClick;
|
|
245
225
|
var sidebarRef = useRef(null);
|
|
246
|
-
return
|
|
247
|
-
onOutsideClick: onOutsideClick,
|
|
248
|
-
excludeRefs: [sidebarRef]
|
|
249
|
-
})), /*#__PURE__*/React.createElement(SPanel,
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}), /*#__PURE__*/React.createElement(PortalProvider, map("PortalProvider", {
|
|
260
|
-
value: sidebarRef
|
|
261
|
-
}), closable && /*#__PURE__*/React.createElement(SidePanel.Close, {
|
|
262
|
-
className: styled.styles["__SidePanel.Close"]
|
|
263
|
-
}), /*#__PURE__*/React.createElement(Children, {
|
|
264
|
-
className: styled.styles["__Children"]
|
|
265
|
-
}))))));
|
|
226
|
+
return _ref6 = sstyled(styles), /*#__PURE__*/React.createElement(React.Fragment, null, visible && /*#__PURE__*/React.createElement(OutsideClick, _ref6.cn("OutsideClick", {
|
|
227
|
+
"onOutsideClick": onOutsideClick,
|
|
228
|
+
"excludeRefs": [sidebarRef]
|
|
229
|
+
})), /*#__PURE__*/React.createElement(SPanel, _ref6.cn("SPanel", _objectSpread({}, _assignProps3({
|
|
230
|
+
"tag": Box,
|
|
231
|
+
"ref": sidebarRef,
|
|
232
|
+
"tabIndex": -1,
|
|
233
|
+
"returnFocus": true,
|
|
234
|
+
"autoFocus": true,
|
|
235
|
+
"transform": placementTransformMap[placement]
|
|
236
|
+
}, _ref3))), /*#__PURE__*/React.createElement(PortalProvider, _ref6.cn("PortalProvider", {
|
|
237
|
+
"value": sidebarRef
|
|
238
|
+
}), closable && /*#__PURE__*/React.createElement(SidePanel.Close, null), /*#__PURE__*/React.createElement(Children, _ref6.cn("Children", {})))));
|
|
266
239
|
}
|
|
267
240
|
|
|
268
|
-
var styled_190 = create([]);
|
|
269
|
-
|
|
270
241
|
function Close(props) {
|
|
271
|
-
var
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
tag: "button"
|
|
277
|
-
|
|
278
|
-
keyboardFocused: keyboardFocused
|
|
279
|
-
}))));
|
|
242
|
+
var _ref4 = this ? this.asProps : arguments[0],
|
|
243
|
+
_ref7;
|
|
244
|
+
|
|
245
|
+
var SClose = Box;
|
|
246
|
+
return _ref7 = sstyled(props.styles), /*#__PURE__*/React.createElement(SClose, _ref7.cn("SClose", _objectSpread({}, _assignProps4({
|
|
247
|
+
"tag": "button"
|
|
248
|
+
}, _ref4))));
|
|
280
249
|
}
|
|
281
250
|
|
|
282
251
|
Close.defaultProps = {
|
|
283
|
-
children: /*#__PURE__*/React.createElement(
|
|
252
|
+
children: /*#__PURE__*/React.createElement(CloseIcon, {
|
|
284
253
|
title: "Close"
|
|
285
254
|
})
|
|
286
255
|
};
|
package/lib/es6/SidePanel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/SidePanel.tsx"],"names":["React","useRef","FocusLock","createComponent","Component","styled","Box","FadeInOut","Transform","Portal","PortalProvider","OutsideClick","CloseS","fire","findComponent","keyboardFocusEnhance","usePreventScroll","placementTransformMap","top","right","bottom","left","RootSidePanel","createRef","e","key","stopPropagation","asProps","Children","SidePanel","Overlay","displayName","Panel","isAdvanceMode","name","delay","duration","usedOverlay","isUsedOverlay","overlay","panel","visible","calculateDelayAnimation","placement","closable","disableEnforceFocus","onOutsideClick","handleOutsideClick","onKeyDown","handleSidebarKeyDown","onClick","handleIconCloseClick","Root","disablePortal","style","props","SOverlay","styles","FocusLockWrapper","forwardRef","ref","other","TransformWrapper","tag","SPanel","sidebarRef","Close","SClose","keyboardFocused","defaultProps","children","enhance"],"mappings":";;;;;;;;;;;;;;AAAA,OAAOA,KAAP,IAAgCC,MAAhC,QAA8C,OAA9C;AACA,OAAOC,SAAP,MAAsB,kBAAtB;AACA,OAAOC,eAAP,IACEC,SADF,EAKEC,MALF,wCAMO,qBANP;AAOA,SAASC,GAAT,QAAoB,yBAApB;AACA,SAASC,SAAT,EAAsDC,SAAtD,QAAuE,0BAAvE;AACA,OAAOC,MAAP,IAA+BC,cAA/B,QAAqD,uBAArD;AACA,OAAOC,YAAP,MAAyB,8BAAzB;AACA,OAAOC,MAAP,MAAmB,iCAAnB;AACA,OAAOC,IAAP,MAAiB,+BAAjB;AACA,OAAOC,aAAP,MAA0B,wCAA1B;AACA,OAAOC,oBAAP,MAAiC,wDAAjC;AACA,OAAOC,gBAAP,MAA6B,+CAA7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA,IAAMC,qBAAqB,GAAG;AAC5BC,EAAAA,GAAG,EAAE,CAAC,qBAAD,EAAwB,iBAAxB,CADuB;AAE5BC,EAAAA,KAAK,EA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AAA,qBAAgE8D;AAAhE,KADK,EAAP;AAGD;;AAEDF,KAAK,CAACG,YAAN,GAAqB;AACnBC,EAAAA,QAAQ,eAAE,oBAAC,MAAD;AAAQ,IAAA,KAAK,EAAC;AAAd;AADS,CAArB;AAGAJ,KAAK,CAACK,OAAN,GAAgB,CAACxD,oBAAoB,EAArB,CAAhB;AAEA,IAAMc,SAAS,GAAG1B,eAAe,CAQ/BmB,aAR+B,EAQhB;AACfQ,EAAAA,OAAO,EAAPA,OADe;AAEfE,EAAAA,KAAK,EAALA,KAFe;AAGfkC,EAAAA,KAAK,EAALA;AAHe,CARgB,CAAjC;AAcA,eAAerC,SAAf","sourcesContent":["import React, { ComponentProps, useRef } from 'react';\nimport FocusLock from 'react-focus-lock';\nimport createComponent, {\n Component,\n IFunctionProps,\n Merge,\n PropGetter,\n styled,\n} from '@semcore/core';\nimport { Box } from '@semcore/flex-box';\nimport { FadeInOut, IFadeInOutProps, ITransformProps, Transform } from '@semcore/animation';\nimport Portal, { IPortalProps, PortalProvider } from '@semcore/portal';\nimport OutsideClick from '@semcore/outside-click';\nimport CloseS from '@semcore/icon/lib/Close/s';\nimport fire from '@semcore/utils/lib/fire';\nimport findComponent from '@semcore/utils/lib/findComponent';\nimport keyboardFocusEnhance from '@semcore/utils/lib/enhances/keyboardFocusEnhance';\nimport usePreventScroll from '@semcore/utils/lib/use/usePreventScroll';\n\nimport style from './style/side-panel.shadow.css';\n\nexport type OnCloseTriggerType = 'onOutsideClick' | 'onEscape' | 'onCloseClick';\nexport type OnCloseType = (\n trigger: OnCloseTriggerType,\n e?: React.MouseEvent | React.KeyboardEvent,\n) => void;\n\nexport type SidePanelPlacement = 'top' | 'left' | 'right' | 'bottom';\n\nexport interface ISidePanelProps extends IPortalProps {\n /** Animation display duration in ms\n * @default 350\n */\n duration?: number;\n /**\n * The property responsible for the visibility of the component\n */\n visible?: boolean;\n /**\n * Callback for the component closure\n */\n onClose?: OnCloseType;\n /**\n * Property for displaying the close button\n * @default true\n */\n closable?: boolean;\n /**\n * Position of a dropdown window\n * @default right\n */\n placement?: SidePanelPlacement;\n}\n\nexport interface ISidePanelOverlayProps extends IFadeInOutProps {\n /**\n * @link ISidePanelProps.visible\n */\n visible?: ISidePanelProps['visible'];\n}\n\nexport interface ISidePanelPanelProps extends ITransformProps {\n /**\n * @link ISidePanelProps.visible\n */\n visible?: ISidePanelProps['visible'];\n /**\n * @link ISidePanelProps.placement\n */\n placement?: ISidePanelProps['placement'];\n /**\n * @link ISidePanelProps.closable\n */\n closable?: ISidePanelProps['closable'];\n\n onOutsideClick?: (e?: React.SyntheticEvent) => void;\n}\n\nexport interface ISidePanelContext extends ISidePanelProps {\n /**\n * The method that encapsulates the props needed to run SidePanel.Overlay\n */\n getOverlayProps?: PropGetter<RootSidePanel['getOverlayProps']>;\n /**\n * The method that encapsulates the props needed to run SidePanel.Panel\n */\n getPanelProps?: PropGetter<RootSidePanel['getPanelProps']>;\n /**\n * The method that encapsulates the props needed to run SidePanel.Close\n */\n getCloseProps?: PropGetter<RootSidePanel['getCloseProps']>;\n}\n\nconst placementTransformMap = {\n top: ['translate(0, -100%)', 'translate(0, 0)'],\n right: ['translate(100%, 0)', 'translate(0, 0)'],\n bottom: ['translate(0, 100%)', 'translate(0, 0)'],\n left: ['translate(-100%, 0)', 'translate(0, 0)'],\n};\n\nclass RootSidePanel extends Component<ISidePanelProps> {\n static displayName = 'SidePanel';\n static style = style;\n static defaultProps = {\n placement: 'right',\n duration: 350,\n closable: true,\n };\n\n sidebarRef = React.createRef<HTMLElement>();\n\n handleSidebarKeyDown = (e) => {\n if (e.key === 'Escape') {\n e.stopPropagation();\n fire(this, 'onClose', 'onEscape', e);\n }\n };\n\n handleIconCloseClick = (e) => {\n fire(this, 'onClose', 'onCloseClick', e);\n };\n\n handleOutsideClick = (e) => {\n fire(this, 'onClose', 'onOutsideClick', e);\n };\n\n isAdvanceMode() {\n return !!findComponent(this.asProps.Children, [\n SidePanel.Overlay.displayName,\n SidePanel.Panel.displayName,\n ]);\n }\n\n isUsedOverlay() {\n return (\n !this.isAdvanceMode() ||\n !!findComponent(this.asProps.Children, [SidePanel.Overlay.displayName])\n );\n }\n\n calculateDelayAnimation(name) {\n const delay = this.asProps.duration / 2;\n const usedOverlay = this.isUsedOverlay();\n\n return {\n overlay: usedOverlay ? [0, delay] : 0,\n panel: usedOverlay ? [delay, 0] : 0,\n }[name];\n }\n\n getOverlayProps() {\n const { visible, duration } = this.asProps;\n return {\n visible,\n duration,\n delay: this.calculateDelayAnimation('overlay'),\n };\n }\n\n getPanelProps() {\n const { placement, visible, closable, duration } = this.asProps;\n\n return {\n visible,\n placement,\n closable,\n duration,\n disableEnforceFocus: !this.isUsedOverlay(),\n delay: this.calculateDelayAnimation('panel'),\n onOutsideClick: this.handleOutsideClick,\n onKeyDown: this.handleSidebarKeyDown,\n };\n }\n\n getCloseProps() {\n return {\n onClick: this.handleIconCloseClick,\n };\n }\n\n render() {\n const Root = this.Root;\n const { Children, disablePortal } = this.asProps;\n\n return (\n <Portal disablePortal={disablePortal}>\n {this.isAdvanceMode() ? (\n <Children />\n ) : (\n <SidePanel.Overlay>\n <Root render={SidePanel.Panel} />\n </SidePanel.Overlay>\n )}\n </Portal>\n );\n }\n}\n\nfunction Overlay(props: IFunctionProps<ISidePanelOverlayProps>) {\n const { Root: SOverlay, styles, visible } = props;\n usePreventScroll(visible);\n\n return styled(styles)(<SOverlay render={FadeInOut} visible={visible} />);\n}\n\nconst FocusLockWrapper = React.forwardRef<HTMLElement, any>(function (\n { disableEnforceFocus, ...other },\n ref,\n) {\n return <FocusLock ref={ref} lockProps={other} disabled={disableEnforceFocus} {...other} />;\n});\n\nconst TransformWrapper = React.forwardRef<HTMLElement, any>(function ({ tag, ...other }, ref) {\n return <Transform tag={FocusLockWrapper} ref={ref} as={tag} {...other} />;\n});\n\nfunction Panel(props: IFunctionProps<ISidePanelPanelProps>) {\n const { Root: SPanel, Children, styles, visible, closable, placement, onOutsideClick } = props;\n\n const sidebarRef = useRef<HTMLElement>(null);\n\n return styled(styles)(\n <>\n {visible && <OutsideClick onOutsideClick={onOutsideClick} excludeRefs={[sidebarRef]} />}\n <SPanel\n render={TransformWrapper}\n tag={Box}\n ref={sidebarRef}\n placement={placement}\n visible={visible}\n tabIndex={-1}\n returnFocus={true}\n autoFocus={true}\n transform={placementTransformMap[placement]}\n >\n <PortalProvider value={sidebarRef}>\n {closable && <SidePanel.Close />}\n <Children />\n </PortalProvider>\n </SPanel>\n </>,\n );\n}\n\nfunction Close(props) {\n const { Root: SClose, styles, keyboardFocused } = props;\n return styled(styles)(\n <SClose render={Box} tag=\"button\" tabIndex={0} keyboardFocused={keyboardFocused} />,\n );\n}\n\nClose.defaultProps = {\n children: <CloseS title=\"Close\" />,\n};\nClose.enhance = [keyboardFocusEnhance()];\n\nconst SidePanel = createComponent<\n ISidePanelProps,\n {\n Overlay: Merge<ISidePanelOverlayProps, ComponentProps<typeof Box>>;\n Panel: Merge<ISidePanelPanelProps, ComponentProps<typeof Box>>;\n Close: ComponentProps<typeof Box>;\n },\n ISidePanelContext\n>(RootSidePanel, {\n Overlay,\n Panel,\n Close,\n});\n\nexport default SidePanel;\n"],"file":"SidePanel.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/SidePanel.js"],"names":["React","ComponentProps","useRef","FocusLock","createComponent","Component","Root","sstyled","Box","FadeInOut","IFadeInOutProps","ITransformProps","Transform","Portal","IPortalProps","PortalProvider","OutsideClick","CloseIcon","fire","findComponent","keyboardFocusEnhance","usePreventScroll","placementTransformMap","top","right","bottom","left","RootSidePanel","createRef","e","key","stopPropagation","asProps","Children","SidePanel","Overlay","displayName","Panel","isAdvanceMode","name","delay","duration","usedOverlay","isUsedOverlay","overlay","panel","visible","calculateDelayAnimation","placement","closable","disableEnforceFocus","onOutsideClick","handleOutsideClick","onKeyDown","handleSidebarKeyDown","onClick","handleIconCloseClick","disablePortal","style","props","SOverlay","styles","FocusLockWrapper","forwardRef","ref","other","TransformWrapper","tag","SP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GAFP;AAAA,WAGO6D,UAHP;AAAA,gBAIY,CAAC,CAJb;AAAA,mBAKe,IALf;AAAA,iBAMa,IANb;AAAA,iBAOa/C,qBAAqB,CAAC0B,SAAD;AAPlC,4BASE,oBAAC,cAAD;AAAA,aAAuBqB;AAAvB,MACGpB,QAAQ,iBAAI,oBAAC,SAAD,CAAW,KAAX,OADf,eAEE,oBAAC,QAAD,2BAFF,CATF,CAFF,CADF;AAmBD;;AAED,SAASqB,KAAT,CAAeX,KAAf,EAAsB;AAAA;AAAA;;AACpB,MAAMY,MAAM,GACiC/D,GAD7C;AACA,iBAAOD,OAAO,CAACoD,KAAK,CAACE,MAAP,CAAd,eAA6B,oBAAC,MAAD;AAAA,WAAyB;AAAzB,cAA7B;AACD;;AAEDS,KAAK,CAACE,YAAN,GAAqB;AACnBC,EAAAA,QAAQ,eAAE,oBAAC,SAAD;AAAW,IAAA,KAAK,EAAC;AAAjB;AADS,CAArB;AAGAH,KAAK,CAACI,OAAN,GAAgB,CAACtD,oBAAoB,EAArB,CAAhB;AAEA,IAAMc,SAAS,GAAG9B,eAAe,CAACuB,aAAD,EAAgB;AAC/CQ,EAAAA,OAAO,EAAPA,OAD+C;AAE/CE,EAAAA,KAAK,EAALA,KAF+C;AAG/CiC,EAAAA,KAAK,EAALA;AAH+C,CAAhB,CAAjC;AAMA,eAAepC,SAAf","sourcesContent":["import React, { ComponentProps, useRef } from 'react';\nimport FocusLock from 'react-focus-lock';\nimport createComponent, { Component, Root, sstyled } from '@semcore/core';\nimport { Box } from '@semcore/flex-box';\nimport { FadeInOut, IFadeInOutProps, ITransformProps, Transform } from '@semcore/animation';\nimport Portal, { IPortalProps, PortalProvider } from '@semcore/portal';\nimport OutsideClick from '@semcore/outside-click';\nimport CloseIcon from '@semcore/icon/Close/l';\nimport fire from '@semcore/utils/lib/fire';\nimport findComponent from '@semcore/utils/lib/findComponent';\nimport keyboardFocusEnhance from '@semcore/utils/lib/enhances/keyboardFocusEnhance';\nimport usePreventScroll from '@semcore/utils/lib/use/usePreventScroll';\n\nimport style from './style/side-panel.shadow.css';\n\nconst placementTransformMap = {\n top: ['translate(0, -100%)', 'translate(0, 0)'],\n right: ['translate(100%, 0)', 'translate(0, 0)'],\n bottom: ['translate(0, 100%)', 'translate(0, 0)'],\n left: ['translate(-100%, 0)', 'translate(0, 0)'],\n};\n\nclass RootSidePanel extends Component {\n static displayName = 'SidePanel';\n static style = style;\n static defaultProps = {\n placement: 'right',\n duration: 350,\n closable: true,\n };\n\n sidebarRef = React.createRef();\n\n handleSidebarKeyDown = (e) => {\n if (e.key === 'Escape') {\n e.stopPropagation();\n fire(this, 'onClose', 'onEscape', e);\n }\n };\n\n handleIconCloseClick = (e) => {\n fire(this, 'onClose', 'onCloseClick', e);\n };\n\n handleOutsideClick = (e) => {\n fire(this, 'onClose', 'onOutsideClick', e);\n };\n\n isAdvanceMode() {\n return !!findComponent(this.asProps.Children, [\n SidePanel.Overlay.displayName,\n SidePanel.Panel.displayName,\n ]);\n }\n\n isUsedOverlay() {\n return (\n !this.isAdvanceMode() ||\n !!findComponent(this.asProps.Children, [SidePanel.Overlay.displayName])\n );\n }\n\n calculateDelayAnimation(name) {\n const delay = this.asProps.duration / 2;\n const usedOverlay = this.isUsedOverlay();\n\n return {\n overlay: usedOverlay ? [0, delay] : 0,\n panel: usedOverlay ? [delay, 0] : 0,\n }[name];\n }\n\n getOverlayProps() {\n const { visible, duration } = this.asProps;\n return {\n visible,\n duration,\n delay: this.calculateDelayAnimation('overlay'),\n };\n }\n\n getPanelProps() {\n const { placement, visible, closable, duration } = this.asProps;\n\n return {\n visible,\n placement,\n closable,\n duration,\n disableEnforceFocus: !this.isUsedOverlay(),\n delay: this.calculateDelayAnimation('panel'),\n onOutsideClick: this.handleOutsideClick,\n onKeyDown: this.handleSidebarKeyDown,\n };\n }\n\n getCloseProps() {\n return {\n onClick: this.handleIconCloseClick,\n };\n }\n\n render() {\n const { Children, disablePortal } = this.asProps;\n\n return (\n <Portal disablePortal={disablePortal}>\n {this.isAdvanceMode() ? (\n <Children />\n ) : (\n <SidePanel.Overlay>\n <Root render={SidePanel.Panel} />\n </SidePanel.Overlay>\n )}\n </Portal>\n );\n }\n}\n\nfunction Overlay(props) {\n const SOverlay = Root;\n usePreventScroll(props.visible);\n return sstyled(props.styles)(<SOverlay render={FadeInOut} />);\n}\n\nconst FocusLockWrapper = React.forwardRef(function({ disableEnforceFocus, ...other }, ref) {\n return <FocusLock ref={ref} lockProps={other} disabled={disableEnforceFocus} {...other} />;\n});\n\nconst TransformWrapper = React.forwardRef(function({ tag, ...other }, ref) {\n return <Transform tag={FocusLockWrapper} ref={ref} as={tag} {...other} />;\n});\n\nfunction Panel(props) {\n const SPanel = Root;\n const { Children, styles, visible, closable, placement, onOutsideClick } = props;\n\n const sidebarRef = useRef(null);\n\n return sstyled(styles)(\n <>\n {visible && <OutsideClick onOutsideClick={onOutsideClick} excludeRefs={[sidebarRef]} />}\n <SPanel\n render={TransformWrapper}\n tag={Box}\n ref={sidebarRef}\n tabIndex={-1}\n returnFocus={true}\n autoFocus={true}\n transform={placementTransformMap[placement]}\n >\n <PortalProvider value={sidebarRef}>\n {closable && <SidePanel.Close />}\n <Children />\n </PortalProvider>\n </SPanel>\n </>,\n );\n}\n\nfunction Close(props) {\n const SClose = Root;\n return sstyled(props.styles)(<SClose render={Box} tag=\"button\" />);\n}\n\nClose.defaultProps = {\n children: <CloseIcon title=\"Close\" />,\n};\nClose.enhance = [keyboardFocusEnhance()];\n\nconst SidePanel = createComponent(RootSidePanel, {\n Overlay,\n Panel,\n Close,\n});\n\nexport default SidePanel;\n"],"file":"SidePanel.js"}
|
package/lib/es6/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.
|
|
1
|
+
{"version":3,"sources":["../../src/index.js"],"names":["default"],"mappings":"AAAA,SAASA,OAAT,QAAwB,aAAxB;AACA,cAAc,aAAd","sourcesContent":["export { default } from './SidePanel';\nexport * from './SidePanel';\n"],"file":"index.js"}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,2 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IPortalProps } from '@semcore/portal';
|
|
3
|
+
import { IFadeInOutProps, ITransformProps } from '@semcore/animation';
|
|
4
|
+
import { CProps, PropGetterFn, ReturnEl } from '@semcore/core';
|
|
5
|
+
import { Box, IBoxProps } from '@semcore/flex-box';
|
|
6
|
+
|
|
7
|
+
export type OnCloseTriggerType = 'onOutsideClick' | 'onEscape' | 'onCloseClick';
|
|
8
|
+
export type OnCloseType = (
|
|
9
|
+
trigger: OnCloseTriggerType,
|
|
10
|
+
e?: React.MouseEvent | React.KeyboardEvent,
|
|
11
|
+
) => void;
|
|
12
|
+
|
|
13
|
+
export type SidePanelPlacement = 'top' | 'left' | 'right' | 'bottom';
|
|
14
|
+
|
|
15
|
+
export interface ISidePanelProps extends IPortalProps {
|
|
16
|
+
/** Animation display duration in ms
|
|
17
|
+
* @default 350
|
|
18
|
+
*/
|
|
19
|
+
duration?: number;
|
|
20
|
+
/**
|
|
21
|
+
* The property responsible for the visibility of the component
|
|
22
|
+
*/
|
|
23
|
+
visible?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Callback for the component closure
|
|
26
|
+
*/
|
|
27
|
+
onClose?: OnCloseType;
|
|
28
|
+
/**
|
|
29
|
+
* Property for displaying the close button
|
|
30
|
+
* @default true
|
|
31
|
+
*/
|
|
32
|
+
closable?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Position of a dropdown window
|
|
35
|
+
* @default right
|
|
36
|
+
*/
|
|
37
|
+
placement?: SidePanelPlacement;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface ISidePanelOverlayProps extends IFadeInOutProps, IBoxProps {}
|
|
41
|
+
|
|
42
|
+
export interface ISidePanelPanelProps extends ITransformProps, IBoxProps {
|
|
43
|
+
onOutsideClick?: (e?: React.SyntheticEvent) => void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface ISidePanelContext {
|
|
47
|
+
getOverlayProps?: PropGetterFn;
|
|
48
|
+
getPanelProps?: PropGetterFn;
|
|
49
|
+
getCloseProps?: PropGetterFn;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declare const SidePanel: (<T>(
|
|
53
|
+
props: CProps<ISidePanelProps & T, ISidePanelContext>,
|
|
54
|
+
) => ReturnEl) & {
|
|
55
|
+
Overlay: <T>(props: ISidePanelOverlayProps & T) => ReturnEl;
|
|
56
|
+
Panel: <T>(props: ISidePanelPanelProps & T) => ReturnEl;
|
|
57
|
+
Close: typeof Box;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export default SidePanel;
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semcore/side-panel",
|
|
3
3
|
"description": "SEMRush SidePanel Component",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/es6/index.js",
|
|
7
7
|
"typings": "lib/types/index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
8
9
|
"author": "Roman Lysov <r.lysov@semrush.com>",
|
|
9
10
|
"license": "MIT",
|
|
10
11
|
"scripts": {
|
|
11
|
-
"build": "build",
|
|
12
|
+
"build": "build --source=js",
|
|
12
13
|
"test": "jest"
|
|
13
14
|
},
|
|
14
15
|
"dependencies": {
|
|
@@ -17,12 +18,12 @@
|
|
|
17
18
|
"@semcore/flex-box": "^4",
|
|
18
19
|
"@semcore/portal": "^2",
|
|
19
20
|
"@semcore/outside-click": "^2",
|
|
20
|
-
"@semcore/icon": "^2",
|
|
21
|
+
"@semcore/icon": "^2.16",
|
|
21
22
|
"react-focus-lock": "^2.3"
|
|
22
23
|
},
|
|
23
24
|
"peerDependencies": {
|
|
24
|
-
"@semcore/core": "^1",
|
|
25
|
-
"react": "
|
|
25
|
+
"@semcore/core": "^1.11",
|
|
26
|
+
"react": "16.8 - 17"
|
|
26
27
|
},
|
|
27
28
|
"jest": {
|
|
28
29
|
"preset": "jest-preset-ui"
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
import React, { ComponentProps, useRef } from 'react';
|
|
2
2
|
import FocusLock from 'react-focus-lock';
|
|
3
|
-
import createComponent, {
|
|
4
|
-
Component,
|
|
5
|
-
IFunctionProps,
|
|
6
|
-
Merge,
|
|
7
|
-
PropGetter,
|
|
8
|
-
styled,
|
|
9
|
-
} from '@semcore/core';
|
|
3
|
+
import createComponent, { Component, Root, sstyled } from '@semcore/core';
|
|
10
4
|
import { Box } from '@semcore/flex-box';
|
|
11
5
|
import { FadeInOut, IFadeInOutProps, ITransformProps, Transform } from '@semcore/animation';
|
|
12
6
|
import Portal, { IPortalProps, PortalProvider } from '@semcore/portal';
|
|
13
7
|
import OutsideClick from '@semcore/outside-click';
|
|
14
|
-
import
|
|
8
|
+
import CloseIcon from '@semcore/icon/Close/l';
|
|
15
9
|
import fire from '@semcore/utils/lib/fire';
|
|
16
10
|
import findComponent from '@semcore/utils/lib/findComponent';
|
|
17
11
|
import keyboardFocusEnhance from '@semcore/utils/lib/enhances/keyboardFocusEnhance';
|
|
@@ -19,78 +13,6 @@ import usePreventScroll from '@semcore/utils/lib/use/usePreventScroll';
|
|
|
19
13
|
|
|
20
14
|
import style from './style/side-panel.shadow.css';
|
|
21
15
|
|
|
22
|
-
export type OnCloseTriggerType = 'onOutsideClick' | 'onEscape' | 'onCloseClick';
|
|
23
|
-
export type OnCloseType = (
|
|
24
|
-
trigger: OnCloseTriggerType,
|
|
25
|
-
e?: React.MouseEvent | React.KeyboardEvent,
|
|
26
|
-
) => void;
|
|
27
|
-
|
|
28
|
-
export type SidePanelPlacement = 'top' | 'left' | 'right' | 'bottom';
|
|
29
|
-
|
|
30
|
-
export interface ISidePanelProps extends IPortalProps {
|
|
31
|
-
/** Animation display duration in ms
|
|
32
|
-
* @default 350
|
|
33
|
-
*/
|
|
34
|
-
duration?: number;
|
|
35
|
-
/**
|
|
36
|
-
* The property responsible for the visibility of the component
|
|
37
|
-
*/
|
|
38
|
-
visible?: boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Callback for the component closure
|
|
41
|
-
*/
|
|
42
|
-
onClose?: OnCloseType;
|
|
43
|
-
/**
|
|
44
|
-
* Property for displaying the close button
|
|
45
|
-
* @default true
|
|
46
|
-
*/
|
|
47
|
-
closable?: boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Position of a dropdown window
|
|
50
|
-
* @default right
|
|
51
|
-
*/
|
|
52
|
-
placement?: SidePanelPlacement;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export interface ISidePanelOverlayProps extends IFadeInOutProps {
|
|
56
|
-
/**
|
|
57
|
-
* @link ISidePanelProps.visible
|
|
58
|
-
*/
|
|
59
|
-
visible?: ISidePanelProps['visible'];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export interface ISidePanelPanelProps extends ITransformProps {
|
|
63
|
-
/**
|
|
64
|
-
* @link ISidePanelProps.visible
|
|
65
|
-
*/
|
|
66
|
-
visible?: ISidePanelProps['visible'];
|
|
67
|
-
/**
|
|
68
|
-
* @link ISidePanelProps.placement
|
|
69
|
-
*/
|
|
70
|
-
placement?: ISidePanelProps['placement'];
|
|
71
|
-
/**
|
|
72
|
-
* @link ISidePanelProps.closable
|
|
73
|
-
*/
|
|
74
|
-
closable?: ISidePanelProps['closable'];
|
|
75
|
-
|
|
76
|
-
onOutsideClick?: (e?: React.SyntheticEvent) => void;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export interface ISidePanelContext extends ISidePanelProps {
|
|
80
|
-
/**
|
|
81
|
-
* The method that encapsulates the props needed to run SidePanel.Overlay
|
|
82
|
-
*/
|
|
83
|
-
getOverlayProps?: PropGetter<RootSidePanel['getOverlayProps']>;
|
|
84
|
-
/**
|
|
85
|
-
* The method that encapsulates the props needed to run SidePanel.Panel
|
|
86
|
-
*/
|
|
87
|
-
getPanelProps?: PropGetter<RootSidePanel['getPanelProps']>;
|
|
88
|
-
/**
|
|
89
|
-
* The method that encapsulates the props needed to run SidePanel.Close
|
|
90
|
-
*/
|
|
91
|
-
getCloseProps?: PropGetter<RootSidePanel['getCloseProps']>;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
16
|
const placementTransformMap = {
|
|
95
17
|
top: ['translate(0, -100%)', 'translate(0, 0)'],
|
|
96
18
|
right: ['translate(100%, 0)', 'translate(0, 0)'],
|
|
@@ -98,7 +20,7 @@ const placementTransformMap = {
|
|
|
98
20
|
left: ['translate(-100%, 0)', 'translate(0, 0)'],
|
|
99
21
|
};
|
|
100
22
|
|
|
101
|
-
class RootSidePanel extends Component
|
|
23
|
+
class RootSidePanel extends Component {
|
|
102
24
|
static displayName = 'SidePanel';
|
|
103
25
|
static style = style;
|
|
104
26
|
static defaultProps = {
|
|
@@ -107,7 +29,7 @@ class RootSidePanel extends Component<ISidePanelProps> {
|
|
|
107
29
|
closable: true,
|
|
108
30
|
};
|
|
109
31
|
|
|
110
|
-
sidebarRef = React.createRef
|
|
32
|
+
sidebarRef = React.createRef();
|
|
111
33
|
|
|
112
34
|
handleSidebarKeyDown = (e) => {
|
|
113
35
|
if (e.key === 'Escape') {
|
|
@@ -179,7 +101,6 @@ class RootSidePanel extends Component<ISidePanelProps> {
|
|
|
179
101
|
}
|
|
180
102
|
|
|
181
103
|
render() {
|
|
182
|
-
const Root = this.Root;
|
|
183
104
|
const { Children, disablePortal } = this.asProps;
|
|
184
105
|
|
|
185
106
|
return (
|
|
@@ -196,38 +117,33 @@ class RootSidePanel extends Component<ISidePanelProps> {
|
|
|
196
117
|
}
|
|
197
118
|
}
|
|
198
119
|
|
|
199
|
-
function Overlay(props
|
|
200
|
-
const
|
|
201
|
-
usePreventScroll(visible);
|
|
202
|
-
|
|
203
|
-
return styled(styles)(<SOverlay render={FadeInOut} visible={visible} />);
|
|
120
|
+
function Overlay(props) {
|
|
121
|
+
const SOverlay = Root;
|
|
122
|
+
usePreventScroll(props.visible);
|
|
123
|
+
return sstyled(props.styles)(<SOverlay render={FadeInOut} />);
|
|
204
124
|
}
|
|
205
125
|
|
|
206
|
-
const FocusLockWrapper = React.forwardRef
|
|
207
|
-
{ disableEnforceFocus, ...other },
|
|
208
|
-
ref,
|
|
209
|
-
) {
|
|
126
|
+
const FocusLockWrapper = React.forwardRef(function({ disableEnforceFocus, ...other }, ref) {
|
|
210
127
|
return <FocusLock ref={ref} lockProps={other} disabled={disableEnforceFocus} {...other} />;
|
|
211
128
|
});
|
|
212
129
|
|
|
213
|
-
const TransformWrapper = React.forwardRef
|
|
130
|
+
const TransformWrapper = React.forwardRef(function({ tag, ...other }, ref) {
|
|
214
131
|
return <Transform tag={FocusLockWrapper} ref={ref} as={tag} {...other} />;
|
|
215
132
|
});
|
|
216
133
|
|
|
217
|
-
function Panel(props
|
|
218
|
-
const
|
|
134
|
+
function Panel(props) {
|
|
135
|
+
const SPanel = Root;
|
|
136
|
+
const { Children, styles, visible, closable, placement, onOutsideClick } = props;
|
|
219
137
|
|
|
220
|
-
const sidebarRef = useRef
|
|
138
|
+
const sidebarRef = useRef(null);
|
|
221
139
|
|
|
222
|
-
return
|
|
140
|
+
return sstyled(styles)(
|
|
223
141
|
<>
|
|
224
142
|
{visible && <OutsideClick onOutsideClick={onOutsideClick} excludeRefs={[sidebarRef]} />}
|
|
225
143
|
<SPanel
|
|
226
144
|
render={TransformWrapper}
|
|
227
145
|
tag={Box}
|
|
228
146
|
ref={sidebarRef}
|
|
229
|
-
placement={placement}
|
|
230
|
-
visible={visible}
|
|
231
147
|
tabIndex={-1}
|
|
232
148
|
returnFocus={true}
|
|
233
149
|
autoFocus={true}
|
|
@@ -243,26 +159,16 @@ function Panel(props: IFunctionProps<ISidePanelPanelProps>) {
|
|
|
243
159
|
}
|
|
244
160
|
|
|
245
161
|
function Close(props) {
|
|
246
|
-
const
|
|
247
|
-
return
|
|
248
|
-
<SClose render={Box} tag="button" tabIndex={0} keyboardFocused={keyboardFocused} />,
|
|
249
|
-
);
|
|
162
|
+
const SClose = Root;
|
|
163
|
+
return sstyled(props.styles)(<SClose render={Box} tag="button" />);
|
|
250
164
|
}
|
|
251
165
|
|
|
252
166
|
Close.defaultProps = {
|
|
253
|
-
children: <
|
|
167
|
+
children: <CloseIcon title="Close" />,
|
|
254
168
|
};
|
|
255
169
|
Close.enhance = [keyboardFocusEnhance()];
|
|
256
170
|
|
|
257
|
-
const SidePanel = createComponent
|
|
258
|
-
ISidePanelProps,
|
|
259
|
-
{
|
|
260
|
-
Overlay: Merge<ISidePanelOverlayProps, ComponentProps<typeof Box>>;
|
|
261
|
-
Panel: Merge<ISidePanelPanelProps, ComponentProps<typeof Box>>;
|
|
262
|
-
Close: ComponentProps<typeof Box>;
|
|
263
|
-
},
|
|
264
|
-
ISidePanelContext
|
|
265
|
-
>(RootSidePanel, {
|
|
171
|
+
const SidePanel = createComponent(RootSidePanel, {
|
|
266
172
|
Overlay,
|
|
267
173
|
Panel,
|
|
268
174
|
Close,
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IPortalProps } from '@semcore/portal';
|
|
3
|
+
import { IFadeInOutProps, ITransformProps } from '@semcore/animation';
|
|
4
|
+
import { CProps, PropGetterFn, ReturnEl } from '@semcore/core';
|
|
5
|
+
import { Box, IBoxProps } from '@semcore/flex-box';
|
|
6
|
+
|
|
7
|
+
export type OnCloseTriggerType = 'onOutsideClick' | 'onEscape' | 'onCloseClick';
|
|
8
|
+
export type OnCloseType = (
|
|
9
|
+
trigger: OnCloseTriggerType,
|
|
10
|
+
e?: React.MouseEvent | React.KeyboardEvent,
|
|
11
|
+
) => void;
|
|
12
|
+
|
|
13
|
+
export type SidePanelPlacement = 'top' | 'left' | 'right' | 'bottom';
|
|
14
|
+
|
|
15
|
+
export interface ISidePanelProps extends IPortalProps {
|
|
16
|
+
/** Animation display duration in ms
|
|
17
|
+
* @default 350
|
|
18
|
+
*/
|
|
19
|
+
duration?: number;
|
|
20
|
+
/**
|
|
21
|
+
* The property responsible for the visibility of the component
|
|
22
|
+
*/
|
|
23
|
+
visible?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Callback for the component closure
|
|
26
|
+
*/
|
|
27
|
+
onClose?: OnCloseType;
|
|
28
|
+
/**
|
|
29
|
+
* Property for displaying the close button
|
|
30
|
+
* @default true
|
|
31
|
+
*/
|
|
32
|
+
closable?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Position of a dropdown window
|
|
35
|
+
* @default right
|
|
36
|
+
*/
|
|
37
|
+
placement?: SidePanelPlacement;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface ISidePanelOverlayProps extends IFadeInOutProps, IBoxProps {}
|
|
41
|
+
|
|
42
|
+
export interface ISidePanelPanelProps extends ITransformProps, IBoxProps {
|
|
43
|
+
onOutsideClick?: (e?: React.SyntheticEvent) => void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface ISidePanelContext {
|
|
47
|
+
getOverlayProps?: PropGetterFn;
|
|
48
|
+
getPanelProps?: PropGetterFn;
|
|
49
|
+
getCloseProps?: PropGetterFn;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declare const SidePanel: (<T>(
|
|
53
|
+
props: CProps<ISidePanelProps & T, ISidePanelContext>,
|
|
54
|
+
) => ReturnEl) & {
|
|
55
|
+
Overlay: <T>(props: ISidePanelOverlayProps & T) => ReturnEl;
|
|
56
|
+
Panel: <T>(props: ISidePanelPanelProps & T) => ReturnEl;
|
|
57
|
+
Close: typeof Box;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export default SidePanel;
|
|
File without changes
|
package/lib/types/SidePanel.d.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import React, { ComponentProps } from 'react';
|
|
2
|
-
import { Component, Merge, PropGetter } from '@semcore/core';
|
|
3
|
-
import { Box } from '@semcore/flex-box';
|
|
4
|
-
import { IFadeInOutProps, ITransformProps } from '@semcore/animation';
|
|
5
|
-
import { IPortalProps } from '@semcore/portal';
|
|
6
|
-
export declare type OnCloseTriggerType = 'onOutsideClick' | 'onEscape' | 'onCloseClick';
|
|
7
|
-
export declare type OnCloseType = (trigger: OnCloseTriggerType, e?: React.MouseEvent | React.KeyboardEvent) => void;
|
|
8
|
-
export declare type SidePanelPlacement = 'top' | 'left' | 'right' | 'bottom';
|
|
9
|
-
export interface ISidePanelProps extends IPortalProps {
|
|
10
|
-
/** Animation display duration in ms
|
|
11
|
-
* @default 350
|
|
12
|
-
*/
|
|
13
|
-
duration?: number;
|
|
14
|
-
/**
|
|
15
|
-
* The property responsible for the visibility of the component
|
|
16
|
-
*/
|
|
17
|
-
visible?: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Callback for the component closure
|
|
20
|
-
*/
|
|
21
|
-
onClose?: OnCloseType;
|
|
22
|
-
/**
|
|
23
|
-
* Property for displaying the close button
|
|
24
|
-
* @default true
|
|
25
|
-
*/
|
|
26
|
-
closable?: boolean;
|
|
27
|
-
/**
|
|
28
|
-
* Position of a dropdown window
|
|
29
|
-
* @default right
|
|
30
|
-
*/
|
|
31
|
-
placement?: SidePanelPlacement;
|
|
32
|
-
}
|
|
33
|
-
export interface ISidePanelOverlayProps extends IFadeInOutProps {
|
|
34
|
-
/**
|
|
35
|
-
* @link ISidePanelProps.visible
|
|
36
|
-
*/
|
|
37
|
-
visible?: ISidePanelProps['visible'];
|
|
38
|
-
}
|
|
39
|
-
export interface ISidePanelPanelProps extends ITransformProps {
|
|
40
|
-
/**
|
|
41
|
-
* @link ISidePanelProps.visible
|
|
42
|
-
*/
|
|
43
|
-
visible?: ISidePanelProps['visible'];
|
|
44
|
-
/**
|
|
45
|
-
* @link ISidePanelProps.placement
|
|
46
|
-
*/
|
|
47
|
-
placement?: ISidePanelProps['placement'];
|
|
48
|
-
/**
|
|
49
|
-
* @link ISidePanelProps.closable
|
|
50
|
-
*/
|
|
51
|
-
closable?: ISidePanelProps['closable'];
|
|
52
|
-
onOutsideClick?: (e?: React.SyntheticEvent) => void;
|
|
53
|
-
}
|
|
54
|
-
export interface ISidePanelContext extends ISidePanelProps {
|
|
55
|
-
/**
|
|
56
|
-
* The method that encapsulates the props needed to run SidePanel.Overlay
|
|
57
|
-
*/
|
|
58
|
-
getOverlayProps?: PropGetter<RootSidePanel['getOverlayProps']>;
|
|
59
|
-
/**
|
|
60
|
-
* The method that encapsulates the props needed to run SidePanel.Panel
|
|
61
|
-
*/
|
|
62
|
-
getPanelProps?: PropGetter<RootSidePanel['getPanelProps']>;
|
|
63
|
-
/**
|
|
64
|
-
* The method that encapsulates the props needed to run SidePanel.Close
|
|
65
|
-
*/
|
|
66
|
-
getCloseProps?: PropGetter<RootSidePanel['getCloseProps']>;
|
|
67
|
-
}
|
|
68
|
-
declare class RootSidePanel extends Component<ISidePanelProps> {
|
|
69
|
-
static displayName: string;
|
|
70
|
-
static style: any;
|
|
71
|
-
static defaultProps: {
|
|
72
|
-
placement: string;
|
|
73
|
-
duration: number;
|
|
74
|
-
closable: boolean;
|
|
75
|
-
};
|
|
76
|
-
sidebarRef: React.RefObject<HTMLElement>;
|
|
77
|
-
handleSidebarKeyDown: (e: any) => void;
|
|
78
|
-
handleIconCloseClick: (e: any) => void;
|
|
79
|
-
handleOutsideClick: (e: any) => void;
|
|
80
|
-
isAdvanceMode(): boolean;
|
|
81
|
-
isUsedOverlay(): boolean;
|
|
82
|
-
calculateDelayAnimation(name: any): any;
|
|
83
|
-
getOverlayProps(): {
|
|
84
|
-
visible: boolean;
|
|
85
|
-
duration: number;
|
|
86
|
-
delay: any;
|
|
87
|
-
};
|
|
88
|
-
getPanelProps(): {
|
|
89
|
-
visible: boolean;
|
|
90
|
-
placement: SidePanelPlacement;
|
|
91
|
-
closable: boolean;
|
|
92
|
-
duration: number;
|
|
93
|
-
disableEnforceFocus: boolean;
|
|
94
|
-
delay: any;
|
|
95
|
-
onOutsideClick: (e: any) => void;
|
|
96
|
-
onKeyDown: (e: any) => void;
|
|
97
|
-
};
|
|
98
|
-
getCloseProps(): {
|
|
99
|
-
onClick: (e: any) => void;
|
|
100
|
-
};
|
|
101
|
-
render(): JSX.Element;
|
|
102
|
-
}
|
|
103
|
-
declare const SidePanel: import("@semcore/core").ComponentType<ISidePanelProps, {
|
|
104
|
-
Overlay: Merge<ISidePanelOverlayProps, ComponentProps<typeof Box>>;
|
|
105
|
-
Panel: Merge<ISidePanelPanelProps, ComponentProps<typeof Box>>;
|
|
106
|
-
Close: ComponentProps<typeof Box>;
|
|
107
|
-
}, ISidePanelContext, {
|
|
108
|
-
[key: string]: (arg: unknown) => void;
|
|
109
|
-
}, null>;
|
|
110
|
-
export default SidePanel;
|