@sproutsocial/seeds-react-menu 0.3.0 → 0.4.1
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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +33 -0
- package/dist/esm/index.js +234 -80
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +43 -17
- package/dist/index.d.ts +43 -17
- package/dist/index.js +228 -72
- package/dist/index.js.map +1 -1
- package/package.json +12 -10
- package/src/Autocomplete/Autocomplete.feature +14 -43
- package/src/Autocomplete/Autocomplete.stories.tsx +128 -0
- package/src/Autocomplete/Autocomplete.tsx +29 -11
- package/src/Autocomplete/AutocompleteInput.tsx +51 -0
- package/src/Autocomplete/AutocompleteTypes.ts +8 -1
- package/src/Autocomplete/__tests__/Autocomplete.test.tsx +142 -89
- package/src/Autocomplete/__tests__/Autocomplete.typetest.tsx +25 -43
- package/src/Autocomplete/index.ts +1 -0
- package/src/MenuContext.tsx +11 -5
- package/src/MenuGroup/MenuGroup.feature +6 -24
- package/src/MenuGroup/MenuGroup.tsx +12 -1
- package/src/MenuGroup/MenuGroupTypes.ts +4 -1
- package/src/MenuGroup/__tests__/MenuGroup.test.tsx +41 -18
- package/src/MenuGroup/__tests__/MenuGroup.typetest.tsx +4 -2
- package/src/MenuItem/MenuItem.tsx +8 -5
- package/src/MenuLabel.tsx +4 -4
- package/src/MenuRoot/MenuRoot.tsx +5 -3
- package/src/SingleSelectMenu/SingleSelectMenu.tsx +2 -2
- package/src/__fixtures__/menu-test-data.ts +36 -0
- package/src/__tests__/Menu.test.tsx +29 -96
- package/src/hooks/useItemsFromChildren.tsx +70 -27
- package/src/index.ts +1 -0
- package/src/reducers/useComboboxStateReducer.tsx +11 -8
- package/src/storybookUtilities/menu-storybook-components.tsx +39 -0
- package/src/types.ts +1 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -8,14 +8,14 @@ CLI Target: es2022
|
|
|
8
8
|
CLI Cleaning output folder
|
|
9
9
|
CJS Build start
|
|
10
10
|
ESM Build start
|
|
11
|
-
ESM dist/esm/index.js
|
|
12
|
-
ESM dist/esm/index.js.map
|
|
13
|
-
ESM ⚡️ Build success in
|
|
14
|
-
CJS dist/index.js
|
|
15
|
-
CJS dist/index.js.map
|
|
16
|
-
CJS ⚡️ Build success in
|
|
11
|
+
ESM dist/esm/index.js 85.79 KB
|
|
12
|
+
ESM dist/esm/index.js.map 264.83 KB
|
|
13
|
+
ESM ⚡️ Build success in 892ms
|
|
14
|
+
CJS dist/index.js 90.75 KB
|
|
15
|
+
CJS dist/index.js.map 265.73 KB
|
|
16
|
+
CJS ⚡️ Build success in 925ms
|
|
17
17
|
DTS Build start
|
|
18
|
-
DTS ⚡️ Build success in
|
|
19
|
-
DTS dist/index.d.ts
|
|
20
|
-
DTS dist/index.d.mts
|
|
21
|
-
Done in
|
|
18
|
+
DTS ⚡️ Build success in 30662ms
|
|
19
|
+
DTS dist/index.d.ts 17.70 KB
|
|
20
|
+
DTS dist/index.d.mts 17.70 KB
|
|
21
|
+
Done in 38.03s.
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @sproutsocial/seeds-react-menu
|
|
2
2
|
|
|
3
|
+
## 0.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9fd8bac: Update dependencies to use semantic package version instead of wildcards
|
|
8
|
+
- Updated dependencies [9fd8bac]
|
|
9
|
+
- @sproutsocial/seeds-react-system-props@3.0.2
|
|
10
|
+
- @sproutsocial/seeds-react-checkbox@1.3.1
|
|
11
|
+
- @sproutsocial/seeds-react-button@1.2.1
|
|
12
|
+
- @sproutsocial/seeds-react-popout@2.1.1
|
|
13
|
+
- @sproutsocial/seeds-react-switch@1.2.1
|
|
14
|
+
- @sproutsocial/seeds-react-input@1.3.2
|
|
15
|
+
- @sproutsocial/seeds-react-label@1.0.1
|
|
16
|
+
- @sproutsocial/seeds-react-radio@1.2.1
|
|
17
|
+
- @sproutsocial/seeds-react-theme@2.2.1
|
|
18
|
+
- @sproutsocial/seeds-react-icon@1.1.2
|
|
19
|
+
- @sproutsocial/seeds-react-box@1.1.2
|
|
20
|
+
|
|
21
|
+
## 0.4.0
|
|
22
|
+
|
|
23
|
+
### Minor Changes
|
|
24
|
+
|
|
25
|
+
- 1e8337a: Added the Autocomplete and AutocompleteInput components, which can be used to make a text-based, single-select autocomplete form input.
|
|
26
|
+
- cc584e7: Adds items prop to MenuGroup
|
|
27
|
+
- Allows passing an array of `items` to the `MenuGroup` component
|
|
28
|
+
- Updates `TypeMenuGroupProps` to require either `children` or `items`
|
|
29
|
+
- Adds `MenuItemComponent` to `TypeMenuGroupProps` to allow custom rendering of menu items
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- Updated dependencies [1e8337a]
|
|
34
|
+
- @sproutsocial/seeds-react-input@1.3.1
|
|
35
|
+
|
|
3
36
|
## 0.3.0
|
|
4
37
|
|
|
5
38
|
### Minor Changes
|
package/dist/esm/index.js
CHANGED
|
@@ -95,7 +95,7 @@ var require_object_assign = __commonJS({
|
|
|
95
95
|
});
|
|
96
96
|
|
|
97
97
|
// src/MenuItem/MenuItem.tsx
|
|
98
|
-
import
|
|
98
|
+
import "react";
|
|
99
99
|
|
|
100
100
|
// src/MenuContext.tsx
|
|
101
101
|
import {
|
|
@@ -112,15 +112,18 @@ var useMenu = ({
|
|
|
112
112
|
items = [],
|
|
113
113
|
isListbox = false,
|
|
114
114
|
isOpen = false,
|
|
115
|
+
itemsMap: itemsMapFromProps,
|
|
115
116
|
...rest
|
|
116
117
|
} = {}) => {
|
|
117
118
|
const menuProps = useMemo(() => ({ ...rest }), [rest]);
|
|
118
119
|
const itemsMap = useMemo(
|
|
119
|
-
() => items.reduce((map, item) => {
|
|
120
|
-
map[`${item.id}`] =
|
|
120
|
+
() => itemsMapFromProps || items.reduce((map, item) => {
|
|
121
|
+
map[`${item.id}`] = {
|
|
122
|
+
...item
|
|
123
|
+
};
|
|
121
124
|
return map;
|
|
122
125
|
}, {}),
|
|
123
|
-
[items]
|
|
126
|
+
[items, itemsMapFromProps]
|
|
124
127
|
);
|
|
125
128
|
return {
|
|
126
129
|
isOpen,
|
|
@@ -133,9 +136,9 @@ var useMenu = ({
|
|
|
133
136
|
var MenuContext = createContext(defaultMenuContext);
|
|
134
137
|
var MenuProvider = ({
|
|
135
138
|
children,
|
|
136
|
-
|
|
139
|
+
menuProps
|
|
137
140
|
}) => {
|
|
138
|
-
const filterContext = useMenu(
|
|
141
|
+
const filterContext = useMenu(menuProps);
|
|
139
142
|
return /* @__PURE__ */ jsx(MenuContext.Provider, { value: { ...filterContext }, children });
|
|
140
143
|
};
|
|
141
144
|
var useMenuContext = () => {
|
|
@@ -222,8 +225,7 @@ function _isNativeReflectConstruct() {
|
|
|
222
225
|
|
|
223
226
|
// ../../node_modules/@babel/runtime/helpers/esm/construct.js
|
|
224
227
|
function _construct(t, e, r) {
|
|
225
|
-
if (_isNativeReflectConstruct())
|
|
226
|
-
return Reflect.construct.apply(null, arguments);
|
|
228
|
+
if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
|
|
227
229
|
var o = [null];
|
|
228
230
|
o.push.apply(o, e);
|
|
229
231
|
var p = new (t.bind.apply(t, o))();
|
|
@@ -234,14 +236,12 @@ function _construct(t, e, r) {
|
|
|
234
236
|
function _wrapNativeSuper(Class) {
|
|
235
237
|
var _cache = typeof Map === "function" ? /* @__PURE__ */ new Map() : void 0;
|
|
236
238
|
_wrapNativeSuper = function _wrapNativeSuper2(Class2) {
|
|
237
|
-
if (Class2 === null || !_isNativeFunction(Class2))
|
|
238
|
-
return Class2;
|
|
239
|
+
if (Class2 === null || !_isNativeFunction(Class2)) return Class2;
|
|
239
240
|
if (typeof Class2 !== "function") {
|
|
240
241
|
throw new TypeError("Super expression must either be null or a function");
|
|
241
242
|
}
|
|
242
243
|
if (typeof _cache !== "undefined") {
|
|
243
|
-
if (_cache.has(Class2))
|
|
244
|
-
return _cache.get(Class2);
|
|
244
|
+
if (_cache.has(Class2)) return _cache.get(Class2);
|
|
245
245
|
_cache.set(Class2, Wrapper);
|
|
246
246
|
}
|
|
247
247
|
function Wrapper() {
|
|
@@ -564,8 +564,7 @@ var namedColorMap = {
|
|
|
564
564
|
yellowgreen: "9acd32"
|
|
565
565
|
};
|
|
566
566
|
function nameToHex(color2) {
|
|
567
|
-
if (typeof color2 !== "string")
|
|
568
|
-
return color2;
|
|
567
|
+
if (typeof color2 !== "string") return color2;
|
|
569
568
|
var normalizedColorName = color2.toLowerCase();
|
|
570
569
|
return namedColorMap[normalizedColorName] ? "#" + namedColorMap[normalizedColorName] : color2;
|
|
571
570
|
}
|
|
@@ -708,8 +707,7 @@ function guard(lowerBoundary, upperBoundary, value) {
|
|
|
708
707
|
return Math.max(lowerBoundary, Math.min(upperBoundary, value));
|
|
709
708
|
}
|
|
710
709
|
function transparentize(amount, color2) {
|
|
711
|
-
if (color2 === "transparent")
|
|
712
|
-
return color2;
|
|
710
|
+
if (color2 === "transparent") return color2;
|
|
713
711
|
var parsedColor = parseToRgb(color2);
|
|
714
712
|
var alpha = typeof parsedColor.alpha === "number" ? parsedColor.alpha : 1;
|
|
715
713
|
var colorWithAlpha = _extends({}, parsedColor, {
|
|
@@ -719,7 +717,7 @@ function transparentize(amount, color2) {
|
|
|
719
717
|
}
|
|
720
718
|
var curriedTransparentize = /* @__PURE__ */ curry(transparentize);
|
|
721
719
|
|
|
722
|
-
// ../seeds-react-mixins/
|
|
720
|
+
// ../seeds-react-mixins/dist/esm/index.js
|
|
723
721
|
import { css } from "styled-components";
|
|
724
722
|
import { theme } from "@sproutsocial/seeds-react-theme";
|
|
725
723
|
var visuallyHidden = css`
|
|
@@ -759,8 +757,7 @@ var merge = function merge2(a, b) {
|
|
|
759
757
|
var result = (0, import_object_assign.default)({}, a, b);
|
|
760
758
|
for (var key in a) {
|
|
761
759
|
var _assign;
|
|
762
|
-
if (!a[key] || typeof b[key] !== "object")
|
|
763
|
-
continue;
|
|
760
|
+
if (!a[key] || typeof b[key] !== "object") continue;
|
|
764
761
|
(0, import_object_assign.default)(result, (_assign = {}, _assign[key] = (0, import_object_assign.default)(a[key], b[key]), _assign));
|
|
765
762
|
}
|
|
766
763
|
return result;
|
|
@@ -802,8 +799,7 @@ var createParser = function createParser2(config9) {
|
|
|
802
799
|
var shouldSort = false;
|
|
803
800
|
var isCacheDisabled = props.theme && props.theme.disableStyledSystemCache;
|
|
804
801
|
for (var key in props) {
|
|
805
|
-
if (!config9[key])
|
|
806
|
-
continue;
|
|
802
|
+
if (!config9[key]) continue;
|
|
807
803
|
var sx = config9[key];
|
|
808
804
|
var raw = props[key];
|
|
809
805
|
var scale = get(props.theme, sx.scale, sx.defaults);
|
|
@@ -877,8 +873,7 @@ var createStyleFunction = function createStyleFunction2(_ref) {
|
|
|
877
873
|
var sx = function sx2(value, scale2, _props) {
|
|
878
874
|
var result = {};
|
|
879
875
|
var n = transform(value, scale2, _props);
|
|
880
|
-
if (n === null)
|
|
881
|
-
return;
|
|
876
|
+
if (n === null) return;
|
|
882
877
|
properties.forEach(function(prop) {
|
|
883
878
|
result[prop] = n;
|
|
884
879
|
});
|
|
@@ -917,8 +912,7 @@ var compose = function compose2() {
|
|
|
917
912
|
parsers[_key] = arguments[_key];
|
|
918
913
|
}
|
|
919
914
|
parsers.forEach(function(parser2) {
|
|
920
|
-
if (!parser2 || !parser2.config)
|
|
921
|
-
return;
|
|
915
|
+
if (!parser2 || !parser2.config) return;
|
|
922
916
|
(0, import_object_assign.default)(config9, parser2.config);
|
|
923
917
|
});
|
|
924
918
|
var parser = createParser(config9);
|
|
@@ -1514,8 +1508,7 @@ var positiveOrNegative = function positiveOrNegative2(scale, value) {
|
|
|
1514
1508
|
}
|
|
1515
1509
|
var absolute = Math.abs(value);
|
|
1516
1510
|
var n = get3(scale, absolute, absolute);
|
|
1517
|
-
if (typeof n === "string")
|
|
1518
|
-
return "-" + n;
|
|
1511
|
+
if (typeof n === "string") return "-" + n;
|
|
1519
1512
|
return n * -1;
|
|
1520
1513
|
};
|
|
1521
1514
|
var transforms = ["margin", "marginTop", "marginRight", "marginBottom", "marginLeft", "marginX", "marginY", "top", "bottom", "left", "right"].reduce(function(acc, curr) {
|
|
@@ -1531,8 +1524,7 @@ var responsive = function responsive2(styles) {
|
|
|
1531
1524
|
}));
|
|
1532
1525
|
for (var key in styles) {
|
|
1533
1526
|
var value = typeof styles[key] === "function" ? styles[key](theme2) : styles[key];
|
|
1534
|
-
if (value == null)
|
|
1535
|
-
continue;
|
|
1527
|
+
if (value == null) continue;
|
|
1536
1528
|
if (!Array.isArray(value)) {
|
|
1537
1529
|
next[key] = value;
|
|
1538
1530
|
continue;
|
|
@@ -1544,8 +1536,7 @@ var responsive = function responsive2(styles) {
|
|
|
1544
1536
|
continue;
|
|
1545
1537
|
}
|
|
1546
1538
|
next[media] = next[media] || {};
|
|
1547
|
-
if (value[i] == null)
|
|
1548
|
-
continue;
|
|
1539
|
+
if (value[i] == null) continue;
|
|
1549
1540
|
next[media][key] = value[i];
|
|
1550
1541
|
}
|
|
1551
1542
|
}
|
|
@@ -1887,7 +1878,7 @@ var useOptionProps = ({
|
|
|
1887
1878
|
};
|
|
1888
1879
|
|
|
1889
1880
|
// src/MenuItem/MenuItem.tsx
|
|
1890
|
-
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
1881
|
+
import { Fragment, jsx as jsx3 } from "react/jsx-runtime";
|
|
1891
1882
|
var MenuItem = ({
|
|
1892
1883
|
id,
|
|
1893
1884
|
children,
|
|
@@ -1899,15 +1890,15 @@ var MenuItem = ({
|
|
|
1899
1890
|
color: color2,
|
|
1900
1891
|
...props
|
|
1901
1892
|
}) => {
|
|
1902
|
-
const { getItemProps, itemsMap, highlightedIndex, isListbox } =
|
|
1903
|
-
const item = itemsMap[id] || { index: 0, id };
|
|
1893
|
+
const { getItemProps, itemsMap, highlightedIndex, isListbox } = useMenuContext();
|
|
1904
1894
|
const { ...optionProps } = useOptionProps({
|
|
1905
1895
|
id,
|
|
1906
1896
|
children,
|
|
1907
1897
|
...props
|
|
1908
1898
|
});
|
|
1899
|
+
const item = itemsMap[id] || { index: 0, id };
|
|
1909
1900
|
const highlighted = highlightedIndex === item?.index;
|
|
1910
|
-
return /* @__PURE__ */ jsx3(MenuItemContainer, { role: "none", children: /* @__PURE__ */ jsx3(
|
|
1901
|
+
return item.hidden ? /* @__PURE__ */ jsx3(Fragment, {}) : /* @__PURE__ */ jsx3(MenuItemContainer, { role: "none", children: /* @__PURE__ */ jsx3(
|
|
1911
1902
|
StyledMenuItem,
|
|
1912
1903
|
{
|
|
1913
1904
|
id,
|
|
@@ -1998,7 +1989,7 @@ var MenuHeaderFeatures = styled2.div`
|
|
|
1998
1989
|
`;
|
|
1999
1990
|
|
|
2000
1991
|
// src/MenuHeader/MenuHeader.tsx
|
|
2001
|
-
import { Fragment, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
1992
|
+
import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
2002
1993
|
var MenuHeader = ({
|
|
2003
1994
|
children,
|
|
2004
1995
|
title,
|
|
@@ -2006,7 +1997,7 @@ var MenuHeader = ({
|
|
|
2006
1997
|
rightAction,
|
|
2007
1998
|
...rest
|
|
2008
1999
|
}) => {
|
|
2009
|
-
return /* @__PURE__ */ jsx4(
|
|
2000
|
+
return /* @__PURE__ */ jsx4(Fragment2, { children: /* @__PURE__ */ jsxs2(MenuHeaderContainer, { $leftAction: !!leftAction, ...rest, children: [
|
|
2010
2001
|
/* @__PURE__ */ jsxs2(MenuHeaderFeatures, { $leftAction: !!leftAction, children: [
|
|
2011
2002
|
leftAction && leftAction,
|
|
2012
2003
|
title && /* @__PURE__ */ jsx4(MenuTitleText, { $leftAction: !!leftAction, children: title }),
|
|
@@ -2094,9 +2085,7 @@ var Container = styled5.span`
|
|
|
2094
2085
|
padding-left: 0;
|
|
2095
2086
|
padding-right: 0;
|
|
2096
2087
|
font-family: ${(props) => props.theme.fontFamily};
|
|
2097
|
-
font-style: ${(props) =>
|
|
2098
|
-
return props.isItalicized && "italic";
|
|
2099
|
-
}};
|
|
2088
|
+
font-style: ${(props) => props.isItalicized && "italic"};
|
|
2100
2089
|
|
|
2101
2090
|
${(props) => props.truncated && css5`
|
|
2102
2091
|
display: block;
|
|
@@ -2190,7 +2179,7 @@ var SmallBodyCopyWithLogic = withTextLogic(SmallBodyCopy);
|
|
|
2190
2179
|
SmallBodyCopyWithLogic.displayName = "Text.SmallBodyCopy";
|
|
2191
2180
|
Text.SmallBodyCopy = SmallBodyCopyWithLogic;
|
|
2192
2181
|
var Text_default = Text;
|
|
2193
|
-
var
|
|
2182
|
+
var index_default = Text_default;
|
|
2194
2183
|
|
|
2195
2184
|
// src/MenuGroup/styles.tsx
|
|
2196
2185
|
var StyledMenuGroup = styled6.li`
|
|
@@ -2209,7 +2198,7 @@ var StyledMenuGroup = styled6.li`
|
|
|
2209
2198
|
${layout}
|
|
2210
2199
|
${space}
|
|
2211
2200
|
`;
|
|
2212
|
-
var StyledTitle = styled6(
|
|
2201
|
+
var StyledTitle = styled6(index_default.SmallSubHeadline)`
|
|
2213
2202
|
margin: ${({ theme: theme2 }) => theme2.space[400]} ${({ theme: theme2 }) => theme2.space[400]}
|
|
2214
2203
|
0px ${({ theme: theme2 }) => theme2.space[400]};
|
|
2215
2204
|
`;
|
|
@@ -2222,14 +2211,20 @@ var StyledMenuGroupUl = styled6.ul`
|
|
|
2222
2211
|
import { jsx as jsx8, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
2223
2212
|
var MenuGroup = ({
|
|
2224
2213
|
titleAs = "h3",
|
|
2225
|
-
children,
|
|
2214
|
+
children: childrenProp,
|
|
2226
2215
|
title,
|
|
2227
2216
|
color: color2,
|
|
2228
2217
|
isSingleSelect,
|
|
2229
2218
|
id,
|
|
2219
|
+
items,
|
|
2220
|
+
MenuItemComponent = MenuItem,
|
|
2230
2221
|
...rest
|
|
2231
2222
|
}) => {
|
|
2232
2223
|
const titleId = `menu-group-title-${Math.random().toString(36).slice(2, 11)}`;
|
|
2224
|
+
const children = childrenProp || !items || !items.length ? childrenProp : items.map((item) => /* @__PURE__ */ jsx8(MenuItemComponent, { ...item }, item.id));
|
|
2225
|
+
if (!children) {
|
|
2226
|
+
return null;
|
|
2227
|
+
}
|
|
2233
2228
|
return /* @__PURE__ */ jsxs3(
|
|
2234
2229
|
StyledMenuGroup,
|
|
2235
2230
|
{
|
|
@@ -2260,7 +2255,7 @@ var CustomPopoutContent = styled7(Popout.Content)`
|
|
|
2260
2255
|
var MenuRoot = ({
|
|
2261
2256
|
children,
|
|
2262
2257
|
menuToggleElement,
|
|
2263
|
-
popoutProps,
|
|
2258
|
+
popoutProps: { focusLockProps, ...popoutProps } = {},
|
|
2264
2259
|
width: width2 = "300px",
|
|
2265
2260
|
...contextProps
|
|
2266
2261
|
}) => {
|
|
@@ -2271,7 +2266,7 @@ var MenuRoot = ({
|
|
|
2271
2266
|
},
|
|
2272
2267
|
[openMenu, closeMenu]
|
|
2273
2268
|
);
|
|
2274
|
-
return /* @__PURE__ */ jsx9(MenuProvider, {
|
|
2269
|
+
return /* @__PURE__ */ jsx9(MenuProvider, { menuProps: contextProps, children: /* @__PURE__ */ jsx9(
|
|
2275
2270
|
Popout,
|
|
2276
2271
|
{
|
|
2277
2272
|
menuPopout: true,
|
|
@@ -2281,7 +2276,8 @@ var MenuRoot = ({
|
|
|
2281
2276
|
focusLockProps: {
|
|
2282
2277
|
// correct jerking motion when scrolling while the Popout is open
|
|
2283
2278
|
// returnFocus: false,
|
|
2284
|
-
crossFrame: false
|
|
2279
|
+
crossFrame: false,
|
|
2280
|
+
...focusLockProps
|
|
2285
2281
|
},
|
|
2286
2282
|
disableWrapperAria: true,
|
|
2287
2283
|
...popoutProps,
|
|
@@ -2292,21 +2288,22 @@ var MenuRoot = ({
|
|
|
2292
2288
|
|
|
2293
2289
|
// src/MenuLabel.tsx
|
|
2294
2290
|
import "react";
|
|
2291
|
+
import { Label } from "@sproutsocial/seeds-react-label";
|
|
2295
2292
|
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
2296
2293
|
var MenuLabel = ({ children, ...rest }) => {
|
|
2297
2294
|
const { getLabelProps } = useMenuContext();
|
|
2298
|
-
return /* @__PURE__ */ jsx10(
|
|
2295
|
+
return /* @__PURE__ */ jsx10(Label, { htmlFor: "fallback_menu_label", ...getLabelProps?.(), ...rest, children });
|
|
2299
2296
|
};
|
|
2300
2297
|
|
|
2301
2298
|
// src/MenuToggleButton.tsx
|
|
2302
|
-
import { useContext as
|
|
2299
|
+
import { useContext as useContext3 } from "react";
|
|
2303
2300
|
import { Button } from "@sproutsocial/seeds-react-button";
|
|
2304
2301
|
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
2305
2302
|
var MenuToggleButton = ({
|
|
2306
2303
|
children,
|
|
2307
2304
|
...rest
|
|
2308
2305
|
}) => {
|
|
2309
|
-
const { getToggleButtonProps, isListbox, getDropdownProps } =
|
|
2306
|
+
const { getToggleButtonProps, isListbox, getDropdownProps } = useContext3(MenuContext);
|
|
2310
2307
|
return /* @__PURE__ */ jsx11(
|
|
2311
2308
|
Button,
|
|
2312
2309
|
{
|
|
@@ -2324,26 +2321,25 @@ var MenuToggleButton = ({
|
|
|
2324
2321
|
};
|
|
2325
2322
|
|
|
2326
2323
|
// src/ActionMenu/ActionMenu.tsx
|
|
2327
|
-
import
|
|
2324
|
+
import React10, { useEffect } from "react";
|
|
2328
2325
|
import {
|
|
2329
2326
|
useSelect as useSelect2
|
|
2330
2327
|
} from "downshift";
|
|
2331
2328
|
|
|
2332
2329
|
// src/hooks/useItemsFromChildren.tsx
|
|
2333
|
-
import
|
|
2330
|
+
import React9, { useMemo as useMemo4 } from "react";
|
|
2334
2331
|
var walkAllChildren = (children, callback) => {
|
|
2335
2332
|
const walk = (element, parents2) => {
|
|
2336
|
-
if (element === null || element === void 0)
|
|
2337
|
-
return;
|
|
2333
|
+
if (element === null || element === void 0) return;
|
|
2338
2334
|
callback(element, parents2);
|
|
2339
2335
|
const newParents = [...parents2, element];
|
|
2340
2336
|
const children2 = element.props?.children;
|
|
2341
|
-
|
|
2337
|
+
React9.Children.toArray(children2).forEach((child) => {
|
|
2342
2338
|
walk(child, newParents);
|
|
2343
2339
|
});
|
|
2344
2340
|
};
|
|
2345
2341
|
const parents = [];
|
|
2346
|
-
|
|
2342
|
+
React9.Children.toArray(children).forEach((child) => {
|
|
2347
2343
|
walk(child, parents);
|
|
2348
2344
|
});
|
|
2349
2345
|
};
|
|
@@ -2351,39 +2347,76 @@ var checkIfIsElement = (element, name) => {
|
|
|
2351
2347
|
return !!(element && typeof element === "object" && "type" in element && typeof element.type !== "string" && typeof element.type.name === "string" && element.type.name === name);
|
|
2352
2348
|
};
|
|
2353
2349
|
var getAllMenuItems = (children) => {
|
|
2354
|
-
const
|
|
2355
|
-
walkAllChildren(children, (element
|
|
2350
|
+
const orderedElements = [];
|
|
2351
|
+
walkAllChildren(children, (element) => {
|
|
2356
2352
|
if (checkIfIsElement(element, "MenuItem")) {
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2353
|
+
orderedElements.push({
|
|
2354
|
+
type: "item",
|
|
2355
|
+
element
|
|
2356
|
+
});
|
|
2357
|
+
} else if (checkIfIsElement(element, "MenuGroup")) {
|
|
2358
|
+
orderedElements.push({
|
|
2359
|
+
type: "group",
|
|
2360
|
+
element
|
|
2360
2361
|
});
|
|
2361
2362
|
}
|
|
2362
2363
|
});
|
|
2363
|
-
return
|
|
2364
|
+
return { orderedElements };
|
|
2364
2365
|
};
|
|
2365
2366
|
var useItemsFromChildren = ({
|
|
2366
2367
|
children
|
|
2367
2368
|
}) => {
|
|
2368
|
-
const { allMenuItems, menuItemsMap } =
|
|
2369
|
-
const
|
|
2369
|
+
const { allMenuItems, menuItemsMap } = useMemo4(() => {
|
|
2370
|
+
const { orderedElements } = getAllMenuItems(children);
|
|
2370
2371
|
const menuItemsMap2 = {};
|
|
2371
|
-
const allMenuItems2 =
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2372
|
+
const allMenuItems2 = [];
|
|
2373
|
+
let index = 0;
|
|
2374
|
+
orderedElements.forEach(({ type, element }) => {
|
|
2375
|
+
if (type === "group") {
|
|
2376
|
+
const menuGroup = element;
|
|
2377
|
+
const items = menuGroup.props.items;
|
|
2378
|
+
if (items) {
|
|
2379
|
+
items.forEach((menuItem) => {
|
|
2380
|
+
const item = {
|
|
2381
|
+
id: menuItem.id,
|
|
2382
|
+
index: index++,
|
|
2383
|
+
disabled: menuItem.disabled,
|
|
2384
|
+
menuItemProps: menuItem,
|
|
2385
|
+
menuGroupProps: element.props
|
|
2386
|
+
};
|
|
2387
|
+
allMenuItems2.push(item);
|
|
2388
|
+
menuItemsMap2[`${item.id}`] = item;
|
|
2389
|
+
});
|
|
2390
|
+
} else if (menuGroup.props.children) {
|
|
2391
|
+
let children2 = menuGroup.props.children;
|
|
2392
|
+
if (!Array.isArray(children2)) {
|
|
2393
|
+
children2 = [children2];
|
|
2394
|
+
}
|
|
2395
|
+
children2.forEach((menuItem) => {
|
|
2396
|
+
const item = {
|
|
2397
|
+
id: menuItem.props.id,
|
|
2398
|
+
index: index++,
|
|
2399
|
+
disabled: menuItem.props.disabled,
|
|
2400
|
+
menuItemProps: menuItem.props,
|
|
2401
|
+
menuGroupProps: element.props
|
|
2402
|
+
};
|
|
2403
|
+
allMenuItems2.push(item);
|
|
2404
|
+
menuItemsMap2[`${item.id}`] = item;
|
|
2405
|
+
});
|
|
2406
|
+
}
|
|
2407
|
+
} else {
|
|
2408
|
+
if (menuItemsMap2[`${element.props.id}`]) return;
|
|
2409
|
+
const menuItem = element;
|
|
2376
2410
|
const item = {
|
|
2377
|
-
id:
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
menuItemProps:
|
|
2381
|
-
menuGroupProps: parentMenuGroup ? parentMenuGroup.props : void 0
|
|
2411
|
+
id: menuItem.props.id,
|
|
2412
|
+
index: index++,
|
|
2413
|
+
disabled: menuItem.props.disabled,
|
|
2414
|
+
menuItemProps: menuItem.props
|
|
2382
2415
|
};
|
|
2416
|
+
allMenuItems2.push(item);
|
|
2383
2417
|
menuItemsMap2[`${item.id}`] = item;
|
|
2384
|
-
return item;
|
|
2385
2418
|
}
|
|
2386
|
-
);
|
|
2419
|
+
});
|
|
2387
2420
|
return { allMenuItems: allMenuItems2, menuItemsMap: menuItemsMap2 };
|
|
2388
2421
|
}, [children]);
|
|
2389
2422
|
return { allMenuItems, menuItemsMap };
|
|
@@ -2394,12 +2427,14 @@ import { useSelect } from "downshift";
|
|
|
2394
2427
|
var useSelectStateReducer = (state, actionAndChanges) => {
|
|
2395
2428
|
const { type, changes } = actionAndChanges;
|
|
2396
2429
|
switch (type) {
|
|
2430
|
+
/** If downshift is blurred by tabbing within the menu, stay open */
|
|
2397
2431
|
case useSelect.stateChangeTypes.ToggleButtonBlur:
|
|
2398
2432
|
return {
|
|
2399
2433
|
...changes,
|
|
2400
2434
|
// keep menu open on blur
|
|
2401
2435
|
isOpen: true
|
|
2402
2436
|
};
|
|
2437
|
+
/** Return standard change payload */
|
|
2403
2438
|
default:
|
|
2404
2439
|
return changes;
|
|
2405
2440
|
}
|
|
@@ -2421,8 +2456,7 @@ var handleStateChange = (changes, currentSelectedItem) => {
|
|
|
2421
2456
|
return;
|
|
2422
2457
|
}
|
|
2423
2458
|
const selectedItem = changes.selectedItem || currentSelectedItem;
|
|
2424
|
-
if (!selectedItem)
|
|
2425
|
-
return;
|
|
2459
|
+
if (!selectedItem) return;
|
|
2426
2460
|
if (selectedItem.disabled) {
|
|
2427
2461
|
return;
|
|
2428
2462
|
}
|
|
@@ -2454,7 +2488,7 @@ var ActionMenu = ({
|
|
|
2454
2488
|
...useSelectProps
|
|
2455
2489
|
}) => {
|
|
2456
2490
|
const { allMenuItems, menuItemsMap } = useItemsFromChildren({ children });
|
|
2457
|
-
const [currentSelectedItem, setCurrentSelectedItem] =
|
|
2491
|
+
const [currentSelectedItem, setCurrentSelectedItem] = React10.useState(null);
|
|
2458
2492
|
const { isOpen, ...useSelectReturnProps } = useSelect2({
|
|
2459
2493
|
...defaultUseSelectProps,
|
|
2460
2494
|
items: allMenuItems,
|
|
@@ -2605,8 +2639,7 @@ var MultiSelectMenu = ({
|
|
|
2605
2639
|
case useSelect4.stateChangeTypes.ToggleButtonKeyDownEnter:
|
|
2606
2640
|
case useSelect4.stateChangeTypes.ToggleButtonKeyDownSpaceButton:
|
|
2607
2641
|
case useSelect4.stateChangeTypes.ItemClick:
|
|
2608
|
-
if (!newSelectedItem)
|
|
2609
|
-
break;
|
|
2642
|
+
if (!newSelectedItem) break;
|
|
2610
2643
|
if (selectedItems?.find((item) => item?.id === newSelectedItem.id)) {
|
|
2611
2644
|
removeSelectedItem(newSelectedItem);
|
|
2612
2645
|
} else {
|
|
@@ -2650,8 +2683,129 @@ var MultiSelectMenu = ({
|
|
|
2650
2683
|
}
|
|
2651
2684
|
);
|
|
2652
2685
|
};
|
|
2686
|
+
|
|
2687
|
+
// src/Autocomplete/Autocomplete.tsx
|
|
2688
|
+
import React13 from "react";
|
|
2689
|
+
import { useCombobox as useCombobox2 } from "downshift";
|
|
2690
|
+
|
|
2691
|
+
// src/reducers/useComboboxStateReducer.tsx
|
|
2692
|
+
import { useCombobox } from "downshift";
|
|
2693
|
+
var useComboboxStateReducer = (state, actionAndChanges) => {
|
|
2694
|
+
const { type, changes } = actionAndChanges;
|
|
2695
|
+
switch (type) {
|
|
2696
|
+
/** If downshift is blurred by tabbing within the menu, stay open */
|
|
2697
|
+
case useCombobox.stateChangeTypes.InputBlur:
|
|
2698
|
+
return {
|
|
2699
|
+
...changes,
|
|
2700
|
+
// keep menu open on blur
|
|
2701
|
+
isOpen: true
|
|
2702
|
+
};
|
|
2703
|
+
/** Return standard change payload */
|
|
2704
|
+
default:
|
|
2705
|
+
return changes;
|
|
2706
|
+
}
|
|
2707
|
+
};
|
|
2708
|
+
var defaultUseComboboxProps = {
|
|
2709
|
+
// disabling while item.hidden so that hidden items are ignored by downshift
|
|
2710
|
+
isItemDisabled: (item) => Boolean(item.disabled || item.hidden)
|
|
2711
|
+
};
|
|
2712
|
+
|
|
2713
|
+
// src/Autocomplete/Autocomplete.tsx
|
|
2714
|
+
import { jsx as jsx15 } from "react/jsx-runtime";
|
|
2715
|
+
var Autocomplete = ({
|
|
2716
|
+
children,
|
|
2717
|
+
stateReducer: externalStateReducer,
|
|
2718
|
+
itemToString: itemToString2 = itemToString,
|
|
2719
|
+
getIsItemVisible = (item, inputValue) => itemToString2(item).toLowerCase().startsWith(inputValue.toLowerCase()),
|
|
2720
|
+
...useComboboxProps
|
|
2721
|
+
}) => {
|
|
2722
|
+
const { allMenuItems } = useItemsFromChildren({ children });
|
|
2723
|
+
const [items, setItems] = React13.useState(allMenuItems);
|
|
2724
|
+
const { isOpen, ...useComboboxReturnProps } = useCombobox2({
|
|
2725
|
+
...defaultUseComboboxProps,
|
|
2726
|
+
items,
|
|
2727
|
+
itemToString: itemToString2,
|
|
2728
|
+
onInputValueChange({ inputValue }) {
|
|
2729
|
+
setItems(
|
|
2730
|
+
inputValue ? allMenuItems.reduce(
|
|
2731
|
+
(items2, item) => [
|
|
2732
|
+
...items2,
|
|
2733
|
+
{ ...item, hidden: !getIsItemVisible(item, inputValue) }
|
|
2734
|
+
],
|
|
2735
|
+
[]
|
|
2736
|
+
) : allMenuItems
|
|
2737
|
+
);
|
|
2738
|
+
},
|
|
2739
|
+
stateReducer: (state, actionAndChanges) => {
|
|
2740
|
+
let newState;
|
|
2741
|
+
newState = useComboboxStateReducer(state, actionAndChanges);
|
|
2742
|
+
return externalStateReducer ? externalStateReducer(state, {
|
|
2743
|
+
...actionAndChanges,
|
|
2744
|
+
changes: newState
|
|
2745
|
+
}) : newState;
|
|
2746
|
+
},
|
|
2747
|
+
...useComboboxProps
|
|
2748
|
+
});
|
|
2749
|
+
return /* @__PURE__ */ jsx15(
|
|
2750
|
+
MenuRoot,
|
|
2751
|
+
{
|
|
2752
|
+
...{
|
|
2753
|
+
isListbox: true,
|
|
2754
|
+
items,
|
|
2755
|
+
itemToString: itemToString2,
|
|
2756
|
+
isOpen,
|
|
2757
|
+
...useComboboxProps,
|
|
2758
|
+
...useComboboxReturnProps
|
|
2759
|
+
},
|
|
2760
|
+
popoutProps: {
|
|
2761
|
+
focusOnContent: false
|
|
2762
|
+
},
|
|
2763
|
+
children
|
|
2764
|
+
}
|
|
2765
|
+
);
|
|
2766
|
+
};
|
|
2767
|
+
|
|
2768
|
+
// src/Autocomplete/AutocompleteInput.tsx
|
|
2769
|
+
import { useContext as useContext4 } from "react";
|
|
2770
|
+
import { Input } from "@sproutsocial/seeds-react-input";
|
|
2771
|
+
import { jsx as jsx16 } from "react/jsx-runtime";
|
|
2772
|
+
var AutocompleteInput = ({
|
|
2773
|
+
onKeyDown,
|
|
2774
|
+
onChange,
|
|
2775
|
+
onInput,
|
|
2776
|
+
onBlur,
|
|
2777
|
+
onClick,
|
|
2778
|
+
inputProps,
|
|
2779
|
+
...rest
|
|
2780
|
+
}) => {
|
|
2781
|
+
const { getInputProps, inputValue } = useContext4(MenuContext);
|
|
2782
|
+
return /* @__PURE__ */ jsx16(
|
|
2783
|
+
Input,
|
|
2784
|
+
{
|
|
2785
|
+
id: "autocomplete_input",
|
|
2786
|
+
name: "autocomplete_input",
|
|
2787
|
+
inputProps: {
|
|
2788
|
+
...getInputProps?.({
|
|
2789
|
+
// refKey: "innerRef",
|
|
2790
|
+
onKeyDown,
|
|
2791
|
+
onChange,
|
|
2792
|
+
onInput,
|
|
2793
|
+
onBlur,
|
|
2794
|
+
onClick,
|
|
2795
|
+
value: inputValue
|
|
2796
|
+
}),
|
|
2797
|
+
...inputProps
|
|
2798
|
+
},
|
|
2799
|
+
autoComplete: false,
|
|
2800
|
+
value: inputValue,
|
|
2801
|
+
...rest
|
|
2802
|
+
}
|
|
2803
|
+
);
|
|
2804
|
+
};
|
|
2653
2805
|
export {
|
|
2654
2806
|
ActionMenu,
|
|
2807
|
+
Autocomplete,
|
|
2808
|
+
AutocompleteInput,
|
|
2655
2809
|
INPUT_TYPES,
|
|
2656
2810
|
MenuContent,
|
|
2657
2811
|
MenuContext,
|