@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.
- package/CHANGELOG.md +7 -0
- package/lib/components/AvatarGroup/AvatarGroup.js.flow +2 -2
- package/lib/components/ButtonDropdown/ButtonDropdown.js +22 -10
- package/lib/components/ButtonDropdown/ButtonDropdown.js.flow +58 -33
- package/lib/components/ButtonDropdown/ButtonDropdown.module.css +8 -1
- package/lib/components/ButtonDropdown/SimpleButtonDropdown.js +3 -0
- package/lib/components/ButtonDropdown/SimpleButtonDropdown.js.flow +6 -1
- package/lib/components/ButtonTabs/ButtonTabDropdown.js +13 -6
- package/lib/components/ButtonTabs/ButtonTabDropdown.js.flow +40 -24
- package/lib/components/ButtonTabs/ButtonTabDropdown.module.css +4 -0
- package/lib/components/ButtonTabs/ButtonTabs.js +2 -0
- package/lib/components/ButtonTabs/ButtonTabs.js.flow +4 -0
- package/lib/components/Dropdown/Dropdown.js +23 -8
- package/lib/components/Dropdown/Dropdown.js.flow +57 -32
- package/lib/components/Dropdown/Dropdown.module.css +5 -0
- package/lib/components/Dropdown/SimpleDropdown.js +2 -0
- package/lib/components/Dropdown/SimpleDropdown.js.flow +4 -0
- package/lib/components/InlineDropdown/InlineDropdown.js +25 -8
- package/lib/components/InlineDropdown/InlineDropdown.js.flow +57 -30
- package/lib/components/InlineDropdown/InlineDropdown.module.css +5 -0
- package/lib/components/InlineDropdown/SimpleInlineDropdown.js +2 -0
- package/lib/components/InlineDropdown/SimpleInlineDropdown.js.flow +4 -0
- package/lib/components/Table/StaticTable.js +1 -1
- package/lib/components/Table/StaticTable.js.flow +1 -1
- package/lib/components/Table/Table.docs.js +1 -1
- package/lib/components/Table/Table.docs.js.flow +1 -1
- package/lib/components/Tabs/TabList/TabDropdown.js +14 -7
- package/lib/components/Tabs/TabList/TabDropdown.js.flow +38 -22
- package/lib/components/Tabs/TabList/TabDropdown.module.css +4 -0
- package/lib/components/Tabs/TabList/TabList.js +4 -2
- package/lib/components/Tabs/TabList/TabList.js.flow +4 -0
- package/lib/components/TokenListInput/TokenListInput.js +26 -7
- package/lib/components/TokenListInput/TokenListInput.js.flow +58 -32
- package/lib/components/TokenListInput/TokenListInput.module.css +5 -0
- package/lib/components/Tooltip/Tooltip.js +2 -1
- package/lib/components/Tooltip/Tooltip.js.flow +2 -2
- package/lib/components/Typeahead/SimpleTypeahead.js +3 -1
- package/lib/components/Typeahead/SimpleTypeahead.js.flow +4 -0
- package/lib/components/Typeahead/Typeahead.js +25 -8
- package/lib/components/Typeahead/Typeahead.js.flow +58 -30
- package/lib/components/Typeahead/Typeahead.module.css +5 -0
- package/lib/hooks/index.js +11 -0
- package/lib/hooks/index.js.flow +1 -0
- package/lib/hooks/useReferenceElementWidth/index.js +16 -0
- package/lib/hooks/useReferenceElementWidth/index.js.flow +3 -0
- package/lib/hooks/useReferenceElementWidth/useReferenceElementWidth.js +21 -0
- package/lib/hooks/useReferenceElementWidth/useReferenceElementWidth.js.flow +23 -0
- 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 {
|
|
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
|
-
|
|
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
|
-
<
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
)}
|
package/lib/hooks/index.js
CHANGED
|
@@ -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;
|
package/lib/hooks/index.js.flow
CHANGED
|
@@ -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,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
|
+
}
|