@homebound/beam 2.237.0 → 2.238.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.
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
2
|
import { IconProps } from "./Icon";
|
|
3
3
|
import { OverlayTriggerProps } from "./internal/OverlayTrigger";
|
|
4
|
-
interface
|
|
4
|
+
interface ButtonMenuBaseProps extends Pick<OverlayTriggerProps, "trigger" | "placement" | "disabled" | "tooltip" | "showActiveBorder"> {
|
|
5
5
|
items: MenuItem[];
|
|
6
6
|
persistentItems?: MenuItem[];
|
|
7
7
|
searchable?: boolean;
|
|
8
8
|
defaultOpen?: boolean;
|
|
9
9
|
contrast?: boolean;
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
interface SelectionButtonMenuProps extends ButtonMenuBaseProps {
|
|
12
|
+
/** Display a menu item as selected based. Use the Menu Item's label to identify */
|
|
13
|
+
selectedItem: string | undefined;
|
|
14
|
+
onChange: (key: string) => void;
|
|
15
|
+
}
|
|
16
|
+
export declare function ButtonMenu(props: ButtonMenuBaseProps | SelectionButtonMenuProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
12
17
|
type MenuItemBase = {
|
|
13
18
|
label: string;
|
|
14
19
|
/** If the `onClick` property is set as a string, then the menu item will be rendered as a link with the `onClick` value being the href */
|
|
@@ -11,6 +11,11 @@ const utils_1 = require("../utils");
|
|
|
11
11
|
const defaultTestId_1 = require("../utils/defaultTestId");
|
|
12
12
|
function ButtonMenu(props) {
|
|
13
13
|
const { defaultOpen, disabled, items, persistentItems, trigger, searchable, contrast = false } = props;
|
|
14
|
+
let selectedItem, onChange;
|
|
15
|
+
if (isSelectionButtonMenuProps(props)) {
|
|
16
|
+
selectedItem = props.selectedItem;
|
|
17
|
+
onChange = props.onChange;
|
|
18
|
+
}
|
|
14
19
|
const state = (0, react_stately_1.useMenuTriggerState)({ isOpen: defaultOpen });
|
|
15
20
|
const buttonRef = (0, react_1.useRef)(null);
|
|
16
21
|
const { menuTriggerProps, menuProps } = (0, react_aria_1.useMenuTrigger)({ isDisabled: !!disabled }, state, buttonRef);
|
|
@@ -21,6 +26,9 @@ function ButtonMenu(props) {
|
|
|
21
26
|
: (0, OverlayTrigger_1.isIconButton)(trigger)
|
|
22
27
|
? trigger.icon
|
|
23
28
|
: trigger.name);
|
|
24
|
-
return ((0, jsx_runtime_1.jsx)(OverlayTrigger_1.OverlayTrigger, { ...props, menuTriggerProps: menuTriggerProps, state: state, buttonRef: buttonRef, ...tid, contrast: contrast, children: (0, jsx_runtime_1.jsx)(Menu_1.Menu, { ariaMenuProps: menuProps, onClose: () => state.close(), items: items, persistentItems: persistentItems, searchable: searchable, contrast: contrast, ...tid }) }));
|
|
29
|
+
return ((0, jsx_runtime_1.jsx)(OverlayTrigger_1.OverlayTrigger, { ...props, menuTriggerProps: menuTriggerProps, state: state, buttonRef: buttonRef, ...tid, contrast: contrast, children: (0, jsx_runtime_1.jsx)(Menu_1.Menu, { ariaMenuProps: menuProps, onClose: () => state.close(), items: items, persistentItems: persistentItems, searchable: searchable, contrast: contrast, selectedItem: selectedItem, onChange: onChange, ...tid }) }));
|
|
25
30
|
}
|
|
26
31
|
exports.ButtonMenu = ButtonMenu;
|
|
32
|
+
function isSelectionButtonMenuProps(props) {
|
|
33
|
+
return typeof props === "object" && "selectedItem" in props && "onChange" in props;
|
|
34
|
+
}
|
|
@@ -7,6 +7,8 @@ interface MenuProps<T> {
|
|
|
7
7
|
searchable?: boolean;
|
|
8
8
|
persistentItems?: MenuItem[];
|
|
9
9
|
contrast: boolean;
|
|
10
|
+
selectedItem: string | undefined;
|
|
11
|
+
onChange: ((key: string) => void) | undefined;
|
|
10
12
|
}
|
|
11
13
|
export declare function Menu<T>(props: PropsWithChildren<MenuProps<T>>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
12
14
|
export {};
|
|
@@ -11,7 +11,7 @@ const Css_1 = require("../../Css");
|
|
|
11
11
|
const MenuSearchField_1 = require("../../inputs/internal/MenuSearchField");
|
|
12
12
|
const utils_1 = require("../../utils");
|
|
13
13
|
function Menu(props) {
|
|
14
|
-
const { ariaMenuProps, items, persistentItems, onClose, searchable, contrast } = props;
|
|
14
|
+
const { ariaMenuProps, items, persistentItems, onClose, searchable, contrast, selectedItem, onChange } = props;
|
|
15
15
|
// Build out the Menu's Tree data to include the Persistent Action, if any. This is a collection of Nodes that is used
|
|
16
16
|
// by React-Aria to keep track of item states such as focus, and provide hooks for calling those actions.
|
|
17
17
|
const tree = (0, react_stately_1.useTreeData)({
|
|
@@ -20,9 +20,7 @@ function Menu(props) {
|
|
|
20
20
|
getChildren: (item) => { var _a; return (_a = item.items) !== null && _a !== void 0 ? _a : []; },
|
|
21
21
|
});
|
|
22
22
|
const [search, setSearch] = (0, react_1.useState)(undefined);
|
|
23
|
-
const { contains } = (0, react_aria_1.useFilter)({
|
|
24
|
-
sensitivity: "base",
|
|
25
|
-
});
|
|
23
|
+
const { contains } = (0, react_aria_1.useFilter)({ sensitivity: "base" });
|
|
26
24
|
// Filter our tree data items based on the search term
|
|
27
25
|
const filteredTree = (0, react_1.useMemo)(() => {
|
|
28
26
|
const { items, ...others } = tree;
|
|
@@ -49,7 +47,12 @@ function Menu(props) {
|
|
|
49
47
|
const state = (0, react_stately_1.useTreeState)({
|
|
50
48
|
children: menuChildren,
|
|
51
49
|
items: filteredTree.items.map((i) => i.value),
|
|
52
|
-
selectionMode: "none",
|
|
50
|
+
selectionMode: typeof onChange === "function" ? "single" : "none",
|
|
51
|
+
disallowEmptySelection: typeof onChange === "function",
|
|
52
|
+
selectedKeys: selectedItem ? [selectedItem] : undefined,
|
|
53
|
+
onSelectionChange: (keys) => {
|
|
54
|
+
keys !== "all" && onChange && onChange([...keys.values()].map((k) => k.toString())[0]);
|
|
55
|
+
},
|
|
53
56
|
});
|
|
54
57
|
const menuRef = (0, react_1.useRef)(null);
|
|
55
58
|
const { menuProps } = (0, react_aria_1.useMenu)({ ...ariaMenuProps, autoFocus: searchable ? false : true }, state, menuRef);
|
|
@@ -17,6 +17,7 @@ function MenuItemImpl(props) {
|
|
|
17
17
|
const menuItem = item.value;
|
|
18
18
|
const { disabled, onClick, label, destructive } = menuItem;
|
|
19
19
|
const isDisabled = Boolean(disabled);
|
|
20
|
+
const isSelected = state.selectionManager.selectedKeys.has(label);
|
|
20
21
|
const isFocused = state.selectionManager.focusedKey === item.key;
|
|
21
22
|
const ref = (0, react_1.useRef)(null);
|
|
22
23
|
const history = (0, react_router_1.useHistory)();
|
|
@@ -55,10 +56,19 @@ function MenuItemImpl(props) {
|
|
|
55
56
|
}, ...tid[(0, defaultTestId_1.defaultTestId)(menuItem.label)], children: (0, Tooltip_1.maybeTooltip)({
|
|
56
57
|
title: (0, Tooltip_1.resolveTooltip)(disabled),
|
|
57
58
|
placement: "right",
|
|
58
|
-
children:
|
|
59
|
+
children: renderMenuItem(menuItem, isSelected, isDisabled, contrast),
|
|
59
60
|
}) }));
|
|
60
61
|
}
|
|
61
62
|
exports.MenuItemImpl = MenuItemImpl;
|
|
63
|
+
function renderMenuItem(menuItem, isSelected, isDisabled, contrast) {
|
|
64
|
+
return ((0, jsx_runtime_1.jsxs)("div", { css: Css_1.Css.df.w100.aic.jcsb.gap2.$, children: [(0, jsx_runtime_1.jsx)("div", { css: Css_1.Css.df.aic.$, children: maybeWrapInLink(menuItem.onClick, isIconMenuItem(menuItem) ? ((0, jsx_runtime_1.jsx)(IconMenuItem, { ...menuItem })) : isImageMenuItem(menuItem) ? ((0, jsx_runtime_1.jsx)(ImageMenuItem, { ...menuItem })) : (menuItem.label), isDisabled) }), isSelected && ((0, jsx_runtime_1.jsx)(Icon_1.Icon, { icon: "check", color: !contrast
|
|
65
|
+
? isDisabled
|
|
66
|
+
? Css_1.Palette.Gray400
|
|
67
|
+
: Css_1.Palette.LightBlue700
|
|
68
|
+
: isDisabled
|
|
69
|
+
? Css_1.Palette.Gray500
|
|
70
|
+
: Css_1.Palette.White }))] }));
|
|
71
|
+
}
|
|
62
72
|
function ImageMenuItem(item) {
|
|
63
73
|
const { src, size = 24, label, isAvatar = false } = item;
|
|
64
74
|
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("span", { css: Css_1.Css.fs0.mr2.$, children: isAvatar ? ((0, jsx_runtime_1.jsx)(Avatar_1.Avatar, { src: src, name: label, size: size === 24 ? "sm" : "lg" })) : ((0, jsx_runtime_1.jsx)("img", { width: size, src: src, css: Css_1.Css.br4.$, alt: label })) }), label] }));
|
package/dist/inputs/Value.js
CHANGED
|
@@ -15,7 +15,8 @@ function keyToValue(key) {
|
|
|
15
15
|
return undefined;
|
|
16
16
|
}
|
|
17
17
|
else if (key.startsWith("__VALUE:boolean:")) {
|
|
18
|
-
|
|
18
|
+
// boolean values end with `;` (i.e. '__VALUE:boolean:true;').
|
|
19
|
+
return key.split(":")[2].startsWith("true");
|
|
19
20
|
}
|
|
20
21
|
else if (key.startsWith("__VALUE:number")) {
|
|
21
22
|
return Number(key.split(":")[2]);
|