@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.
Files changed (70) hide show
  1. package/.cspell/custom-words.txt +3 -0
  2. package/.storybook/main.js +40 -28
  3. package/.storybook/manager.js +0 -4
  4. package/.storybook/preview-head.html +15 -6
  5. package/.storybook/preview.js +0 -5
  6. package/CHANGELOG.md +22 -0
  7. package/babel.config.js +1 -0
  8. package/lib/components/Badge/Badge.module.css +1 -0
  9. package/lib/components/ButtonDropdown/ButtonDropdown.js +10 -9
  10. package/lib/components/ButtonDropdown/ButtonDropdown.js.flow +6 -4
  11. package/lib/components/Chip/Chip.js +1 -1
  12. package/lib/components/Chip/Chip.js.flow +2 -2
  13. package/lib/components/CollapsibleCard/CollapsibleCard.js +3 -0
  14. package/lib/components/CollapsibleCard/CollapsibleCard.js.flow +4 -0
  15. package/lib/components/Dialog/Dialog.js +23 -2
  16. package/lib/components/Dialog/Dialog.js.flow +38 -0
  17. package/lib/components/Dropdown/Dropdown.js +10 -9
  18. package/lib/components/Dropdown/Dropdown.js.flow +6 -4
  19. package/lib/components/FocusManager/FocusManager.js +7 -5
  20. package/lib/components/FocusManager/FocusManager.js.flow +3 -3
  21. package/lib/components/InlineDropdown/InlineDropdown.js +10 -9
  22. package/lib/components/InlineDropdown/InlineDropdown.js.flow +6 -4
  23. package/lib/components/Menu/Menu.js +48 -12
  24. package/lib/components/Menu/Menu.js.flow +102 -9
  25. package/lib/components/Menu/Menu.module.css +10 -0
  26. package/lib/components/Menu/MenuOptionButton.js +21 -4
  27. package/lib/components/Menu/MenuOptionButton.js.flow +21 -0
  28. package/lib/components/Modal/Modal.js +35 -8
  29. package/lib/components/Modal/Modal.js.flow +52 -7
  30. package/lib/components/Modal/Modal.module.css +1 -3
  31. package/lib/components/Panel/Panel.js +21 -1
  32. package/lib/components/Panel/Panel.js.flow +30 -1
  33. package/lib/components/Panel/Panel.module.css +0 -1
  34. package/lib/components/Table/DefaultRow.js +5 -5
  35. package/lib/components/Table/DefaultRow.js.flow +14 -11
  36. package/lib/components/Table/StaticTable.js +5 -1
  37. package/lib/components/Table/StaticTable.js.flow +4 -0
  38. package/lib/components/Table/Table.js.flow +2 -0
  39. package/lib/components/Tabs/TabList/TabDropdown.js +10 -9
  40. package/lib/components/Tabs/TabList/TabDropdown.js.flow +6 -4
  41. package/lib/components/Toast/Toast.js +7 -5
  42. package/lib/components/Toast/Toast.js.flow +5 -3
  43. package/lib/components/Tooltip/Tooltip.js +22 -25
  44. package/lib/components/Tooltip/Tooltip.js.flow +25 -22
  45. package/lib/components/Typeahead/Typeahead.js +10 -9
  46. package/lib/components/Typeahead/Typeahead.js.flow +6 -4
  47. package/lib/hooks/index.js +55 -0
  48. package/lib/hooks/index.js.flow +5 -0
  49. package/lib/hooks/useCopyToClipboard.js +31 -0
  50. package/lib/hooks/useCopyToClipboard.js.flow +31 -0
  51. package/lib/hooks/useInputState.js +23 -0
  52. package/lib/hooks/useInputState.js.flow +28 -0
  53. package/lib/hooks/useLockedBody.js +54 -0
  54. package/lib/hooks/useLockedBody.js.flow +55 -0
  55. package/lib/hooks/useToggle.js +18 -0
  56. package/lib/hooks/useToggle.js.flow +17 -0
  57. package/lib/hooks/useWindowSize.js +32 -0
  58. package/lib/hooks/useWindowSize.js.flow +37 -0
  59. package/lib/styles/typography.module.css +1 -0
  60. package/lib/types/common.js +0 -1
  61. package/lib/utils/index.js +11 -0
  62. package/lib/utils/index.js.flow +1 -0
  63. package/lib/utils/menu.js +57 -2
  64. package/lib/utils/menu.js.flow +109 -1
  65. package/lib/utils/string.js +4 -2
  66. package/lib/utils/string.js.flow +3 -0
  67. package/lib/utils/tokens.js +74 -0
  68. package/lib/utils/tokens.js.flow +82 -0
  69. package/package.json +18 -16
  70. 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-dom-interactions';
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 {spaceNone, spaceXXSmall} from '../../styles/variables/_space';
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 bodyRef = React.useRef(document.querySelector('body'));
97
- const [open, setOpen] = React.useState(false);
98
- const {x, y, reference, floating, strategy, context} = useFloating({
97
+ const [isOpen, setIsOpen] = React.useState(false);
98
+ const {refs, floatingStyles, context, strategy} = useFloating({
99
+ open: isOpen,
100
+ onOpenChange: setIsOpen,
99
101
  placement,
100
- open,
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 = React.useMemo(
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
- {open &&
141
- createPortal(
144
+ <FloatingPortal>
145
+ {isOpen && (
142
146
  <>
143
147
  {!hidden && (
144
148
  <div
145
- ref={floating}
149
+ ref={refs.setFloating}
146
150
  className={classify(css.tooltip, classNames?.tooltip)}
147
151
  style={{
148
152
  position: strategy,
149
- top: y ?? spaceNone,
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 _reactDom = require("@floating-ui/react-dom");
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
- reference,
43
- floating,
42
+ refs,
44
43
  strategy
45
- } = (0, _reactDom.useFloating)({
44
+ } = (0, _react2.useFloating)({
45
+ open: true,
46
46
  strategy: 'absolute',
47
47
  placement: 'bottom-start',
48
- whileElementsMounted: _reactDom.autoUpdate,
49
- middleware: [(0, _reactDom.flip)(), (0, _reactDom.offset)(parseInt(_space.spaceXXSmall))]
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: reference,
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: floating,
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-dom';
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, reference, floating, strategy} = useFloating({
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={reference}
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={floating}
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
  )}
@@ -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
  });
@@ -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
+ }
@@ -253,6 +253,7 @@
253
253
  .link {
254
254
  border-radius: calc(borderRadiusXSmall / 2);
255
255
  cursor: pointer;
256
+ width: fit-content;
256
257
  }
257
258
 
258
259
  .underline {
@@ -1 +0,0 @@
1
- "use strict";
@@ -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
  });
@@ -8,3 +8,4 @@ export * from './makeClassNameComponent';
8
8
  export * from './menu';
9
9
  export * from './merge-refs';
10
10
  export * from './string';
11
+ export * from './tokens';