@spaced-out/ui-design-system 0.3.46 → 0.3.47-beta.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/lib/components/AvatarGroup/AvatarGroup.js.flow +2 -2
  3. package/lib/components/ButtonDropdown/ButtonDropdown.js +22 -10
  4. package/lib/components/ButtonDropdown/ButtonDropdown.js.flow +58 -33
  5. package/lib/components/ButtonDropdown/ButtonDropdown.module.css +8 -1
  6. package/lib/components/ButtonDropdown/SimpleButtonDropdown.js +3 -0
  7. package/lib/components/ButtonDropdown/SimpleButtonDropdown.js.flow +6 -1
  8. package/lib/components/ButtonTabs/ButtonTabDropdown.js +13 -6
  9. package/lib/components/ButtonTabs/ButtonTabDropdown.js.flow +40 -24
  10. package/lib/components/ButtonTabs/ButtonTabDropdown.module.css +4 -0
  11. package/lib/components/ButtonTabs/ButtonTabs.js +2 -0
  12. package/lib/components/ButtonTabs/ButtonTabs.js.flow +4 -0
  13. package/lib/components/Dropdown/Dropdown.js +23 -8
  14. package/lib/components/Dropdown/Dropdown.js.flow +57 -32
  15. package/lib/components/Dropdown/Dropdown.module.css +5 -0
  16. package/lib/components/Dropdown/SimpleDropdown.js +2 -0
  17. package/lib/components/Dropdown/SimpleDropdown.js.flow +4 -0
  18. package/lib/components/InlineDropdown/InlineDropdown.js +25 -8
  19. package/lib/components/InlineDropdown/InlineDropdown.js.flow +57 -30
  20. package/lib/components/InlineDropdown/InlineDropdown.module.css +5 -0
  21. package/lib/components/InlineDropdown/SimpleInlineDropdown.js +2 -0
  22. package/lib/components/InlineDropdown/SimpleInlineDropdown.js.flow +4 -0
  23. package/lib/components/Table/StaticTable.js +1 -1
  24. package/lib/components/Table/StaticTable.js.flow +1 -1
  25. package/lib/components/Table/Table.docs.js +1 -1
  26. package/lib/components/Table/Table.docs.js.flow +1 -1
  27. package/lib/components/Tabs/TabList/TabDropdown.js +14 -7
  28. package/lib/components/Tabs/TabList/TabDropdown.js.flow +38 -22
  29. package/lib/components/Tabs/TabList/TabDropdown.module.css +4 -0
  30. package/lib/components/Tabs/TabList/TabList.js +4 -2
  31. package/lib/components/Tabs/TabList/TabList.js.flow +4 -0
  32. package/lib/components/TokenListInput/TokenListInput.js +26 -7
  33. package/lib/components/TokenListInput/TokenListInput.js.flow +58 -32
  34. package/lib/components/TokenListInput/TokenListInput.module.css +5 -0
  35. package/lib/components/Tooltip/Tooltip.js +2 -1
  36. package/lib/components/Tooltip/Tooltip.js.flow +2 -2
  37. package/lib/components/Typeahead/SimpleTypeahead.js +3 -1
  38. package/lib/components/Typeahead/SimpleTypeahead.js.flow +4 -0
  39. package/lib/components/Typeahead/Typeahead.js +25 -8
  40. package/lib/components/Typeahead/Typeahead.js.flow +58 -30
  41. package/lib/components/Typeahead/Typeahead.module.css +5 -0
  42. package/lib/hooks/index.js +11 -0
  43. package/lib/hooks/index.js.flow +1 -0
  44. package/lib/hooks/useReferenceElementWidth/index.js +16 -0
  45. package/lib/hooks/useReferenceElementWidth/index.js.flow +3 -0
  46. package/lib/hooks/useReferenceElementWidth/useReferenceElementWidth.js +21 -0
  47. package/lib/hooks/useReferenceElementWidth/useReferenceElementWidth.js.flow +23 -0
  48. package/package.json +1 -1
@@ -7,12 +7,16 @@ import {
7
7
  // $FlowFixMe[untyped-import]
8
8
  flip,
9
9
  // $FlowFixMe[untyped-import]
10
+ FloatingFocusManager,
11
+ // $FlowFixMe[untyped-import]
12
+ FloatingPortal,
13
+ // $FlowFixMe[untyped-import]
10
14
  offset,
11
15
  // $FlowFixMe[untyped-import]
12
16
  useFloating,
13
17
  } from '@floating-ui/react';
14
18
 
