@homebound/beam 2.236.0 → 2.238.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/dist/components/ButtonDatePicker.js +5 -3
- package/dist/components/ButtonMenu.d.ts +8 -2
- package/dist/components/ButtonMenu.js +18 -3
- package/dist/components/ButtonModal.js +8 -1
- package/dist/components/NavLink.d.ts +8 -2
- package/dist/components/NavLink.js +7 -12
- package/dist/components/Table/components/EditColumnsButton.js +8 -1
- package/dist/components/internal/Menu.d.ts +3 -0
- package/dist/components/internal/Menu.js +10 -7
- package/dist/components/internal/MenuItem.d.ts +1 -0
- package/dist/components/internal/MenuItem.js +13 -3
- package/dist/components/internal/MenuSection.d.ts +1 -0
- package/dist/components/internal/MenuSection.js +2 -2
- package/dist/components/internal/OverlayTrigger.d.ts +9 -3
- package/dist/components/internal/OverlayTrigger.js +13 -6
- package/package.json +1 -1
|
@@ -17,9 +17,11 @@ function ButtonDatePicker(props) {
|
|
|
17
17
|
const { menuTriggerProps, menuProps } = (0, react_aria_1.useMenuTrigger)({ isDisabled: !!disabled }, state, buttonRef);
|
|
18
18
|
const tid = (0, utils_1.useTestIds)(props, (0, OverlayTrigger_1.isTextButton)(trigger)
|
|
19
19
|
? (0, defaultTestId_1.defaultTestId)((0, OverlayTrigger_1.labelOr)(trigger, "buttonDatePicker"))
|
|
20
|
-
: (0, OverlayTrigger_1.
|
|
21
|
-
? trigger.
|
|
22
|
-
:
|
|
20
|
+
: (0, OverlayTrigger_1.isNavLinkButton)(trigger)
|
|
21
|
+
? (0, defaultTestId_1.defaultTestId)(trigger.navLabel)
|
|
22
|
+
: (0, OverlayTrigger_1.isIconButton)(trigger)
|
|
23
|
+
? trigger.icon
|
|
24
|
+
: trigger.name);
|
|
23
25
|
return ((0, jsx_runtime_1.jsx)(OverlayTrigger_1.OverlayTrigger, { ...props, menuTriggerProps: menuTriggerProps, state: state, buttonRef: buttonRef, ...tid, children: (0, jsx_runtime_1.jsx)(DatePickerOverlay_1.DatePickerOverlay, { overlayProps: menuProps, children: (0, jsx_runtime_1.jsx)(DatePicker_1.DatePicker, { ...datePickerProps, onSelect: (d) => {
|
|
24
26
|
onSelect(d);
|
|
25
27
|
state.close();
|
|
@@ -1,13 +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
|
+
contrast?: boolean;
|
|
9
10
|
}
|
|
10
|
-
|
|
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;
|
|
11
17
|
type MenuItemBase = {
|
|
12
18
|
label: string;
|
|
13
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 */
|
|
@@ -8,12 +8,27 @@ const react_stately_1 = require("react-stately");
|
|
|
8
8
|
const Menu_1 = require("./internal/Menu");
|
|
9
9
|
const OverlayTrigger_1 = require("./internal/OverlayTrigger");
|
|
10
10
|
const utils_1 = require("../utils");
|
|
11
|
+
const defaultTestId_1 = require("../utils/defaultTestId");
|
|
11
12
|
function ButtonMenu(props) {
|
|
12
|
-
const { defaultOpen, disabled, items, persistentItems, trigger, searchable } = props;
|
|
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
|
+
}
|
|
13
19
|
const state = (0, react_stately_1.useMenuTriggerState)({ isOpen: defaultOpen });
|
|
14
20
|
const buttonRef = (0, react_1.useRef)(null);
|
|
15
21
|
const { menuTriggerProps, menuProps } = (0, react_aria_1.useMenuTrigger)({ isDisabled: !!disabled }, state, buttonRef);
|
|
16
|
-
const tid = (0, utils_1.useTestIds)(props, (0, OverlayTrigger_1.isTextButton)(trigger)
|
|
17
|
-
|
|
22
|
+
const tid = (0, utils_1.useTestIds)(props, (0, OverlayTrigger_1.isTextButton)(trigger)
|
|
23
|
+
? (0, OverlayTrigger_1.labelOr)(trigger, "buttonMenu")
|
|
24
|
+
: (0, OverlayTrigger_1.isNavLinkButton)(trigger)
|
|
25
|
+
? (0, defaultTestId_1.defaultTestId)(trigger.navLabel)
|
|
26
|
+
: (0, OverlayTrigger_1.isIconButton)(trigger)
|
|
27
|
+
? trigger.icon
|
|
28
|
+
: trigger.name);
|
|
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 }) }));
|
|
18
30
|
}
|
|
19
31
|
exports.ButtonMenu = ButtonMenu;
|
|
32
|
+
function isSelectionButtonMenuProps(props) {
|
|
33
|
+
return typeof props === "object" && "selectedItem" in props && "onChange" in props;
|
|
34
|
+
}
|
|
@@ -7,13 +7,20 @@ const react_aria_1 = require("react-aria");
|
|
|
7
7
|
const react_stately_1 = require("react-stately");
|
|
8
8
|
const OverlayTrigger_1 = require("./internal/OverlayTrigger");
|
|
9
9
|
const utils_1 = require("../utils");
|
|
10
|
+
const defaultTestId_1 = require("../utils/defaultTestId");
|
|
10
11
|
const ContextualModal_1 = require("./internal/ContextualModal");
|
|
11
12
|
function ButtonModal(props) {
|
|
12
13
|
const { storybookDefaultOpen, trigger, disabled, content, title } = props;
|
|
13
14
|
const state = (0, react_stately_1.useMenuTriggerState)({ isOpen: storybookDefaultOpen });
|
|
14
15
|
const buttonRef = (0, react_1.useRef)(null);
|
|
15
16
|
const { menuTriggerProps } = (0, react_aria_1.useMenuTrigger)({ isDisabled: !!disabled }, state, buttonRef);
|
|
16
|
-
const tid = (0, utils_1.useTestIds)(props, (0, OverlayTrigger_1.isTextButton)(trigger)
|
|
17
|
+
const tid = (0, utils_1.useTestIds)(props, (0, OverlayTrigger_1.isTextButton)(trigger)
|
|
18
|
+
? (0, OverlayTrigger_1.labelOr)(trigger, "buttonModal")
|
|
19
|
+
: (0, OverlayTrigger_1.isNavLinkButton)(trigger)
|
|
20
|
+
? (0, defaultTestId_1.defaultTestId)(trigger.navLabel)
|
|
21
|
+
: (0, OverlayTrigger_1.isIconButton)(trigger)
|
|
22
|
+
? trigger.icon
|
|
23
|
+
: trigger.name);
|
|
17
24
|
return ((0, jsx_runtime_1.jsx)(OverlayTrigger_1.OverlayTrigger, { ...props, menuTriggerProps: menuTriggerProps, state: state, buttonRef: buttonRef, ...tid, children: (0, jsx_runtime_1.jsx)(ContextualModal_1.ContextualModal, { content: content, title: title, close: state.close }) }));
|
|
18
25
|
}
|
|
19
26
|
exports.ButtonModal = ButtonModal;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { AriaButtonProps } from "@react-types/button";
|
|
2
|
+
import { RefObject } from "react";
|
|
1
3
|
import type { IconKey } from "./";
|
|
2
4
|
import { Properties } from "../Css";
|
|
3
5
|
import { BeamFocusableProps } from "../interfaces";
|
|
@@ -5,15 +7,19 @@ export interface NavLinkProps extends BeamFocusableProps {
|
|
|
5
7
|
/** active indicates the user is on the current page */
|
|
6
8
|
active?: boolean;
|
|
7
9
|
disabled?: boolean;
|
|
8
|
-
href
|
|
10
|
+
/** if `href` isn't provided, it is treated as a <button> */
|
|
11
|
+
href?: string;
|
|
9
12
|
label: string;
|
|
10
13
|
icon?: IconKey;
|
|
11
14
|
variant: NavLinkVariant;
|
|
12
15
|
openInNew?: boolean;
|
|
13
16
|
contrast?: boolean;
|
|
17
|
+
/** HTML attributes to apply to the button element when it is being used to trigger a menu. */
|
|
18
|
+
menuTriggerProps?: AriaButtonProps;
|
|
19
|
+
buttonRef?: RefObject<HTMLElement>;
|
|
14
20
|
}
|
|
15
21
|
type NavLinkVariant = "side" | "global";
|
|
16
|
-
export declare function NavLink(props: NavLinkProps):
|
|
22
|
+
export declare function NavLink(props: NavLinkProps): JSX.Element;
|
|
17
23
|
export declare function getNavLinkStyles(variant: NavLinkVariant, contrast: boolean): {
|
|
18
24
|
baseStyles: Properties;
|
|
19
25
|
hoverStyles: Properties;
|
|
@@ -4,30 +4,25 @@ exports.getNavLinkStyles = exports.NavLink = void 0;
|
|
|
4
4
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const react_aria_1 = require("react-aria");
|
|
7
|
-
const react_router_dom_1 = require("react-router-dom");
|
|
8
7
|
const components_1 = require("./");
|
|
9
8
|
const Css_1 = require("../Css");
|
|
10
|
-
const
|
|
9
|
+
const useGetRef_1 = require("../hooks/useGetRef");
|
|
10
|
+
const getInteractiveElement_1 = require("../utils/getInteractiveElement");
|
|
11
11
|
const Icon_1 = require("./Icon");
|
|
12
12
|
function NavLink(props) {
|
|
13
|
-
const { disabled: isDisabled, label, openInNew, contrast = false, ...otherProps } = props;
|
|
14
|
-
const ariaProps = { children: label, isDisabled, ...otherProps };
|
|
13
|
+
const { disabled: isDisabled, label, openInNew, contrast = false, menuTriggerProps, buttonRef, ...otherProps } = props;
|
|
14
|
+
const ariaProps = { children: label, isDisabled, ...menuTriggerProps, ...otherProps };
|
|
15
15
|
const { href, active = false, icon = false, variant } = ariaProps;
|
|
16
|
-
const ref = (0,
|
|
17
|
-
const { buttonProps, isPressed } = (0, react_aria_1.useButton)({ ...ariaProps, elementType: "a" }, ref);
|
|
18
|
-
// remove `type=button` from being passed into the component, as it causes style issues in Safari.
|
|
19
|
-
const { type, ...otherButtonProps } = buttonProps;
|
|
16
|
+
const ref = (0, useGetRef_1.useGetRef)(buttonRef);
|
|
17
|
+
const { buttonProps, isPressed } = (0, react_aria_1.useButton)({ ...ariaProps, elementType: href ? "a" : "button" }, ref);
|
|
20
18
|
const { hoverProps, isHovered } = (0, react_aria_1.useHover)({ isDisabled });
|
|
21
19
|
const { isFocusVisible, focusProps } = (0, react_aria_1.useFocusRing)(ariaProps);
|
|
22
20
|
const { baseStyles, activeStyles, focusRingStyles, hoverStyles, disabledStyles, pressedStyles } = (0, react_1.useMemo)(() => getNavLinkStyles(variant, contrast), [variant, contrast]);
|
|
23
|
-
const external = (0, utils_1.isAbsoluteUrl)(href) || openInNew;
|
|
24
21
|
const linkAttributes = {
|
|
25
22
|
className: components_1.navLink,
|
|
26
23
|
ref: ref,
|
|
27
|
-
rel: external ? "noopener noreferrer" : undefined,
|
|
28
24
|
/** does not focus if disabled */
|
|
29
25
|
tabIndex: isDisabled ? -1 : 0,
|
|
30
|
-
target: external ? "_blank" : undefined,
|
|
31
26
|
/** aria-current represents the current page within a set of pages */
|
|
32
27
|
"aria-current": active ? "page" : undefined,
|
|
33
28
|
css: {
|
|
@@ -40,7 +35,7 @@ function NavLink(props) {
|
|
|
40
35
|
},
|
|
41
36
|
};
|
|
42
37
|
const linkContent = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [label, icon && ((0, jsx_runtime_1.jsx)("span", { css: Css_1.Css.ml1.$, children: (0, jsx_runtime_1.jsx)(Icon_1.Icon, { icon: icon }) }))] }));
|
|
43
|
-
return
|
|
38
|
+
return (0, getInteractiveElement_1.getButtonOrLink)(linkContent, href, { ...(0, react_aria_1.mergeProps)(buttonProps, focusProps, hoverProps), ...linkAttributes });
|
|
44
39
|
}
|
|
45
40
|
exports.NavLink = NavLink;
|
|
46
41
|
function getNavLinkStyles(variant, contrast) {
|
|
@@ -11,12 +11,19 @@ const Css_1 = require("../../../Css");
|
|
|
11
11
|
const hooks_1 = require("../../../hooks");
|
|
12
12
|
const inputs_1 = require("../../../inputs");
|
|
13
13
|
const utils_1 = require("../../../utils");
|
|
14
|
+
const defaultTestId_1 = require("../../../utils/defaultTestId");
|
|
14
15
|
function EditColumnsButton(props) {
|
|
15
16
|
const { defaultOpen, disabled, columns, trigger, title, api } = props;
|
|
16
17
|
const state = (0, react_stately_1.useMenuTriggerState)({ isOpen: defaultOpen });
|
|
17
18
|
const buttonRef = (0, react_1.useRef)(null);
|
|
18
19
|
const { menuTriggerProps } = (0, react_aria_1.useMenuTrigger)({ isDisabled: !!disabled }, state, buttonRef);
|
|
19
|
-
const tid = (0, utils_1.useTestIds)(props, (0, OverlayTrigger_1.isTextButton)(trigger)
|
|
20
|
+
const tid = (0, utils_1.useTestIds)(props, (0, OverlayTrigger_1.isTextButton)(trigger)
|
|
21
|
+
? (0, OverlayTrigger_1.labelOr)(trigger, "editColumnsButton")
|
|
22
|
+
: (0, OverlayTrigger_1.isNavLinkButton)(trigger)
|
|
23
|
+
? (0, defaultTestId_1.defaultTestId)(trigger.navLabel)
|
|
24
|
+
: (0, OverlayTrigger_1.isIconButton)(trigger)
|
|
25
|
+
? trigger.icon
|
|
26
|
+
: trigger.name);
|
|
20
27
|
const { options } = (0, react_1.useMemo)(() => {
|
|
21
28
|
return columns.reduce((acc, column) => {
|
|
22
29
|
// Only include options that can be hidden and have the `name` property defined.
|
|
@@ -6,6 +6,9 @@ interface MenuProps<T> {
|
|
|
6
6
|
items: MenuItem[];
|
|
7
7
|
searchable?: boolean;
|
|
8
8
|
persistentItems?: MenuItem[];
|
|
9
|
+
contrast: boolean;
|
|
10
|
+
selectedItem: string | undefined;
|
|
11
|
+
onChange: ((key: string) => void) | undefined;
|
|
9
12
|
}
|
|
10
13
|
export declare function Menu<T>(props: PropsWithChildren<MenuProps<T>>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
11
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 } = 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);
|
|
@@ -60,8 +63,8 @@ function Menu(props) {
|
|
|
60
63
|
return ((0, jsx_runtime_1.jsx)(react_aria_1.FocusScope, { children: (0, jsx_runtime_1.jsxs)("div", {
|
|
61
64
|
// Using `max-height: inherit` allows us to take advantage of the height set on the overlay container, which updates based on the available space for the overlay within the viewport
|
|
62
65
|
css: {
|
|
63
|
-
...Css_1.Css.df.fdc.myPx(4).bgWhite.outline0.br4.bshBasic.maxh("inherit").overflowAuto.$,
|
|
66
|
+
...Css_1.Css.df.fdc.myPx(4).bgWhite.outline0.br4.bshBasic.maxh("inherit").overflowAuto.if(contrast).bgGray900.$,
|
|
64
67
|
"&:hover": Css_1.Css.bshHover.$,
|
|
65
|
-
}, children: [searchable && ((0, jsx_runtime_1.jsx)(MenuSearchField_1.MenuSearchField, { label: "", value: search, placeholder: "Search...", labelStyle: "inline", onChange: setSearch, ...tid })), (0, jsx_runtime_1.jsx)("ul", { css: Css_1.Css.listReset.$, ...menuProps, ref: menuRef, ...tid.menu, children: [...state.collection].map((item) => ((0, jsx_runtime_1.jsx)(MenuSection_1.MenuSectionImpl, { section: item, state: state, onClose: onClose, ...tid }, item.key))) })] }) }));
|
|
68
|
+
}, children: [searchable && ((0, jsx_runtime_1.jsx)(MenuSearchField_1.MenuSearchField, { label: "", value: search, placeholder: "Search...", labelStyle: "inline", onChange: setSearch, ...tid })), (0, jsx_runtime_1.jsx)("ul", { css: Css_1.Css.listReset.$, ...menuProps, ref: menuRef, ...tid.menu, children: [...state.collection].map((item) => ((0, jsx_runtime_1.jsx)(MenuSection_1.MenuSectionImpl, { section: item, state: state, onClose: onClose, contrast: contrast, ...tid }, item.key))) })] }) }));
|
|
66
69
|
}
|
|
67
70
|
exports.Menu = Menu;
|
|
@@ -13,10 +13,11 @@ const Css_1 = require("../../Css");
|
|
|
13
13
|
const utils_1 = require("../../utils");
|
|
14
14
|
const defaultTestId_1 = require("../../utils/defaultTestId");
|
|
15
15
|
function MenuItemImpl(props) {
|
|
16
|
-
const { item, state, onClose } = props;
|
|
16
|
+
const { item, state, onClose, contrast } = 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)();
|
|
@@ -48,17 +49,26 @@ function MenuItemImpl(props) {
|
|
|
48
49
|
}, state, ref);
|
|
49
50
|
return ((0, jsx_runtime_1.jsx)("li", { ...menuItemProps, ...hoverProps, ref: ref, css: {
|
|
50
51
|
...Css_1.Css.df.aic.py1.px2.cursorPointer.outline0.mh("42px").$,
|
|
51
|
-
...(!isDisabled && isHovered ? Css_1.Css.bgGray100.$ : {}),
|
|
52
|
+
...(!isDisabled && isHovered ? (contrast ? Css_1.Css.bgGray800.$ : Css_1.Css.bgGray100.$) : {}),
|
|
52
53
|
...(isFocused ? Css_1.Css.add("boxShadow", `inset 0 0 0 1px ${Css_1.Palette.LightBlue700}`).$ : {}),
|
|
53
54
|
...(isDisabled ? Css_1.Css.gray500.cursorNotAllowed.$ : {}),
|
|
54
55
|
...(destructive ? Css_1.Css.red600.$ : {}),
|
|
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] }));
|
|
@@ -7,11 +7,11 @@ const internal_1 = require("./");
|
|
|
7
7
|
const Css_1 = require("../../Css");
|
|
8
8
|
const utils_1 = require("../../utils");
|
|
9
9
|
function MenuSectionImpl(props) {
|
|
10
|
-
const { section, state, onClose } = props;
|
|
10
|
+
const { section, state, onClose, contrast } = props;
|
|
11
11
|
const { itemProps, groupProps } = (0, react_aria_1.useMenuSection)(props.section);
|
|
12
12
|
const { separatorProps } = (0, react_aria_1.useSeparator)({ elementType: "li" });
|
|
13
13
|
const isPersistentSection = section.key !== state.collection.getFirstKey();
|
|
14
14
|
const tid = (0, utils_1.useTestIds)(props);
|
|
15
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [isPersistentSection && (0, jsx_runtime_1.jsx)("li", { ...separatorProps, css: Css_1.Css.bt.bGray200.$ }), (0, jsx_runtime_1.jsx)("li", { ...itemProps, css: Css_1.Css.if(!isPersistentSection).overflowAuto.$, children: (0, jsx_runtime_1.jsx)("ul", { css: Css_1.Css.listReset.$, ...groupProps, ...tid[isPersistentSection ? "persistentItems" : "menuItems"], children: [...section.childNodes].map((item) => ((0, jsx_runtime_1.jsx)(internal_1.MenuItemImpl, { item: item, state: state, onClose: onClose, ...tid }, item.key))) }) })] }));
|
|
15
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [isPersistentSection && (0, jsx_runtime_1.jsx)("li", { ...separatorProps, css: Css_1.Css.bt.bGray200.$ }), (0, jsx_runtime_1.jsx)("li", { ...itemProps, css: Css_1.Css.if(!isPersistentSection).overflowAuto.if(contrast).white.$, children: (0, jsx_runtime_1.jsx)("ul", { css: Css_1.Css.listReset.$, ...groupProps, ...tid[isPersistentSection ? "persistentItems" : "menuItems"], children: [...section.childNodes].map((item) => ((0, jsx_runtime_1.jsx)(internal_1.MenuItemImpl, { item: item, state: state, onClose: onClose, contrast: contrast, ...tid }, item.key))) }) })] }));
|
|
16
16
|
}
|
|
17
17
|
exports.MenuSectionImpl = MenuSectionImpl;
|
|
@@ -4,14 +4,18 @@ import { MenuTriggerState } from "react-stately";
|
|
|
4
4
|
import { AvatarButtonProps } from "../AvatarButton";
|
|
5
5
|
import { ButtonProps, ButtonVariant } from "../Button";
|
|
6
6
|
import { IconButtonProps } from "../IconButton";
|
|
7
|
+
import { NavLinkProps } from "../NavLink";
|
|
7
8
|
interface TextButtonTriggerProps extends Pick<ButtonProps, "label" | "variant" | "size" | "icon"> {
|
|
8
9
|
}
|
|
9
10
|
interface IconButtonTriggerProps extends Pick<IconButtonProps, "icon" | "color" | "compact" | "contrast"> {
|
|
10
11
|
}
|
|
11
12
|
interface AvatarButtonTriggerProps extends Pick<AvatarButtonProps, "src" | "name" | "size"> {
|
|
12
13
|
}
|
|
14
|
+
interface NavLinkButtonTriggerProps extends Pick<NavLinkProps, "active" | "variant" | "icon"> {
|
|
15
|
+
navLabel: string;
|
|
16
|
+
}
|
|
13
17
|
export interface OverlayTriggerProps {
|
|
14
|
-
trigger: TextButtonTriggerProps | IconButtonTriggerProps | AvatarButtonTriggerProps;
|
|
18
|
+
trigger: TextButtonTriggerProps | IconButtonTriggerProps | AvatarButtonTriggerProps | NavLinkButtonTriggerProps;
|
|
15
19
|
/** Defaults to "left" */
|
|
16
20
|
placement?: "left" | "right";
|
|
17
21
|
/** Whether the Button is disabled. If a ReactNode, it's treated as a "disabled reason" that's shown in a tooltip. */
|
|
@@ -30,10 +34,12 @@ export interface OverlayTriggerProps {
|
|
|
30
34
|
variant?: ButtonVariant;
|
|
31
35
|
hideEndAdornment?: boolean;
|
|
32
36
|
showActiveBorder?: boolean;
|
|
37
|
+
contrast?: boolean;
|
|
33
38
|
}
|
|
34
39
|
export declare function OverlayTrigger(props: OverlayTriggerProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
35
|
-
export declare function isTextButton(trigger: TextButtonTriggerProps | IconButtonTriggerProps | AvatarButtonTriggerProps): trigger is TextButtonTriggerProps;
|
|
36
|
-
export declare function isIconButton(trigger: TextButtonTriggerProps | IconButtonTriggerProps | AvatarButtonTriggerProps): trigger is IconButtonTriggerProps;
|
|
40
|
+
export declare function isTextButton(trigger: TextButtonTriggerProps | IconButtonTriggerProps | AvatarButtonTriggerProps | NavLinkButtonTriggerProps): trigger is TextButtonTriggerProps;
|
|
41
|
+
export declare function isIconButton(trigger: TextButtonTriggerProps | IconButtonTriggerProps | AvatarButtonTriggerProps | NavLinkButtonTriggerProps): trigger is IconButtonTriggerProps;
|
|
42
|
+
export declare function isNavLinkButton(trigger: TextButtonTriggerProps | IconButtonTriggerProps | AvatarButtonTriggerProps | NavLinkButtonTriggerProps): trigger is NavLinkButtonTriggerProps;
|
|
37
43
|
export declare function labelOr(trigger: {
|
|
38
44
|
label: unknown;
|
|
39
45
|
}, fallback: string): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.labelOr = exports.isIconButton = exports.isTextButton = exports.OverlayTrigger = void 0;
|
|
3
|
+
exports.labelOr = exports.isNavLinkButton = exports.isIconButton = exports.isTextButton = exports.OverlayTrigger = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const react_aria_1 = require("react-aria");
|
|
@@ -9,11 +9,12 @@ const Button_1 = require("../Button");
|
|
|
9
9
|
const Icon_1 = require("../Icon");
|
|
10
10
|
const IconButton_1 = require("../IconButton");
|
|
11
11
|
const internal_1 = require("./");
|
|
12
|
+
const NavLink_1 = require("../NavLink");
|
|
12
13
|
const Css_1 = require("../../Css");
|
|
13
14
|
const utils_1 = require("../../utils");
|
|
14
15
|
const defaultTestId_1 = require("../../utils/defaultTestId");
|
|
15
16
|
function OverlayTrigger(props) {
|
|
16
|
-
const { trigger, buttonRef, menuTriggerProps, placement, state, disabled, tooltip, children, variant, hideEndAdornment, showActiveBorder = false, } = props;
|
|
17
|
+
const { trigger, buttonRef, menuTriggerProps, placement, state, disabled, tooltip, children, variant, hideEndAdornment, showActiveBorder = false, contrast = false, } = props;
|
|
17
18
|
const popoverRef = (0, react_1.useRef)(null);
|
|
18
19
|
const { overlayProps: positionProps } = (0, react_aria_1.useOverlayPosition)({
|
|
19
20
|
targetRef: buttonRef,
|
|
@@ -26,10 +27,12 @@ function OverlayTrigger(props) {
|
|
|
26
27
|
});
|
|
27
28
|
const tid = (0, utils_1.useTestIds)(props, isTextButton(trigger)
|
|
28
29
|
? (0, defaultTestId_1.defaultTestId)(labelOr(trigger, "overlayTrigger"))
|
|
29
|
-
:
|
|
30
|
-
? trigger.
|
|
31
|
-
: trigger
|
|
32
|
-
|
|
30
|
+
: isNavLinkButton(trigger)
|
|
31
|
+
? (0, defaultTestId_1.defaultTestId)(trigger.navLabel)
|
|
32
|
+
: isIconButton(trigger)
|
|
33
|
+
? trigger.icon
|
|
34
|
+
: trigger.name);
|
|
35
|
+
return ((0, jsx_runtime_1.jsxs)("div", { css: Css_1.Css.relative.dib.$, children: [isTextButton(trigger) ? ((0, jsx_runtime_1.jsx)(Button_1.Button, { variant: variant ? variant : "secondary", contrast: contrast, ...trigger, menuTriggerProps: menuTriggerProps, buttonRef: buttonRef, endAdornment: !hideEndAdornment ? (0, jsx_runtime_1.jsx)(Icon_1.Icon, { icon: state.isOpen ? "chevronUp" : "chevronDown" }) : null, disabled: disabled, tooltip: tooltip, onClick: utils_1.noop, forceFocusStyles: showActiveBorder && state.isOpen, ...tid })) : isNavLinkButton(trigger) ? ((0, jsx_runtime_1.jsx)(NavLink_1.NavLink, { ...trigger, label: trigger.navLabel, disabled: !!disabled, contrast: contrast, menuTriggerProps: menuTriggerProps, buttonRef: buttonRef, ...tid })) : isIconButton(trigger) ? ((0, jsx_runtime_1.jsx)(IconButton_1.IconButton, { ...trigger, menuTriggerProps: menuTriggerProps, buttonRef: buttonRef, ...tid, disabled: disabled, tooltip: tooltip, onClick: utils_1.noop, forceFocusStyles: showActiveBorder && state.isOpen })) : ((0, jsx_runtime_1.jsx)(AvatarButton_1.AvatarButton, { ...trigger, menuTriggerProps: menuTriggerProps, buttonRef: buttonRef, ...tid, disabled: disabled, tooltip: tooltip, onClick: utils_1.noop, forceFocusStyles: showActiveBorder && state.isOpen })), state.isOpen && ((0, jsx_runtime_1.jsx)(internal_1.Popover, { triggerRef: buttonRef, popoverRef: popoverRef, positionProps: positionProps, onClose: () => state.close(), isOpen: state.isOpen, children: children }))] }));
|
|
33
36
|
}
|
|
34
37
|
exports.OverlayTrigger = OverlayTrigger;
|
|
35
38
|
function isTextButton(trigger) {
|
|
@@ -40,6 +43,10 @@ function isIconButton(trigger) {
|
|
|
40
43
|
return trigger && typeof trigger === "object" && "icon" in trigger;
|
|
41
44
|
}
|
|
42
45
|
exports.isIconButton = isIconButton;
|
|
46
|
+
function isNavLinkButton(trigger) {
|
|
47
|
+
return trigger && typeof trigger === "object" && "navLabel" in trigger;
|
|
48
|
+
}
|
|
49
|
+
exports.isNavLinkButton = isNavLinkButton;
|
|
43
50
|
function labelOr(trigger, fallback) {
|
|
44
51
|
return typeof trigger.label === "string" ? trigger.label : fallback;
|
|
45
52
|
}
|