@spaced-out/ui-design-system 0.1.26 → 0.1.27
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/.cspell/custom-words.txt +3 -0
- package/.storybook/main.js +40 -28
- package/.storybook/manager.js +0 -4
- package/.storybook/preview-head.html +15 -6
- package/.storybook/preview.js +0 -5
- package/CHANGELOG.md +22 -0
- package/babel.config.js +1 -0
- package/lib/components/Badge/Badge.module.css +1 -0
- package/lib/components/ButtonDropdown/ButtonDropdown.js +10 -9
- package/lib/components/ButtonDropdown/ButtonDropdown.js.flow +6 -4
- package/lib/components/Chip/Chip.js +1 -1
- package/lib/components/Chip/Chip.js.flow +2 -2
- package/lib/components/CollapsibleCard/CollapsibleCard.js +3 -0
- package/lib/components/CollapsibleCard/CollapsibleCard.js.flow +4 -0
- package/lib/components/Dialog/Dialog.js +23 -2
- package/lib/components/Dialog/Dialog.js.flow +38 -0
- package/lib/components/Dropdown/Dropdown.js +10 -9
- package/lib/components/Dropdown/Dropdown.js.flow +6 -4
- package/lib/components/FocusManager/FocusManager.js +7 -5
- package/lib/components/FocusManager/FocusManager.js.flow +3 -3
- package/lib/components/InlineDropdown/InlineDropdown.js +10 -9
- package/lib/components/InlineDropdown/InlineDropdown.js.flow +6 -4
- package/lib/components/Menu/Menu.js +48 -12
- package/lib/components/Menu/Menu.js.flow +102 -9
- package/lib/components/Menu/Menu.module.css +10 -0
- package/lib/components/Menu/MenuOptionButton.js +21 -4
- package/lib/components/Menu/MenuOptionButton.js.flow +21 -0
- package/lib/components/Modal/Modal.js +35 -8
- package/lib/components/Modal/Modal.js.flow +52 -7
- package/lib/components/Modal/Modal.module.css +1 -3
- package/lib/components/Panel/Panel.js +21 -1
- package/lib/components/Panel/Panel.js.flow +30 -1
- package/lib/components/Panel/Panel.module.css +0 -1
- package/lib/components/Table/DefaultRow.js +5 -5
- package/lib/components/Table/DefaultRow.js.flow +14 -11
- package/lib/components/Table/StaticTable.js +5 -1
- package/lib/components/Table/StaticTable.js.flow +4 -0
- package/lib/components/Table/Table.js.flow +2 -0
- package/lib/components/Tabs/TabList/TabDropdown.js +10 -9
- package/lib/components/Tabs/TabList/TabDropdown.js.flow +6 -4
- package/lib/components/Toast/Toast.js +7 -5
- package/lib/components/Toast/Toast.js.flow +5 -3
- package/lib/components/Tooltip/Tooltip.js +22 -25
- package/lib/components/Tooltip/Tooltip.js.flow +25 -22
- package/lib/components/Typeahead/Typeahead.js +10 -9
- package/lib/components/Typeahead/Typeahead.js.flow +6 -4
- package/lib/hooks/index.js +55 -0
- package/lib/hooks/index.js.flow +5 -0
- package/lib/hooks/useCopyToClipboard.js +31 -0
- package/lib/hooks/useCopyToClipboard.js.flow +31 -0
- package/lib/hooks/useInputState.js +23 -0
- package/lib/hooks/useInputState.js.flow +28 -0
- package/lib/hooks/useLockedBody.js +54 -0
- package/lib/hooks/useLockedBody.js.flow +55 -0
- package/lib/hooks/useToggle.js +18 -0
- package/lib/hooks/useToggle.js.flow +17 -0
- package/lib/hooks/useWindowSize.js +32 -0
- package/lib/hooks/useWindowSize.js.flow +37 -0
- package/lib/styles/typography.module.css +1 -0
- package/lib/types/common.js +0 -1
- package/lib/utils/index.js +11 -0
- package/lib/utils/index.js.flow +1 -0
- package/lib/utils/menu.js +57 -2
- package/lib/utils/menu.js.flow +109 -1
- package/lib/utils/string.js +4 -2
- package/lib/utils/string.js.flow +3 -0
- package/lib/utils/tokens.js +74 -0
- package/lib/utils/tokens.js.flow +82 -0
- package/package.json +18 -16
- package/.storybook/public/favicon.svg +0 -6
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// @flow strict
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
// $FlowFixMe[untyped-import]
|
|
5
|
-
import {createPortal} from 'react-dom';
|
|
6
4
|
import {
|
|
7
5
|
// $FlowFixMe[untyped-import]
|
|
8
6
|
autoUpdate,
|
|
9
7
|
// $FlowFixMe[untyped-import]
|
|
10
8
|
flip,
|
|
11
9
|
// $FlowFixMe[untyped-import]
|
|
10
|
+
FloatingPortal,
|
|
11
|
+
// $FlowFixMe[untyped-import]
|
|
12
12
|
offset,
|
|
13
13
|
// $FlowFixMe[untyped-import]
|
|
14
14
|
shift,
|
|
@@ -23,14 +23,15 @@ import {
|
|
|
23
23
|
// $FlowFixMe[untyped-import]
|
|
24
24
|
useInteractions,
|
|
25
25
|
// $FlowFixMe[untyped-import]
|
|
26
|
+
useMergeRefs,
|
|
27
|
+
// $FlowFixMe[untyped-import]
|
|
26
28
|
useRole,
|
|
27
|
-
} from '@floating-ui/react
|
|
29
|
+
} from '@floating-ui/react';
|
|
28
30
|
|
|
29
31
|
import * as ELEVATION from '../../styles/variables/_elevation';
|
|
30
32
|
import * as MOTION from '../../styles/variables/_motion';
|
|
31
|
-
import {
|
|
33
|
+
import {spaceXXSmall} from '../../styles/variables/_space';
|
|
32
34
|
import {classify} from '../../utils/classify';
|
|
33
|
-
import {mergeRefs} from '../../utils/merge-refs';
|
|
34
35
|
import {capitalize} from '../../utils/string';
|
|
35
36
|
import {Truncate} from '../Truncate';
|
|
36
37
|
|
|
@@ -93,14 +94,20 @@ export const Tooltip = ({
|
|
|
93
94
|
elevation = ELEVATION['elevationTooltip'],
|
|
94
95
|
hidden,
|
|
95
96
|
}: TooltipProps): React.Node => {
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
|
|
97
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
|
98
|
+
const {refs, floatingStyles, context, strategy} = useFloating({
|
|
99
|
+
open: isOpen,
|
|
100
|
+
onOpenChange: setIsOpen,
|
|
99
101
|
placement,
|
|
100
|
-
|
|
101
|
-
onOpenChange: setOpen,
|
|
102
|
-
middleware: [offset(parseInt(spaceXXSmall)), flip(), shift()],
|
|
102
|
+
// Make sure the tooltip stays on the screen
|
|
103
103
|
whileElementsMounted: autoUpdate,
|
|
104
|
+
middleware: [
|
|
105
|
+
offset(parseInt(spaceXXSmall)),
|
|
106
|
+
flip({
|
|
107
|
+
fallbackAxisSideDirection: 'start',
|
|
108
|
+
}),
|
|
109
|
+
shift(),
|
|
110
|
+
],
|
|
104
111
|
});
|
|
105
112
|
|
|
106
113
|
const motionDurationToken =
|
|
@@ -123,10 +130,7 @@ export const Tooltip = ({
|
|
|
123
130
|
]);
|
|
124
131
|
|
|
125
132
|
// Note(Nishant) Preserve the consumer's ref
|
|
126
|
-
const ref =
|
|
127
|
-
() => mergeRefs([reference, children.ref]),
|
|
128
|
-
[reference, children],
|
|
129
|
-
);
|
|
133
|
+
const ref = useMergeRefs([refs.setReference, children.ref]);
|
|
130
134
|
|
|
131
135
|
return (
|
|
132
136
|
<>
|
|
@@ -137,17 +141,16 @@ export const Tooltip = ({
|
|
|
137
141
|
...children.props,
|
|
138
142
|
}),
|
|
139
143
|
)}
|
|
140
|
-
|
|
141
|
-
|
|
144
|
+
<FloatingPortal>
|
|
145
|
+
{isOpen && (
|
|
142
146
|
<>
|
|
143
147
|
{!hidden && (
|
|
144
148
|
<div
|
|
145
|
-
ref={
|
|
149
|
+
ref={refs.setFloating}
|
|
146
150
|
className={classify(css.tooltip, classNames?.tooltip)}
|
|
147
151
|
style={{
|
|
148
152
|
position: strategy,
|
|
149
|
-
|
|
150
|
-
left: x ?? spaceNone,
|
|
153
|
+
...floatingStyles,
|
|
151
154
|
'--tooltip-elevation': elevation,
|
|
152
155
|
}}
|
|
153
156
|
{...getFloatingProps()}
|
|
@@ -177,9 +180,9 @@ export const Tooltip = ({
|
|
|
177
180
|
)}
|
|
178
181
|
</div>
|
|
179
182
|
)}
|
|
180
|
-
|
|
181
|
-
bodyRef.current,
|
|
183
|
+
</>
|
|
182
184
|
)}
|
|
185
|
+
</FloatingPortal>
|
|
183
186
|
</>
|
|
184
187
|
);
|
|
185
188
|
};
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.Typeahead = void 0;
|
|
7
7
|
var React = _interopRequireWildcard(require("react"));
|
|
8
|
-
var
|
|
8
|
+
var _react2 = require("@floating-ui/react");
|
|
9
9
|
var _color = require("../../styles/variables/_color");
|
|
10
10
|
var _size = require("../../styles/variables/_size");
|
|
11
11
|
var _space = require("../../styles/variables/_space");
|
|
@@ -39,14 +39,14 @@ const Typeahead = _ref => {
|
|
|
39
39
|
const {
|
|
40
40
|
x,
|
|
41
41
|
y,
|
|
42
|
-
|
|
43
|
-
floating,
|
|
42
|
+
refs,
|
|
44
43
|
strategy
|
|
45
|
-
} = (0,
|
|
44
|
+
} = (0, _react2.useFloating)({
|
|
45
|
+
open: true,
|
|
46
46
|
strategy: 'absolute',
|
|
47
47
|
placement: 'bottom-start',
|
|
48
|
-
whileElementsMounted:
|
|
49
|
-
middleware: [(0,
|
|
48
|
+
whileElementsMounted: _react2.autoUpdate,
|
|
49
|
+
middleware: [(0, _react2.flip)(), (0, _react2.offset)(parseInt(_space.spaceXXSmall))]
|
|
50
50
|
});
|
|
51
51
|
const onMenuToggle = isOpen => {
|
|
52
52
|
isOpen ? onMenuOpen && onMenuOpen() : onMenuClose && onMenuClose();
|
|
@@ -76,7 +76,7 @@ const Typeahead = _ref => {
|
|
|
76
76
|
ref: typeaheadRef,
|
|
77
77
|
onClickCapture: cancelNext
|
|
78
78
|
}, /*#__PURE__*/React.createElement(_SearchInput.SearchInput, _extends({}, inputProps, {
|
|
79
|
-
boxRef:
|
|
79
|
+
boxRef: refs.setReference,
|
|
80
80
|
size: size,
|
|
81
81
|
placeholder: placeholder,
|
|
82
82
|
value: typeaheadInputText,
|
|
@@ -105,7 +105,7 @@ const Typeahead = _ref => {
|
|
|
105
105
|
}
|
|
106
106
|
})), isOpen && !isLoading && menu && filteredOptions && !!filteredOptions.length && /*#__PURE__*/React.createElement("div", {
|
|
107
107
|
onClickCapture: cancelNext,
|
|
108
|
-
ref:
|
|
108
|
+
ref: refs.setFloating,
|
|
109
109
|
style: {
|
|
110
110
|
position: strategy,
|
|
111
111
|
top: y ?? _space.spaceNone,
|
|
@@ -121,7 +121,8 @@ const Typeahead = _ref => {
|
|
|
121
121
|
clickAway();
|
|
122
122
|
}
|
|
123
123
|
},
|
|
124
|
-
size: menu.size || size
|
|
124
|
+
size: menu.size || size,
|
|
125
|
+
onTabOut: clickAway
|
|
125
126
|
}))));
|
|
126
127
|
});
|
|
127
128
|
};
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
offset,
|
|
11
11
|
// $FlowFixMe[untyped-import]
|
|
12
12
|
useFloating,
|
|
13
|
-
} from '@floating-ui/react
|
|
13
|
+
} from '@floating-ui/react';
|
|
14
14
|
|
|
15
15
|
import {colorBackgroundTertiary} from '../../styles/variables/_color';
|
|
16
16
|
import {sizeFluid} from '../../styles/variables/_size';
|
|
@@ -60,7 +60,8 @@ export const Typeahead = ({
|
|
|
60
60
|
const typeaheadRef = React.useRef();
|
|
61
61
|
const [filteredOptions, setFilteredOptions] = React.useState(menu?.options);
|
|
62
62
|
|
|
63
|
-
const {x, y,
|
|
63
|
+
const {x, y, refs, strategy} = useFloating({
|
|
64
|
+
open: true,
|
|
64
65
|
strategy: 'absolute',
|
|
65
66
|
placement: 'bottom-start',
|
|
66
67
|
whileElementsMounted: autoUpdate,
|
|
@@ -99,7 +100,7 @@ export const Typeahead = ({
|
|
|
99
100
|
>
|
|
100
101
|
<SearchInput
|
|
101
102
|
{...inputProps}
|
|
102
|
-
boxRef={
|
|
103
|
+
boxRef={refs.setReference}
|
|
103
104
|
size={size}
|
|
104
105
|
placeholder={placeholder}
|
|
105
106
|
value={typeaheadInputText}
|
|
@@ -132,7 +133,7 @@ export const Typeahead = ({
|
|
|
132
133
|
!!filteredOptions.length && (
|
|
133
134
|
<div
|
|
134
135
|
onClickCapture={cancelNext}
|
|
135
|
-
ref={
|
|
136
|
+
ref={refs.setFloating}
|
|
136
137
|
style={{
|
|
137
138
|
position: strategy,
|
|
138
139
|
top: y ?? spaceNone,
|
|
@@ -154,6 +155,7 @@ export const Typeahead = ({
|
|
|
154
155
|
}
|
|
155
156
|
}}
|
|
156
157
|
size={menu.size || size}
|
|
158
|
+
onTabOut={clickAway}
|
|
157
159
|
/>
|
|
158
160
|
</div>
|
|
159
161
|
)}
|
package/lib/hooks/index.js
CHANGED
|
@@ -3,6 +3,39 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _useCopyToClipboard = require("./useCopyToClipboard");
|
|
7
|
+
Object.keys(_useCopyToClipboard).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _useCopyToClipboard[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _useCopyToClipboard[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _useInputState = require("./useInputState");
|
|
18
|
+
Object.keys(_useInputState).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _useInputState[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _useInputState[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _useLockedBody = require("./useLockedBody");
|
|
29
|
+
Object.keys(_useLockedBody).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _useLockedBody[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _useLockedBody[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
6
39
|
var _useMountTransition = require("./useMountTransition");
|
|
7
40
|
Object.keys(_useMountTransition).forEach(function (key) {
|
|
8
41
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -35,4 +68,26 @@ Object.keys(_useToastPortal).forEach(function (key) {
|
|
|
35
68
|
return _useToastPortal[key];
|
|
36
69
|
}
|
|
37
70
|
});
|
|
71
|
+
});
|
|
72
|
+
var _useToggle = require("./useToggle");
|
|
73
|
+
Object.keys(_useToggle).forEach(function (key) {
|
|
74
|
+
if (key === "default" || key === "__esModule") return;
|
|
75
|
+
if (key in exports && exports[key] === _useToggle[key]) return;
|
|
76
|
+
Object.defineProperty(exports, key, {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function () {
|
|
79
|
+
return _useToggle[key];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
var _useWindowSize = require("./useWindowSize");
|
|
84
|
+
Object.keys(_useWindowSize).forEach(function (key) {
|
|
85
|
+
if (key === "default" || key === "__esModule") return;
|
|
86
|
+
if (key in exports && exports[key] === _useWindowSize[key]) return;
|
|
87
|
+
Object.defineProperty(exports, key, {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function () {
|
|
90
|
+
return _useWindowSize[key];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
38
93
|
});
|
package/lib/hooks/index.js.flow
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
// @flow strict
|
|
2
2
|
|
|
3
|
+
export * from './useCopyToClipboard';
|
|
4
|
+
export * from './useInputState';
|
|
5
|
+
export * from './useLockedBody';
|
|
3
6
|
export * from './useMountTransition';
|
|
4
7
|
export * from './usePagination';
|
|
5
8
|
export * from './useToastPortal';
|
|
9
|
+
export * from './useToggle';
|
|
10
|
+
export * from './useWindowSize';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useCopyToClipboard = useCopyToClipboard;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
|
|
9
|
+
// Return success
|
|
10
|
+
|
|
11
|
+
function useCopyToClipboard() {
|
|
12
|
+
const [copiedText, setCopiedText] = (0, _react.useState)(null);
|
|
13
|
+
const copy = async text => {
|
|
14
|
+
if (!navigator.clipboard) {
|
|
15
|
+
console.warn('Clipboard not supported');
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Try to save to clipboard then save it in the state if worked
|
|
20
|
+
try {
|
|
21
|
+
await navigator.clipboard.writeText(text);
|
|
22
|
+
setCopiedText(text);
|
|
23
|
+
return true;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.warn('Copy failed', error);
|
|
26
|
+
setCopiedText(null);
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
return [copiedText, copy];
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// @flow strict
|
|
2
|
+
|
|
3
|
+
import {useState} from 'react';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
type CopiedValue = string | null;
|
|
7
|
+
type CopyFn = (text: string) => Promise<boolean>; // Return success
|
|
8
|
+
|
|
9
|
+
export function useCopyToClipboard(): [CopiedValue, CopyFn] {
|
|
10
|
+
const [copiedText, setCopiedText] = useState<CopiedValue>(null);
|
|
11
|
+
|
|
12
|
+
const copy: CopyFn = async (text) => {
|
|
13
|
+
if (!navigator.clipboard) {
|
|
14
|
+
console.warn('Clipboard not supported');
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Try to save to clipboard then save it in the state if worked
|
|
19
|
+
try {
|
|
20
|
+
await navigator.clipboard.writeText(text);
|
|
21
|
+
setCopiedText(text);
|
|
22
|
+
return true;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
console.warn('Copy failed', error);
|
|
25
|
+
setCopiedText(null);
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
return [copiedText, copy];
|
|
31
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useInputState = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Simple Hook to use with input tag. The primary purpose is an abstraction over input onChange property.
|
|
11
|
+
* () => {
|
|
12
|
+
* const [value, onChange] = useInputState("");
|
|
13
|
+
*
|
|
14
|
+
* return <Input type="text" value={value} onChange={onChange} />;
|
|
15
|
+
* }
|
|
16
|
+
*/
|
|
17
|
+
const useInputState = function () {
|
|
18
|
+
let initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
19
|
+
const [state, setState] = (0, _react.useState)(initialState);
|
|
20
|
+
const setInputState = (0, _react.useCallback)(event => setState(event && event.target.value), []);
|
|
21
|
+
return [state, setInputState];
|
|
22
|
+
};
|
|
23
|
+
exports.useInputState = useInputState;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// @flow strict
|
|
2
|
+
|
|
3
|
+
import {useCallback, useState} from 'react';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
type ReturnType = [
|
|
7
|
+
string,
|
|
8
|
+
(event: SyntheticInputEvent<HTMLInputElement>) => void,
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Simple Hook to use with input tag. The primary purpose is an abstraction over input onChange property.
|
|
13
|
+
* () => {
|
|
14
|
+
* const [value, onChange] = useInputState("");
|
|
15
|
+
*
|
|
16
|
+
* return <Input type="text" value={value} onChange={onChange} />;
|
|
17
|
+
* }
|
|
18
|
+
*/
|
|
19
|
+
export const useInputState = (initialState: string = ''): ReturnType => {
|
|
20
|
+
const [state, setState] = useState(initialState);
|
|
21
|
+
|
|
22
|
+
const setInputState = useCallback(
|
|
23
|
+
(event) => setState(event && event.target.value),
|
|
24
|
+
[],
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
return [state, setInputState];
|
|
28
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useLockedBody = useLockedBody;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
|
|
9
|
+
function useLockedBody() {
|
|
10
|
+
let initialLocked = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
11
|
+
const [locked, setLocked] = (0, _react.useState)(initialLocked);
|
|
12
|
+
|
|
13
|
+
// Do the side effect before render
|
|
14
|
+
(0, _react.useLayoutEffect)(() => {
|
|
15
|
+
if (!locked) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Save initial body style
|
|
20
|
+
const originalOverflow = document.body?.style.overflow || '';
|
|
21
|
+
const originalPaddingRight = document.body?.style.paddingRight || '';
|
|
22
|
+
|
|
23
|
+
// Lock body scroll
|
|
24
|
+
if (document.body) {
|
|
25
|
+
document.body.style.overflow = 'hidden';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Get the scrollBar width
|
|
29
|
+
// TODO(Nishant): Fetch the scrollBar width from the browser
|
|
30
|
+
const scrollBarWidth = 0;
|
|
31
|
+
|
|
32
|
+
// Avoid width reflow
|
|
33
|
+
if (!!scrollBarWidth && document.body) {
|
|
34
|
+
document.body.style.paddingRight = `${scrollBarWidth}px`;
|
|
35
|
+
}
|
|
36
|
+
return () => {
|
|
37
|
+
if (document.body) {
|
|
38
|
+
document.body.style.overflow = originalOverflow;
|
|
39
|
+
}
|
|
40
|
+
if (!!scrollBarWidth && document.body) {
|
|
41
|
+
document.body.style.paddingRight = originalPaddingRight;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}, [locked]);
|
|
45
|
+
|
|
46
|
+
// Update state if initialValue changes
|
|
47
|
+
(0, _react.useEffect)(() => {
|
|
48
|
+
if (locked !== initialLocked) {
|
|
49
|
+
setLocked(initialLocked);
|
|
50
|
+
}
|
|
51
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
52
|
+
}, [initialLocked]);
|
|
53
|
+
return [locked, setLocked];
|
|
54
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// @flow strict
|
|
2
|
+
|
|
3
|
+
import {useEffect, useLayoutEffect, useState} from 'react';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
type ReturnType = [boolean, (locked: boolean) => void];
|
|
7
|
+
|
|
8
|
+
export function useLockedBody(initialLocked: boolean = false): ReturnType {
|
|
9
|
+
const [locked, setLocked] = useState(initialLocked);
|
|
10
|
+
|
|
11
|
+
// Do the side effect before render
|
|
12
|
+
useLayoutEffect(() => {
|
|
13
|
+
if (!locked) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Save initial body style
|
|
18
|
+
const originalOverflow = document.body?.style.overflow || '';
|
|
19
|
+
const originalPaddingRight = document.body?.style.paddingRight || '';
|
|
20
|
+
|
|
21
|
+
// Lock body scroll
|
|
22
|
+
if (document.body) {
|
|
23
|
+
document.body.style.overflow = 'hidden';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Get the scrollBar width
|
|
27
|
+
// TODO(Nishant): Fetch the scrollBar width from the browser
|
|
28
|
+
const scrollBarWidth = 0;
|
|
29
|
+
|
|
30
|
+
// Avoid width reflow
|
|
31
|
+
if (!!scrollBarWidth && document.body) {
|
|
32
|
+
document.body.style.paddingRight = `${scrollBarWidth}px`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return () => {
|
|
36
|
+
if (document.body) {
|
|
37
|
+
document.body.style.overflow = originalOverflow;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!!scrollBarWidth && document.body) {
|
|
41
|
+
document.body.style.paddingRight = originalPaddingRight;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}, [locked]);
|
|
45
|
+
|
|
46
|
+
// Update state if initialValue changes
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (locked !== initialLocked) {
|
|
49
|
+
setLocked(initialLocked);
|
|
50
|
+
}
|
|
51
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
52
|
+
}, [initialLocked]);
|
|
53
|
+
|
|
54
|
+
return [locked, setLocked];
|
|
55
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useToggle = useToggle;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
|
|
9
|
+
function useToggle() {
|
|
10
|
+
let initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
11
|
+
// Initialize the state
|
|
12
|
+
const [stateValue, setStateValue] = (0, _react.useState)(initialState);
|
|
13
|
+
|
|
14
|
+
// Define and memorize toggle function in case we pass down the component,
|
|
15
|
+
// This function change the boolean value to it's opposite value
|
|
16
|
+
const toggle = (0, _react.useCallback)(() => setStateValue(state => !state), []);
|
|
17
|
+
return [stateValue, toggle];
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// @flow strict
|
|
2
|
+
|
|
3
|
+
import {useCallback, useState} from 'react';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export function useToggle(
|
|
7
|
+
initialState: boolean = false,
|
|
8
|
+
): [boolean, (newValue: boolean) => void] {
|
|
9
|
+
// Initialize the state
|
|
10
|
+
const [stateValue, setStateValue] = useState(initialState);
|
|
11
|
+
|
|
12
|
+
// Define and memorize toggle function in case we pass down the component,
|
|
13
|
+
// This function change the boolean value to it's opposite value
|
|
14
|
+
const toggle = useCallback(() => setStateValue((state) => !state), []);
|
|
15
|
+
|
|
16
|
+
return [stateValue, toggle];
|
|
17
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useWindowSize = useWindowSize;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
|
|
9
|
+
function useWindowSize() {
|
|
10
|
+
const [windowSize, setWindowSize] = (0, _react.useState)({
|
|
11
|
+
width: 0,
|
|
12
|
+
height: 0
|
|
13
|
+
});
|
|
14
|
+
(0, _react.useEffect)(() => {
|
|
15
|
+
const handler = () => {
|
|
16
|
+
setWindowSize({
|
|
17
|
+
width: window.innerWidth,
|
|
18
|
+
height: window.innerHeight
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Set size at the first client-side load
|
|
23
|
+
handler();
|
|
24
|
+
window.addEventListener('resize', handler);
|
|
25
|
+
|
|
26
|
+
// Remove event listener on cleanup
|
|
27
|
+
return () => {
|
|
28
|
+
window.removeEventListener('resize', handler);
|
|
29
|
+
};
|
|
30
|
+
}, []);
|
|
31
|
+
return windowSize;
|
|
32
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// @flow strict
|
|
2
|
+
|
|
3
|
+
import {useEffect, useState} from 'react';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
type WindowSize = {
|
|
7
|
+
width: number,
|
|
8
|
+
height: number,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function useWindowSize(): WindowSize {
|
|
12
|
+
const [windowSize, setWindowSize] = useState<WindowSize>({
|
|
13
|
+
width: 0,
|
|
14
|
+
height: 0,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const handler = () => {
|
|
19
|
+
setWindowSize({
|
|
20
|
+
width: window.innerWidth,
|
|
21
|
+
height: window.innerHeight,
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// Set size at the first client-side load
|
|
26
|
+
handler();
|
|
27
|
+
|
|
28
|
+
window.addEventListener('resize', handler);
|
|
29
|
+
|
|
30
|
+
// Remove event listener on cleanup
|
|
31
|
+
return () => {
|
|
32
|
+
window.removeEventListener('resize', handler);
|
|
33
|
+
};
|
|
34
|
+
}, []);
|
|
35
|
+
|
|
36
|
+
return windowSize;
|
|
37
|
+
}
|
package/lib/types/common.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/lib/utils/index.js
CHANGED
|
@@ -90,4 +90,15 @@ Object.keys(_string).forEach(function (key) {
|
|
|
90
90
|
return _string[key];
|
|
91
91
|
}
|
|
92
92
|
});
|
|
93
|
+
});
|
|
94
|
+
var _tokens = require("./tokens");
|
|
95
|
+
Object.keys(_tokens).forEach(function (key) {
|
|
96
|
+
if (key === "default" || key === "__esModule") return;
|
|
97
|
+
if (key in exports && exports[key] === _tokens[key]) return;
|
|
98
|
+
Object.defineProperty(exports, key, {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function () {
|
|
101
|
+
return _tokens[key];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
93
104
|
});
|
package/lib/utils/index.js.flow
CHANGED