@sproutsocial/seeds-react-menu 0.4.0 → 0.5.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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +35 -0
- package/dist/esm/index.js +221 -137
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +126 -101
- package/dist/index.d.ts +126 -101
- package/dist/index.js +236 -151
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
- package/src/ActionMenu/ActionMenu.tsx +10 -3
- package/src/ActionMenu/ActionMenuTypes.ts +10 -6
- package/src/ActionMenu/__tests__/ActionMenu.test.tsx +0 -22
- package/src/ActionMenu/__tests__/ActionMenu.typetest.tsx +32 -3
- package/src/Autocomplete/Autocomplete.stories.tsx +24 -0
- package/src/Autocomplete/Autocomplete.tsx +10 -4
- package/src/Autocomplete/AutocompleteTypes.ts +6 -3
- package/src/Autocomplete/__tests__/Autocomplete.typetest.tsx +34 -3
- package/src/MenuContent/MenuContent.tsx +14 -1
- package/src/MenuContent/MenuContentTypes.ts +5 -5
- package/src/MenuContent/__tests__/MenuContent.typetest.tsx +17 -1
- package/src/MenuGroup/MenuGroup.feature +6 -6
- package/src/MenuGroup/MenuGroup.tsx +2 -1
- package/src/MenuGroup/MenuGroupTypes.ts +4 -6
- package/src/MenuGroup/__tests__/MenuGroup.typetest.tsx +23 -4
- package/src/MenuItem/MenuItem.tsx +0 -1
- package/src/MultiSelectMenu/MultiSelectMenu.tsx +10 -3
- package/src/MultiSelectMenu/MultiSelectMenuTypes.ts +8 -6
- package/src/MultiSelectMenu/__tests__/MultiSelectMenu.test.tsx +0 -43
- package/src/MultiSelectMenu/__tests__/MultiSelectMenu.typetest.tsx +29 -2
- package/src/SingleSelectMenu/SingleSelectMenu.tsx +10 -3
- package/src/SingleSelectMenu/SingleSelectMenuTypes.ts +7 -5
- package/src/SingleSelectMenu/__tests__/SingleSelectMenu.typetest.tsx +32 -2
- package/src/__tests__/Menu.test.tsx +38 -0
- package/src/hooks/useMenuChildren.tsx +210 -0
- package/src/index.ts +1 -1
- package/src/types.ts +26 -1
- package/src/hooks/useItemsFromChildren.tsx +0 -131
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
|
-
CJS dist/index.js
|
|
12
|
-
CJS dist/index.js.map
|
|
13
|
-
CJS ⚡️ Build success in
|
|
14
|
-
ESM dist/esm/index.js
|
|
15
|
-
ESM dist/esm/index.js.map
|
|
16
|
-
ESM ⚡️ Build success in
|
|
11
|
+
CJS dist/index.js 93.30 KB
|
|
12
|
+
CJS dist/index.js.map 271.01 KB
|
|
13
|
+
CJS ⚡️ Build success in 795ms
|
|
14
|
+
ESM dist/esm/index.js 88.24 KB
|
|
15
|
+
ESM dist/esm/index.js.map 270.17 KB
|
|
16
|
+
ESM ⚡️ Build success in 802ms
|
|
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 27251ms
|
|
19
|
+
DTS dist/index.d.ts 19.56 KB
|
|
20
|
+
DTS dist/index.d.mts 19.56 KB
|
|
21
|
+
Done in 34.03s.
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# @sproutsocial/seeds-react-menu
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 523648e: Adds `items` and `MenuItemComponent` props to 5 Menu components
|
|
8
|
+
- The following changes have been made to several Menu components:
|
|
9
|
+
- Adds an `items` prop, so that menu items can be passed as an array of objects, instead of as children elements
|
|
10
|
+
- Adds a `MenuItemComponent` prop to allow custom rendering of menu items. This prop is optional and has a default value of the `MenuItem` component.
|
|
11
|
+
- Updates the type to require either `children` or `items`, but not both.
|
|
12
|
+
- Additionally, the `MenuItemComponent` prop can only be used with the `items` prop.
|
|
13
|
+
- Affected components:
|
|
14
|
+
- ActionMenu
|
|
15
|
+
- SingleSelectMenu
|
|
16
|
+
- MultiSelectMenu
|
|
17
|
+
- Autocomplete
|
|
18
|
+
- MenuContent
|
|
19
|
+
|
|
20
|
+
## 0.4.1
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- 9fd8bac: Update dependencies to use semantic package version instead of wildcards
|
|
25
|
+
- Updated dependencies [9fd8bac]
|
|
26
|
+
- @sproutsocial/seeds-react-system-props@3.0.2
|
|
27
|
+
- @sproutsocial/seeds-react-checkbox@1.3.1
|
|
28
|
+
- @sproutsocial/seeds-react-button@1.2.1
|
|
29
|
+
- @sproutsocial/seeds-react-popout@2.1.1
|
|
30
|
+
- @sproutsocial/seeds-react-switch@1.2.1
|
|
31
|
+
- @sproutsocial/seeds-react-input@1.3.2
|
|
32
|
+
- @sproutsocial/seeds-react-label@1.0.1
|
|
33
|
+
- @sproutsocial/seeds-react-radio@1.2.1
|
|
34
|
+
- @sproutsocial/seeds-react-theme@2.2.1
|
|
35
|
+
- @sproutsocial/seeds-react-icon@1.1.2
|
|
36
|
+
- @sproutsocial/seeds-react-box@1.1.2
|
|
37
|
+
|
|
3
38
|
## 0.4.0
|
|
4
39
|
|
|
5
40
|
### Minor Changes
|
package/dist/esm/index.js
CHANGED
|
@@ -94,9 +94,6 @@ var require_object_assign = __commonJS({
|
|
|
94
94
|
}
|
|
95
95
|
});
|
|
96
96
|
|
|
97
|
-
// src/MenuItem/MenuItem.tsx
|
|
98
|
-
import "react";
|
|
99
|
-
|
|
100
97
|
// src/MenuContext.tsx
|
|
101
98
|
import {
|
|
102
99
|
createContext,
|
|
@@ -2015,15 +2012,173 @@ var StyledMenuContent = styled3(motion.ul)`
|
|
|
2015
2012
|
padding: 0;
|
|
2016
2013
|
`;
|
|
2017
2014
|
|
|
2015
|
+
// src/hooks/useMenuChildren.tsx
|
|
2016
|
+
import React4, { useMemo as useMemo3 } from "react";
|
|
2017
|
+
import { Fragment as Fragment3, jsx as jsx5 } from "react/jsx-runtime";
|
|
2018
|
+
var walkAllChildren = (children, callback) => {
|
|
2019
|
+
const walk = (element, parents2) => {
|
|
2020
|
+
if (element === null || element === void 0) return;
|
|
2021
|
+
callback(element, parents2);
|
|
2022
|
+
const newParents = [...parents2, element];
|
|
2023
|
+
const children2 = element.props?.children;
|
|
2024
|
+
React4.Children.toArray(children2).forEach((child) => {
|
|
2025
|
+
walk(child, newParents);
|
|
2026
|
+
});
|
|
2027
|
+
};
|
|
2028
|
+
const parents = [];
|
|
2029
|
+
React4.Children.toArray(children).forEach((child) => {
|
|
2030
|
+
walk(child, parents);
|
|
2031
|
+
});
|
|
2032
|
+
};
|
|
2033
|
+
var getComponentName = (element) => {
|
|
2034
|
+
if (element && typeof element === "object" && "type" in element && typeof element.type !== "string" && typeof element.type.name === "string") {
|
|
2035
|
+
return element.type.name;
|
|
2036
|
+
}
|
|
2037
|
+
};
|
|
2038
|
+
var getAllMenuItems = (children) => {
|
|
2039
|
+
const orderedElements = [];
|
|
2040
|
+
walkAllChildren(children, (element) => {
|
|
2041
|
+
switch (getComponentName(element)) {
|
|
2042
|
+
case "MenuItem":
|
|
2043
|
+
orderedElements.push({
|
|
2044
|
+
type: "item",
|
|
2045
|
+
element
|
|
2046
|
+
});
|
|
2047
|
+
break;
|
|
2048
|
+
case "MenuGroup":
|
|
2049
|
+
orderedElements.push({
|
|
2050
|
+
type: "group",
|
|
2051
|
+
element
|
|
2052
|
+
});
|
|
2053
|
+
break;
|
|
2054
|
+
case "MenuContent":
|
|
2055
|
+
orderedElements.push({
|
|
2056
|
+
type: "content",
|
|
2057
|
+
element
|
|
2058
|
+
});
|
|
2059
|
+
break;
|
|
2060
|
+
default:
|
|
2061
|
+
break;
|
|
2062
|
+
}
|
|
2063
|
+
});
|
|
2064
|
+
return { orderedElements };
|
|
2065
|
+
};
|
|
2066
|
+
var mapMenuItems = ({
|
|
2067
|
+
items,
|
|
2068
|
+
MenuItemComponent
|
|
2069
|
+
}) => {
|
|
2070
|
+
return /* @__PURE__ */ jsx5(Fragment3, { children: items.map((menuItem) => /* @__PURE__ */ jsx5(MenuItemComponent, { ...menuItem }, menuItem.id)) });
|
|
2071
|
+
};
|
|
2072
|
+
var useMenuChildren = ({
|
|
2073
|
+
children: childrenProp,
|
|
2074
|
+
items,
|
|
2075
|
+
MenuItemComponent = MenuItem
|
|
2076
|
+
}) => {
|
|
2077
|
+
const { allMenuItems, menuItemsMap, children } = useMemo3(() => {
|
|
2078
|
+
let children2 = /* @__PURE__ */ jsx5(Fragment3, {});
|
|
2079
|
+
let index = 0;
|
|
2080
|
+
const menuItemsMap2 = {};
|
|
2081
|
+
const allMenuItems2 = [];
|
|
2082
|
+
if (items && items.length) {
|
|
2083
|
+
items.forEach((menuItem) => {
|
|
2084
|
+
const item = {
|
|
2085
|
+
id: menuItem.id,
|
|
2086
|
+
index: index++,
|
|
2087
|
+
disabled: menuItem.disabled,
|
|
2088
|
+
menuItemProps: menuItem
|
|
2089
|
+
};
|
|
2090
|
+
allMenuItems2.push(item);
|
|
2091
|
+
menuItemsMap2[`${item.id}`] = item;
|
|
2092
|
+
});
|
|
2093
|
+
children2 = /* @__PURE__ */ jsx5(MenuContent, { children: mapMenuItems({ items, MenuItemComponent }) });
|
|
2094
|
+
} else if (childrenProp) {
|
|
2095
|
+
children2 = childrenProp;
|
|
2096
|
+
const { orderedElements } = getAllMenuItems(childrenProp);
|
|
2097
|
+
orderedElements.forEach(({ type, element }) => {
|
|
2098
|
+
if (type === "content") {
|
|
2099
|
+
const menuContent = element;
|
|
2100
|
+
const items2 = menuContent.props.items;
|
|
2101
|
+
if (items2) {
|
|
2102
|
+
items2.forEach((menuItem) => {
|
|
2103
|
+
const item = {
|
|
2104
|
+
id: menuItem.id,
|
|
2105
|
+
index: index++,
|
|
2106
|
+
children: menuItem.children,
|
|
2107
|
+
disabled: menuItem.disabled,
|
|
2108
|
+
menuItemProps: menuItem
|
|
2109
|
+
};
|
|
2110
|
+
allMenuItems2.push(item);
|
|
2111
|
+
menuItemsMap2[`${item.id}`] = item;
|
|
2112
|
+
});
|
|
2113
|
+
}
|
|
2114
|
+
} else if (type === "group") {
|
|
2115
|
+
const menuGroup = element;
|
|
2116
|
+
const items2 = menuGroup.props.items;
|
|
2117
|
+
if (items2) {
|
|
2118
|
+
items2.forEach((menuItem) => {
|
|
2119
|
+
const item = {
|
|
2120
|
+
id: menuItem.id,
|
|
2121
|
+
index: index++,
|
|
2122
|
+
children: menuItem.children,
|
|
2123
|
+
disabled: menuItem.disabled,
|
|
2124
|
+
menuItemProps: menuItem,
|
|
2125
|
+
menuGroupProps: element.props
|
|
2126
|
+
};
|
|
2127
|
+
allMenuItems2.push(item);
|
|
2128
|
+
menuItemsMap2[`${item.id}`] = item;
|
|
2129
|
+
});
|
|
2130
|
+
} else if (menuGroup.props.children) {
|
|
2131
|
+
let children3 = menuGroup.props.children;
|
|
2132
|
+
if (!Array.isArray(children3)) {
|
|
2133
|
+
children3 = [children3];
|
|
2134
|
+
}
|
|
2135
|
+
children3.forEach((menuItem) => {
|
|
2136
|
+
const item = {
|
|
2137
|
+
id: menuItem.props.id,
|
|
2138
|
+
index: index++,
|
|
2139
|
+
children: menuItem.props.children,
|
|
2140
|
+
disabled: menuItem.props.disabled,
|
|
2141
|
+
menuItemProps: menuItem.props,
|
|
2142
|
+
menuGroupProps: element.props
|
|
2143
|
+
};
|
|
2144
|
+
allMenuItems2.push(item);
|
|
2145
|
+
menuItemsMap2[`${item.id}`] = item;
|
|
2146
|
+
});
|
|
2147
|
+
}
|
|
2148
|
+
} else {
|
|
2149
|
+
if (menuItemsMap2[`${element.props.id}`]) return;
|
|
2150
|
+
const menuItem = element;
|
|
2151
|
+
const item = {
|
|
2152
|
+
id: menuItem.props.id,
|
|
2153
|
+
index: index++,
|
|
2154
|
+
disabled: menuItem.props.disabled,
|
|
2155
|
+
menuItemProps: menuItem.props
|
|
2156
|
+
};
|
|
2157
|
+
allMenuItems2.push(item);
|
|
2158
|
+
menuItemsMap2[`${item.id}`] = item;
|
|
2159
|
+
}
|
|
2160
|
+
});
|
|
2161
|
+
}
|
|
2162
|
+
return { allMenuItems: allMenuItems2, menuItemsMap: menuItemsMap2, children: children2 };
|
|
2163
|
+
}, [childrenProp, items, MenuItemComponent]);
|
|
2164
|
+
return { allMenuItems, menuItemsMap, children };
|
|
2165
|
+
};
|
|
2166
|
+
|
|
2018
2167
|
// src/MenuContent/MenuContent.tsx
|
|
2019
|
-
import { jsx as
|
|
2168
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
2020
2169
|
var MenuContent = ({
|
|
2021
2170
|
id = "menu_content",
|
|
2022
|
-
children,
|
|
2171
|
+
children: childrenProp,
|
|
2172
|
+
items,
|
|
2173
|
+
MenuItemComponent = MenuItem,
|
|
2023
2174
|
...rest
|
|
2024
2175
|
}) => {
|
|
2025
2176
|
const { getToggleButtonProps, getMenuProps, isListbox } = useMenuContext();
|
|
2026
|
-
|
|
2177
|
+
const children = childrenProp || !items || !items.length ? childrenProp : mapMenuItems({ items, MenuItemComponent });
|
|
2178
|
+
if (!children) {
|
|
2179
|
+
return null;
|
|
2180
|
+
}
|
|
2181
|
+
return /* @__PURE__ */ jsx6(
|
|
2027
2182
|
StyledMenuContent,
|
|
2028
2183
|
{
|
|
2029
2184
|
autoFocus: true,
|
|
@@ -2056,9 +2211,9 @@ var StyledMenuFooterBox = styled4(Box2)`
|
|
|
2056
2211
|
`;
|
|
2057
2212
|
|
|
2058
2213
|
// src/MenuFooter/MenuFooter.tsx
|
|
2059
|
-
import { jsx as
|
|
2214
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
2060
2215
|
var MenuFooter = ({ children, ...rest }) => {
|
|
2061
|
-
return /* @__PURE__ */
|
|
2216
|
+
return /* @__PURE__ */ jsx7(StyledMenuFooterBox, { ...rest, children });
|
|
2062
2217
|
};
|
|
2063
2218
|
|
|
2064
2219
|
// src/MenuGroup/MenuGroup.tsx
|
|
@@ -2078,7 +2233,7 @@ import {
|
|
|
2078
2233
|
GRID,
|
|
2079
2234
|
TYPOGRAPHY
|
|
2080
2235
|
} from "@sproutsocial/seeds-react-system-props";
|
|
2081
|
-
import { jsx as
|
|
2236
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
2082
2237
|
import "react";
|
|
2083
2238
|
var Container = styled5.span`
|
|
2084
2239
|
margin: 0;
|
|
@@ -2139,7 +2294,7 @@ var SmallBodyCopy = styled22(styles_default)`
|
|
|
2139
2294
|
`;
|
|
2140
2295
|
var Text = ({ fontSize: fontSize2, children, qa, color: color2, ...rest }) => {
|
|
2141
2296
|
const qaText = typeof children === "string" ? children : void 0;
|
|
2142
|
-
return /* @__PURE__ */
|
|
2297
|
+
return /* @__PURE__ */ jsx8(
|
|
2143
2298
|
styles_default,
|
|
2144
2299
|
{
|
|
2145
2300
|
typeScale: fontSize2,
|
|
@@ -2154,7 +2309,7 @@ var Text = ({ fontSize: fontSize2, children, qa, color: color2, ...rest }) => {
|
|
|
2154
2309
|
var withTextLogic = (Component) => {
|
|
2155
2310
|
return ({ children, ...props }) => {
|
|
2156
2311
|
const qaText = typeof children === "string" ? children : void 0;
|
|
2157
|
-
return /* @__PURE__ */
|
|
2312
|
+
return /* @__PURE__ */ jsx8(Component, { "data-qa-text": qaText, ...props, children });
|
|
2158
2313
|
};
|
|
2159
2314
|
};
|
|
2160
2315
|
var HeadlineWithLogic = withTextLogic(Headline);
|
|
@@ -2208,7 +2363,7 @@ var StyledMenuGroupUl = styled6.ul`
|
|
|
2208
2363
|
`;
|
|
2209
2364
|
|
|
2210
2365
|
// src/MenuGroup/MenuGroup.tsx
|
|
2211
|
-
import { jsx as
|
|
2366
|
+
import { jsx as jsx9, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
2212
2367
|
var MenuGroup = ({
|
|
2213
2368
|
titleAs = "h3",
|
|
2214
2369
|
children: childrenProp,
|
|
@@ -2221,7 +2376,7 @@ var MenuGroup = ({
|
|
|
2221
2376
|
...rest
|
|
2222
2377
|
}) => {
|
|
2223
2378
|
const titleId = `menu-group-title-${Math.random().toString(36).slice(2, 11)}`;
|
|
2224
|
-
const children = childrenProp || !items || !items.length ? childrenProp :
|
|
2379
|
+
const children = childrenProp || !items || !items.length ? childrenProp : mapMenuItems({ items, MenuItemComponent });
|
|
2225
2380
|
if (!children) {
|
|
2226
2381
|
return null;
|
|
2227
2382
|
}
|
|
@@ -2235,8 +2390,8 @@ var MenuGroup = ({
|
|
|
2235
2390
|
color: color2,
|
|
2236
2391
|
...rest,
|
|
2237
2392
|
children: [
|
|
2238
|
-
title && /* @__PURE__ */
|
|
2239
|
-
/* @__PURE__ */
|
|
2393
|
+
title && /* @__PURE__ */ jsx9(StyledTitle, { role: "heading", as: titleAs, id: titleId, children: title }),
|
|
2394
|
+
/* @__PURE__ */ jsx9(StyledMenuGroupUl, { children })
|
|
2240
2395
|
]
|
|
2241
2396
|
}
|
|
2242
2397
|
);
|
|
@@ -2246,7 +2401,7 @@ var MenuGroup = ({
|
|
|
2246
2401
|
import { useCallback } from "react";
|
|
2247
2402
|
import styled7 from "styled-components";
|
|
2248
2403
|
import { Popout } from "@sproutsocial/seeds-react-popout";
|
|
2249
|
-
import { jsx as
|
|
2404
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
2250
2405
|
var CustomPopoutContent = styled7(Popout.Content)`
|
|
2251
2406
|
padding: 0;
|
|
2252
2407
|
margin-left: 0;
|
|
@@ -2266,13 +2421,13 @@ var MenuRoot = ({
|
|
|
2266
2421
|
},
|
|
2267
2422
|
[openMenu, closeMenu]
|
|
2268
2423
|
);
|
|
2269
|
-
return /* @__PURE__ */
|
|
2424
|
+
return /* @__PURE__ */ jsx10(MenuProvider, { menuProps: contextProps, children: /* @__PURE__ */ jsx10(
|
|
2270
2425
|
Popout,
|
|
2271
2426
|
{
|
|
2272
2427
|
menuPopout: true,
|
|
2273
2428
|
isOpen: !!isOpen,
|
|
2274
2429
|
setIsOpen,
|
|
2275
|
-
content: /* @__PURE__ */
|
|
2430
|
+
content: /* @__PURE__ */ jsx10(CustomPopoutContent, { width: width2, children }),
|
|
2276
2431
|
focusLockProps: {
|
|
2277
2432
|
// correct jerking motion when scrolling while the Popout is open
|
|
2278
2433
|
// returnFocus: false,
|
|
@@ -2289,22 +2444,22 @@ var MenuRoot = ({
|
|
|
2289
2444
|
// src/MenuLabel.tsx
|
|
2290
2445
|
import "react";
|
|
2291
2446
|
import { Label } from "@sproutsocial/seeds-react-label";
|
|
2292
|
-
import { jsx as
|
|
2447
|
+
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
2293
2448
|
var MenuLabel = ({ children, ...rest }) => {
|
|
2294
2449
|
const { getLabelProps } = useMenuContext();
|
|
2295
|
-
return /* @__PURE__ */
|
|
2450
|
+
return /* @__PURE__ */ jsx11(Label, { htmlFor: "fallback_menu_label", ...getLabelProps?.(), ...rest, children });
|
|
2296
2451
|
};
|
|
2297
2452
|
|
|
2298
2453
|
// src/MenuToggleButton.tsx
|
|
2299
2454
|
import { useContext as useContext3 } from "react";
|
|
2300
2455
|
import { Button } from "@sproutsocial/seeds-react-button";
|
|
2301
|
-
import { jsx as
|
|
2456
|
+
import { jsx as jsx12 } from "react/jsx-runtime";
|
|
2302
2457
|
var MenuToggleButton = ({
|
|
2303
2458
|
children,
|
|
2304
2459
|
...rest
|
|
2305
2460
|
}) => {
|
|
2306
2461
|
const { getToggleButtonProps, isListbox, getDropdownProps } = useContext3(MenuContext);
|
|
2307
|
-
return /* @__PURE__ */
|
|
2462
|
+
return /* @__PURE__ */ jsx12(
|
|
2308
2463
|
Button,
|
|
2309
2464
|
{
|
|
2310
2465
|
appearance: "secondary",
|
|
@@ -2326,102 +2481,6 @@ import {
|
|
|
2326
2481
|
useSelect as useSelect2
|
|
2327
2482
|
} from "downshift";
|
|
2328
2483
|
|
|
2329
|
-
// src/hooks/useItemsFromChildren.tsx
|
|
2330
|
-
import React9, { useMemo as useMemo4 } from "react";
|
|
2331
|
-
var walkAllChildren = (children, callback) => {
|
|
2332
|
-
const walk = (element, parents2) => {
|
|
2333
|
-
if (element === null || element === void 0) return;
|
|
2334
|
-
callback(element, parents2);
|
|
2335
|
-
const newParents = [...parents2, element];
|
|
2336
|
-
const children2 = element.props?.children;
|
|
2337
|
-
React9.Children.toArray(children2).forEach((child) => {
|
|
2338
|
-
walk(child, newParents);
|
|
2339
|
-
});
|
|
2340
|
-
};
|
|
2341
|
-
const parents = [];
|
|
2342
|
-
React9.Children.toArray(children).forEach((child) => {
|
|
2343
|
-
walk(child, parents);
|
|
2344
|
-
});
|
|
2345
|
-
};
|
|
2346
|
-
var checkIfIsElement = (element, name) => {
|
|
2347
|
-
return !!(element && typeof element === "object" && "type" in element && typeof element.type !== "string" && typeof element.type.name === "string" && element.type.name === name);
|
|
2348
|
-
};
|
|
2349
|
-
var getAllMenuItems = (children) => {
|
|
2350
|
-
const orderedElements = [];
|
|
2351
|
-
walkAllChildren(children, (element) => {
|
|
2352
|
-
if (checkIfIsElement(element, "MenuItem")) {
|
|
2353
|
-
orderedElements.push({
|
|
2354
|
-
type: "item",
|
|
2355
|
-
element
|
|
2356
|
-
});
|
|
2357
|
-
} else if (checkIfIsElement(element, "MenuGroup")) {
|
|
2358
|
-
orderedElements.push({
|
|
2359
|
-
type: "group",
|
|
2360
|
-
element
|
|
2361
|
-
});
|
|
2362
|
-
}
|
|
2363
|
-
});
|
|
2364
|
-
return { orderedElements };
|
|
2365
|
-
};
|
|
2366
|
-
var useItemsFromChildren = ({
|
|
2367
|
-
children
|
|
2368
|
-
}) => {
|
|
2369
|
-
const { allMenuItems, menuItemsMap } = useMemo4(() => {
|
|
2370
|
-
const { orderedElements } = getAllMenuItems(children);
|
|
2371
|
-
const menuItemsMap2 = {};
|
|
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;
|
|
2410
|
-
const item = {
|
|
2411
|
-
id: menuItem.props.id,
|
|
2412
|
-
index: index++,
|
|
2413
|
-
disabled: menuItem.props.disabled,
|
|
2414
|
-
menuItemProps: menuItem.props
|
|
2415
|
-
};
|
|
2416
|
-
allMenuItems2.push(item);
|
|
2417
|
-
menuItemsMap2[`${item.id}`] = item;
|
|
2418
|
-
}
|
|
2419
|
-
});
|
|
2420
|
-
return { allMenuItems: allMenuItems2, menuItemsMap: menuItemsMap2 };
|
|
2421
|
-
}, [children]);
|
|
2422
|
-
return { allMenuItems, menuItemsMap };
|
|
2423
|
-
};
|
|
2424
|
-
|
|
2425
2484
|
// src/reducers/useSelectStateReducer.tsx
|
|
2426
2485
|
import { useSelect } from "downshift";
|
|
2427
2486
|
var useSelectStateReducer = (state, actionAndChanges) => {
|
|
@@ -2450,7 +2509,7 @@ var itemToString = (item) => {
|
|
|
2450
2509
|
};
|
|
2451
2510
|
|
|
2452
2511
|
// src/ActionMenu/ActionMenu.tsx
|
|
2453
|
-
import { jsx as
|
|
2512
|
+
import { jsx as jsx13 } from "react/jsx-runtime";
|
|
2454
2513
|
var handleStateChange = (changes, currentSelectedItem) => {
|
|
2455
2514
|
if (!(changes.type === useSelect2.stateChangeTypes.ToggleButtonKeyDownEnter || changes.type === useSelect2.stateChangeTypes.ToggleButtonKeyDownSpaceButton)) {
|
|
2456
2515
|
return;
|
|
@@ -2483,11 +2542,17 @@ var handleStateChange = (changes, currentSelectedItem) => {
|
|
|
2483
2542
|
}
|
|
2484
2543
|
};
|
|
2485
2544
|
var ActionMenu = ({
|
|
2486
|
-
children,
|
|
2545
|
+
children: childrenProp,
|
|
2546
|
+
items,
|
|
2547
|
+
MenuItemComponent = MenuItem,
|
|
2487
2548
|
stateReducer: externalStateReducer,
|
|
2488
2549
|
...useSelectProps
|
|
2489
2550
|
}) => {
|
|
2490
|
-
const { allMenuItems, menuItemsMap } =
|
|
2551
|
+
const { allMenuItems, menuItemsMap, children } = useMenuChildren({
|
|
2552
|
+
children: childrenProp,
|
|
2553
|
+
items,
|
|
2554
|
+
MenuItemComponent
|
|
2555
|
+
});
|
|
2491
2556
|
const [currentSelectedItem, setCurrentSelectedItem] = React10.useState(null);
|
|
2492
2557
|
const { isOpen, ...useSelectReturnProps } = useSelect2({
|
|
2493
2558
|
...defaultUseSelectProps,
|
|
@@ -2507,7 +2572,7 @@ var ActionMenu = ({
|
|
|
2507
2572
|
useEffect(() => {
|
|
2508
2573
|
setCurrentSelectedItem(useSelectReturnProps.selectedItem);
|
|
2509
2574
|
}, [useSelectReturnProps.selectedItem]);
|
|
2510
|
-
return /* @__PURE__ */
|
|
2575
|
+
return /* @__PURE__ */ jsx13(
|
|
2511
2576
|
MenuRoot,
|
|
2512
2577
|
{
|
|
2513
2578
|
...{
|
|
@@ -2527,13 +2592,19 @@ var ActionMenu = ({
|
|
|
2527
2592
|
// src/SingleSelectMenu/SingleSelectMenu.tsx
|
|
2528
2593
|
import "react";
|
|
2529
2594
|
import { useSelect as useSelect3 } from "downshift";
|
|
2530
|
-
import { jsx as
|
|
2595
|
+
import { jsx as jsx14 } from "react/jsx-runtime";
|
|
2531
2596
|
var SingleSelectMenu = ({
|
|
2532
|
-
children,
|
|
2597
|
+
children: childrenProp,
|
|
2533
2598
|
stateReducer: externalStateReducer,
|
|
2599
|
+
items,
|
|
2600
|
+
MenuItemComponent = MenuItem,
|
|
2534
2601
|
...useSelectProps
|
|
2535
2602
|
}) => {
|
|
2536
|
-
const { allMenuItems, menuItemsMap } =
|
|
2603
|
+
const { allMenuItems, menuItemsMap, children } = useMenuChildren({
|
|
2604
|
+
children: childrenProp,
|
|
2605
|
+
items,
|
|
2606
|
+
MenuItemComponent
|
|
2607
|
+
});
|
|
2537
2608
|
const { isOpen, ...useSelectReturnProps } = useSelect3({
|
|
2538
2609
|
...defaultUseSelectProps,
|
|
2539
2610
|
items: allMenuItems,
|
|
@@ -2548,7 +2619,7 @@ var SingleSelectMenu = ({
|
|
|
2548
2619
|
},
|
|
2549
2620
|
...useSelectProps
|
|
2550
2621
|
});
|
|
2551
|
-
return /* @__PURE__ */
|
|
2622
|
+
return /* @__PURE__ */ jsx14(
|
|
2552
2623
|
MenuRoot,
|
|
2553
2624
|
{
|
|
2554
2625
|
...{
|
|
@@ -2571,7 +2642,7 @@ import {
|
|
|
2571
2642
|
useSelect as useSelect4,
|
|
2572
2643
|
useMultipleSelection
|
|
2573
2644
|
} from "downshift";
|
|
2574
|
-
import { jsx as
|
|
2645
|
+
import { jsx as jsx15 } from "react/jsx-runtime";
|
|
2575
2646
|
var selectReducerForMultiSelect = (state, actionAndChanges) => {
|
|
2576
2647
|
const { changes, type } = actionAndChanges;
|
|
2577
2648
|
switch (type) {
|
|
@@ -2591,14 +2662,20 @@ var selectReducerForMultiSelect = (state, actionAndChanges) => {
|
|
|
2591
2662
|
return changes;
|
|
2592
2663
|
};
|
|
2593
2664
|
var MultiSelectMenu = ({
|
|
2594
|
-
children,
|
|
2665
|
+
children: childrenProp,
|
|
2666
|
+
items,
|
|
2667
|
+
MenuItemComponent = MenuItem,
|
|
2595
2668
|
stateReducer: externalStateReducer,
|
|
2596
2669
|
getA11yMultiStatusMessage,
|
|
2597
2670
|
onMultiSelectStateChange,
|
|
2598
2671
|
multiSelectStateReducer,
|
|
2599
2672
|
...useSelectProps
|
|
2600
2673
|
}) => {
|
|
2601
|
-
const { allMenuItems, menuItemsMap } =
|
|
2674
|
+
const { allMenuItems, menuItemsMap, children } = useMenuChildren({
|
|
2675
|
+
children: childrenProp,
|
|
2676
|
+
items,
|
|
2677
|
+
MenuItemComponent
|
|
2678
|
+
});
|
|
2602
2679
|
const multiSelectOverrides = Object.entries({
|
|
2603
2680
|
...useSelectProps,
|
|
2604
2681
|
getA11yStatusMessage: getA11yMultiStatusMessage,
|
|
@@ -2658,7 +2735,7 @@ var MultiSelectMenu = ({
|
|
|
2658
2735
|
},
|
|
2659
2736
|
...useSelectProps
|
|
2660
2737
|
});
|
|
2661
|
-
return /* @__PURE__ */
|
|
2738
|
+
return /* @__PURE__ */ jsx15(
|
|
2662
2739
|
MenuRoot,
|
|
2663
2740
|
{
|
|
2664
2741
|
...{
|
|
@@ -2711,15 +2788,21 @@ var defaultUseComboboxProps = {
|
|
|
2711
2788
|
};
|
|
2712
2789
|
|
|
2713
2790
|
// src/Autocomplete/Autocomplete.tsx
|
|
2714
|
-
import { jsx as
|
|
2791
|
+
import { jsx as jsx16 } from "react/jsx-runtime";
|
|
2715
2792
|
var Autocomplete = ({
|
|
2716
|
-
children,
|
|
2793
|
+
children: childrenProp,
|
|
2717
2794
|
stateReducer: externalStateReducer,
|
|
2795
|
+
items: itemsProp,
|
|
2796
|
+
MenuItemComponent = MenuItem,
|
|
2718
2797
|
itemToString: itemToString2 = itemToString,
|
|
2719
2798
|
getIsItemVisible = (item, inputValue) => itemToString2(item).toLowerCase().startsWith(inputValue.toLowerCase()),
|
|
2720
2799
|
...useComboboxProps
|
|
2721
2800
|
}) => {
|
|
2722
|
-
const { allMenuItems } =
|
|
2801
|
+
const { allMenuItems, children } = useMenuChildren({
|
|
2802
|
+
children: childrenProp,
|
|
2803
|
+
items: itemsProp,
|
|
2804
|
+
MenuItemComponent
|
|
2805
|
+
});
|
|
2723
2806
|
const [items, setItems] = React13.useState(allMenuItems);
|
|
2724
2807
|
const { isOpen, ...useComboboxReturnProps } = useCombobox2({
|
|
2725
2808
|
...defaultUseComboboxProps,
|
|
@@ -2746,7 +2829,7 @@ var Autocomplete = ({
|
|
|
2746
2829
|
},
|
|
2747
2830
|
...useComboboxProps
|
|
2748
2831
|
});
|
|
2749
|
-
return /* @__PURE__ */
|
|
2832
|
+
return /* @__PURE__ */ jsx16(
|
|
2750
2833
|
MenuRoot,
|
|
2751
2834
|
{
|
|
2752
2835
|
...{
|
|
@@ -2768,7 +2851,7 @@ var Autocomplete = ({
|
|
|
2768
2851
|
// src/Autocomplete/AutocompleteInput.tsx
|
|
2769
2852
|
import { useContext as useContext4 } from "react";
|
|
2770
2853
|
import { Input } from "@sproutsocial/seeds-react-input";
|
|
2771
|
-
import { jsx as
|
|
2854
|
+
import { jsx as jsx17 } from "react/jsx-runtime";
|
|
2772
2855
|
var AutocompleteInput = ({
|
|
2773
2856
|
onKeyDown,
|
|
2774
2857
|
onChange,
|
|
@@ -2779,7 +2862,7 @@ var AutocompleteInput = ({
|
|
|
2779
2862
|
...rest
|
|
2780
2863
|
}) => {
|
|
2781
2864
|
const { getInputProps, inputValue } = useContext4(MenuContext);
|
|
2782
|
-
return /* @__PURE__ */
|
|
2865
|
+
return /* @__PURE__ */ jsx17(
|
|
2783
2866
|
Input,
|
|
2784
2867
|
{
|
|
2785
2868
|
id: "autocomplete_input",
|
|
@@ -2828,8 +2911,9 @@ export {
|
|
|
2828
2911
|
StyledMenuItem,
|
|
2829
2912
|
StyledTitle,
|
|
2830
2913
|
defaultUseSelectProps,
|
|
2831
|
-
|
|
2914
|
+
mapMenuItems,
|
|
2832
2915
|
useMenu,
|
|
2916
|
+
useMenuChildren,
|
|
2833
2917
|
useMenuContext,
|
|
2834
2918
|
useSelectStateReducer
|
|
2835
2919
|
};
|