15
- import {sizeFluid} from '../../styles/variables/_size';
19
+ import {useReferenceElementWidth} from '../../hooks';
16
20
  import {spaceNone, spaceXXSmall} from '../../styles/variables/_space';
17
21
  import {classify} from '../../utils/classify';
18
22
  import {type ClickAwayRefType, ClickAway} from '../../utils/click-away';
@@ -21,6 +25,8 @@ import type {InputProps} from '../Input';
21
25
  import type {MenuOption, MenuProps} from '../Menu';
22
26
  import {Menu} from '../Menu';
23
27
  import {SearchInput} from '../SearchInput';
28
+ import type {ElevationType} from '../Tooltip';
29
+ import {getElevationValue} from '../Tooltip';
24
30
 
25
31
  import css from './Typeahead.module.css';
26
32
 
@@ -40,6 +46,7 @@ type BaseTypeaheadProps = {
40
46
  isLoading?: boolean,
41
47
  menuOpenOffset?: number,
42
48
  clickAwayRef?: ClickAwayRefType,
49
+ elevation?: ElevationType,
43
50
  ...
44
51
  };
45
52
 
@@ -69,12 +76,14 @@ const BaseTypeahead: React$AbstractComponent<
69
76
  menuOpenOffset = 1,
70
77
  onFocus,
71
78
  clickAwayRef,
79
+ elevation = 'modal',
72
80
  ...inputProps
73
81
  }: BaseTypeaheadProps,
74
82
  ref,
75
83
  ): React.Node => {
76
84
  const menuOptions = menu?.options;
77
- const {x, y, refs, strategy} = useFloating({
85
+
86
+ const {x, y, refs, strategy, context} = useFloating({
78
87
  open: true,
79
88
  strategy: 'absolute',
80
89
  placement: 'bottom-start',
@@ -82,6 +91,8 @@ const BaseTypeahead: React$AbstractComponent<
82
91
  middleware: [flip(), offset(parseInt(spaceXXSmall))],
83
92
  });
84
93
 
94
+ const dropdownWidth = useReferenceElementWidth(refs.reference?.current);
95
+
85
96
  const onMenuToggle = (isOpen: boolean) => {
86
97
  isOpen ? onMenuOpen && onMenuOpen() : onMenuClose && onMenuClose();
87
98
  };
@@ -92,7 +103,6 @@ const BaseTypeahead: React$AbstractComponent<
92
103
  <div
93
104
  data-testid="Typeahead"
94
105
  className={classify(css.typeaheadContainer, classNames?.wrapper)}
95
- ref={boundaryRef}
96
106
  >
97
107
  <SearchInput
98
108
  {...inputProps}
@@ -129,33 +139,51 @@ const BaseTypeahead: React$AbstractComponent<
129
139
  menu &&
130
140
  menuOptions &&
131
141
  !!menuOptions.length && (
132
- <div
133
- ref={refs.setFloating}
134
- style={{
135
- position: strategy,
136
- top: y ?? spaceNone,
137
- left: x ?? spaceNone,
138
- width: sizeFluid,
139
- }}
140
- >
141
- <Menu
142
- {...menu}
143
- options={menuOptions}
144
- onSelect={(option, e) => {
145
- onSelect && onSelect(option, e);
146
- if (
147
- // option.keepMenuOpenOnOptionSelect - to allow the menu persist its open stat upon option selection in normal variant
148
- !option.keepMenuOpenOnOptionSelect &&
149
- (!menu.optionsVariant ||
150
- menu.optionsVariant === 'normal')
151
- ) {
152
- clickAway();
153
- }
154
- }}
155
- size={menu.size || size}
156
- onTabOut={clickAway}
157
- />
158
- </div>
142
+ <FloatingPortal>
143
+ <FloatingFocusManager
144
+ modal={false}
145
+ context={context}
146
+ returnFocus={false}
147
+ initialFocus={refs.reference}
148
+ >
149
+ <div
150
+ ref={mergeRefs([refs.setFloating, boundaryRef])}
151
+ className={css.menuWrapper}
152
+ style={{
153
+ position: strategy,
154
+ top: y ?? spaceNone,
155
+ left: x ?? spaceNone,
156
+ /* NOTE(Sharad): The FloatingPortal renders the menu outside the normal DOM structure,
157
+ so its parent is effectively the <body> element. This means the menu
158
+ would otherwise default to the body's width. To support fluid width,
159
+ we must manually set the dropdown width here; otherwise, it uses a fixed width.
160
+ Also, Only treat menu as non-fluid if isFluid is strictly false, since default is true in menu and undefined means fluid. */
161
+ ...(menu.isFluid !== false && {
162
+ '--dropdown-width': dropdownWidth,
163
+ }),
164
+ '--menu-elevation': getElevationValue(elevation),
165
+ }}
166
+ >
167
+ <Menu
168
+ {...menu}
169
+ options={menuOptions}
170
+ onSelect={(option, e) => {
171
+ onSelect && onSelect(option, e);
172
+ if (
173
+ // option.keepMenuOpenOnOptionSelect - to allow the menu persist its open stat upon option selection in normal variant
174
+ !option.keepMenuOpenOnOptionSelect &&
175
+ (!menu.optionsVariant ||
176
+ menu.optionsVariant === 'normal')
177
+ ) {
178
+ clickAway();
179
+ }
180
+ }}
181
+ size={menu.size || size}
182
+ onTabOut={clickAway}
183
+ />
184
+ </div>
185
+ </FloatingFocusManager>
186
+ </FloatingPortal>
159
187
  )}
160
188
  </div>
161
189
  )}
