@invoicebox/ui 0.1.0-alpha.317 → 0.1.0-alpha.318
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/dist/components/common/AppCardLink/index.js +2 -1
- package/dist/components/common/Drawer/index.js +2 -8
- package/dist/components/common/Drawer/index.stories.js +22 -7
- package/dist/esm/components/common/AppCardLink/index.js +2 -1
- package/dist/esm/components/common/Drawer/index.js +2 -8
- package/dist/esm/components/common/Drawer/index.stories.js +22 -7
- package/dist/esm/hooks/useLockBodyScroll/index.js +45 -0
- package/dist/hooks/useLockBodyScroll/index.d.ts +1 -0
- package/dist/hooks/useLockBodyScroll/index.js +51 -0
- package/package.json +5 -2
|
@@ -27,7 +27,8 @@ var AppCardLink = exports.AppCardLink = function AppCardLink(_ref) {
|
|
|
27
27
|
var AppCardComponent = appCardMap[variant];
|
|
28
28
|
return /*#__PURE__*/_react["default"].createElement(S.Wrapper, {
|
|
29
29
|
href: href,
|
|
30
|
-
target: '_blank'
|
|
30
|
+
target: '_blank',
|
|
31
|
+
rel: "noopener noreferrer"
|
|
31
32
|
}, /*#__PURE__*/_react["default"].createElement(AppCardComponent, {
|
|
32
33
|
height: height
|
|
33
34
|
}));
|
|
@@ -10,6 +10,7 @@ var _reactDom = require("react-dom");
|
|
|
10
10
|
var S = _interopRequireWildcard(require("./styles"));
|
|
11
11
|
var _Typography = require("../Typography");
|
|
12
12
|
var _palette = require("../../../palette");
|
|
13
|
+
var _useLockBodyScroll = require("../../../hooks/useLockBodyScroll");
|
|
13
14
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
14
15
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
15
16
|
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
@@ -75,14 +76,7 @@ var Drawer = exports.Drawer = function Drawer(_ref) {
|
|
|
75
76
|
}, [shouldRender, isOpen]);
|
|
76
77
|
|
|
77
78
|
// Блокируем скролл фона, пока боттомшит открыт (как делал react-modal-sheet).
|
|
78
|
-
(0,
|
|
79
|
-
if (!shouldRender) return undefined;
|
|
80
|
-
var prev = document.body.style.overflow;
|
|
81
|
-
document.body.style.overflow = 'hidden';
|
|
82
|
-
return function () {
|
|
83
|
-
document.body.style.overflow = prev;
|
|
84
|
-
};
|
|
85
|
-
}, [shouldRender]);
|
|
79
|
+
(0, _useLockBodyScroll.useLockBodyScroll)(shouldRender);
|
|
86
80
|
var handleTransitionEnd = (0, _react.useCallback)(function (event) {
|
|
87
81
|
if (event.target !== sheetRef.current || event.propertyName !== 'transform') return;
|
|
88
82
|
if (isOpen && isEntered && onOpenEnd) onOpenEnd();
|
|
@@ -45,19 +45,34 @@ var Counter = function Counter() {
|
|
|
45
45
|
function Render(args) {
|
|
46
46
|
var _useState3 = (0, _react.useState)(false),
|
|
47
47
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
isOpenDrawer1 = _useState4[0],
|
|
49
|
+
setIsOpenDrawer1 = _useState4[1];
|
|
50
|
+
var _useState5 = (0, _react.useState)(false),
|
|
51
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
52
|
+
isOpenDrawer2 = _useState6[0],
|
|
53
|
+
setIsOpenDrawer2 = _useState6[1];
|
|
50
54
|
return /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_.Drawer, _extends({}, args, {
|
|
51
55
|
onClose: function onClose() {
|
|
52
|
-
return
|
|
56
|
+
return setIsOpenDrawer1(false);
|
|
53
57
|
},
|
|
54
|
-
isOpen:
|
|
55
|
-
}), "Content", /*#__PURE__*/_react["default"].createElement(
|
|
58
|
+
isOpen: isOpenDrawer1
|
|
59
|
+
}), "Drawer 1 Content", /*#__PURE__*/_react["default"].createElement("button", {
|
|
56
60
|
type: 'button',
|
|
57
61
|
onClick: function onClick() {
|
|
58
|
-
|
|
62
|
+
setIsOpenDrawer2(true);
|
|
63
|
+
setIsOpenDrawer1(false);
|
|
59
64
|
}
|
|
60
|
-
}, "Open"))
|
|
65
|
+
}, "Open drawer 2"), /*#__PURE__*/_react["default"].createElement(Counter, null)), /*#__PURE__*/_react["default"].createElement(_.Drawer, _extends({}, args, {
|
|
66
|
+
onClose: function onClose() {
|
|
67
|
+
return setIsOpenDrawer2(false);
|
|
68
|
+
},
|
|
69
|
+
isOpen: isOpenDrawer2
|
|
70
|
+
}), "Drawer 2 Content", /*#__PURE__*/_react["default"].createElement(Counter, null)), /*#__PURE__*/_react["default"].createElement("button", {
|
|
71
|
+
type: 'button',
|
|
72
|
+
onClick: function onClick() {
|
|
73
|
+
return setIsOpenDrawer1(true);
|
|
74
|
+
}
|
|
75
|
+
}, "Open drawer 1"));
|
|
61
76
|
}
|
|
62
77
|
var commonArgs = {
|
|
63
78
|
children: 'Children',
|
|
@@ -17,7 +17,8 @@ export var AppCardLink = function AppCardLink(_ref) {
|
|
|
17
17
|
var AppCardComponent = appCardMap[variant];
|
|
18
18
|
return /*#__PURE__*/React.createElement(S.Wrapper, {
|
|
19
19
|
href: href,
|
|
20
|
-
target: '_blank'
|
|
20
|
+
target: '_blank',
|
|
21
|
+
rel: "noopener noreferrer"
|
|
21
22
|
}, /*#__PURE__*/React.createElement(AppCardComponent, {
|
|
22
23
|
height: height
|
|
23
24
|
}));
|
|
@@ -9,6 +9,7 @@ import { createPortal } from 'react-dom';
|
|
|
9
9
|
import * as S from './styles';
|
|
10
10
|
import { Typography } from '../Typography';
|
|
11
11
|
import { useComponentPalette } from '../../../palette';
|
|
12
|
+
import { useLockBodyScroll } from '../../../hooks/useLockBodyScroll';
|
|
12
13
|
var ANIMATION_MS = 300;
|
|
13
14
|
var DRAG_CLOSE_THRESHOLD = 80;
|
|
14
15
|
export var Drawer = function Drawer(_ref) {
|
|
@@ -66,14 +67,7 @@ export var Drawer = function Drawer(_ref) {
|
|
|
66
67
|
}, [shouldRender, isOpen]);
|
|
67
68
|
|
|
68
69
|
// Блокируем скролл фона, пока боттомшит открыт (как делал react-modal-sheet).
|
|
69
|
-
|
|
70
|
-
if (!shouldRender) return undefined;
|
|
71
|
-
var prev = document.body.style.overflow;
|
|
72
|
-
document.body.style.overflow = 'hidden';
|
|
73
|
-
return function () {
|
|
74
|
-
document.body.style.overflow = prev;
|
|
75
|
-
};
|
|
76
|
-
}, [shouldRender]);
|
|
70
|
+
useLockBodyScroll(shouldRender);
|
|
77
71
|
var handleTransitionEnd = useCallback(function (event) {
|
|
78
72
|
if (event.target !== sheetRef.current || event.propertyName !== 'transform') return;
|
|
79
73
|
if (isOpen && isEntered && onOpenEnd) onOpenEnd();
|
|
@@ -37,19 +37,34 @@ var Counter = function Counter() {
|
|
|
37
37
|
function Render(args) {
|
|
38
38
|
var _useState3 = useState(false),
|
|
39
39
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
isOpenDrawer1 = _useState4[0],
|
|
41
|
+
setIsOpenDrawer1 = _useState4[1];
|
|
42
|
+
var _useState5 = useState(false),
|
|
43
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
44
|
+
isOpenDrawer2 = _useState6[0],
|
|
45
|
+
setIsOpenDrawer2 = _useState6[1];
|
|
42
46
|
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Drawer, _extends({}, args, {
|
|
43
47
|
onClose: function onClose() {
|
|
44
|
-
return
|
|
48
|
+
return setIsOpenDrawer1(false);
|
|
45
49
|
},
|
|
46
|
-
isOpen:
|
|
47
|
-
}), "Content", /*#__PURE__*/React.createElement(
|
|
50
|
+
isOpen: isOpenDrawer1
|
|
51
|
+
}), "Drawer 1 Content", /*#__PURE__*/React.createElement("button", {
|
|
48
52
|
type: 'button',
|
|
49
53
|
onClick: function onClick() {
|
|
50
|
-
|
|
54
|
+
setIsOpenDrawer2(true);
|
|
55
|
+
setIsOpenDrawer1(false);
|
|
51
56
|
}
|
|
52
|
-
}, "Open"))
|
|
57
|
+
}, "Open drawer 2"), /*#__PURE__*/React.createElement(Counter, null)), /*#__PURE__*/React.createElement(Drawer, _extends({}, args, {
|
|
58
|
+
onClose: function onClose() {
|
|
59
|
+
return setIsOpenDrawer2(false);
|
|
60
|
+
},
|
|
61
|
+
isOpen: isOpenDrawer2
|
|
62
|
+
}), "Drawer 2 Content", /*#__PURE__*/React.createElement(Counter, null)), /*#__PURE__*/React.createElement("button", {
|
|
63
|
+
type: 'button',
|
|
64
|
+
onClick: function onClick() {
|
|
65
|
+
return setIsOpenDrawer1(true);
|
|
66
|
+
}
|
|
67
|
+
}, "Open drawer 1"));
|
|
53
68
|
}
|
|
54
69
|
var commonArgs = {
|
|
55
70
|
children: 'Children',
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useId, useLayoutEffect } from 'react';
|
|
2
|
+
var SCROLL_LOCK_STATE_KEY = '__invoiceboxBodyScrollLockState';
|
|
3
|
+
function getState() {
|
|
4
|
+
var global = globalThis;
|
|
5
|
+
if (!global[SCROLL_LOCK_STATE_KEY]) {
|
|
6
|
+
global[SCROLL_LOCK_STATE_KEY] = {
|
|
7
|
+
locks: new Set(),
|
|
8
|
+
originalBodyOverflow: ''
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
return global[SCROLL_LOCK_STATE_KEY];
|
|
12
|
+
}
|
|
13
|
+
function lockBodyScroll(lockId) {
|
|
14
|
+
var state = getState();
|
|
15
|
+
if (state.locks.size === 0) {
|
|
16
|
+
state.originalBodyOverflow = document.body.style.overflow;
|
|
17
|
+
document.body.style.overflow = 'hidden';
|
|
18
|
+
}
|
|
19
|
+
state.locks.add(lockId);
|
|
20
|
+
}
|
|
21
|
+
function unlockBodyScroll(lockId) {
|
|
22
|
+
var state = getState();
|
|
23
|
+
if (!state.locks["delete"](lockId)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (state.locks.size === 0) {
|
|
27
|
+
if (state.originalBodyOverflow) {
|
|
28
|
+
document.body.style.overflow = state.originalBodyOverflow;
|
|
29
|
+
} else {
|
|
30
|
+
document.body.style.removeProperty('overflow');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export var useLockBodyScroll = function useLockBodyScroll(locked) {
|
|
35
|
+
var lockId = useId();
|
|
36
|
+
useLayoutEffect(function () {
|
|
37
|
+
if (!locked) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
lockBodyScroll(lockId);
|
|
41
|
+
return function () {
|
|
42
|
+
unlockBodyScroll(lockId);
|
|
43
|
+
};
|
|
44
|
+
}, [locked, lockId]);
|
|
45
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useLockBodyScroll: (locked: boolean) => void;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useLockBodyScroll = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var SCROLL_LOCK_STATE_KEY = '__invoiceboxBodyScrollLockState';
|
|
9
|
+
function getState() {
|
|
10
|
+
var global = globalThis;
|
|
11
|
+
if (!global[SCROLL_LOCK_STATE_KEY]) {
|
|
12
|
+
global[SCROLL_LOCK_STATE_KEY] = {
|
|
13
|
+
locks: new Set(),
|
|
14
|
+
originalBodyOverflow: ''
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return global[SCROLL_LOCK_STATE_KEY];
|
|
18
|
+
}
|
|
19
|
+
function lockBodyScroll(lockId) {
|
|
20
|
+
var state = getState();
|
|
21
|
+
if (state.locks.size === 0) {
|
|
22
|
+
state.originalBodyOverflow = document.body.style.overflow;
|
|
23
|
+
document.body.style.overflow = 'hidden';
|
|
24
|
+
}
|
|
25
|
+
state.locks.add(lockId);
|
|
26
|
+
}
|
|
27
|
+
function unlockBodyScroll(lockId) {
|
|
28
|
+
var state = getState();
|
|
29
|
+
if (!state.locks["delete"](lockId)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (state.locks.size === 0) {
|
|
33
|
+
if (state.originalBodyOverflow) {
|
|
34
|
+
document.body.style.overflow = state.originalBodyOverflow;
|
|
35
|
+
} else {
|
|
36
|
+
document.body.style.removeProperty('overflow');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
var useLockBodyScroll = exports.useLockBodyScroll = function useLockBodyScroll(locked) {
|
|
41
|
+
var lockId = (0, _react.useId)();
|
|
42
|
+
(0, _react.useLayoutEffect)(function () {
|
|
43
|
+
if (!locked) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
lockBodyScroll(lockId);
|
|
47
|
+
return function () {
|
|
48
|
+
unlockBodyScroll(lockId);
|
|
49
|
+
};
|
|
50
|
+
}, [locked, lockId]);
|
|
51
|
+
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@invoicebox/ui",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.318",
|
|
4
4
|
"description": "Invoicebox UI",
|
|
5
5
|
"license": "Apache License 2.0",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"storybook": "storybook dev -p 6006",
|
|
8
8
|
"release": "./release.sh",
|
|
9
|
-
"test": "jest"
|
|
9
|
+
"test": "jest",
|
|
10
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
11
|
+
"typecheck": "tsc --project tsconfig.json --noEmit --emitDeclarationOnly false",
|
|
12
|
+
"build": "rm -rf dist && babel src --extensions .ts,.tsx --out-dir dist --copy-files && babel src --extensions .ts,.tsx --out-dir dist/esm --copy-files --config-file ./babel.config.esm.json && tsc --project tsconfig.json"
|
|
10
13
|
},
|
|
11
14
|
"bugs": {
|
|
12
15
|
"url": "https://github.com/InvoiceBox/invoicebox-ui/issues"
|