@launchpad-ui/menu 0.2.6 → 0.3.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/Menu.d.ts +3 -2
- package/dist/Menu.d.ts.map +1 -1
- package/dist/MenuBase.d.ts +6 -2
- package/dist/MenuBase.d.ts.map +1 -1
- package/dist/MenuDivider.d.ts +1 -1
- package/dist/MenuDivider.d.ts.map +1 -1
- package/dist/MenuItem.d.ts +2 -2
- package/dist/MenuItem.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +29 -17
- package/dist/index.es.js.map +3 -3
- package/dist/index.js +31 -18
- package/dist/index.js.map +3 -3
- package/dist/styles/Menu.css +1 -1
- package/dist/styles/Menu.css.map +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +5 -4
package/dist/Menu.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
+
import type { MenuSize } from './types';
|
2
|
+
import type { FocusManager } from '@react-aria/focus';
|
1
3
|
import type { ReactElement } from 'react';
|
2
|
-
import { FocusManager } from '@react-aria/focus';
|
3
4
|
declare type ControlledMenuProps<T> = {
|
4
5
|
children: React.ReactNode;
|
5
6
|
onSelect?: (item: T) => void;
|
@@ -17,7 +18,7 @@ declare type ControlledMenuProps<T> = {
|
|
17
18
|
* Sets the width of the menu. This is especially useful when using virtual items
|
18
19
|
* since the width cannot be automatically set by the widest element.
|
19
20
|
*/
|
20
|
-
|
21
|
+
size?: MenuSize;
|
21
22
|
/**
|
22
23
|
* Sets the number out of elements rendered outside of the view window
|
23
24
|
* when using virtualization
|
package/dist/Menu.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Menu.d.ts","sourceRoot":"","sources":["../src/Menu.tsx"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"Menu.d.ts","sourceRoot":"","sources":["../src/Menu.tsx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
|
2
3
|
import './styles/Menu.css';
|
3
|
-
declare type MenuBaseProps = React.ComponentPropsWithRef<'div'
|
4
|
-
|
4
|
+
declare type MenuBaseProps = React.ComponentPropsWithRef<'div'> & {
|
5
|
+
isVirtual?: boolean;
|
6
|
+
size?: MenuSize;
|
7
|
+
};
|
8
|
+
declare const MenuBase: import("react").ForwardRefExoticComponent<Pick<MenuBaseProps, "key" | "size" | keyof import("react").HTMLAttributes<HTMLDivElement> | "isVirtual"> & import("react").RefAttributes<HTMLDivElement>>;
|
5
9
|
export { MenuBase };
|
6
10
|
export type { MenuBaseProps };
|
7
11
|
//# sourceMappingURL=MenuBase.d.ts.map
|
package/dist/MenuBase.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"MenuBase.d.ts","sourceRoot":"","sources":["../src/MenuBase.tsx"],"names":[],"mappings":";
|
1
|
+
{"version":3,"file":"MenuBase.d.ts","sourceRoot":"","sources":["../src/MenuBase.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAKxC,OAAO,mBAAmB,CAAC;AAE3B,aAAK,aAAa,GAAG,KAAK,CAAC,qBAAqB,CAAC,KAAK,CAAC,GAAG;IACxD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,IAAI,CAAC,EAAE,QAAQ,CAAC;CACjB,CAAC;AAEF,QAAA,MAAM,QAAQ,qMAab,CAAC;AAIF,OAAO,EAAE,QAAQ,EAAE,CAAC;AACpB,YAAY,EAAE,aAAa,EAAE,CAAC"}
|
package/dist/MenuDivider.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/// <reference types="react" />
|
2
|
-
import { SeparatorProps } from '@react-aria/separator';
|
2
|
+
import type { SeparatorProps } from '@react-aria/separator';
|
3
3
|
import './styles/Menu.css';
|
4
4
|
declare type MenuDividerProps = SeparatorProps & {
|
5
5
|
innerRef?: React.RefObject<HTMLDivElement>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"MenuDivider.d.ts","sourceRoot":"","sources":["../src/MenuDivider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,
|
1
|
+
{"version":3,"file":"MenuDivider.d.ts","sourceRoot":"","sources":["../src/MenuDivider.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAI5D,OAAO,mBAAmB,CAAC;AAE3B,aAAK,gBAAgB,GAAG,cAAc,GAAG;IACvC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;CAC5C,CAAC;AAEF,QAAA,MAAM,WAAW,2CAAoD,gBAAgB,gBAOpF,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC;AACvB,YAAY,EAAE,gBAAgB,EAAE,CAAC"}
|
package/dist/MenuItem.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/// <reference types="react" />
|
2
|
+
import type { Icon } from '@launchpad-ui/icons';
|
2
3
|
import type { PopoverPlacement } from '@launchpad-ui/popover';
|
3
|
-
import { Icon } from '@launchpad-ui/icons';
|
4
4
|
import { Tooltip } from '@launchpad-ui/tooltip';
|
5
5
|
import { Link } from 'react-router-dom';
|
6
6
|
import './styles/Menu.css';
|
@@ -15,10 +15,10 @@ declare type MenuItemOwnProps = {
|
|
15
15
|
disabled?: boolean;
|
16
16
|
nested?: boolean;
|
17
17
|
groupHeader?: boolean;
|
18
|
-
innerRef?: React.RefObject<HTMLDivElement>;
|
19
18
|
tooltip?: string | React.ReactElement;
|
20
19
|
tooltipOptions?: typeof Tooltip;
|
21
20
|
tooltipPlacement?: PopoverPlacement;
|
21
|
+
asChild?: boolean;
|
22
22
|
};
|
23
23
|
declare const defaultElement = "button";
|
24
24
|
declare type MenuItemProps<P, T extends React.ElementType = typeof defaultElement> = PolymorphicPropsWithRef<(MenuItemOwnProps & {
|
package/dist/MenuItem.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"MenuItem.d.ts","sourceRoot":"","sources":["../src/MenuItem.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,
|
1
|
+
{"version":3,"file":"MenuItem.d.ts","sourceRoot":"","sources":["../src/MenuItem.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAG9D,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAIhD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,OAAO,mBAAmB,CAAC;AAG3B,aAAK,KAAK,CAAC,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC;AAExC,aAAK,kBAAkB,CAAC,CAAC,EAAE,CAAC,SAAS,KAAK,CAAC,WAAW,IAAI,CAAC,GAAG;IAAE,SAAS,CAAC,EAAE,CAAC,CAAA;CAAE,CAAC;AAEhF,aAAK,uBAAuB,CAAC,CAAC,EAAE,CAAC,SAAS,KAAK,CAAC,WAAW,IAAI,KAAK,CAClE,CAAC,SAAS,MAAM,GAAG,CAAC,iBAAiB,GACjC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,GAC5C,KAAK,CAAC,qBAAqB,CAAC,CAAC,CAAC,EAClC,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CACzB,CAAC;AAEF,aAAK,gBAAgB,GAAG;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,IAAI,CAAC,EAAE,OAAO,IAAI,GAAG,IAAI,CAAC;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,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AM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.es.js
CHANGED
@@ -5,11 +5,15 @@ import * as React from "react";
|
|
5
5
|
import cx from "clsx";
|
6
6
|
import { forwardRef } from "react";
|
7
7
|
import "./styles/Menu.css";
|
8
|
-
var MenuBase = forwardRef(({ children, ...props }, ref) => {
|
9
|
-
const
|
8
|
+
var MenuBase = forwardRef(({ children, size, isVirtual, ...props }, ref) => {
|
9
|
+
const classes = cx("Menu", {
|
10
|
+
"Menu--isVirtual": isVirtual,
|
11
|
+
[`MenuSize--${size}`]: size
|
12
|
+
});
|
10
13
|
return /* @__PURE__ */ React.createElement("div", {
|
11
14
|
...props,
|
12
|
-
|
15
|
+
role: "menu",
|
16
|
+
className: classes,
|
13
17
|
ref
|
14
18
|
}, children);
|
15
19
|
});
|
@@ -33,6 +37,7 @@ var MenuDivider = ({ elementType = "div", orientation, innerRef }) => {
|
|
33
37
|
// src/MenuItem.tsx
|
34
38
|
import { IconSize } from "@launchpad-ui/icons";
|
35
39
|
import { Tooltip } from "@launchpad-ui/tooltip";
|
40
|
+
import { Slot } from "@radix-ui/react-slot";
|
36
41
|
import { FocusRing } from "@react-aria/focus";
|
37
42
|
import cx2 from "clsx";
|
38
43
|
import { Link } from "react-router-dom";
|
@@ -45,36 +50,35 @@ var MenuItem = ({
|
|
45
50
|
component,
|
46
51
|
children,
|
47
52
|
isHighlighted,
|
48
|
-
icon:
|
53
|
+
icon: Icon,
|
49
54
|
nested,
|
50
55
|
groupHeader,
|
51
56
|
item,
|
52
57
|
disabled,
|
53
58
|
className,
|
54
|
-
innerRef,
|
55
59
|
tooltip,
|
56
60
|
role = "menuitem",
|
57
61
|
tooltipPlacement,
|
58
62
|
onKeyDown,
|
59
63
|
tooltipOptions,
|
64
|
+
asChild,
|
60
65
|
...rest
|
61
66
|
} = props;
|
62
|
-
const Component = component || defaultElement;
|
67
|
+
const Component = component || (asChild ? Slot : defaultElement);
|
63
68
|
const renderedItem = /* @__PURE__ */ React.createElement(FocusRing, {
|
64
69
|
focusRingClass: "has-focus"
|
65
70
|
}, /* @__PURE__ */ React.createElement(Component, {
|
66
71
|
...rest,
|
67
|
-
ref: innerRef,
|
68
72
|
disabled,
|
69
73
|
"aria-disabled": disabled ? disabled : void 0,
|
70
74
|
className: cx2("Menu-item", className, { "is-highlighted": isHighlighted }, { "Menu-item--nested": nested }, { "Menu-item--header": groupHeader }),
|
71
75
|
role,
|
72
76
|
onKeyDown
|
73
|
-
},
|
77
|
+
}, asChild ? children : /* @__PURE__ */ React.createElement(React.Fragment, null, Icon && /* @__PURE__ */ React.createElement("span", {
|
74
78
|
className: "Menu-item-icon"
|
75
|
-
}, /* @__PURE__ */ React.createElement(
|
79
|
+
}, /* @__PURE__ */ React.createElement(Icon, {
|
76
80
|
size: IconSize.SMALL
|
77
|
-
})), children));
|
81
|
+
})), children)));
|
78
82
|
if (tooltip) {
|
79
83
|
return /* @__PURE__ */ React.createElement(Tooltip, {
|
80
84
|
content: tooltip,
|
@@ -175,7 +179,7 @@ var Menu = (props) => {
|
|
175
179
|
onSelect,
|
176
180
|
enableVirtualization,
|
177
181
|
itemHeight,
|
178
|
-
|
182
|
+
size,
|
179
183
|
overscan = 1
|
180
184
|
} = props;
|
181
185
|
const focusManager = useFocusManager();
|
@@ -246,11 +250,10 @@ var Menu = (props) => {
|
|
246
250
|
}
|
247
251
|
}, { items: [], searchElement: null });
|
248
252
|
}, [children, enableVirtualization, menuItemClassName, handleArrowDown, handleArrowUp, onSelect]);
|
249
|
-
const menuClassName = cx3({ "Menu--isVirtual": enableVirtualization }, { [`MenuSize--${menuWidth}`]: menuWidth });
|
250
253
|
if (enableVirtualization) {
|
251
254
|
return /* @__PURE__ */ React.createElement(MenuBase, {
|
252
|
-
|
253
|
-
|
255
|
+
isVirtual: true,
|
256
|
+
size
|
254
257
|
}, /* @__PURE__ */ React.createElement(ItemVirtualizer, {
|
255
258
|
items: Children.toArray(reduceItems.items),
|
256
259
|
searchElement: reduceItems.searchElement,
|
@@ -262,8 +265,7 @@ var Menu = (props) => {
|
|
262
265
|
}));
|
263
266
|
}
|
264
267
|
return /* @__PURE__ */ React.createElement(MenuBase, {
|
265
|
-
|
266
|
-
className: menuClassName
|
268
|
+
size
|
267
269
|
}, reduceItems.searchElement, /* @__PURE__ */ React.createElement(MenuItemList, {
|
268
270
|
role: "presentation"
|
269
271
|
}, reduceItems.items));
|
@@ -406,6 +408,15 @@ var ItemVirtualizer = (props) => {
|
|
406
408
|
}
|
407
409
|
}, renderItems)));
|
408
410
|
};
|
411
|
+
|
412
|
+
// src/types.ts
|
413
|
+
var MenuSize = /* @__PURE__ */ ((MenuSize2) => {
|
414
|
+
MenuSize2["SMALL"] = "sm";
|
415
|
+
MenuSize2["MEDIUM"] = "md";
|
416
|
+
MenuSize2["LARGE"] = "lg";
|
417
|
+
MenuSize2["EXTRA_LARGE"] = "xl";
|
418
|
+
return MenuSize2;
|
419
|
+
})(MenuSize || {});
|
409
420
|
export {
|
410
421
|
Menu,
|
411
422
|
MenuBase,
|
@@ -413,6 +424,7 @@ export {
|
|
413
424
|
MenuItem,
|
414
425
|
MenuItemLink,
|
415
426
|
MenuItemList,
|
416
|
-
MenuSearch
|
427
|
+
MenuSearch,
|
428
|
+
MenuSize
|
417
429
|
};
|
418
430
|
//# sourceMappingURL=index.es.js.map
|
package/dist/index.es.js.map
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
|
-
"sources": ["../../../scripts/react-shim.js", "../src/MenuBase.tsx", "../src/MenuDivider.tsx", "../src/MenuItem.tsx", "../src/MenuItemList.tsx", "../src/MenuSearch.tsx", "../src/Menu.tsx", "../src/utils.ts"],
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import cx from 'clsx';\nimport { forwardRef } from 'react';\n\nimport './styles/Menu.css';\n\ntype MenuBaseProps = React.ComponentPropsWithRef<'div'>;\n\n// This is the pure presentational component that contains menu items\nconst MenuBase = forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(\n ({ children, ...props }, ref) => {\n const className = cx('Menu', props.className);\n return (\n <div {...props} className={className} ref={ref}>\n {children}\n </div>\n );\n }\n);\n\nMenuBase.displayName = 'MenuBase';\n\nexport { MenuBase };\nexport type { MenuBaseProps };\n", "import { SeparatorProps, useSeparator } from '@react-aria/separator';\n\nimport './styles/Menu.css';\n\ntype MenuDividerProps = SeparatorProps & {\n innerRef?: React.RefObject<HTMLDivElement>;\n};\n\nconst MenuDivider = ({ elementType = 'div', orientation, innerRef }: MenuDividerProps) => {\n const { separatorProps } = useSeparator({\n orientation,\n elementType,\n });\n\n return <div {...separatorProps} ref={innerRef} className=\"Menu-divider\" />;\n};\n\nexport { MenuDivider };\nexport type { MenuDividerProps };\n", "import type { PopoverPlacement } from '@launchpad-ui/popover';\n\nimport { Icon, IconSize } from '@launchpad-ui/icons';\nimport { Tooltip } from '@launchpad-ui/tooltip';\nimport { FocusRing } from '@react-aria/focus';\nimport cx from 'clsx';\nimport { Link } from 'react-router-dom';\n\nimport './styles/Menu.css';\n\n// Merge two types and get rid of overlapping definitions\ntype Merge<T, U> = Omit<T, keyof U> & U;\n\ntype PropsWithComponent<P, T extends React.ElementType> = P & { component?: T };\n\ntype PolymorphicPropsWithRef<P, T extends React.ElementType> = Merge<\n T extends keyof JSX.IntrinsicElements\n ? React.PropsWithRef<JSX.IntrinsicElements[T]>\n : React.ComponentPropsWithRef<T>,\n PropsWithComponent<P, T>\n>;\n\ntype MenuItemOwnProps = {\n isHighlighted?: boolean;\n icon?: typeof Icon | null;\n disabled?: boolean;\n nested?: boolean;\n groupHeader?: boolean;\n innerRef?: React.RefObject<HTMLDivElement>;\n tooltip?: string | React.ReactElement;\n tooltipOptions?: typeof Tooltip;\n tooltipPlacement?: PopoverPlacement;\n};\n\nconst defaultElement = 'button';\n\ntype MenuItemProps<\n P,\n T extends React.ElementType = typeof defaultElement\n> = PolymorphicPropsWithRef<\n | (MenuItemOwnProps & {\n item: P; // Infer the type if it is included\n })\n | (MenuItemOwnProps & {\n item?: undefined;\n }),\n T\n>;\n\nconst MenuItem = <P, T extends React.ElementType = typeof defaultElement>({\n ...props\n}: MenuItemProps<P, T>) => {\n const {\n component,\n children,\n isHighlighted,\n icon: Icon,\n nested,\n groupHeader,\n item,\n disabled,\n className,\n innerRef,\n tooltip,\n role = 'menuitem',\n tooltipPlacement,\n onKeyDown,\n tooltipOptions,\n ...rest\n } = props;\n\n const Component: React.ElementType = component || defaultElement;\n\n const renderedItem = (\n <FocusRing focusRingClass=\"has-focus\">\n <Component\n {...rest}\n ref={innerRef}\n disabled={disabled}\n aria-disabled={disabled ? disabled : undefined}\n className={cx(\n 'Menu-item',\n className,\n { 'is-highlighted': isHighlighted },\n { 'Menu-item--nested': nested },\n { 'Menu-item--header': groupHeader }\n )}\n role={role}\n onKeyDown={onKeyDown}\n >\n {Icon && (\n <span className=\"Menu-item-icon\">\n <Icon size={IconSize.SMALL} />\n </span>\n )}\n {children}\n </Component>\n </FocusRing>\n );\n\n if (tooltip) {\n return (\n <Tooltip\n content={tooltip}\n rootElementStyle={{ display: 'block' }}\n allowBoundaryElementOverflow\n placement={tooltipPlacement ? tooltipPlacement : 'bottom'}\n {...(tooltipOptions || {})}\n >\n {renderedItem}\n </Tooltip>\n );\n }\n\n return renderedItem;\n};\n\ntype MenuItemLinkOwnProps = {\n disabled?: boolean;\n useHistory?: boolean;\n newTab?: boolean;\n};\n\ntype MenuItemLinkProps<P, T extends React.ElementType = typeof Link> =\n | Merge<Omit<MenuItemProps<P, T>, 'component' | 'item'>, MenuItemLinkOwnProps> &\n (\n | {\n item?: undefined;\n }\n | {\n item: P;\n }\n );\n\n// By default, this is a Link component whenever useHistory is\n// explicitly not false\nconst MenuItemLink = <P, T extends React.ElementType = typeof Link>({\n to,\n disabled = false,\n useHistory = true,\n newTab = false,\n children,\n ...props\n}: MenuItemLinkProps<P, T>) => {\n const finalProps = {\n ...props,\n disabled,\n component: useHistory ? Link : ('a' as const),\n [useHistory ? 'to' : 'href']: disabled ? '' : to,\n rel: newTab ? 'noopener noreferrer' : undefined,\n target: newTab ? '_blank' : undefined,\n };\n\n // Ideally if this item is disabled, it should be a button rather\n // than a link https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-is-valid.md\n\n return <MenuItem {...finalProps}>{children}</MenuItem>;\n};\n\nexport { MenuItem, MenuItemLink };\nexport type { MenuItemProps, MenuItemLinkProps };\n", "import { forwardRef } from 'react';\n\nimport './styles/Menu.css';\n\ntype MenuItemListProps = Omit<React.ComponentPropsWithRef<'div'>, 'className'>;\n\nconst MenuItemList = forwardRef<HTMLDivElement, MenuItemListProps>(({ children, ...rest }, ref) => (\n <div {...rest} ref={ref} data-test-id=\"menu-item-list\" className=\"Menu-item-list\">\n {children}\n </div>\n));\n\nMenuItemList.displayName = 'MenuItemList';\n\nexport { MenuItemList };\nexport type { MenuItemListProps };\n", "import type { ChangeEvent } from 'react';\n\nimport { forwardRef } from 'react';\n\nimport './styles/Menu.css';\n\ntype MenuSearchProps = {\n ariaLabel?: string;\n value?: string;\n placeholder?: string;\n onChange?(event: ChangeEvent<HTMLInputElement>): void;\n};\n\nconst MenuSearch = forwardRef<HTMLInputElement, MenuSearchProps>((props, ref) => {\n const { ariaLabel, placeholder, ...finalProps } = props;\n\n return (\n <div className=\"Menu-search\">\n <input\n {...finalProps}\n ref={ref}\n className=\"Menu-search-input FormInput FormInput--tiny\"\n type=\"search\"\n autoComplete=\"off\"\n placeholder={placeholder}\n aria-label={ariaLabel || 'Search'}\n />\n <div\n className=\"Menu-search-hidden-placeholder Menu-search-input FormInput FormInput--tiny\"\n aria-hidden=\"true\"\n >\n {placeholder}\n </div>\n </div>\n );\n});\n\nMenuSearch.displayName = 'MenuSearch';\n\nexport { MenuSearch };\nexport type { MenuSearchProps };\n", "import type { KeyboardEvent, ReactElement } from 'react';\n\nimport { FocusManager, useFocusManager } from '@react-aria/focus';\nimport cx from 'clsx';\nimport { isNil, noop } from 'lodash-es';\nimport { Children, cloneElement, useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { useVirtual } from 'react-virtual';\nimport { v4 } from 'uuid';\n\nimport { MenuBase } from './MenuBase';\nimport { MenuDivider } from './MenuDivider';\nimport { MenuItem, MenuItemLink, MenuItemProps } from './MenuItem';\nimport { MenuItemList } from './MenuItemList';\nimport { MenuSearch } from './MenuSearch';\nimport {\n chainEventHandlers,\n createItemId,\n getNodeForIndex,\n handleKeyboardInteractions,\n} from './utils';\n\ntype ControlledMenuProps<T> = {\n children: React.ReactNode;\n onSelect?: (item: T) => void;\n /**\n * Menus items are rendered using react-virtual for\n * additional rendering performance.\n */\n enableVirtualization?: boolean;\n /**\n * Class name to be applied to all MenuItem and MenuItemLink components\n * in the menu.\n */\n menuItemClassName?: string;\n /**\n * Sets the width of the menu. This is especially useful when using virtual items\n * since the width cannot be automatically set by the widest element.\n */\n menuWidth?: 'tiny' | 'small' | 'med' | 'large' | 'xLarge';\n /**\n * Sets the number out of elements rendered outside of the view window\n * when using virtualization\n */\n overscan?: number;\n /**\n * Sets the height for each menu item when using virtualization.\n *\n */\n itemHeight?: number;\n};\n\ntype MenuProps<T extends number | string> = ControlledMenuProps<T>;\n\nconst Menu = <T extends number | string>(props: MenuProps<T>) => {\n const {\n children,\n menuItemClassName,\n onSelect,\n enableVirtualization,\n itemHeight,\n menuWidth,\n overscan = 1,\n } = props;\n\n const focusManager = useFocusManager();\n\n const handleArrowDown = useCallback(() => {\n focusManager.focusNext({ wrap: true });\n }, [focusManager]);\n\n const handleArrowUp = useCallback(() => {\n focusManager.focusPrevious({ wrap: true });\n }, [focusManager]);\n\n const reduceItems = useMemo(() => {\n const childrenProps = Children.toArray(children);\n if (enableVirtualization) {\n // the virtualized menu has its own handlers and props\n let searchElem = null;\n let elements: ReactElement[] = [];\n (childrenProps as ReactElement[]).forEach((child: ReactElement) => {\n switch (child.type) {\n case MenuSearch:\n searchElem = child;\n break;\n case MenuItem:\n case MenuItemLink:\n case MenuDivider:\n elements = elements.concat(child);\n break;\n default:\n break;\n }\n });\n return { items: elements, searchElement: searchElem };\n }\n\n return (childrenProps as ReactElement[]).reduce(\n (\n { items, searchElement }: { items: ReactElement[]; searchElement: null | ReactElement },\n child\n ) => {\n switch (child.type) {\n case MenuSearch:\n return {\n items,\n searchElement: cloneElement(child, {\n onKeyDown: (e: KeyboardEvent) =>\n handleKeyboardInteractions(e, {\n handleDown: handleArrowDown,\n handleUp: handleArrowUp,\n }),\n }),\n };\n case MenuItem:\n case MenuItemLink:\n return {\n items: items.concat(\n child.props.disabled\n ? cloneElement(child, {\n onClick: noop,\n onKeyDown: noop,\n tabIndex: -1,\n disabled: true,\n })\n : cloneElement(child, {\n className: cx(child.props.className, menuItemClassName),\n item: child.props.item ?? items.length,\n // set focus on the first menu item if there is no search input, and set in the tab order\n onClick: chainEventHandlers(child.props.onClick, () => {\n onSelect?.(child.props.item ?? items.length);\n }),\n onKeyDown: (e: KeyboardEvent) =>\n handleKeyboardInteractions(e, {\n handleDown: handleArrowDown,\n handleUp: handleArrowUp,\n }),\n })\n ),\n searchElement,\n };\n case MenuDivider:\n return { items: items.concat(child), searchElement };\n default:\n return { items, searchElement };\n }\n },\n { items: [], searchElement: null }\n );\n }, [children, enableVirtualization, menuItemClassName, handleArrowDown, handleArrowUp, onSelect]);\n\n const menuClassName = cx(\n { 'Menu--isVirtual': enableVirtualization },\n { [`MenuSize--${menuWidth}`]: menuWidth }\n );\n\n if (enableVirtualization) {\n return (\n <MenuBase role=\"menu\" className={menuClassName}>\n <ItemVirtualizer<T>\n items={Children.toArray(reduceItems.items) as ReactElement[]}\n searchElement={reduceItems.searchElement}\n overscan={overscan}\n menuItemClassName={menuItemClassName}\n onSelect={onSelect}\n itemHeight={itemHeight}\n focusManager={focusManager}\n />\n </MenuBase>\n );\n }\n\n return (\n <MenuBase role=\"menu\" className={menuClassName}>\n {reduceItems.searchElement}\n <MenuItemList role=\"presentation\">{reduceItems.items}</MenuItemList>\n </MenuBase>\n );\n};\n\ntype ItemVirtualizerProps<T> = Omit<ControlledMenuProps<T>, 'children'> & {\n items: ReactElement[] | null;\n searchElement?: React.ReactElement | null;\n focusManager: FocusManager;\n};\n\nconst ItemVirtualizer = <T extends number | string>(props: ItemVirtualizerProps<T>) => {\n const {\n overscan,\n searchElement,\n itemHeight = 33,\n menuItemClassName,\n items: items,\n focusManager,\n onSelect,\n } = props;\n\n const menuId = useRef(`menu-ctrl-${v4()}`);\n\n const focusedItemIndex = useRef<number | null>(null);\n const parentRef = useRef<HTMLDivElement | null>(null);\n const searchRef = useRef<HTMLInputElement>();\n\n const [nextFocusValue, setNextFocusValue] = useState<number | null>(null);\n\n const hasSearch = !!searchElement;\n\n const lastVirtualItemIndex = items ? items.length - 1 : 0;\n\n const rowVirtualizer = useVirtual({\n size: items !== null ? items.length : 0,\n parentRef,\n estimateSize: useCallback(() => itemHeight, [itemHeight]),\n overscan,\n });\n\n const focusSearchBar = useCallback(() => {\n rowVirtualizer.scrollToIndex(0);\n searchRef.current?.focus?.();\n }, [rowVirtualizer]);\n\n /**\n * Scrolls to the menu item with the index provided and\n * then manually focuses it using a side effect in useEffect\n */\n const focusMenuItem = useCallback(\n (index: number) => {\n rowVirtualizer.scrollToIndex(index);\n setNextFocusValue(index);\n },\n [rowVirtualizer]\n );\n\n const handleKeyboardFocusInteraction = useCallback(\n (direction: 'next' | 'previous') => {\n if (isNil(focusedItemIndex.current)) {\n return;\n }\n const nextIndex =\n direction === 'next' ? focusedItemIndex.current + 1 : focusedItemIndex.current - 1;\n const shouldWrap =\n (direction === 'next' && focusedItemIndex.current === lastVirtualItemIndex) ||\n (direction === 'previous' && focusedItemIndex.current === 0);\n if (shouldWrap) {\n // we are at the end of the list so we will\n // scroll back to the beginning of the list\n if (hasSearch) {\n focusSearchBar();\n } else {\n // if at end, wrap to beginning, else focus last item\n focusMenuItem(direction === 'next' ? 0 : lastVirtualItemIndex);\n }\n return;\n }\n switch (direction) {\n case 'next':\n rowVirtualizer.scrollToIndex(nextIndex);\n focusManager.focusNext();\n break;\n case 'previous':\n rowVirtualizer.scrollToIndex(nextIndex);\n focusManager.focusPrevious();\n break;\n default:\n break;\n }\n },\n [focusManager, focusMenuItem, focusSearchBar, hasSearch, lastVirtualItemIndex, rowVirtualizer]\n );\n\n const getItemProps = useCallback(\n (itemElem: ReactElement, index: number) => {\n const childProps = itemElem.props as MenuItemProps<T>;\n switch (itemElem.type) {\n case MenuItem:\n case MenuItemLink:\n return {\n className: cx(childProps.className, menuItemClassName),\n // set focus on the first menu item if there is no search input, and set in the tab order\n onKeyDown: childProps.disabled\n ? noop\n : (e: KeyboardEvent) =>\n handleKeyboardFocusKeydown(e, {\n handleFocusBackward: handleKeyboardFocusInteraction,\n handleFocusForward: handleKeyboardFocusInteraction,\n }),\n onFocus: chainEventHandlers(childProps.onFocus, () => {\n focusedItemIndex.current = index;\n }),\n id: createItemId(index, menuId.current),\n onBlur: chainEventHandlers(childProps.onBlur, () => {\n focusedItemIndex.current = null;\n }),\n onClick: childProps.disabled\n ? noop\n : chainEventHandlers(childProps.onClick, () => {\n onSelect?.(childProps.item as T);\n }),\n } as MenuItemProps<T>;\n default:\n return {};\n }\n },\n [handleKeyboardFocusInteraction, menuItemClassName, onSelect]\n );\n\n useEffect(() => {\n if (nextFocusValue !== null) {\n requestAnimationFrame(() => {\n const element = getNodeForIndex(nextFocusValue, menuId.current);\n element?.focus();\n });\n setNextFocusValue(null);\n }\n }, [nextFocusValue]);\n\n /**\n * Calls handleFocusForward when the user is attempting to focus forward using\n * tab or arrow keys. Calls handleFocusBackward when the users wants to move backward.\n */\n const handleKeyboardFocusKeydown = (\n e: KeyboardEvent,\n callbacks: Record<\n 'handleFocusForward' | 'handleFocusBackward',\n (direction: 'next' | 'previous') => void\n >\n ) => {\n const keyOps = ['Tab', 'ArrowUp', 'ArrowDown'];\n if (keyOps.includes(e.key)) {\n e.preventDefault();\n e.stopPropagation();\n if ((e.key === 'Tab' && e.shiftKey) || e.key === 'ArrowUp') {\n callbacks.handleFocusBackward?.('previous');\n } else if (e.key === 'ArrowDown' || e.key === 'Tab') {\n callbacks.handleFocusForward?.('next');\n }\n }\n };\n\n const renderSearch = useMemo(\n () =>\n searchElement\n ? cloneElement(searchElement, {\n onKeyDown: (e: KeyboardEvent) =>\n handleKeyboardFocusKeydown(e, {\n handleFocusBackward: () => focusMenuItem(lastVirtualItemIndex),\n handleFocusForward: () => focusMenuItem(0),\n }),\n ref: searchRef,\n })\n : null,\n [searchElement, lastVirtualItemIndex, focusMenuItem]\n );\n\n const renderItems = useMemo(\n () =>\n rowVirtualizer.virtualItems.map((virtualRow) => {\n if (!items) {\n return null;\n }\n const elem = items[virtualRow.index];\n return (\n <div\n key={virtualRow.index}\n ref={\n elem.type !== MenuItem || elem.type !== MenuItemLink\n ? virtualRow.measureRef\n : undefined\n }\n role=\"presentation\"\n className={cx('VirtualMenu-item')}\n style={{\n transform: `translateY(${virtualRow.start}px)`,\n }}\n >\n {cloneElement(elem, getItemProps(elem, virtualRow.index))}\n </div>\n );\n }),\n [rowVirtualizer.virtualItems, items, getItemProps]\n );\n\n return (\n <>\n {renderSearch}\n <MenuItemList ref={parentRef} role=\"presentation\">\n <div\n role=\"presentation\"\n className=\"VirtualMenu-item-list\"\n style={{\n height: `${rowVirtualizer.totalSize}px`,\n }}\n >\n {renderItems}\n </div>\n </MenuItemList>\n </>\n );\n};\n\nexport { Menu, ItemVirtualizer };\nexport type { MenuProps, ItemVirtualizerProps };\n", "import type { KeyboardEvent } from 'react';\n\nimport { isFunction } from 'lodash-es';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyFunction = (...args: any[]) => any;\n\nconst createItemId = (index: number, id: string) => `${id}-item-${index}`;\n\nconst getNodeForIndex = (index: number | null, menuId: string) =>\n index === null ? index : document.getElementById(createItemId(index, menuId));\n\nconst handleKeyboardInteractions = (\n event: React.KeyboardEvent,\n keyHandlers: Partial<\n Record<'handleUp' | 'handleDown' | 'handleEnter', (e: KeyboardEvent) => void>\n >\n) => {\n const ops = {\n ArrowUp: keyHandlers.handleUp,\n ArrowDown: keyHandlers.handleDown,\n Enter: keyHandlers.handleEnter,\n } as Record<string, (e: KeyboardEvent) => void | undefined>;\n\n if (ops[event.key]) {\n event.preventDefault();\n ops[event.key]?.call(globalThis, event);\n }\n};\n\nconst chainEventHandlers =\n (...handlers: Array<AnyFunction | undefined>) =>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (event: any) => {\n handlers.forEach((h) => isFunction(h) && h(event));\n };\n\nexport { createItemId, getNodeForIndex, handleKeyboardInteractions, chainEventHandlers };\n"],
|
5
|
-
"mappings": ";AAAA;;;
|
3
|
+
"sources": ["../../../scripts/react-shim.js", "../src/MenuBase.tsx", "../src/MenuDivider.tsx", "../src/MenuItem.tsx", "../src/MenuItemList.tsx", "../src/MenuSearch.tsx", "../src/Menu.tsx", "../src/utils.ts", "../src/types.ts"],
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import type { MenuSize } from './types';\n\nimport cx from 'clsx';\nimport { forwardRef } from 'react';\n\nimport './styles/Menu.css';\n\ntype MenuBaseProps = React.ComponentPropsWithRef<'div'> & {\n isVirtual?: boolean;\n size?: MenuSize;\n};\n\nconst MenuBase = forwardRef<HTMLDivElement, MenuBaseProps>(\n ({ children, size, isVirtual, ...props }, ref) => {\n const classes = cx('Menu', {\n 'Menu--isVirtual': isVirtual,\n [`MenuSize--${size}`]: size,\n });\n\n return (\n <div {...props} role=\"menu\" className={classes} ref={ref}>\n {children}\n </div>\n );\n }\n);\n\nMenuBase.displayName = 'MenuBase';\n\nexport { MenuBase };\nexport type { MenuBaseProps };\n", "import type { SeparatorProps } from '@react-aria/separator';\n\nimport { useSeparator } from '@react-aria/separator';\n\nimport './styles/Menu.css';\n\ntype MenuDividerProps = SeparatorProps & {\n innerRef?: React.RefObject<HTMLDivElement>;\n};\n\nconst MenuDivider = ({ elementType = 'div', orientation, innerRef }: MenuDividerProps) => {\n const { separatorProps } = useSeparator({\n orientation,\n elementType,\n });\n\n return <div {...separatorProps} ref={innerRef} className=\"Menu-divider\" />;\n};\n\nexport { MenuDivider };\nexport type { MenuDividerProps };\n", "import type { Icon } from '@launchpad-ui/icons';\nimport type { PopoverPlacement } from '@launchpad-ui/popover';\n\nimport { IconSize } from '@launchpad-ui/icons';\nimport { Tooltip } from '@launchpad-ui/tooltip';\nimport { Slot } from '@radix-ui/react-slot';\nimport { FocusRing } from '@react-aria/focus';\nimport cx from 'clsx';\nimport { Link } from 'react-router-dom';\n\nimport './styles/Menu.css';\n\n// Merge two types and get rid of overlapping definitions\ntype Merge<T, U> = Omit<T, keyof U> & U;\n\ntype PropsWithComponent<P, T extends React.ElementType> = P & { component?: T };\n\ntype PolymorphicPropsWithRef<P, T extends React.ElementType> = Merge<\n T extends keyof JSX.IntrinsicElements\n ? React.PropsWithRef<JSX.IntrinsicElements[T]>\n : React.ComponentPropsWithRef<T>,\n PropsWithComponent<P, T>\n>;\n\ntype MenuItemOwnProps = {\n isHighlighted?: boolean;\n icon?: typeof Icon | null;\n disabled?: boolean;\n nested?: boolean;\n groupHeader?: boolean;\n tooltip?: string | React.ReactElement;\n tooltipOptions?: typeof Tooltip;\n tooltipPlacement?: PopoverPlacement;\n asChild?: boolean;\n};\n\nconst defaultElement = 'button';\n\ntype MenuItemProps<\n P,\n T extends React.ElementType = typeof defaultElement\n> = PolymorphicPropsWithRef<\n | (MenuItemOwnProps & {\n item: P; // Infer the type if it is included\n })\n | (MenuItemOwnProps & {\n item?: undefined;\n }),\n T\n>;\n\nconst MenuItem = <P, T extends React.ElementType = typeof defaultElement>({\n ...props\n}: MenuItemProps<P, T>) => {\n const {\n // TODO: remove component prop once we migrate over to asChild format\n component,\n children,\n isHighlighted,\n icon: Icon,\n nested,\n groupHeader,\n item,\n disabled,\n className,\n tooltip,\n role = 'menuitem',\n tooltipPlacement,\n onKeyDown,\n tooltipOptions,\n asChild,\n ...rest\n } = props;\n\n const Component: React.ElementType = component || (asChild ? Slot : defaultElement);\n\n const renderedItem = (\n <FocusRing focusRingClass=\"has-focus\">\n <Component\n {...rest}\n disabled={disabled}\n aria-disabled={disabled ? disabled : undefined}\n className={cx(\n 'Menu-item',\n className,\n { 'is-highlighted': isHighlighted },\n { 'Menu-item--nested': nested },\n { 'Menu-item--header': groupHeader }\n )}\n role={role}\n onKeyDown={onKeyDown}\n >\n {asChild ? (\n children\n ) : (\n <>\n {Icon && (\n <span className=\"Menu-item-icon\">\n <Icon size={IconSize.SMALL} />\n </span>\n )}\n {children}\n </>\n )}\n </Component>\n </FocusRing>\n );\n\n if (tooltip) {\n return (\n <Tooltip\n content={tooltip}\n rootElementStyle={{ display: 'block' }}\n allowBoundaryElementOverflow\n placement={tooltipPlacement ? tooltipPlacement : 'bottom'}\n {...(tooltipOptions || {})}\n >\n {renderedItem}\n </Tooltip>\n );\n }\n\n return renderedItem;\n};\n\ntype MenuItemLinkOwnProps = {\n disabled?: boolean;\n useHistory?: boolean;\n newTab?: boolean;\n};\n\ntype MenuItemLinkProps<P, T extends React.ElementType = typeof Link> =\n | Merge<Omit<MenuItemProps<P, T>, 'component' | 'item'>, MenuItemLinkOwnProps> &\n (\n | {\n item?: undefined;\n }\n | {\n item: P;\n }\n );\n\n// By default, this is a Link component whenever useHistory is\n// explicitly not false\n// TODO: deprecate this component\nconst MenuItemLink = <P, T extends React.ElementType = typeof Link>({\n to,\n disabled = false,\n useHistory = true,\n newTab = false,\n children,\n ...props\n}: MenuItemLinkProps<P, T>) => {\n const finalProps = {\n ...props,\n disabled,\n component: useHistory ? Link : ('a' as const),\n [useHistory ? 'to' : 'href']: disabled ? '' : to,\n rel: newTab ? 'noopener noreferrer' : undefined,\n target: newTab ? '_blank' : undefined,\n };\n\n // Ideally if this item is disabled, it should be a button rather\n // than a link https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-is-valid.md\n\n return <MenuItem {...finalProps}>{children}</MenuItem>;\n};\n\nexport { MenuItem, MenuItemLink };\nexport type { MenuItemProps, MenuItemLinkProps };\n", "import { forwardRef } from 'react';\n\nimport './styles/Menu.css';\n\ntype MenuItemListProps = Omit<React.ComponentPropsWithRef<'div'>, 'className'>;\n\nconst MenuItemList = forwardRef<HTMLDivElement, MenuItemListProps>(({ children, ...rest }, ref) => (\n <div {...rest} ref={ref} data-test-id=\"menu-item-list\" className=\"Menu-item-list\">\n {children}\n </div>\n));\n\nMenuItemList.displayName = 'MenuItemList';\n\nexport { MenuItemList };\nexport type { MenuItemListProps };\n", "import type { ChangeEvent } from 'react';\n\nimport { forwardRef } from 'react';\n\nimport './styles/Menu.css';\n\ntype MenuSearchProps = {\n ariaLabel?: string;\n value?: string;\n placeholder?: string;\n onChange?(event: ChangeEvent<HTMLInputElement>): void;\n};\n\nconst MenuSearch = forwardRef<HTMLInputElement, MenuSearchProps>((props, ref) => {\n const { ariaLabel, placeholder, ...finalProps } = props;\n\n return (\n <div className=\"Menu-search\">\n <input\n {...finalProps}\n ref={ref}\n className=\"Menu-search-input FormInput FormInput--tiny\"\n type=\"search\"\n autoComplete=\"off\"\n placeholder={placeholder}\n aria-label={ariaLabel || 'Search'}\n />\n <div\n className=\"Menu-search-hidden-placeholder Menu-search-input FormInput FormInput--tiny\"\n aria-hidden=\"true\"\n >\n {placeholder}\n </div>\n </div>\n );\n});\n\nMenuSearch.displayName = 'MenuSearch';\n\nexport { MenuSearch };\nexport type { MenuSearchProps };\n", "import type { MenuItemProps } from './MenuItem';\nimport type { MenuSize } from './types';\nimport type { FocusManager } from '@react-aria/focus';\nimport type { KeyboardEvent, ReactElement } from 'react';\n\nimport { useFocusManager } from '@react-aria/focus';\nimport cx from 'clsx';\nimport { isNil, noop } from 'lodash-es';\nimport { Children, cloneElement, useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { useVirtual } from 'react-virtual';\nimport { v4 } from 'uuid';\n\nimport { MenuBase } from './MenuBase';\nimport { MenuDivider } from './MenuDivider';\nimport { MenuItem, MenuItemLink } from './MenuItem';\nimport { MenuItemList } from './MenuItemList';\nimport { MenuSearch } from './MenuSearch';\nimport {\n chainEventHandlers,\n createItemId,\n getNodeForIndex,\n handleKeyboardInteractions,\n} from './utils';\n\ntype ControlledMenuProps<T> = {\n children: React.ReactNode;\n onSelect?: (item: T) => void;\n /**\n * Menus items are rendered using react-virtual for\n * additional rendering performance.\n */\n enableVirtualization?: boolean;\n /**\n * Class name to be applied to all MenuItem and MenuItemLink components\n * in the menu.\n */\n menuItemClassName?: string;\n /**\n * Sets the width of the menu. This is especially useful when using virtual items\n * since the width cannot be automatically set by the widest element.\n */\n size?: MenuSize;\n /**\n * Sets the number out of elements rendered outside of the view window\n * when using virtualization\n */\n overscan?: number;\n /**\n * Sets the height for each menu item when using virtualization.\n *\n */\n itemHeight?: number;\n};\n\ntype MenuProps<T extends number | string> = ControlledMenuProps<T>;\n\nconst Menu = <T extends number | string>(props: MenuProps<T>) => {\n const {\n children,\n menuItemClassName,\n onSelect,\n enableVirtualization,\n itemHeight,\n size,\n overscan = 1,\n } = props;\n\n const focusManager = useFocusManager();\n\n const handleArrowDown = useCallback(() => {\n focusManager.focusNext({ wrap: true });\n }, [focusManager]);\n\n const handleArrowUp = useCallback(() => {\n focusManager.focusPrevious({ wrap: true });\n }, [focusManager]);\n\n const reduceItems = useMemo(() => {\n const childrenProps = Children.toArray(children);\n if (enableVirtualization) {\n // the virtualized menu has its own handlers and props\n let searchElem = null;\n let elements: ReactElement[] = [];\n (childrenProps as ReactElement[]).forEach((child: ReactElement) => {\n switch (child.type) {\n case MenuSearch:\n searchElem = child;\n break;\n case MenuItem:\n case MenuItemLink:\n case MenuDivider:\n elements = elements.concat(child);\n break;\n default:\n break;\n }\n });\n return { items: elements, searchElement: searchElem };\n }\n\n return (childrenProps as ReactElement[]).reduce(\n (\n { items, searchElement }: { items: ReactElement[]; searchElement: null | ReactElement },\n child\n ) => {\n switch (child.type) {\n case MenuSearch:\n return {\n items,\n searchElement: cloneElement(child, {\n onKeyDown: (e: KeyboardEvent) =>\n handleKeyboardInteractions(e, {\n handleDown: handleArrowDown,\n handleUp: handleArrowUp,\n }),\n }),\n };\n case MenuItem:\n case MenuItemLink:\n return {\n items: items.concat(\n child.props.disabled\n ? cloneElement(child, {\n onClick: noop,\n onKeyDown: noop,\n tabIndex: -1,\n disabled: true,\n })\n : cloneElement(child, {\n className: cx(child.props.className, menuItemClassName),\n item: child.props.item ?? items.length,\n // set focus on the first menu item if there is no search input, and set in the tab order\n onClick: chainEventHandlers(child.props.onClick, () => {\n onSelect?.(child.props.item ?? items.length);\n }),\n onKeyDown: (e: KeyboardEvent) =>\n handleKeyboardInteractions(e, {\n handleDown: handleArrowDown,\n handleUp: handleArrowUp,\n }),\n })\n ),\n searchElement,\n };\n case MenuDivider:\n return { items: items.concat(child), searchElement };\n default:\n return { items, searchElement };\n }\n },\n { items: [], searchElement: null }\n );\n }, [children, enableVirtualization, menuItemClassName, handleArrowDown, handleArrowUp, onSelect]);\n\n if (enableVirtualization) {\n return (\n <MenuBase isVirtual size={size}>\n <ItemVirtualizer<T>\n items={Children.toArray(reduceItems.items) as ReactElement[]}\n searchElement={reduceItems.searchElement}\n overscan={overscan}\n menuItemClassName={menuItemClassName}\n onSelect={onSelect}\n itemHeight={itemHeight}\n focusManager={focusManager}\n />\n </MenuBase>\n );\n }\n\n return (\n <MenuBase size={size}>\n {reduceItems.searchElement}\n <MenuItemList role=\"presentation\">{reduceItems.items}</MenuItemList>\n </MenuBase>\n );\n};\n\ntype ItemVirtualizerProps<T> = Omit<ControlledMenuProps<T>, 'children'> & {\n items: ReactElement[] | null;\n searchElement?: React.ReactElement | null;\n focusManager: FocusManager;\n};\n\nconst ItemVirtualizer = <T extends number | string>(props: ItemVirtualizerProps<T>) => {\n const {\n overscan,\n searchElement,\n itemHeight = 33,\n menuItemClassName,\n items: items,\n focusManager,\n onSelect,\n } = props;\n\n const menuId = useRef(`menu-ctrl-${v4()}`);\n\n const focusedItemIndex = useRef<number | null>(null);\n const parentRef = useRef<HTMLDivElement | null>(null);\n const searchRef = useRef<HTMLInputElement>();\n\n const [nextFocusValue, setNextFocusValue] = useState<number | null>(null);\n\n const hasSearch = !!searchElement;\n\n const lastVirtualItemIndex = items ? items.length - 1 : 0;\n\n const rowVirtualizer = useVirtual({\n size: items !== null ? items.length : 0,\n parentRef,\n estimateSize: useCallback(() => itemHeight, [itemHeight]),\n overscan,\n });\n\n const focusSearchBar = useCallback(() => {\n rowVirtualizer.scrollToIndex(0);\n searchRef.current?.focus?.();\n }, [rowVirtualizer]);\n\n /**\n * Scrolls to the menu item with the index provided and\n * then manually focuses it using a side effect in useEffect\n */\n const focusMenuItem = useCallback(\n (index: number) => {\n rowVirtualizer.scrollToIndex(index);\n setNextFocusValue(index);\n },\n [rowVirtualizer]\n );\n\n const handleKeyboardFocusInteraction = useCallback(\n (direction: 'next' | 'previous') => {\n if (isNil(focusedItemIndex.current)) {\n return;\n }\n const nextIndex =\n direction === 'next' ? focusedItemIndex.current + 1 : focusedItemIndex.current - 1;\n const shouldWrap =\n (direction === 'next' && focusedItemIndex.current === lastVirtualItemIndex) ||\n (direction === 'previous' && focusedItemIndex.current === 0);\n if (shouldWrap) {\n // we are at the end of the list so we will\n // scroll back to the beginning of the list\n if (hasSearch) {\n focusSearchBar();\n } else {\n // if at end, wrap to beginning, else focus last item\n focusMenuItem(direction === 'next' ? 0 : lastVirtualItemIndex);\n }\n return;\n }\n switch (direction) {\n case 'next':\n rowVirtualizer.scrollToIndex(nextIndex);\n focusManager.focusNext();\n break;\n case 'previous':\n rowVirtualizer.scrollToIndex(nextIndex);\n focusManager.focusPrevious();\n break;\n default:\n break;\n }\n },\n [focusManager, focusMenuItem, focusSearchBar, hasSearch, lastVirtualItemIndex, rowVirtualizer]\n );\n\n const getItemProps = useCallback(\n (itemElem: ReactElement, index: number) => {\n const childProps = itemElem.props as MenuItemProps<T>;\n switch (itemElem.type) {\n case MenuItem:\n case MenuItemLink:\n return {\n className: cx(childProps.className, menuItemClassName),\n // set focus on the first menu item if there is no search input, and set in the tab order\n onKeyDown: childProps.disabled\n ? noop\n : (e: KeyboardEvent) =>\n handleKeyboardFocusKeydown(e, {\n handleFocusBackward: handleKeyboardFocusInteraction,\n handleFocusForward: handleKeyboardFocusInteraction,\n }),\n onFocus: chainEventHandlers(childProps.onFocus, () => {\n focusedItemIndex.current = index;\n }),\n id: createItemId(index, menuId.current),\n onBlur: chainEventHandlers(childProps.onBlur, () => {\n focusedItemIndex.current = null;\n }),\n onClick: childProps.disabled\n ? noop\n : chainEventHandlers(childProps.onClick, () => {\n onSelect?.(childProps.item as T);\n }),\n } as MenuItemProps<T>;\n default:\n return {};\n }\n },\n [handleKeyboardFocusInteraction, menuItemClassName, onSelect]\n );\n\n useEffect(() => {\n if (nextFocusValue !== null) {\n requestAnimationFrame(() => {\n const element = getNodeForIndex(nextFocusValue, menuId.current);\n element?.focus();\n });\n setNextFocusValue(null);\n }\n }, [nextFocusValue]);\n\n /**\n * Calls handleFocusForward when the user is attempting to focus forward using\n * tab or arrow keys. Calls handleFocusBackward when the users wants to move backward.\n */\n const handleKeyboardFocusKeydown = (\n e: KeyboardEvent,\n callbacks: Record<\n 'handleFocusForward' | 'handleFocusBackward',\n (direction: 'next' | 'previous') => void\n >\n ) => {\n const keyOps = ['Tab', 'ArrowUp', 'ArrowDown'];\n if (keyOps.includes(e.key)) {\n e.preventDefault();\n e.stopPropagation();\n if ((e.key === 'Tab' && e.shiftKey) || e.key === 'ArrowUp') {\n callbacks.handleFocusBackward?.('previous');\n } else if (e.key === 'ArrowDown' || e.key === 'Tab') {\n callbacks.handleFocusForward?.('next');\n }\n }\n };\n\n const renderSearch = useMemo(\n () =>\n searchElement\n ? cloneElement(searchElement, {\n onKeyDown: (e: KeyboardEvent) =>\n handleKeyboardFocusKeydown(e, {\n handleFocusBackward: () => focusMenuItem(lastVirtualItemIndex),\n handleFocusForward: () => focusMenuItem(0),\n }),\n ref: searchRef,\n })\n : null,\n [searchElement, lastVirtualItemIndex, focusMenuItem]\n );\n\n const renderItems = useMemo(\n () =>\n rowVirtualizer.virtualItems.map((virtualRow) => {\n if (!items) {\n return null;\n }\n const elem = items[virtualRow.index];\n return (\n <div\n key={virtualRow.index}\n ref={\n elem.type !== MenuItem || elem.type !== MenuItemLink\n ? virtualRow.measureRef\n : undefined\n }\n role=\"presentation\"\n className={cx('VirtualMenu-item')}\n style={{\n transform: `translateY(${virtualRow.start}px)`,\n }}\n >\n {cloneElement(elem, getItemProps(elem, virtualRow.index))}\n </div>\n );\n }),\n [rowVirtualizer.virtualItems, items, getItemProps]\n );\n\n return (\n <>\n {renderSearch}\n <MenuItemList ref={parentRef} role=\"presentation\">\n <div\n role=\"presentation\"\n className=\"VirtualMenu-item-list\"\n style={{\n height: `${rowVirtualizer.totalSize}px`,\n }}\n >\n {renderItems}\n </div>\n </MenuItemList>\n </>\n );\n};\n\nexport { Menu, ItemVirtualizer };\nexport type { MenuProps, ItemVirtualizerProps };\n", "import type { KeyboardEvent } from 'react';\n\nimport { isFunction } from 'lodash-es';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyFunction = (...args: any[]) => any;\n\nconst createItemId = (index: number, id: string) => `${id}-item-${index}`;\n\nconst getNodeForIndex = (index: number | null, menuId: string) =>\n index === null ? index : document.getElementById(createItemId(index, menuId));\n\nconst handleKeyboardInteractions = (\n event: React.KeyboardEvent,\n keyHandlers: Partial<\n Record<'handleUp' | 'handleDown' | 'handleEnter', (e: KeyboardEvent) => void>\n >\n) => {\n const ops = {\n ArrowUp: keyHandlers.handleUp,\n ArrowDown: keyHandlers.handleDown,\n Enter: keyHandlers.handleEnter,\n } as Record<string, (e: KeyboardEvent) => void | undefined>;\n\n if (ops[event.key]) {\n event.preventDefault();\n ops[event.key]?.call(globalThis, event);\n }\n};\n\nconst chainEventHandlers =\n (...handlers: Array<AnyFunction | undefined>) =>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (event: any) => {\n handlers.forEach((h) => isFunction(h) && h(event));\n };\n\nexport { createItemId, getNodeForIndex, handleKeyboardInteractions, chainEventHandlers };\n", "enum MenuSize {\n SMALL = 'sm',\n MEDIUM = 'md',\n LARGE = 'lg',\n EXTRA_LARGE = 'xl',\n}\n\nexport { MenuSize };\n"],
|
5
|
+
"mappings": ";AAAA;;;ACEA;AACA;AAEA;AAOA,IAAM,WAAW,WACf,CAAC,EAAE,UAAU,MAAM,cAAc,SAAS,QAAQ;AAChD,QAAM,UAAU,GAAG,QAAQ;AAAA,IACzB,mBAAmB;AAAA,IACnB,CAAC,aAAa,SAAS;AAAA,EACzB,CAAC;AAED,SACE,oCAAC;AAAA,IAAK,GAAG;AAAA,IAAO,MAAK;AAAA,IAAO,WAAW;AAAA,IAAS;AAAA,KAC7C,QACH;AAEJ,CACF;AAEA,SAAS,cAAc;;;ACzBvB;AAEA;AAMA,IAAM,cAAc,CAAC,EAAE,cAAc,OAAO,aAAa,eAAiC;AACxF,QAAM,EAAE,mBAAmB,aAAa;AAAA,IACtC;AAAA,IACA;AAAA,EACF,CAAC;AAED,SAAO,oCAAC;AAAA,IAAK,GAAG;AAAA,IAAgB,KAAK;AAAA,IAAU,WAAU;AAAA,GAAe;AAC1E;;;ACdA;AACA;AACA;AACA;AACA;AACA;AAEA;AA0BA,IAAM,iBAAiB;AAevB,IAAM,WAAW,CAAyD;AAAA,KACrE;AAAA,MACsB;AACzB,QAAM;AAAA,IAEJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,OACG;AAAA,MACD;AAEJ,QAAM,YAA+B,a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AA,IACT;AACA,UAAM,OAAO,MAAM,WAAW;AAC9B,WACE,oCAAC;AAAA,MACC,KAAK,WAAW;AAAA,MAChB,KACE,KAAK,SAAS,YAAY,KAAK,SAAS,eACpC,WAAW,aACX;AAAA,MAEN,MAAK;AAAA,MACL,WAAW,IAAG,kBAAkB;AAAA,MAChC,OAAO;AAAA,QACL,WAAW,cAAc,WAAW;AAAA,MACtC;AAAA,OAEC,aAAa,MAAM,aAAa,MAAM,WAAW,KAAK,CAAC,CAC1D;AAAA,EAEJ,CAAC,GACH,CAAC,eAAe,cAAc,OAAO,YAAY,CACnD;AAEA,SACE,0DACG,cACD,oCAAC;AAAA,IAAa,KAAK;AAAA,IAAW,MAAK;AAAA,KACjC,oCAAC;AAAA,IACC,MAAK;AAAA,IACL,WAAU;AAAA,IACV,OAAO;AAAA,MACL,QAAQ,GAAG,eAAe;AAAA,IAC5B;AAAA,KAEC,WACH,CACF,CACF;AAEJ;;;AE5YA,IAAK,WAAL,kBAAK,cAAL;AACE,uBAAQ;AACR,wBAAS;AACT,uBAAQ;AACR,6BAAc;AAJX;AAAA;",
|
6
6
|
"names": []
|
7
7
|
}
|
package/dist/index.js
CHANGED
@@ -29,7 +29,8 @@ __export(src_exports, {
|
|
29
29
|
MenuItem: () => MenuItem,
|
30
30
|
MenuItemLink: () => MenuItemLink,
|
31
31
|
MenuItemList: () => MenuItemList,
|
32
|
-
MenuSearch: () => MenuSearch
|
32
|
+
MenuSearch: () => MenuSearch,
|
33
|
+
MenuSize: () => MenuSize
|
33
34
|
});
|
34
35
|
module.exports = __toCommonJS(src_exports);
|
35
36
|
|
@@ -40,11 +41,15 @@ var React = __toESM(require("react"));
|
|
40
41
|
var import_clsx = __toESM(require("clsx"));
|
41
42
|
var import_react = require("react");
|
42
43
|
var import_Menu = require("./styles/Menu.css");
|
43
|
-
var MenuBase = (0, import_react.forwardRef)(({ children, ...props }, ref) => {
|
44
|
-
const
|
44
|
+
var MenuBase = (0, import_react.forwardRef)(({ children, size, isVirtual, ...props }, ref) => {
|
45
|
+
const classes = (0, import_clsx.default)("Menu", {
|
46
|
+
"Menu--isVirtual": isVirtual,
|
47
|
+
[`MenuSize--${size}`]: size
|
48
|
+
});
|
45
49
|
return /* @__PURE__ */ React.createElement("div", {
|
46
50
|
...props,
|
47
|
-
|
51
|
+
role: "menu",
|
52
|
+
className: classes,
|
48
53
|
ref
|
49
54
|
}, children);
|
50
55
|
});
|
@@ -68,6 +73,7 @@ var MenuDivider = ({ elementType = "div", orientation, innerRef }) => {
|
|
68
73
|
// src/MenuItem.tsx
|
69
74
|
var import_icons = require("@launchpad-ui/icons");
|
70
75
|
var import_tooltip = require("@launchpad-ui/tooltip");
|
76
|
+
var import_react_slot = require("@radix-ui/react-slot");
|
71
77
|
var import_focus = require("@react-aria/focus");
|
72
78
|
var import_clsx2 = __toESM(require("clsx"));
|
73
79
|
var import_react_router_dom = require("react-router-dom");
|
@@ -80,36 +86,35 @@ var MenuItem = ({
|
|
80
86
|
component,
|
81
87
|
children,
|
82
88
|
isHighlighted,
|
83
|
-
icon:
|
89
|
+
icon: Icon,
|
84
90
|
nested,
|
85
91
|
groupHeader,
|
86
92
|
item,
|
87
93
|
disabled,
|
88
94
|
className,
|
89
|
-
innerRef,
|
90
95
|
tooltip,
|
91
96
|
role = "menuitem",
|
92
97
|
tooltipPlacement,
|
93
98
|
onKeyDown,
|
94
99
|
tooltipOptions,
|
100
|
+
asChild,
|
95
101
|
...rest
|
96
102
|
} = props;
|
97
|
-
const Component = component || defaultElement;
|
103
|
+
const Component = component || (asChild ? import_react_slot.Slot : defaultElement);
|
98
104
|
const renderedItem = /* @__PURE__ */ React.createElement(import_focus.FocusRing, {
|
99
105
|
focusRingClass: "has-focus"
|
100
106
|
}, /* @__PURE__ */ React.createElement(Component, {
|
101
107
|
...rest,
|
102
|
-
ref: innerRef,
|
103
108
|
disabled,
|
104
109
|
"aria-disabled": disabled ? disabled : void 0,
|
105
110
|
className: (0, import_clsx2.default)("Menu-item", className, { "is-highlighted": isHighlighted }, { "Menu-item--nested": nested }, { "Menu-item--header": groupHeader }),
|
106
111
|
role,
|
107
112
|
onKeyDown
|
108
|
-
},
|
113
|
+
}, asChild ? children : /* @__PURE__ */ React.createElement(React.Fragment, null, Icon && /* @__PURE__ */ React.createElement("span", {
|
109
114
|
className: "Menu-item-icon"
|
110
|
-
}, /* @__PURE__ */ React.createElement(
|
115
|
+
}, /* @__PURE__ */ React.createElement(Icon, {
|
111
116
|
size: import_icons.IconSize.SMALL
|
112
|
-
})), children));
|
117
|
+
})), children)));
|
113
118
|
if (tooltip) {
|
114
119
|
return /* @__PURE__ */ React.createElement(import_tooltip.Tooltip, {
|
115
120
|
content: tooltip,
|
@@ -210,7 +215,7 @@ var Menu = (props) => {
|
|
210
215
|
onSelect,
|
211
216
|
enableVirtualization,
|
212
217
|
itemHeight,
|
213
|
-
|
218
|
+
size,
|
214
219
|
overscan = 1
|
215
220
|
} = props;
|
216
221
|
const focusManager = (0, import_focus2.useFocusManager)();
|
@@ -281,11 +286,10 @@ var Menu = (props) => {
|
|
281
286
|
}
|
282
287
|
}, { items: [], searchElement: null });
|
283
288
|
}, [children, enableVirtualization, menuItemClassName, handleArrowDown, handleArrowUp, onSelect]);
|
284
|
-
const menuClassName = (0, import_clsx3.default)({ "Menu--isVirtual": enableVirtualization }, { [`MenuSize--${menuWidth}`]: menuWidth });
|
285
289
|
if (enableVirtualization) {
|
286
290
|
return /* @__PURE__ */ React.createElement(MenuBase, {
|
287
|
-
|
288
|
-
|
291
|
+
isVirtual: true,
|
292
|
+
size
|
289
293
|
}, /* @__PURE__ */ React.createElement(ItemVirtualizer, {
|
290
294
|
items: import_react4.Children.toArray(reduceItems.items),
|
291
295
|
searchElement: reduceItems.searchElement,
|
@@ -297,8 +301,7 @@ var Menu = (props) => {
|
|
297
301
|
}));
|
298
302
|
}
|
299
303
|
return /* @__PURE__ */ React.createElement(MenuBase, {
|
300
|
-
|
301
|
-
className: menuClassName
|
304
|
+
size
|
302
305
|
}, reduceItems.searchElement, /* @__PURE__ */ React.createElement(MenuItemList, {
|
303
306
|
role: "presentation"
|
304
307
|
}, reduceItems.items));
|
@@ -441,6 +444,15 @@ var ItemVirtualizer = (props) => {
|
|
441
444
|
}
|
442
445
|
}, renderItems)));
|
443
446
|
};
|
447
|
+
|
448
|
+
// src/types.ts
|
449
|
+
var MenuSize = /* @__PURE__ */ ((MenuSize2) => {
|
450
|
+
MenuSize2["SMALL"] = "sm";
|
451
|
+
MenuSize2["MEDIUM"] = "md";
|
452
|
+
MenuSize2["LARGE"] = "lg";
|
453
|
+
MenuSize2["EXTRA_LARGE"] = "xl";
|
454
|
+
return MenuSize2;
|
455
|
+
})(MenuSize || {});
|
444
456
|
// Annotate the CommonJS export names for ESM import in node:
|
445
457
|
0 && (module.exports = {
|
446
458
|
Menu,
|
@@ -449,6 +461,7 @@ var ItemVirtualizer = (props) => {
|
|
449
461
|
MenuItem,
|
450
462
|
MenuItemLink,
|
451
463
|
MenuItemList,
|
452
|
-
MenuSearch
|
464
|
+
MenuSearch,
|
465
|
+
MenuSize
|
453
466
|
});
|
454
467
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
|
-
"sources": ["../src/index.ts", "../../../scripts/react-shim.js", "../src/MenuBase.tsx", "../src/MenuDivider.tsx", "../src/MenuItem.tsx", "../src/MenuItemList.tsx", "../src/MenuSearch.tsx", "../src/Menu.tsx", "../src/utils.ts"],
|
4
|
-
"sourcesContent": ["export type { MenuBaseProps } from './MenuBase';\nexport type { MenuDividerProps } from './MenuDivider';\nexport type { MenuItemProps, MenuItemLinkProps } from './MenuItem';\nexport type { MenuItemListProps } from './MenuItemList';\nexport type { MenuSearchProps } from './MenuSearch';\nexport type { MenuProps } from './Menu';\nexport { MenuBase } from './MenuBase';\nexport { MenuDivider } from './MenuDivider';\nexport { MenuItem, MenuItemLink } from './MenuItem';\nexport { MenuItemList } from './MenuItemList';\nexport { MenuSearch } from './MenuSearch';\nexport { Menu } from './Menu';\n", "import * as React from 'react';\nexport { React };\n", "import cx from 'clsx';\nimport { forwardRef } from 'react';\n\nimport './styles/Menu.css';\n\ntype MenuBaseProps = React.ComponentPropsWithRef<'div'>;\n\n// This is the pure presentational component that contains menu items\nconst MenuBase = forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(\n ({ children, ...props }, ref) => {\n const className = cx('Menu', props.className);\n return (\n <div {...props} className={className} ref={ref}>\n {children}\n </div>\n );\n }\n);\n\nMenuBase.displayName = 'MenuBase';\n\nexport { MenuBase };\nexport type { MenuBaseProps };\n", "import { SeparatorProps, useSeparator } from '@react-aria/separator';\n\nimport './styles/Menu.css';\n\ntype MenuDividerProps = SeparatorProps & {\n innerRef?: React.RefObject<HTMLDivElement>;\n};\n\nconst MenuDivider = ({ elementType = 'div', orientation, innerRef }: MenuDividerProps) => {\n const { separatorProps } = useSeparator({\n orientation,\n elementType,\n });\n\n return <div {...separatorProps} ref={innerRef} className=\"Menu-divider\" />;\n};\n\nexport { MenuDivider };\nexport type { MenuDividerProps };\n", "import type { PopoverPlacement } from '@launchpad-ui/popover';\n\nimport { Icon, IconSize } from '@launchpad-ui/icons';\nimport { Tooltip } from '@launchpad-ui/tooltip';\nimport { FocusRing } from '@react-aria/focus';\nimport cx from 'clsx';\nimport { Link } from 'react-router-dom';\n\nimport './styles/Menu.css';\n\n// Merge two types and get rid of overlapping definitions\ntype Merge<T, U> = Omit<T, keyof U> & U;\n\ntype PropsWithComponent<P, T extends React.ElementType> = P & { component?: T };\n\ntype PolymorphicPropsWithRef<P, T extends React.ElementType> = Merge<\n T extends keyof JSX.IntrinsicElements\n ? React.PropsWithRef<JSX.IntrinsicElements[T]>\n : React.ComponentPropsWithRef<T>,\n PropsWithComponent<P, T>\n>;\n\ntype MenuItemOwnProps = {\n isHighlighted?: boolean;\n icon?: typeof Icon | null;\n disabled?: boolean;\n nested?: boolean;\n groupHeader?: boolean;\n innerRef?: React.RefObject<HTMLDivElement>;\n tooltip?: string | React.ReactElement;\n tooltipOptions?: typeof Tooltip;\n tooltipPlacement?: PopoverPlacement;\n};\n\nconst defaultElement = 'button';\n\ntype MenuItemProps<\n P,\n T extends React.ElementType = typeof defaultElement\n> = PolymorphicPropsWithRef<\n | (MenuItemOwnProps & {\n item: P; // Infer the type if it is included\n })\n | (MenuItemOwnProps & {\n item?: undefined;\n }),\n T\n>;\n\nconst MenuItem = <P, T extends React.ElementType = typeof defaultElement>({\n ...props\n}: MenuItemProps<P, T>) => {\n const {\n component,\n children,\n isHighlighted,\n icon: Icon,\n nested,\n groupHeader,\n item,\n disabled,\n className,\n innerRef,\n tooltip,\n role = 'menuitem',\n tooltipPlacement,\n onKeyDown,\n tooltipOptions,\n ...rest\n } = props;\n\n const Component: React.ElementType = component || defaultElement;\n\n const renderedItem = (\n <FocusRing focusRingClass=\"has-focus\">\n <Component\n {...rest}\n ref={innerRef}\n disabled={disabled}\n aria-disabled={disabled ? disabled : undefined}\n className={cx(\n 'Menu-item',\n className,\n { 'is-highlighted': isHighlighted },\n { 'Menu-item--nested': nested },\n { 'Menu-item--header': groupHeader }\n )}\n role={role}\n onKeyDown={onKeyDown}\n >\n {Icon && (\n <span className=\"Menu-item-icon\">\n <Icon size={IconSize.SMALL} />\n </span>\n )}\n {children}\n </Component>\n </FocusRing>\n );\n\n if (tooltip) {\n return (\n <Tooltip\n content={tooltip}\n rootElementStyle={{ display: 'block' }}\n allowBoundaryElementOverflow\n placement={tooltipPlacement ? tooltipPlacement : 'bottom'}\n {...(tooltipOptions || {})}\n >\n {renderedItem}\n </Tooltip>\n );\n }\n\n return renderedItem;\n};\n\ntype MenuItemLinkOwnProps = {\n disabled?: boolean;\n useHistory?: boolean;\n newTab?: boolean;\n};\n\ntype MenuItemLinkProps<P, T extends React.ElementType = typeof Link> =\n | Merge<Omit<MenuItemProps<P, T>, 'component' | 'item'>, MenuItemLinkOwnProps> &\n (\n | {\n item?: undefined;\n }\n | {\n item: P;\n }\n );\n\n// By default, this is a Link component whenever useHistory is\n// explicitly not false\nconst MenuItemLink = <P, T extends React.ElementType = typeof Link>({\n to,\n disabled = false,\n useHistory = true,\n newTab = false,\n children,\n ...props\n}: MenuItemLinkProps<P, T>) => {\n const finalProps = {\n ...props,\n disabled,\n component: useHistory ? Link : ('a' as const),\n [useHistory ? 'to' : 'href']: disabled ? '' : to,\n rel: newTab ? 'noopener noreferrer' : undefined,\n target: newTab ? '_blank' : undefined,\n };\n\n // Ideally if this item is disabled, it should be a button rather\n // than a link https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-is-valid.md\n\n return <MenuItem {...finalProps}>{children}</MenuItem>;\n};\n\nexport { MenuItem, MenuItemLink };\nexport type { MenuItemProps, MenuItemLinkProps };\n", "import { forwardRef } from 'react';\n\nimport './styles/Menu.css';\n\ntype MenuItemListProps = Omit<React.ComponentPropsWithRef<'div'>, 'className'>;\n\nconst MenuItemList = forwardRef<HTMLDivElement, MenuItemListProps>(({ children, ...rest }, ref) => (\n <div {...rest} ref={ref} data-test-id=\"menu-item-list\" className=\"Menu-item-list\">\n {children}\n </div>\n));\n\nMenuItemList.displayName = 'MenuItemList';\n\nexport { MenuItemList };\nexport type { MenuItemListProps };\n", "import type { ChangeEvent } from 'react';\n\nimport { forwardRef } from 'react';\n\nimport './styles/Menu.css';\n\ntype MenuSearchProps = {\n ariaLabel?: string;\n value?: string;\n placeholder?: string;\n onChange?(event: ChangeEvent<HTMLInputElement>): void;\n};\n\nconst MenuSearch = forwardRef<HTMLInputElement, MenuSearchProps>((props, ref) => {\n const { ariaLabel, placeholder, ...finalProps } = props;\n\n return (\n <div className=\"Menu-search\">\n <input\n {...finalProps}\n ref={ref}\n className=\"Menu-search-input FormInput FormInput--tiny\"\n type=\"search\"\n autoComplete=\"off\"\n placeholder={placeholder}\n aria-label={ariaLabel || 'Search'}\n />\n <div\n className=\"Menu-search-hidden-placeholder Menu-search-input FormInput FormInput--tiny\"\n aria-hidden=\"true\"\n >\n {placeholder}\n </div>\n </div>\n );\n});\n\nMenuSearch.displayName = 'MenuSearch';\n\nexport { MenuSearch };\nexport type { MenuSearchProps };\n", "import type { KeyboardEvent, ReactElement } from 'react';\n\nimport { FocusManager, useFocusManager } from '@react-aria/focus';\nimport cx from 'clsx';\nimport { isNil, noop } from 'lodash-es';\nimport { Children, cloneElement, useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { useVirtual } from 'react-virtual';\nimport { v4 } from 'uuid';\n\nimport { MenuBase } from './MenuBase';\nimport { MenuDivider } from './MenuDivider';\nimport { MenuItem, MenuItemLink, MenuItemProps } from './MenuItem';\nimport { MenuItemList } from './MenuItemList';\nimport { MenuSearch } from './MenuSearch';\nimport {\n chainEventHandlers,\n createItemId,\n getNodeForIndex,\n handleKeyboardInteractions,\n} from './utils';\n\ntype ControlledMenuProps<T> = {\n children: React.ReactNode;\n onSelect?: (item: T) => void;\n /**\n * Menus items are rendered using react-virtual for\n * additional rendering performance.\n */\n enableVirtualization?: boolean;\n /**\n * Class name to be applied to all MenuItem and MenuItemLink components\n * in the menu.\n */\n menuItemClassName?: string;\n /**\n * Sets the width of the menu. This is especially useful when using virtual items\n * since the width cannot be automatically set by the widest element.\n */\n menuWidth?: 'tiny' | 'small' | 'med' | 'large' | 'xLarge';\n /**\n * Sets the number out of elements rendered outside of the view window\n * when using virtualization\n */\n overscan?: number;\n /**\n * Sets the height for each menu item when using virtualization.\n *\n */\n itemHeight?: number;\n};\n\ntype MenuProps<T extends number | string> = ControlledMenuProps<T>;\n\nconst Menu = <T extends number | string>(props: MenuProps<T>) => {\n const {\n children,\n menuItemClassName,\n onSelect,\n enableVirtualization,\n itemHeight,\n menuWidth,\n overscan = 1,\n } = props;\n\n const focusManager = useFocusManager();\n\n const handleArrowDown = useCallback(() => {\n focusManager.focusNext({ wrap: true });\n }, [focusManager]);\n\n const handleArrowUp = useCallback(() => {\n focusManager.focusPrevious({ wrap: true });\n }, [focusManager]);\n\n const reduceItems = useMemo(() => {\n const childrenProps = Children.toArray(children);\n if (enableVirtualization) {\n // the virtualized menu has its own handlers and props\n let searchElem = null;\n let elements: ReactElement[] = [];\n (childrenProps as ReactElement[]).forEach((child: ReactElement) => {\n switch (child.type) {\n case MenuSearch:\n searchElem = child;\n break;\n case MenuItem:\n case MenuItemLink:\n case MenuDivider:\n elements = elements.concat(child);\n break;\n default:\n break;\n }\n });\n return { items: elements, searchElement: searchElem };\n }\n\n return (childrenProps as ReactElement[]).reduce(\n (\n { items, searchElement }: { items: ReactElement[]; searchElement: null | ReactElement },\n child\n ) => {\n switch (child.type) {\n case MenuSearch:\n return {\n items,\n searchElement: cloneElement(child, {\n onKeyDown: (e: KeyboardEvent) =>\n handleKeyboardInteractions(e, {\n handleDown: handleArrowDown,\n handleUp: handleArrowUp,\n }),\n }),\n };\n case MenuItem:\n case MenuItemLink:\n return {\n items: items.concat(\n child.props.disabled\n ? cloneElement(child, {\n onClick: noop,\n onKeyDown: noop,\n tabIndex: -1,\n disabled: true,\n })\n : cloneElement(child, {\n className: cx(child.props.className, menuItemClassName),\n item: child.props.item ?? items.length,\n // set focus on the first menu item if there is no search input, and set in the tab order\n onClick: chainEventHandlers(child.props.onClick, () => {\n onSelect?.(child.props.item ?? items.length);\n }),\n onKeyDown: (e: KeyboardEvent) =>\n handleKeyboardInteractions(e, {\n handleDown: handleArrowDown,\n handleUp: handleArrowUp,\n }),\n })\n ),\n searchElement,\n };\n case MenuDivider:\n return { items: items.concat(child), searchElement };\n default:\n return { items, searchElement };\n }\n },\n { items: [], searchElement: null }\n );\n }, [children, enableVirtualization, menuItemClassName, handleArrowDown, handleArrowUp, onSelect]);\n\n const menuClassName = cx(\n { 'Menu--isVirtual': enableVirtualization },\n { [`MenuSize--${menuWidth}`]: menuWidth }\n );\n\n if (enableVirtualization) {\n return (\n <MenuBase role=\"menu\" className={menuClassName}>\n <ItemVirtualizer<T>\n items={Children.toArray(reduceItems.items) as ReactElement[]}\n searchElement={reduceItems.searchElement}\n overscan={overscan}\n menuItemClassName={menuItemClassName}\n onSelect={onSelect}\n itemHeight={itemHeight}\n focusManager={focusManager}\n />\n </MenuBase>\n );\n }\n\n return (\n <MenuBase role=\"menu\" className={menuClassName}>\n {reduceItems.searchElement}\n <MenuItemList role=\"presentation\">{reduceItems.items}</MenuItemList>\n </MenuBase>\n );\n};\n\ntype ItemVirtualizerProps<T> = Omit<ControlledMenuProps<T>, 'children'> & {\n items: ReactElement[] | null;\n searchElement?: React.ReactElement | null;\n focusManager: FocusManager;\n};\n\nconst ItemVirtualizer = <T extends number | string>(props: ItemVirtualizerProps<T>) => {\n const {\n overscan,\n searchElement,\n itemHeight = 33,\n menuItemClassName,\n items: items,\n focusManager,\n onSelect,\n } = props;\n\n const menuId = useRef(`menu-ctrl-${v4()}`);\n\n const focusedItemIndex = useRef<number | null>(null);\n const parentRef = useRef<HTMLDivElement | null>(null);\n const searchRef = useRef<HTMLInputElement>();\n\n const [nextFocusValue, setNextFocusValue] = useState<number | null>(null);\n\n const hasSearch = !!searchElement;\n\n const lastVirtualItemIndex = items ? items.length - 1 : 0;\n\n const rowVirtualizer = useVirtual({\n size: items !== null ? items.length : 0,\n parentRef,\n estimateSize: useCallback(() => itemHeight, [itemHeight]),\n overscan,\n });\n\n const focusSearchBar = useCallback(() => {\n rowVirtualizer.scrollToIndex(0);\n searchRef.current?.focus?.();\n }, [rowVirtualizer]);\n\n /**\n * Scrolls to the menu item with the index provided and\n * then manually focuses it using a side effect in useEffect\n */\n const focusMenuItem = useCallback(\n (index: number) => {\n rowVirtualizer.scrollToIndex(index);\n setNextFocusValue(index);\n },\n [rowVirtualizer]\n );\n\n const handleKeyboardFocusInteraction = useCallback(\n (direction: 'next' | 'previous') => {\n if (isNil(focusedItemIndex.current)) {\n return;\n }\n const nextIndex =\n direction === 'next' ? focusedItemIndex.current + 1 : focusedItemIndex.current - 1;\n const shouldWrap =\n (direction === 'next' && focusedItemIndex.current === lastVirtualItemIndex) ||\n (direction === 'previous' && focusedItemIndex.current === 0);\n if (shouldWrap) {\n // we are at the end of the list so we will\n // scroll back to the beginning of the list\n if (hasSearch) {\n focusSearchBar();\n } else {\n // if at end, wrap to beginning, else focus last item\n focusMenuItem(direction === 'next' ? 0 : lastVirtualItemIndex);\n }\n return;\n }\n switch (direction) {\n case 'next':\n rowVirtualizer.scrollToIndex(nextIndex);\n focusManager.focusNext();\n break;\n case 'previous':\n rowVirtualizer.scrollToIndex(nextIndex);\n focusManager.focusPrevious();\n break;\n default:\n break;\n }\n },\n [focusManager, focusMenuItem, focusSearchBar, hasSearch, lastVirtualItemIndex, rowVirtualizer]\n );\n\n const getItemProps = useCallback(\n (itemElem: ReactElement, index: number) => {\n const childProps = itemElem.props as MenuItemProps<T>;\n switch (itemElem.type) {\n case MenuItem:\n case MenuItemLink:\n return {\n className: cx(childProps.className, menuItemClassName),\n // set focus on the first menu item if there is no search input, and set in the tab order\n onKeyDown: childProps.disabled\n ? noop\n : (e: KeyboardEvent) =>\n handleKeyboardFocusKeydown(e, {\n handleFocusBackward: handleKeyboardFocusInteraction,\n handleFocusForward: handleKeyboardFocusInteraction,\n }),\n onFocus: chainEventHandlers(childProps.onFocus, () => {\n focusedItemIndex.current = index;\n }),\n id: createItemId(index, menuId.current),\n onBlur: chainEventHandlers(childProps.onBlur, () => {\n focusedItemIndex.current = null;\n }),\n onClick: childProps.disabled\n ? noop\n : chainEventHandlers(childProps.onClick, () => {\n onSelect?.(childProps.item as T);\n }),\n } as MenuItemProps<T>;\n default:\n return {};\n }\n },\n [handleKeyboardFocusInteraction, menuItemClassName, onSelect]\n );\n\n useEffect(() => {\n if (nextFocusValue !== null) {\n requestAnimationFrame(() => {\n const element = getNodeForIndex(nextFocusValue, menuId.current);\n element?.focus();\n });\n setNextFocusValue(null);\n }\n }, [nextFocusValue]);\n\n /**\n * Calls handleFocusForward when the user is attempting to focus forward using\n * tab or arrow keys. Calls handleFocusBackward when the users wants to move backward.\n */\n const handleKeyboardFocusKeydown = (\n e: KeyboardEvent,\n callbacks: Record<\n 'handleFocusForward' | 'handleFocusBackward',\n (direction: 'next' | 'previous') => void\n >\n ) => {\n const keyOps = ['Tab', 'ArrowUp', 'ArrowDown'];\n if (keyOps.includes(e.key)) {\n e.preventDefault();\n e.stopPropagation();\n if ((e.key === 'Tab' && e.shiftKey) || e.key === 'ArrowUp') {\n callbacks.handleFocusBackward?.('previous');\n } else if (e.key === 'ArrowDown' || e.key === 'Tab') {\n callbacks.handleFocusForward?.('next');\n }\n }\n };\n\n const renderSearch = useMemo(\n () =>\n searchElement\n ? cloneElement(searchElement, {\n onKeyDown: (e: KeyboardEvent) =>\n handleKeyboardFocusKeydown(e, {\n handleFocusBackward: () => focusMenuItem(lastVirtualItemIndex),\n handleFocusForward: () => focusMenuItem(0),\n }),\n ref: searchRef,\n })\n : null,\n [searchElement, lastVirtualItemIndex, focusMenuItem]\n );\n\n const renderItems = useMemo(\n () =>\n rowVirtualizer.virtualItems.map((virtualRow) => {\n if (!items) {\n return null;\n }\n const elem = items[virtualRow.index];\n return (\n <div\n key={virtualRow.index}\n ref={\n elem.type !== MenuItem || elem.type !== MenuItemLink\n ? virtualRow.measureRef\n : undefined\n }\n role=\"presentation\"\n className={cx('VirtualMenu-item')}\n style={{\n transform: `translateY(${virtualRow.start}px)`,\n }}\n >\n {cloneElement(elem, getItemProps(elem, virtualRow.index))}\n </div>\n );\n }),\n [rowVirtualizer.virtualItems, items, getItemProps]\n );\n\n return (\n <>\n {renderSearch}\n <MenuItemList ref={parentRef} role=\"presentation\">\n <div\n role=\"presentation\"\n className=\"VirtualMenu-item-list\"\n style={{\n height: `${rowVirtualizer.totalSize}px`,\n }}\n >\n {renderItems}\n </div>\n </MenuItemList>\n </>\n );\n};\n\nexport { Menu, ItemVirtualizer };\nexport type { MenuProps, ItemVirtualizerProps };\n", "import type { KeyboardEvent } from 'react';\n\nimport { isFunction } from 'lodash-es';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyFunction = (...args: any[]) => any;\n\nconst createItemId = (index: number, id: string) => `${id}-item-${index}`;\n\nconst getNodeForIndex = (index: number | null, menuId: string) =>\n index === null ? index : document.getElementById(createItemId(index, menuId));\n\nconst handleKeyboardInteractions = (\n event: React.KeyboardEvent,\n keyHandlers: Partial<\n Record<'handleUp' | 'handleDown' | 'handleEnter', (e: KeyboardEvent) => void>\n >\n) => {\n const ops = {\n ArrowUp: keyHandlers.handleUp,\n ArrowDown: keyHandlers.handleDown,\n Enter: keyHandlers.handleEnter,\n } as Record<string, (e: KeyboardEvent) => void | undefined>;\n\n if (ops[event.key]) {\n event.preventDefault();\n ops[event.key]?.call(globalThis, event);\n }\n};\n\nconst chainEventHandlers =\n (...handlers: Array<AnyFunction | undefined>) =>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (event: any) => {\n handlers.forEach((h) => isFunction(h) && h(event));\n };\n\nexport { createItemId, getNodeForIndex, handleKeyboardInteractions, chainEventHandlers };\n"],
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;;;
|
3
|
+
"sources": ["../src/index.ts", "../../../scripts/react-shim.js", "../src/MenuBase.tsx", "../src/MenuDivider.tsx", "../src/MenuItem.tsx", "../src/MenuItemList.tsx", "../src/MenuSearch.tsx", "../src/Menu.tsx", "../src/utils.ts", "../src/types.ts"],
|
4
|
+
"sourcesContent": ["export type { MenuBaseProps } from './MenuBase';\nexport type { MenuDividerProps } from './MenuDivider';\nexport type { MenuItemProps, MenuItemLinkProps } from './MenuItem';\nexport type { MenuItemListProps } from './MenuItemList';\nexport type { MenuSearchProps } from './MenuSearch';\nexport type { MenuProps } from './Menu';\nexport { MenuBase } from './MenuBase';\nexport { MenuDivider } from './MenuDivider';\nexport { MenuItem, MenuItemLink } from './MenuItem';\nexport { MenuItemList } from './MenuItemList';\nexport { MenuSearch } from './MenuSearch';\nexport { Menu } from './Menu';\nexport { MenuSize } from './types';\n", "import * as React from 'react';\nexport { React };\n", "import type { MenuSize } from './types';\n\nimport cx from 'clsx';\nimport { forwardRef } from 'react';\n\nimport './styles/Menu.css';\n\ntype MenuBaseProps = React.ComponentPropsWithRef<'div'> & {\n isVirtual?: boolean;\n size?: MenuSize;\n};\n\nconst MenuBase = forwardRef<HTMLDivElement, MenuBaseProps>(\n ({ children, size, isVirtual, ...props }, ref) => {\n const classes = cx('Menu', {\n 'Menu--isVirtual': isVirtual,\n [`MenuSize--${size}`]: size,\n });\n\n return (\n <div {...props} role=\"menu\" className={classes} ref={ref}>\n {children}\n </div>\n );\n }\n);\n\nMenuBase.displayName = 'MenuBase';\n\nexport { MenuBase };\nexport type { MenuBaseProps };\n", "import type { SeparatorProps } from '@react-aria/separator';\n\nimport { useSeparator } from '@react-aria/separator';\n\nimport './styles/Menu.css';\n\ntype MenuDividerProps = SeparatorProps & {\n innerRef?: React.RefObject<HTMLDivElement>;\n};\n\nconst MenuDivider = ({ elementType = 'div', orientation, innerRef }: MenuDividerProps) => {\n const { separatorProps } = useSeparator({\n orientation,\n elementType,\n });\n\n return <div {...separatorProps} ref={innerRef} className=\"Menu-divider\" />;\n};\n\nexport { MenuDivider };\nexport type { MenuDividerProps };\n", "import type { Icon } from '@launchpad-ui/icons';\nimport type { PopoverPlacement } from '@launchpad-ui/popover';\n\nimport { IconSize } from '@launchpad-ui/icons';\nimport { Tooltip } from '@launchpad-ui/tooltip';\nimport { Slot } from '@radix-ui/react-slot';\nimport { FocusRing } from '@react-aria/focus';\nimport cx from 'clsx';\nimport { Link } from 'react-router-dom';\n\nimport './styles/Menu.css';\n\n// Merge two types and get rid of overlapping definitions\ntype Merge<T, U> = Omit<T, keyof U> & U;\n\ntype PropsWithComponent<P, T extends React.ElementType> = P & { component?: T };\n\ntype PolymorphicPropsWithRef<P, T extends React.ElementType> = Merge<\n T extends keyof JSX.IntrinsicElements\n ? React.PropsWithRef<JSX.IntrinsicElements[T]>\n : React.ComponentPropsWithRef<T>,\n PropsWithComponent<P, T>\n>;\n\ntype MenuItemOwnProps = {\n isHighlighted?: boolean;\n icon?: typeof Icon | null;\n disabled?: boolean;\n nested?: boolean;\n groupHeader?: boolean;\n tooltip?: string | React.ReactElement;\n tooltipOptions?: typeof Tooltip;\n tooltipPlacement?: PopoverPlacement;\n asChild?: boolean;\n};\n\nconst defaultElement = 'button';\n\ntype MenuItemProps<\n P,\n T extends React.ElementType = typeof defaultElement\n> = PolymorphicPropsWithRef<\n | (MenuItemOwnProps & {\n item: P; // Infer the type if it is included\n })\n | (MenuItemOwnProps & {\n item?: undefined;\n }),\n T\n>;\n\nconst MenuItem = <P, T extends React.ElementType = typeof defaultElement>({\n ...props\n}: MenuItemProps<P, T>) => {\n const {\n // TODO: remove component prop once we migrate over to asChild format\n component,\n children,\n isHighlighted,\n icon: Icon,\n nested,\n groupHeader,\n item,\n disabled,\n className,\n tooltip,\n role = 'menuitem',\n tooltipPlacement,\n onKeyDown,\n tooltipOptions,\n asChild,\n ...rest\n } = props;\n\n const Component: React.ElementType = component || (asChild ? Slot : defaultElement);\n\n const renderedItem = (\n <FocusRing focusRingClass=\"has-focus\">\n <Component\n {...rest}\n disabled={disabled}\n aria-disabled={disabled ? disabled : undefined}\n className={cx(\n 'Menu-item',\n className,\n { 'is-highlighted': isHighlighted },\n { 'Menu-item--nested': nested },\n { 'Menu-item--header': groupHeader }\n )}\n role={role}\n onKeyDown={onKeyDown}\n >\n {asChild ? (\n children\n ) : (\n <>\n {Icon && (\n <span className=\"Menu-item-icon\">\n <Icon size={IconSize.SMALL} />\n </span>\n )}\n {children}\n </>\n )}\n </Component>\n </FocusRing>\n );\n\n if (tooltip) {\n return (\n <Tooltip\n content={tooltip}\n rootElementStyle={{ display: 'block' }}\n allowBoundaryElementOverflow\n placement={tooltipPlacement ? tooltipPlacement : 'bottom'}\n {...(tooltipOptions || {})}\n >\n {renderedItem}\n </Tooltip>\n );\n }\n\n return renderedItem;\n};\n\ntype MenuItemLinkOwnProps = {\n disabled?: boolean;\n useHistory?: boolean;\n newTab?: boolean;\n};\n\ntype MenuItemLinkProps<P, T extends React.ElementType = typeof Link> =\n | Merge<Omit<MenuItemProps<P, T>, 'component' | 'item'>, MenuItemLinkOwnProps> &\n (\n | {\n item?: undefined;\n }\n | {\n item: P;\n }\n );\n\n// By default, this is a Link component whenever useHistory is\n// explicitly not false\n// TODO: deprecate this component\nconst MenuItemLink = <P, T extends React.ElementType = typeof Link>({\n to,\n disabled = false,\n useHistory = true,\n newTab = false,\n children,\n ...props\n}: MenuItemLinkProps<P, T>) => {\n const finalProps = {\n ...props,\n disabled,\n component: useHistory ? Link : ('a' as const),\n [useHistory ? 'to' : 'href']: disabled ? '' : to,\n rel: newTab ? 'noopener noreferrer' : undefined,\n target: newTab ? '_blank' : undefined,\n };\n\n // Ideally if this item is disabled, it should be a button rather\n // than a link https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-is-valid.md\n\n return <MenuItem {...finalProps}>{children}</MenuItem>;\n};\n\nexport { MenuItem, MenuItemLink };\nexport type { MenuItemProps, MenuItemLinkProps };\n", "import { forwardRef } from 'react';\n\nimport './styles/Menu.css';\n\ntype MenuItemListProps = Omit<React.ComponentPropsWithRef<'div'>, 'className'>;\n\nconst MenuItemList = forwardRef<HTMLDivElement, MenuItemListProps>(({ children, ...rest }, ref) => (\n <div {...rest} ref={ref} data-test-id=\"menu-item-list\" className=\"Menu-item-list\">\n {children}\n </div>\n));\n\nMenuItemList.displayName = 'MenuItemList';\n\nexport { MenuItemList };\nexport type { MenuItemListProps };\n", "import type { ChangeEvent } from 'react';\n\nimport { forwardRef } from 'react';\n\nimport './styles/Menu.css';\n\ntype MenuSearchProps = {\n ariaLabel?: string;\n value?: string;\n placeholder?: string;\n onChange?(event: ChangeEvent<HTMLInputElement>): void;\n};\n\nconst MenuSearch = forwardRef<HTMLInputElement, MenuSearchProps>((props, ref) => {\n const { ariaLabel, placeholder, ...finalProps } = props;\n\n return (\n <div className=\"Menu-search\">\n <input\n {...finalProps}\n ref={ref}\n className=\"Menu-search-input FormInput FormInput--tiny\"\n type=\"search\"\n autoComplete=\"off\"\n placeholder={placeholder}\n aria-label={ariaLabel || 'Search'}\n />\n <div\n className=\"Menu-search-hidden-placeholder Menu-search-input FormInput FormInput--tiny\"\n aria-hidden=\"true\"\n >\n {placeholder}\n </div>\n </div>\n );\n});\n\nMenuSearch.displayName = 'MenuSearch';\n\nexport { MenuSearch };\nexport type { MenuSearchProps };\n", "import type { MenuItemProps } from './MenuItem';\nimport type { MenuSize } from './types';\nimport type { FocusManager } from '@react-aria/focus';\nimport type { KeyboardEvent, ReactElement } from 'react';\n\nimport { useFocusManager } from '@react-aria/focus';\nimport cx from 'clsx';\nimport { isNil, noop } from 'lodash-es';\nimport { Children, cloneElement, useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { useVirtual } from 'react-virtual';\nimport { v4 } from 'uuid';\n\nimport { MenuBase } from './MenuBase';\nimport { MenuDivider } from './MenuDivider';\nimport { MenuItem, MenuItemLink } from './MenuItem';\nimport { MenuItemList } from './MenuItemList';\nimport { MenuSearch } from './MenuSearch';\nimport {\n chainEventHandlers,\n createItemId,\n getNodeForIndex,\n handleKeyboardInteractions,\n} from './utils';\n\ntype ControlledMenuProps<T> = {\n children: React.ReactNode;\n onSelect?: (item: T) => void;\n /**\n * Menus items are rendered using react-virtual for\n * additional rendering performance.\n */\n enableVirtualization?: boolean;\n /**\n * Class name to be applied to all MenuItem and MenuItemLink components\n * in the menu.\n */\n menuItemClassName?: string;\n /**\n * Sets the width of the menu. This is especially useful when using virtual items\n * since the width cannot be automatically set by the widest element.\n */\n size?: MenuSize;\n /**\n * Sets the number out of elements rendered outside of the view window\n * when using virtualization\n */\n overscan?: number;\n /**\n * Sets the height for each menu item when using virtualization.\n *\n */\n itemHeight?: number;\n};\n\ntype MenuProps<T extends number | string> = ControlledMenuProps<T>;\n\nconst Menu = <T extends number | string>(props: MenuProps<T>) => {\n const {\n children,\n menuItemClassName,\n onSelect,\n enableVirtualization,\n itemHeight,\n size,\n overscan = 1,\n } = props;\n\n const focusManager = useFocusManager();\n\n const handleArrowDown = useCallback(() => {\n focusManager.focusNext({ wrap: true });\n }, [focusManager]);\n\n const handleArrowUp = useCallback(() => {\n focusManager.focusPrevious({ wrap: true });\n }, [focusManager]);\n\n const reduceItems = useMemo(() => {\n const childrenProps = Children.toArray(children);\n if (enableVirtualization) {\n // the virtualized menu has its own handlers and props\n let searchElem = null;\n let elements: ReactElement[] = [];\n (childrenProps as ReactElement[]).forEach((child: ReactElement) => {\n switch (child.type) {\n case MenuSearch:\n searchElem = child;\n break;\n case MenuItem:\n case MenuItemLink:\n case MenuDivider:\n elements = elements.concat(child);\n break;\n default:\n break;\n }\n });\n return { items: elements, searchElement: searchElem };\n }\n\n return (childrenProps as ReactElement[]).reduce(\n (\n { items, searchElement }: { items: ReactElement[]; searchElement: null | ReactElement },\n child\n ) => {\n switch (child.type) {\n case MenuSearch:\n return {\n items,\n searchElement: cloneElement(child, {\n onKeyDown: (e: KeyboardEvent) =>\n handleKeyboardInteractions(e, {\n handleDown: handleArrowDown,\n handleUp: handleArrowUp,\n }),\n }),\n };\n case MenuItem:\n case MenuItemLink:\n return {\n items: items.concat(\n child.props.disabled\n ? cloneElement(child, {\n onClick: noop,\n onKeyDown: noop,\n tabIndex: -1,\n disabled: true,\n })\n : cloneElement(child, {\n className: cx(child.props.className, menuItemClassName),\n item: child.props.item ?? items.length,\n // set focus on the first menu item if there is no search input, and set in the tab order\n onClick: chainEventHandlers(child.props.onClick, () => {\n onSelect?.(child.props.item ?? items.length);\n }),\n onKeyDown: (e: KeyboardEvent) =>\n handleKeyboardInteractions(e, {\n handleDown: handleArrowDown,\n handleUp: handleArrowUp,\n }),\n })\n ),\n searchElement,\n };\n case MenuDivider:\n return { items: items.concat(child), searchElement };\n default:\n return { items, searchElement };\n }\n },\n { items: [], searchElement: null }\n );\n }, [children, enableVirtualization, menuItemClassName, handleArrowDown, handleArrowUp, onSelect]);\n\n if (enableVirtualization) {\n return (\n <MenuBase isVirtual size={size}>\n <ItemVirtualizer<T>\n items={Children.toArray(reduceItems.items) as ReactElement[]}\n searchElement={reduceItems.searchElement}\n overscan={overscan}\n menuItemClassName={menuItemClassName}\n onSelect={onSelect}\n itemHeight={itemHeight}\n focusManager={focusManager}\n />\n </MenuBase>\n );\n }\n\n return (\n <MenuBase size={size}>\n {reduceItems.searchElement}\n <MenuItemList role=\"presentation\">{reduceItems.items}</MenuItemList>\n </MenuBase>\n );\n};\n\ntype ItemVirtualizerProps<T> = Omit<ControlledMenuProps<T>, 'children'> & {\n items: ReactElement[] | null;\n searchElement?: React.ReactElement | null;\n focusManager: FocusManager;\n};\n\nconst ItemVirtualizer = <T extends number | string>(props: ItemVirtualizerProps<T>) => {\n const {\n overscan,\n searchElement,\n itemHeight = 33,\n menuItemClassName,\n items: items,\n focusManager,\n onSelect,\n } = props;\n\n const menuId = useRef(`menu-ctrl-${v4()}`);\n\n const focusedItemIndex = useRef<number | null>(null);\n const parentRef = useRef<HTMLDivElement | null>(null);\n const searchRef = useRef<HTMLInputElement>();\n\n const [nextFocusValue, setNextFocusValue] = useState<number | null>(null);\n\n const hasSearch = !!searchElement;\n\n const lastVirtualItemIndex = items ? items.length - 1 : 0;\n\n const rowVirtualizer = useVirtual({\n size: items !== null ? items.length : 0,\n parentRef,\n estimateSize: useCallback(() => itemHeight, [itemHeight]),\n overscan,\n });\n\n const focusSearchBar = useCallback(() => {\n rowVirtualizer.scrollToIndex(0);\n searchRef.current?.focus?.();\n }, [rowVirtualizer]);\n\n /**\n * Scrolls to the menu item with the index provided and\n * then manually focuses it using a side effect in useEffect\n */\n const focusMenuItem = useCallback(\n (index: number) => {\n rowVirtualizer.scrollToIndex(index);\n setNextFocusValue(index);\n },\n [rowVirtualizer]\n );\n\n const handleKeyboardFocusInteraction = useCallback(\n (direction: 'next' | 'previous') => {\n if (isNil(focusedItemIndex.current)) {\n return;\n }\n const nextIndex =\n direction === 'next' ? focusedItemIndex.current + 1 : focusedItemIndex.current - 1;\n const shouldWrap =\n (direction === 'next' && focusedItemIndex.current === lastVirtualItemIndex) ||\n (direction === 'previous' && focusedItemIndex.current === 0);\n if (shouldWrap) {\n // we are at the end of the list so we will\n // scroll back to the beginning of the list\n if (hasSearch) {\n focusSearchBar();\n } else {\n // if at end, wrap to beginning, else focus last item\n focusMenuItem(direction === 'next' ? 0 : lastVirtualItemIndex);\n }\n return;\n }\n switch (direction) {\n case 'next':\n rowVirtualizer.scrollToIndex(nextIndex);\n focusManager.focusNext();\n break;\n case 'previous':\n rowVirtualizer.scrollToIndex(nextIndex);\n focusManager.focusPrevious();\n break;\n default:\n break;\n }\n },\n [focusManager, focusMenuItem, focusSearchBar, hasSearch, lastVirtualItemIndex, rowVirtualizer]\n );\n\n const getItemProps = useCallback(\n (itemElem: ReactElement, index: number) => {\n const childProps = itemElem.props as MenuItemProps<T>;\n switch (itemElem.type) {\n case MenuItem:\n case MenuItemLink:\n return {\n className: cx(childProps.className, menuItemClassName),\n // set focus on the first menu item if there is no search input, and set in the tab order\n onKeyDown: childProps.disabled\n ? noop\n : (e: KeyboardEvent) =>\n handleKeyboardFocusKeydown(e, {\n handleFocusBackward: handleKeyboardFocusInteraction,\n handleFocusForward: handleKeyboardFocusInteraction,\n }),\n onFocus: chainEventHandlers(childProps.onFocus, () => {\n focusedItemIndex.current = index;\n }),\n id: createItemId(index, menuId.current),\n onBlur: chainEventHandlers(childProps.onBlur, () => {\n focusedItemIndex.current = null;\n }),\n onClick: childProps.disabled\n ? noop\n : chainEventHandlers(childProps.onClick, () => {\n onSelect?.(childProps.item as T);\n }),\n } as MenuItemProps<T>;\n default:\n return {};\n }\n },\n [handleKeyboardFocusInteraction, menuItemClassName, onSelect]\n );\n\n useEffect(() => {\n if (nextFocusValue !== null) {\n requestAnimationFrame(() => {\n const element = getNodeForIndex(nextFocusValue, menuId.current);\n element?.focus();\n });\n setNextFocusValue(null);\n }\n }, [nextFocusValue]);\n\n /**\n * Calls handleFocusForward when the user is attempting to focus forward using\n * tab or arrow keys. Calls handleFocusBackward when the users wants to move backward.\n */\n const handleKeyboardFocusKeydown = (\n e: KeyboardEvent,\n callbacks: Record<\n 'handleFocusForward' | 'handleFocusBackward',\n (direction: 'next' | 'previous') => void\n >\n ) => {\n const keyOps = ['Tab', 'ArrowUp', 'ArrowDown'];\n if (keyOps.includes(e.key)) {\n e.preventDefault();\n e.stopPropagation();\n if ((e.key === 'Tab' && e.shiftKey) || e.key === 'ArrowUp') {\n callbacks.handleFocusBackward?.('previous');\n } else if (e.key === 'ArrowDown' || e.key === 'Tab') {\n callbacks.handleFocusForward?.('next');\n }\n }\n };\n\n const renderSearch = useMemo(\n () =>\n searchElement\n ? cloneElement(searchElement, {\n onKeyDown: (e: KeyboardEvent) =>\n handleKeyboardFocusKeydown(e, {\n handleFocusBackward: () => focusMenuItem(lastVirtualItemIndex),\n handleFocusForward: () => focusMenuItem(0),\n }),\n ref: searchRef,\n })\n : null,\n [searchElement, lastVirtualItemIndex, focusMenuItem]\n );\n\n const renderItems = useMemo(\n () =>\n rowVirtualizer.virtualItems.map((virtualRow) => {\n if (!items) {\n return null;\n }\n const elem = items[virtualRow.index];\n return (\n <div\n key={virtualRow.index}\n ref={\n elem.type !== MenuItem || elem.type !== MenuItemLink\n ? virtualRow.measureRef\n : undefined\n }\n role=\"presentation\"\n className={cx('VirtualMenu-item')}\n style={{\n transform: `translateY(${virtualRow.start}px)`,\n }}\n >\n {cloneElement(elem, getItemProps(elem, virtualRow.index))}\n </div>\n );\n }),\n [rowVirtualizer.virtualItems, items, getItemProps]\n );\n\n return (\n <>\n {renderSearch}\n <MenuItemList ref={parentRef} role=\"presentation\">\n <div\n role=\"presentation\"\n className=\"VirtualMenu-item-list\"\n style={{\n height: `${rowVirtualizer.totalSize}px`,\n }}\n >\n {renderItems}\n </div>\n </MenuItemList>\n </>\n );\n};\n\nexport { Menu, ItemVirtualizer };\nexport type { MenuProps, ItemVirtualizerProps };\n", "import type { KeyboardEvent } from 'react';\n\nimport { isFunction } from 'lodash-es';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyFunction = (...args: any[]) => any;\n\nconst createItemId = (index: number, id: string) => `${id}-item-${index}`;\n\nconst getNodeForIndex = (index: number | null, menuId: string) =>\n index === null ? index : document.getElementById(createItemId(index, menuId));\n\nconst handleKeyboardInteractions = (\n event: React.KeyboardEvent,\n keyHandlers: Partial<\n Record<'handleUp' | 'handleDown' | 'handleEnter', (e: KeyboardEvent) => void>\n >\n) => {\n const ops = {\n ArrowUp: keyHandlers.handleUp,\n ArrowDown: keyHandlers.handleDown,\n Enter: keyHandlers.handleEnter,\n } as Record<string, (e: KeyboardEvent) => void | undefined>;\n\n if (ops[event.key]) {\n event.preventDefault();\n ops[event.key]?.call(globalThis, event);\n }\n};\n\nconst chainEventHandlers =\n (...handlers: Array<AnyFunction | undefined>) =>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (event: any) => {\n handlers.forEach((h) => isFunction(h) && h(event));\n };\n\nexport { createItemId, getNodeForIndex, handleKeyboardInteractions, chainEventHandlers };\n", "enum MenuSize {\n SMALL = 'sm',\n MEDIUM = 'md',\n LARGE = 'lg',\n EXTRA_LARGE = 'xl',\n}\n\nexport { MenuSize };\n"],
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;;;ACEvB,kBAAe;AACf,mBAA2B;AAE3B,kBAAO;AAOP,IAAM,WAAW,6BACf,CAAC,EAAE,UAAU,MAAM,cAAc,SAAS,QAAQ;AAChD,QAAM,UAAU,yBAAG,QAAQ;AAAA,IACzB,mBAAmB;AAAA,IACnB,CAAC,aAAa,SAAS;AAAA,EACzB,CAAC;AAED,SACE,oCAAC;AAAA,IAAK,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J,CAAC,GACH,CAAC,eAAe,cAAc,OAAO,YAAY,CACnD;AAEA,SACE,0DACG,cACD,oCAAC;AAAA,IAAa,KAAK;AAAA,IAAW,MAAK;AAAA,KACjC,oCAAC;AAAA,IACC,MAAK;AAAA,IACL,WAAU;AAAA,IACV,OAAO;AAAA,MACL,QAAQ,GAAG,eAAe;AAAA,IAC5B;AAAA,KAEC,WACH,CACF,CACF;AAEJ;;;AE5YA,IAAK,WAAL,kBAAK,cAAL;AACE,uBAAQ;AACR,wBAAS;AACT,uBAAQ;AACR,6BAAc;AAJX;AAAA;",
|
6
6
|
"names": []
|
7
7
|
}
|
package/dist/styles/Menu.css
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
.Menu
|
1
|
+
.Menu-item{color:var(--color-text);background:var(--color-background);cursor:pointer;text-align:left;text-overflow:ellipsis;white-space:nowrap;-webkit-user-select:none;user-select:none;font-size:1.3rem;line-height:inherit;width:100%;border-width:0;outline:none;padding:.6rem 2.5rem;text-decoration:none;display:block;position:relative;overflow:hidden}.Menu-item:first-child{border-top-left-radius:var(--border-radius);border-top-right-radius:var(--border-radius)}.Menu-item:last-child{border-bottom-left-radius:var(--border-radius);border-bottom-right-radius:var(--border-radius)}.Menu-item-list{min-width:12rem;max-height:55vh;overflow:auto}.Menu-item-list>.Menu-item:last-child{border-bottom-left-radius:var(--border-radius);border-bottom-right-radius:var(--border-radius)}.Menu .Menu-item:not([disabled],[aria-disabled]):active{box-shadow:none;background-color:var(--color-blue-200);color:var(--color-blue-600);text-decoration:none}.Menu .Menu-item:not([disabled],[aria-disabled]):hover:not(:active,.has-focus){background-color:var(--color-background-hover);box-shadow:inset 0 0 0 1px var(--color-gray-600)}.Menu .Menu-item:not([disabled],[aria-disabled]).has-focus{background-color:var(--color-background-hover);box-shadow:inset 0 0 0 2px var(--color-focus)}.Menu-item-list>.VirtualMenu-item-list .VirtualMenu-item:last-child .Menu-item{border-bottom-left-radius:var(--border-radius);border-bottom-right-radius:var(--border-radius)}.Menu:focus{outline:none}.Menu a.Menu-item:focus:not(:hover,.has-focus){box-shadow:none;text-decoration:none}.Menu a.Menu-item:active[disabled],.Menu a.Menu-item:active[aria-disabled]{color:var(--color-text-subtle-primary);text-decoration:none}:is(.Menu .Menu-item-list:first-child,.Menu [hidden]:first-child+.Menu .Menu-item-list)>.Menu-item:first-child,:is(.Menu .Menu-item-list:first-child,.Menu [hidden]:first-child+.Menu .Menu-item-list)>.VirtualMenu-item-list .VirtualMenu-item:first-child .Menu-item{border-top-left-radius:var(--border-radius);border-top-right-radius:var(--border-radius)}.Menu-item--nested{padding-left:4rem}.Menu-item--header{font-weight:var(--font-weight-medium)}.Menu-item .Gravatar{margin-right:.5rem}.Menu-item.is-highlighted{background-color:var(--color-background-hover);box-shadow:inset 0 0 0 1px var(--color-gray-600)}.Menu-item.is-highlighted:active{background-color:var(--color-blue-200);color:var(--color-blue-600);box-shadow:none}.Menu-item[aria-disabled],.Menu-item[disabled]{color:var(--color-text-subtle-primary);cursor:default}.Menu-item-icon{position:absolute;top:50%;left:.5rem;transform:translateY(-50%)}.Menu-divider{border-top:1px solid var(--color-border)}.Menu-search{border-bottom:1px solid var(--color-border);padding:1rem;font-size:1.3rem}.Menu-search:first-child{border-top-left-radius:var(--border-radius);border-top-right-radius:var(--border-radius)}.Menu-clear.Button{color:var(--color-system-red-600);font-size:1.3rem;font-weight:var(--font-weight-medium);width:100%;border-bottom:1px solid var(--color-border);padding:1rem;text-decoration:none}.Menu-clear.Button:active,.Menu-clear.Button:focus,.Menu-clear.Button:hover{box-shadow:unset;color:var(--color-system-red-600);border-bottom-color:var(--color-border);background-color:var(--color-background-hover);outline:none}.Popover-content .Menu-search{width:100%}.Popover-content .Menu-search .Menu-search-hidden-placeholder{height:0;visibility:hidden;border:none;padding-top:0;padding-bottom:0}.Menu--isVirtual{flex-direction:column;align-items:stretch;display:flex}.MenuSize--xl{width:32rem}.MenuSize--lg{width:24rem}.MenuSize--md{width:16rem}.MenuSize--sm{width:12rem}.VirtualMenu-item-list{width:100%;position:relative}.VirtualMenu-item{width:100%;position:absolute;top:0;left:0}
|
2
2
|
/*# sourceMappingURL=Menu.css.map */
|
package/dist/styles/Menu.css.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sourceRoot":null,"mappings":"
|
1
|
+
{"version":3,"sourceRoot":null,"mappings":"AAAA,+VAmBE,gHAKA,qHAMF,8DAMA,qIAME,gKAOA,+KAKA,wJAMF,8KAME,yBAME,oFAMA,uIASA,gWAYJ,qCAIA,yDAIA,wCAIA,0HAIE,oHAOF,qGAMA,gFAOA,uDAIA,uFAMA,kHAKA,qMAUA,mOAUA,yCAIE,oIASF,wEAMA,0BAIA,0BAIA,0BAIA,0BAIA,oDAKA","sources":["src/styles/Menu.css"],"sourcesContent":[".Menu-item {\n display: block;\n position: relative;\n color: var(--color-text);\n background: var(--color-background);\n text-decoration: none;\n cursor: pointer;\n outline: none;\n padding: 0.6rem 2.5rem;\n text-align: left;\n font-size: 1.3rem;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n user-select: none;\n line-height: inherit;\n border-width: 0;\n width: 100%;\n\n &:first-child {\n border-top-left-radius: var(--border-radius);\n border-top-right-radius: var(--border-radius);\n }\n\n &:last-child {\n border-bottom-left-radius: var(--border-radius);\n border-bottom-right-radius: var(--border-radius);\n }\n}\n\n.Menu-item-list {\n min-width: 12rem;\n overflow: auto;\n max-height: 55vh;\n}\n\n.Menu-item-list > .Menu-item:last-child {\n border-bottom-left-radius: var(--border-radius);\n border-bottom-right-radius: var(--border-radius);\n}\n\n.Menu .Menu-item:not([disabled], [aria-disabled]) {\n &:active {\n text-decoration: none;\n box-shadow: none;\n background-color: var(--color-blue-200);\n color: var(--color-blue-600);\n }\n\n &:hover:not(:active, .has-focus) {\n background-color: var(--color-background-hover);\n box-shadow: inset 0 0 0 1px var(--color-gray-600);\n }\n\n &.has-focus {\n background-color: var(--color-background-hover);\n box-shadow: inset 0 0 0 2px var(--color-focus);\n }\n}\n\n.Menu-item-list > .VirtualMenu-item-list .VirtualMenu-item:last-child .Menu-item {\n border-bottom-left-radius: var(--border-radius);\n border-bottom-right-radius: var(--border-radius);\n}\n\n.Menu {\n &:focus {\n outline: none;\n }\n\n /* Override our link styles for MenuItemLink component */\n & a.Menu-item {\n &:focus:not(:hover, .has-focus) {\n text-decoration: none;\n box-shadow: none;\n }\n\n /* Ensures that links that are disabled don't show active styles */\n &:active[disabled],\n &:active[aria-disabled] {\n text-decoration: none;\n color: var(--color-text-subtle-primary);\n }\n }\n\n & .Menu-item-list:first-child,\n & [hidden]:first-child + & .Menu-item-list {\n & > .Menu-item:first-child {\n border-top-left-radius: var(--border-radius);\n border-top-right-radius: var(--border-radius);\n }\n\n & > .VirtualMenu-item-list .VirtualMenu-item:first-child .Menu-item {\n border-top-left-radius: var(--border-radius);\n border-top-right-radius: var(--border-radius);\n }\n }\n}\n\n.Menu-item--nested {\n padding-left: 4rem;\n}\n\n.Menu-item--header {\n font-weight: var(--font-weight-medium);\n}\n\n.Menu-item .Gravatar {\n margin-right: 0.5rem;\n}\n\n.Menu-item.is-highlighted {\n background-color: var(--color-background-hover);\n box-shadow: inset 0 0 0 1px var(--color-gray-600);\n\n &:active {\n background-color: var(--color-blue-200);\n color: var(--color-blue-600);\n box-shadow: none;\n }\n}\n\n.Menu-item[aria-disabled],\n.Menu-item[disabled] {\n color: var(--color-text-subtle-primary);\n cursor: default;\n}\n\n.Menu-item-icon {\n position: absolute;\n left: 0.5rem;\n top: 50%;\n transform: translateY(-50%);\n}\n\n.Menu-divider {\n border-top: 1px solid var(--color-border);\n}\n\n.Menu-search {\n padding: 1rem;\n font-size: 1.3rem;\n border-bottom: 1px solid var(--color-border);\n}\n\n.Menu-search:first-child {\n border-top-left-radius: var(--border-radius);\n border-top-right-radius: var(--border-radius);\n}\n\n.Menu-clear.Button {\n text-decoration: none;\n color: var(--color-system-red-600);\n font-size: 1.3rem;\n font-weight: var(--font-weight-medium);\n padding: 1rem;\n width: 100%;\n border-bottom: 1px solid var(--color-border);\n}\n\n.Menu-clear.Button:active,\n.Menu-clear.Button:focus,\n.Menu-clear.Button:hover {\n outline: none;\n box-shadow: unset;\n color: var(--color-system-red-600);\n border-bottom-color: var(--color-border);\n background-color: var(--color-background-hover);\n}\n\n.Popover-content .Menu-search {\n width: 100%;\n\n /* Removing anything that could give it some height */\n & .Menu-search-hidden-placeholder {\n padding-top: 0;\n padding-bottom: 0;\n height: 0;\n border: none;\n visibility: hidden;\n }\n}\n\n.Menu--isVirtual {\n display: flex;\n align-items: stretch;\n flex-direction: column;\n}\n\n.MenuSize--xl {\n width: 32rem;\n}\n\n.MenuSize--lg {\n width: 24rem;\n}\n\n.MenuSize--md {\n width: 16rem;\n}\n\n.MenuSize--sm {\n width: 12rem;\n}\n\n.VirtualMenu-item-list {\n width: 100%;\n position: relative;\n}\n\n.VirtualMenu-item {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n}\n"],"names":[]}
|
package/dist/types.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,aAAK,QAAQ;IACX,KAAK,OAAO;IACZ,MAAM,OAAO;IACb,KAAK,OAAO;IACZ,WAAW,OAAO;CACnB;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@launchpad-ui/menu",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.3.0",
|
4
4
|
"status": "beta",
|
5
5
|
"publishConfig": {
|
6
6
|
"access": "public"
|
@@ -27,9 +27,10 @@
|
|
27
27
|
"source": "src/index.ts",
|
28
28
|
"dependencies": {
|
29
29
|
"@launchpad-ui/icons": "~0.2.2",
|
30
|
-
"@launchpad-ui/popover": "~0.
|
30
|
+
"@launchpad-ui/popover": "~0.5.0",
|
31
31
|
"@launchpad-ui/tokens": "~0.1.5",
|
32
|
-
"@launchpad-ui/tooltip": "~0.2
|
32
|
+
"@launchpad-ui/tooltip": "~0.3.2",
|
33
|
+
"@radix-ui/react-slot": "^1.0.0",
|
33
34
|
"@react-aria/focus": "^3.6.0",
|
34
35
|
"@react-aria/separator": "^3.2.0",
|
35
36
|
"clsx": "^1.2.0",
|
@@ -49,7 +50,7 @@
|
|
49
50
|
"react-dom": "^18.2.0"
|
50
51
|
},
|
51
52
|
"scripts": {
|
52
|
-
"build": "tsc --project tsconfig.build.json && node build.js",
|
53
|
+
"build": "tsc --project tsconfig.build.json && node ../../scripts/build.js",
|
53
54
|
"clean": "rm -rf dist",
|
54
55
|
"e2e": "playwright test --config=../../playwright.config.ct.ts",
|
55
56
|
"lint": "eslint '**/*.{ts,tsx,js}' && stylelint '**/*.css' --ignore-path ../../.stylelintignore",
|