@@ -9,3 +9,8 @@
9
9
  width: sizeFluid;
10
10
  height: fit-content;
11
11
  }
12
+
13
+ .menuWrapper {
14
+ width: var(--dropdown-width);
15
+ z-index: var(--menu-elevation);
16
+ }
@@ -124,6 +124,17 @@ Object.keys(_usePagination).forEach(function (key) {
124
124
  }
125
125
  });
126
126
  });
127
+ var _useReferenceElementWidth = require("./useReferenceElementWidth");
128
+ Object.keys(_useReferenceElementWidth).forEach(function (key) {
129
+ if (key === "default" || key === "__esModule") return;
130
+ if (key in exports && exports[key] === _useReferenceElementWidth[key]) return;
131
+ Object.defineProperty(exports, key, {
132
+ enumerable: true,
133
+ get: function () {
134
+ return _useReferenceElementWidth[key];
135
+ }
136
+ });
137
+ });
127
138
  var _useResizeObserver = require("./useResizeObserver");
128
139
  Object.keys(_useResizeObserver).forEach(function (key) {
129
140
  if (key === "default" || key === "__esModule") return;
@@ -11,6 +11,7 @@ export * from './useLockedBody';
11
11
  export * from './useModal';
12
12
  export * from './useMountTransition';
13
13
  export * from './usePagination';
14
+ export * from './useReferenceElementWidth';
14
15
  export * from './useResizeObserver';
15
16
  export * from './useToastPortal';
16
17
  export * from './useToggle';
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _useReferenceElementWidth = require("./useReferenceElementWidth");
7
+ Object.keys(_useReferenceElementWidth).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _useReferenceElementWidth[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _useReferenceElementWidth[key];
14
+ }
15
+ });
16
+ });
@@ -0,0 +1,3 @@
1
+ // @flow strict
2
+
3
+ export * from './useReferenceElementWidth';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useReferenceElementWidth = useReferenceElementWidth;
7
+ var React = _interopRequireWildcard(require("react"));
8
+ var _size = require("../../styles/variables/_size");
9
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
10
+ const MIN_FLUID_WIDTH = 160;
11
+ function useReferenceElementWidth(ref) {
12
+ let minWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : MIN_FLUID_WIDTH;
13
+ const [width, setWidth] = React.useState(_size.sizeFluid);
14
+ const refWidth = ref?.offsetWidth;
15
+ React.useLayoutEffect(() => {
16
+ if (refWidth) {
17
+ setWidth(Math.max(refWidth, minWidth) + 'px');
18
+ }
19
+ }, [refWidth, minWidth]);
20
+ return width;
21
+ }
@@ -0,0 +1,23 @@
1
+ // @flow strict
2
+ import * as React from 'react';
3
+
4
+ import {sizeFluid} from '../../styles/variables/_size';
5
+
6
+
7
+ const MIN_FLUID_WIDTH = 160;
8
+
9
+ export function useReferenceElementWidth(
10
+ ref: ?HTMLElement,
11
+ minWidth: number = MIN_FLUID_WIDTH,
12
+ ): string {
13
+ const [width, setWidth] = React.useState(sizeFluid);
14
+
15
+ const refWidth = ref?.offsetWidth;
16
+ React.useLayoutEffect(() => {
17
+ if (refWidth) {
18
+ setWidth(Math.max(refWidth, minWidth) + 'px');
19
+ }
20
+ }, [refWidth, minWidth]);
21
+
22
+ return width;
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spaced-out/ui-design-system",
3
- "version": "0.3.46",
3
+ "version": "0.3.47-beta.0",
4
4
  "main": "index.js",
5
5
  "description": "Sense UI components library",
6
6
  "author": {