@vector-im/compound-web 8.1.0 → 8.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Menu/ContextMenu.cjs +2 -1
- package/dist/components/Menu/ContextMenu.cjs.map +1 -1
- package/dist/components/Menu/ContextMenu.d.ts.map +1 -1
- package/dist/components/Menu/ContextMenu.js +2 -1
- package/dist/components/Menu/ContextMenu.js.map +1 -1
- package/dist/components/Menu/ContextMenu.module.css.cjs +9 -0
- package/dist/components/Menu/ContextMenu.module.css.cjs.map +1 -0
- package/dist/components/Menu/ContextMenu.module.css.js +9 -0
- package/dist/components/Menu/ContextMenu.module.css.js.map +1 -0
- package/dist/components/Menu/Menu.cjs +1 -13
- package/dist/components/Menu/Menu.cjs.map +1 -1
- package/dist/components/Menu/Menu.d.ts.map +1 -1
- package/dist/components/Menu/Menu.js +1 -13
- package/dist/components/Menu/Menu.js.map +1 -1
- package/dist/style.css.css +10 -0
- package/package.json +1 -1
- package/src/components/Menu/ContextMenu.module.css +10 -0
- package/src/components/Menu/ContextMenu.tsx +2 -1
- package/src/components/Menu/Menu.tsx +1 -11
|
@@ -7,6 +7,7 @@ const FloatingMenu = require("./FloatingMenu.cjs");
|
|
|
7
7
|
const vaul = require("vaul");
|
|
8
8
|
const classNames = require("classnames");
|
|
9
9
|
const DrawerMenu_module = require("./DrawerMenu.module.css.cjs");
|
|
10
|
+
const ContextMenu_module = require("./ContextMenu.module.css.cjs");
|
|
10
11
|
const MenuContext = require("./MenuContext.cjs");
|
|
11
12
|
const DrawerMenu = require("./DrawerMenu.cjs");
|
|
12
13
|
const platform = require("../../utils/platform.cjs");
|
|
@@ -57,7 +58,7 @@ const ContextMenu = ({
|
|
|
57
58
|
] }) })
|
|
58
59
|
] }) : /* @__PURE__ */ jsxRuntime.jsxs(reactContextMenu.Root, { onOpenChange, children: [
|
|
59
60
|
trigger,
|
|
60
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactContextMenu.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(reactContextMenu.Content, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(FloatingMenu.FloatingMenu, { showTitle, title, children }) }) })
|
|
61
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactContextMenu.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(reactContextMenu.Content, { asChild: true, className: classNames(ContextMenu_module.default.content), children: /* @__PURE__ */ jsxRuntime.jsx(FloatingMenu.FloatingMenu, { showTitle, title, children }) }) })
|
|
61
62
|
] });
|
|
62
63
|
};
|
|
63
64
|
exports.ContextMenu = ContextMenu;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextMenu.cjs","sources":["../../../src/components/Menu/ContextMenu.tsx"],"sourcesContent":["/*\nCopyright 2023 New Vector Ltd.\n\nSPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial\nPlease see LICENSE files in the repository root for full details.\n*/\n\nimport React, { FC, ReactNode, useCallback, useMemo, useState } from \"react\";\nimport {\n Root,\n Trigger,\n Portal,\n Content,\n ContextMenuItem,\n} from \"@radix-ui/react-context-menu\";\nimport { FloatingMenu } from \"./FloatingMenu\";\nimport { Drawer } from \"vaul\";\nimport classnames from \"classnames\";\nimport drawerStyles from \"./DrawerMenu.module.css\";\nimport { MenuContext, MenuData, MenuItemWrapperProps } from \"./MenuContext\";\nimport { DrawerMenu } from \"./DrawerMenu\";\nimport { getPlatform } from \"../../utils/platform\";\n\ninterface Props {\n /**\n * The menu title.\n */\n title: string;\n /**\n * Wether the title is displayed.\n * @default true\n */\n showTitle?: boolean;\n /**\n * Event handler called when the open state of the menu changes.\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * The trigger that can be right-clicked or long-pressed to open the menu.\n * This must be a component that accepts a ref and spreads props.\n * https://www.radix-ui.com/primitives/docs/guides/composition\n */\n trigger: ReactNode;\n /**\n * Whether the functionality of this menu is available through some other\n * keyboard-accessible means. Preferably this should be true, because context\n * menus are potentially difficult to discover, but if false the trigger will\n * become focusable so that it can be opened via keyboard navigation.\n */\n hasAccessibleAlternative: boolean;\n /**\n * The menu contents.\n */\n children: ReactNode;\n}\n\nconst ContextMenuItemWrapper: FC<MenuItemWrapperProps> = ({\n onSelect,\n children,\n}) => (\n <ContextMenuItem onSelect={onSelect ?? undefined} asChild>\n {children}\n </ContextMenuItem>\n);\n\n/**\n * A menu opened by right-clicking or long-pressing another UI element.\n */\nexport const ContextMenu: FC<Props> = ({\n title,\n showTitle = true,\n onOpenChange: onOpenChangeProp,\n trigger: triggerProp,\n hasAccessibleAlternative,\n children: childrenProp,\n}) => {\n const [open, setOpen] = useState(false);\n const onOpenChange = useCallback(\n (value: boolean) => {\n setOpen(value);\n onOpenChangeProp?.(value);\n },\n [setOpen, onOpenChangeProp],\n );\n\n // Normally, the menu takes the form of a floating box. But on Android and\n // iOS, the menu should morph into a drawer\n const platform = getPlatform();\n const drawer = platform === \"android\" || platform === \"ios\";\n const context: MenuData = useMemo(\n () => ({\n MenuItemWrapper: drawer ? null : ContextMenuItemWrapper,\n onOpenChange,\n }),\n [onOpenChange],\n );\n const children = (\n <MenuContext.Provider value={context}>{childrenProp}</MenuContext.Provider>\n );\n\n const trigger = (\n <Trigger\n aria-haspopup=\"menu\"\n tabIndex={hasAccessibleAlternative ? undefined : 0}\n asChild\n >\n {triggerProp}\n </Trigger>\n );\n\n // This is a small hack: Vaul drawers only support buttons as triggers, so\n // we end up mounting an empty Radix context menu tree alongside the\n // drawer tree, purely so we can use its Trigger component (which supports\n // touch for free). The resulting behavior and DOM tree looks exactly the\n // same as if Vaul provided a long-press trigger of its own, so I think\n // this is fine.\n return drawer ? (\n <>\n <Root onOpenChange={onOpenChange}>{trigger}</Root>\n <Drawer.Root open={open} onOpenChange={onOpenChange}>\n <Drawer.Portal>\n <Drawer.Overlay className={classnames(drawerStyles.bg)} />\n <Drawer.Content asChild>\n <DrawerMenu title={title}>{children}</DrawerMenu>\n </Drawer.Content>\n </Drawer.Portal>\n </Drawer.Root>\n </>\n ) : (\n <Root onOpenChange={onOpenChange}>\n {trigger}\n <Portal>\n <Content asChild>\n <FloatingMenu showTitle={showTitle} title={title}>\n {children}\n </FloatingMenu>\n </Content>\n </Portal>\n </Root>\n );\n};\n"],"names":["ContextMenuItem","useState","useCallback","platform","getPlatform","useMemo","jsx","MenuContext","Trigger","jsxs","Fragment","Root","Drawer","classnames","drawerStyles","DrawerMenu","Portal","Content","FloatingMenu"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ContextMenu.cjs","sources":["../../../src/components/Menu/ContextMenu.tsx"],"sourcesContent":["/*\nCopyright 2023 New Vector Ltd.\n\nSPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial\nPlease see LICENSE files in the repository root for full details.\n*/\n\nimport React, { FC, ReactNode, useCallback, useMemo, useState } from \"react\";\nimport {\n Root,\n Trigger,\n Portal,\n Content,\n ContextMenuItem,\n} from \"@radix-ui/react-context-menu\";\nimport { FloatingMenu } from \"./FloatingMenu\";\nimport { Drawer } from \"vaul\";\nimport classnames from \"classnames\";\nimport drawerStyles from \"./DrawerMenu.module.css\";\nimport contextStyles from \"./ContextMenu.module.css\";\nimport { MenuContext, MenuData, MenuItemWrapperProps } from \"./MenuContext\";\nimport { DrawerMenu } from \"./DrawerMenu\";\nimport { getPlatform } from \"../../utils/platform\";\n\ninterface Props {\n /**\n * The menu title.\n */\n title: string;\n /**\n * Wether the title is displayed.\n * @default true\n */\n showTitle?: boolean;\n /**\n * Event handler called when the open state of the menu changes.\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * The trigger that can be right-clicked or long-pressed to open the menu.\n * This must be a component that accepts a ref and spreads props.\n * https://www.radix-ui.com/primitives/docs/guides/composition\n */\n trigger: ReactNode;\n /**\n * Whether the functionality of this menu is available through some other\n * keyboard-accessible means. Preferably this should be true, because context\n * menus are potentially difficult to discover, but if false the trigger will\n * become focusable so that it can be opened via keyboard navigation.\n */\n hasAccessibleAlternative: boolean;\n /**\n * The menu contents.\n */\n children: ReactNode;\n}\n\nconst ContextMenuItemWrapper: FC<MenuItemWrapperProps> = ({\n onSelect,\n children,\n}) => (\n <ContextMenuItem onSelect={onSelect ?? undefined} asChild>\n {children}\n </ContextMenuItem>\n);\n\n/**\n * A menu opened by right-clicking or long-pressing another UI element.\n */\nexport const ContextMenu: FC<Props> = ({\n title,\n showTitle = true,\n onOpenChange: onOpenChangeProp,\n trigger: triggerProp,\n hasAccessibleAlternative,\n children: childrenProp,\n}) => {\n const [open, setOpen] = useState(false);\n const onOpenChange = useCallback(\n (value: boolean) => {\n setOpen(value);\n onOpenChangeProp?.(value);\n },\n [setOpen, onOpenChangeProp],\n );\n\n // Normally, the menu takes the form of a floating box. But on Android and\n // iOS, the menu should morph into a drawer\n const platform = getPlatform();\n const drawer = platform === \"android\" || platform === \"ios\";\n const context: MenuData = useMemo(\n () => ({\n MenuItemWrapper: drawer ? null : ContextMenuItemWrapper,\n onOpenChange,\n }),\n [onOpenChange],\n );\n const children = (\n <MenuContext.Provider value={context}>{childrenProp}</MenuContext.Provider>\n );\n\n const trigger = (\n <Trigger\n aria-haspopup=\"menu\"\n tabIndex={hasAccessibleAlternative ? undefined : 0}\n asChild\n >\n {triggerProp}\n </Trigger>\n );\n\n // This is a small hack: Vaul drawers only support buttons as triggers, so\n // we end up mounting an empty Radix context menu tree alongside the\n // drawer tree, purely so we can use its Trigger component (which supports\n // touch for free). The resulting behavior and DOM tree looks exactly the\n // same as if Vaul provided a long-press trigger of its own, so I think\n // this is fine.\n return drawer ? (\n <>\n <Root onOpenChange={onOpenChange}>{trigger}</Root>\n <Drawer.Root open={open} onOpenChange={onOpenChange}>\n <Drawer.Portal>\n <Drawer.Overlay className={classnames(drawerStyles.bg)} />\n <Drawer.Content asChild>\n <DrawerMenu title={title}>{children}</DrawerMenu>\n </Drawer.Content>\n </Drawer.Portal>\n </Drawer.Root>\n </>\n ) : (\n <Root onOpenChange={onOpenChange}>\n {trigger}\n <Portal>\n <Content asChild className={classnames(contextStyles.content)}>\n <FloatingMenu showTitle={showTitle} title={title}>\n {children}\n </FloatingMenu>\n </Content>\n </Portal>\n </Root>\n );\n};\n"],"names":["ContextMenuItem","useState","useCallback","platform","getPlatform","useMemo","jsx","MenuContext","Trigger","jsxs","Fragment","Root","Drawer","classnames","drawerStyles","DrawerMenu","Portal","Content","contextStyles","FloatingMenu"],"mappings":";;;;;;;;;;;;;AAyDA,MAAM,yBAAmD,CAAC;AAAA,EACxD;AAAA,EACA;AACF,qCACGA,kCAAgB,EAAA,UAAU,YAAY,QAAW,SAAO,MACtD,UACH;AAMK,MAAM,cAAyB,CAAC;AAAA,EACrC;AAAA,EACA,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,SAAS;AAAA,EACT;AAAA,EACA,UAAU;AACZ,MAAM;AACJ,QAAM,CAAC,MAAM,OAAO,IAAIC,MAAAA,SAAS,KAAK;AACtC,QAAM,eAAeC,MAAA;AAAA,IACnB,CAAC,UAAmB;AAClB,cAAQ,KAAK;AACb,yBAAmB,KAAK;AAAA,IAC1B;AAAA,IACA,CAAC,SAAS,gBAAgB;AAAA,EAC5B;AAIA,QAAMC,aAAWC,SAAAA,YAAY;AACvB,QAAA,SAASD,eAAa,aAAaA,eAAa;AACtD,QAAM,UAAoBE,MAAA;AAAA,IACxB,OAAO;AAAA,MACL,iBAAiB,SAAS,OAAO;AAAA,MACjC;AAAA,IAAA;AAAA,IAEF,CAAC,YAAY;AAAA,EACf;AACA,QAAM,WACHC,+BAAAC,YAAAA,YAAY,UAAZ,EAAqB,OAAO,SAAU,UAAa,cAAA;AAGtD,QAAM,UACJD,2BAAA;AAAA,IAACE,iBAAA;AAAA,IAAA;AAAA,MACC,iBAAc;AAAA,MACd,UAAU,2BAA2B,SAAY;AAAA,MACjD,SAAO;AAAA,MAEN,UAAA;AAAA,IAAA;AAAA,EACH;AASF,SAAO,SAEHC,2BAAAA,KAAAC,WAAA,UAAA,EAAA,UAAA;AAAA,IAACJ,2BAAAA,IAAAK,iBAAAA,MAAA,EAAK,cAA6B,UAAQ,QAAA,CAAA;AAAA,IAC3CL,2BAAAA,IAACM,YAAO,MAAP,EAAY,MAAY,cACvB,UAAAH,gCAACG,KAAAA,OAAO,QAAP,EACC,UAAA;AAAA,MAAAN,+BAACM,KAAAA,OAAO,SAAP,EAAe,WAAWC,WAAWC,kBAAA,QAAa,EAAE,GAAG;AAAA,MACxDR,2BAAAA,IAACM,KAAO,OAAA,SAAP,EAAe,SAAO,MACrB,UAACN,2BAAAA,IAAAS,WAAAA,YAAA,EAAW,OAAe,SAAS,CAAA,EACtC,CAAA;AAAA,IAAA,EAAA,CACF,EACF,CAAA;AAAA,EACF,EAAA,CAAA,IAECN,2BAAA,KAAAE,iBAAA,MAAA,EAAK,cACH,UAAA;AAAA,IAAA;AAAA,mCACAK,iBAAAA,QACC,EAAA,UAAAV,2BAAA,IAACW,iBAAQ,SAAA,EAAA,SAAO,MAAC,WAAWJ,WAAWK,mBAAc,QAAA,OAAO,GAC1D,UAACZ,2BAAAA,IAAAa,aAAA,cAAA,EAAa,WAAsB,OACjC,UACH,GACF,EACF,CAAA;AAAA,EAAA,GACF;AAEJ;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextMenu.d.ts","sourceRoot":"","sources":["../../../src/components/Menu/ContextMenu.tsx"],"names":[],"mappings":"AAOA,OAAc,EAAE,EAAE,EAAE,SAAS,EAAkC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"ContextMenu.d.ts","sourceRoot":"","sources":["../../../src/components/Menu/ContextMenu.tsx"],"names":[],"mappings":"AAOA,OAAc,EAAE,EAAE,EAAE,SAAS,EAAkC,MAAM,OAAO,CAAC;AAiB7E,UAAU,KAAK;IACb;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC;;;;OAIG;IACH,OAAO,EAAE,SAAS,CAAC;IACnB;;;;;OAKG;IACH,wBAAwB,EAAE,OAAO,CAAC;IAClC;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAC;CACrB;AAWD;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,EAAE,CAAC,KAAK,CAwEjC,CAAC"}
|
|
@@ -5,6 +5,7 @@ import { FloatingMenu } from "./FloatingMenu.js";
|
|
|
5
5
|
import { Drawer } from "vaul";
|
|
6
6
|
import classNames from "classnames";
|
|
7
7
|
import drawerMenu from "./DrawerMenu.module.css.js";
|
|
8
|
+
import contextStyles from "./ContextMenu.module.css.js";
|
|
8
9
|
import { MenuContext } from "./MenuContext.js";
|
|
9
10
|
import { DrawerMenu } from "./DrawerMenu.js";
|
|
10
11
|
import { getPlatform } from "../../utils/platform.js";
|
|
@@ -55,7 +56,7 @@ const ContextMenu = ({
|
|
|
55
56
|
] }) })
|
|
56
57
|
] }) : /* @__PURE__ */ jsxs(Root, { onOpenChange, children: [
|
|
57
58
|
trigger,
|
|
58
|
-
/* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(Content, { asChild: true, children: /* @__PURE__ */ jsx(FloatingMenu, { showTitle, title, children }) }) })
|
|
59
|
+
/* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(Content, { asChild: true, className: classNames(contextStyles.content), children: /* @__PURE__ */ jsx(FloatingMenu, { showTitle, title, children }) }) })
|
|
59
60
|
] });
|
|
60
61
|
};
|
|
61
62
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextMenu.js","sources":["../../../src/components/Menu/ContextMenu.tsx"],"sourcesContent":["/*\nCopyright 2023 New Vector Ltd.\n\nSPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial\nPlease see LICENSE files in the repository root for full details.\n*/\n\nimport React, { FC, ReactNode, useCallback, useMemo, useState } from \"react\";\nimport {\n Root,\n Trigger,\n Portal,\n Content,\n ContextMenuItem,\n} from \"@radix-ui/react-context-menu\";\nimport { FloatingMenu } from \"./FloatingMenu\";\nimport { Drawer } from \"vaul\";\nimport classnames from \"classnames\";\nimport drawerStyles from \"./DrawerMenu.module.css\";\nimport { MenuContext, MenuData, MenuItemWrapperProps } from \"./MenuContext\";\nimport { DrawerMenu } from \"./DrawerMenu\";\nimport { getPlatform } from \"../../utils/platform\";\n\ninterface Props {\n /**\n * The menu title.\n */\n title: string;\n /**\n * Wether the title is displayed.\n * @default true\n */\n showTitle?: boolean;\n /**\n * Event handler called when the open state of the menu changes.\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * The trigger that can be right-clicked or long-pressed to open the menu.\n * This must be a component that accepts a ref and spreads props.\n * https://www.radix-ui.com/primitives/docs/guides/composition\n */\n trigger: ReactNode;\n /**\n * Whether the functionality of this menu is available through some other\n * keyboard-accessible means. Preferably this should be true, because context\n * menus are potentially difficult to discover, but if false the trigger will\n * become focusable so that it can be opened via keyboard navigation.\n */\n hasAccessibleAlternative: boolean;\n /**\n * The menu contents.\n */\n children: ReactNode;\n}\n\nconst ContextMenuItemWrapper: FC<MenuItemWrapperProps> = ({\n onSelect,\n children,\n}) => (\n <ContextMenuItem onSelect={onSelect ?? undefined} asChild>\n {children}\n </ContextMenuItem>\n);\n\n/**\n * A menu opened by right-clicking or long-pressing another UI element.\n */\nexport const ContextMenu: FC<Props> = ({\n title,\n showTitle = true,\n onOpenChange: onOpenChangeProp,\n trigger: triggerProp,\n hasAccessibleAlternative,\n children: childrenProp,\n}) => {\n const [open, setOpen] = useState(false);\n const onOpenChange = useCallback(\n (value: boolean) => {\n setOpen(value);\n onOpenChangeProp?.(value);\n },\n [setOpen, onOpenChangeProp],\n );\n\n // Normally, the menu takes the form of a floating box. But on Android and\n // iOS, the menu should morph into a drawer\n const platform = getPlatform();\n const drawer = platform === \"android\" || platform === \"ios\";\n const context: MenuData = useMemo(\n () => ({\n MenuItemWrapper: drawer ? null : ContextMenuItemWrapper,\n onOpenChange,\n }),\n [onOpenChange],\n );\n const children = (\n <MenuContext.Provider value={context}>{childrenProp}</MenuContext.Provider>\n );\n\n const trigger = (\n <Trigger\n aria-haspopup=\"menu\"\n tabIndex={hasAccessibleAlternative ? undefined : 0}\n asChild\n >\n {triggerProp}\n </Trigger>\n );\n\n // This is a small hack: Vaul drawers only support buttons as triggers, so\n // we end up mounting an empty Radix context menu tree alongside the\n // drawer tree, purely so we can use its Trigger component (which supports\n // touch for free). The resulting behavior and DOM tree looks exactly the\n // same as if Vaul provided a long-press trigger of its own, so I think\n // this is fine.\n return drawer ? (\n <>\n <Root onOpenChange={onOpenChange}>{trigger}</Root>\n <Drawer.Root open={open} onOpenChange={onOpenChange}>\n <Drawer.Portal>\n <Drawer.Overlay className={classnames(drawerStyles.bg)} />\n <Drawer.Content asChild>\n <DrawerMenu title={title}>{children}</DrawerMenu>\n </Drawer.Content>\n </Drawer.Portal>\n </Drawer.Root>\n </>\n ) : (\n <Root onOpenChange={onOpenChange}>\n {trigger}\n <Portal>\n <Content asChild>\n <FloatingMenu showTitle={showTitle} title={title}>\n {children}\n </FloatingMenu>\n </Content>\n </Portal>\n </Root>\n );\n};\n"],"names":["classnames","drawerStyles"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ContextMenu.js","sources":["../../../src/components/Menu/ContextMenu.tsx"],"sourcesContent":["/*\nCopyright 2023 New Vector Ltd.\n\nSPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial\nPlease see LICENSE files in the repository root for full details.\n*/\n\nimport React, { FC, ReactNode, useCallback, useMemo, useState } from \"react\";\nimport {\n Root,\n Trigger,\n Portal,\n Content,\n ContextMenuItem,\n} from \"@radix-ui/react-context-menu\";\nimport { FloatingMenu } from \"./FloatingMenu\";\nimport { Drawer } from \"vaul\";\nimport classnames from \"classnames\";\nimport drawerStyles from \"./DrawerMenu.module.css\";\nimport contextStyles from \"./ContextMenu.module.css\";\nimport { MenuContext, MenuData, MenuItemWrapperProps } from \"./MenuContext\";\nimport { DrawerMenu } from \"./DrawerMenu\";\nimport { getPlatform } from \"../../utils/platform\";\n\ninterface Props {\n /**\n * The menu title.\n */\n title: string;\n /**\n * Wether the title is displayed.\n * @default true\n */\n showTitle?: boolean;\n /**\n * Event handler called when the open state of the menu changes.\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * The trigger that can be right-clicked or long-pressed to open the menu.\n * This must be a component that accepts a ref and spreads props.\n * https://www.radix-ui.com/primitives/docs/guides/composition\n */\n trigger: ReactNode;\n /**\n * Whether the functionality of this menu is available through some other\n * keyboard-accessible means. Preferably this should be true, because context\n * menus are potentially difficult to discover, but if false the trigger will\n * become focusable so that it can be opened via keyboard navigation.\n */\n hasAccessibleAlternative: boolean;\n /**\n * The menu contents.\n */\n children: ReactNode;\n}\n\nconst ContextMenuItemWrapper: FC<MenuItemWrapperProps> = ({\n onSelect,\n children,\n}) => (\n <ContextMenuItem onSelect={onSelect ?? undefined} asChild>\n {children}\n </ContextMenuItem>\n);\n\n/**\n * A menu opened by right-clicking or long-pressing another UI element.\n */\nexport const ContextMenu: FC<Props> = ({\n title,\n showTitle = true,\n onOpenChange: onOpenChangeProp,\n trigger: triggerProp,\n hasAccessibleAlternative,\n children: childrenProp,\n}) => {\n const [open, setOpen] = useState(false);\n const onOpenChange = useCallback(\n (value: boolean) => {\n setOpen(value);\n onOpenChangeProp?.(value);\n },\n [setOpen, onOpenChangeProp],\n );\n\n // Normally, the menu takes the form of a floating box. But on Android and\n // iOS, the menu should morph into a drawer\n const platform = getPlatform();\n const drawer = platform === \"android\" || platform === \"ios\";\n const context: MenuData = useMemo(\n () => ({\n MenuItemWrapper: drawer ? null : ContextMenuItemWrapper,\n onOpenChange,\n }),\n [onOpenChange],\n );\n const children = (\n <MenuContext.Provider value={context}>{childrenProp}</MenuContext.Provider>\n );\n\n const trigger = (\n <Trigger\n aria-haspopup=\"menu\"\n tabIndex={hasAccessibleAlternative ? undefined : 0}\n asChild\n >\n {triggerProp}\n </Trigger>\n );\n\n // This is a small hack: Vaul drawers only support buttons as triggers, so\n // we end up mounting an empty Radix context menu tree alongside the\n // drawer tree, purely so we can use its Trigger component (which supports\n // touch for free). The resulting behavior and DOM tree looks exactly the\n // same as if Vaul provided a long-press trigger of its own, so I think\n // this is fine.\n return drawer ? (\n <>\n <Root onOpenChange={onOpenChange}>{trigger}</Root>\n <Drawer.Root open={open} onOpenChange={onOpenChange}>\n <Drawer.Portal>\n <Drawer.Overlay className={classnames(drawerStyles.bg)} />\n <Drawer.Content asChild>\n <DrawerMenu title={title}>{children}</DrawerMenu>\n </Drawer.Content>\n </Drawer.Portal>\n </Drawer.Root>\n </>\n ) : (\n <Root onOpenChange={onOpenChange}>\n {trigger}\n <Portal>\n <Content asChild className={classnames(contextStyles.content)}>\n <FloatingMenu showTitle={showTitle} title={title}>\n {children}\n </FloatingMenu>\n </Content>\n </Portal>\n </Root>\n );\n};\n"],"names":["classnames","drawerStyles"],"mappings":";;;;;;;;;;;AAyDA,MAAM,yBAAmD,CAAC;AAAA,EACxD;AAAA,EACA;AACF,0BACG,iBAAgB,EAAA,UAAU,YAAY,QAAW,SAAO,MACtD,UACH;AAMK,MAAM,cAAyB,CAAC;AAAA,EACrC;AAAA,EACA,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,SAAS;AAAA,EACT;AAAA,EACA,UAAU;AACZ,MAAM;AACJ,QAAM,CAAC,MAAM,OAAO,IAAI,SAAS,KAAK;AACtC,QAAM,eAAe;AAAA,IACnB,CAAC,UAAmB;AAClB,cAAQ,KAAK;AACb,yBAAmB,KAAK;AAAA,IAC1B;AAAA,IACA,CAAC,SAAS,gBAAgB;AAAA,EAC5B;AAIA,QAAM,WAAW,YAAY;AACvB,QAAA,SAAS,aAAa,aAAa,aAAa;AACtD,QAAM,UAAoB;AAAA,IACxB,OAAO;AAAA,MACL,iBAAiB,SAAS,OAAO;AAAA,MACjC;AAAA,IAAA;AAAA,IAEF,CAAC,YAAY;AAAA,EACf;AACA,QAAM,WACH,oBAAA,YAAY,UAAZ,EAAqB,OAAO,SAAU,UAAa,cAAA;AAGtD,QAAM,UACJ;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,iBAAc;AAAA,MACd,UAAU,2BAA2B,SAAY;AAAA,MACjD,SAAO;AAAA,MAEN,UAAA;AAAA,IAAA;AAAA,EACH;AASF,SAAO,SAEH,qBAAA,UAAA,EAAA,UAAA;AAAA,IAAC,oBAAA,MAAA,EAAK,cAA6B,UAAQ,QAAA,CAAA;AAAA,IAC3C,oBAAC,OAAO,MAAP,EAAY,MAAY,cACvB,UAAA,qBAAC,OAAO,QAAP,EACC,UAAA;AAAA,MAAA,oBAAC,OAAO,SAAP,EAAe,WAAWA,WAAWC,WAAa,EAAE,GAAG;AAAA,MACxD,oBAAC,OAAO,SAAP,EAAe,SAAO,MACrB,UAAC,oBAAA,YAAA,EAAW,OAAe,SAAS,CAAA,EACtC,CAAA;AAAA,IAAA,EAAA,CACF,EACF,CAAA;AAAA,EACF,EAAA,CAAA,IAEC,qBAAA,MAAA,EAAK,cACH,UAAA;AAAA,IAAA;AAAA,wBACA,QACC,EAAA,UAAA,oBAAC,SAAQ,EAAA,SAAO,MAAC,WAAWD,WAAW,cAAc,OAAO,GAC1D,UAAC,oBAAA,cAAA,EAAa,WAAsB,OACjC,UACH,GACF,EACF,CAAA;AAAA,EAAA,GACF;AAEJ;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const content = "_content_vnv5k_8";
|
|
4
|
+
const contextStyles = {
|
|
5
|
+
content
|
|
6
|
+
};
|
|
7
|
+
exports.content = content;
|
|
8
|
+
exports.default = contextStyles;
|
|
9
|
+
//# sourceMappingURL=ContextMenu.module.css.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContextMenu.module.css.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContextMenu.module.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -42,19 +42,7 @@ const Menu = ({
|
|
|
42
42
|
] })
|
|
43
43
|
] }) : /* @__PURE__ */ jsxRuntime.jsxs(reactDropdownMenu.Root, { open, onOpenChange, children: [
|
|
44
44
|
/* @__PURE__ */ jsxRuntime.jsx(reactDropdownMenu.Trigger, { asChild: true, children: trigger }),
|
|
45
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactDropdownMenu.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
46
|
-
reactDropdownMenu.Content,
|
|
47
|
-
{
|
|
48
|
-
asChild: true,
|
|
49
|
-
side,
|
|
50
|
-
align,
|
|
51
|
-
sideOffset: 8,
|
|
52
|
-
onCloseAutoFocus: (event) => {
|
|
53
|
-
event.preventDefault();
|
|
54
|
-
},
|
|
55
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(FloatingMenu.FloatingMenu, { title, showTitle, children })
|
|
56
|
-
}
|
|
57
|
-
) })
|
|
45
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactDropdownMenu.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(reactDropdownMenu.Content, { asChild: true, side, align, sideOffset: 8, children: /* @__PURE__ */ jsxRuntime.jsx(FloatingMenu.FloatingMenu, { title, showTitle, children }) }) })
|
|
58
46
|
] });
|
|
59
47
|
};
|
|
60
48
|
exports.Menu = Menu;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Menu.cjs","sources":["../../../src/components/Menu/Menu.tsx"],"sourcesContent":["/*\nCopyright 2023 New Vector Ltd.\n\nSPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial\nPlease see LICENSE files in the repository root for full details.\n*/\n\nimport React, { FC, ReactNode, useMemo } from \"react\";\nimport {\n Root,\n Trigger,\n Portal,\n Content,\n DropdownMenuItem,\n} from \"@radix-ui/react-dropdown-menu\";\nimport { FloatingMenu } from \"./FloatingMenu\";\nimport { Drawer } from \"vaul\";\nimport classnames from \"classnames\";\nimport drawerMenu from \"./DrawerMenu.module.css\";\nimport { MenuContext, MenuData, MenuItemWrapperProps } from \"./MenuContext\";\nimport { DrawerMenu } from \"./DrawerMenu\";\nimport { getPlatform } from \"../../utils/platform\";\n\ninterface Props {\n /**\n * The menu title. This can be hidden with `showTitle={false}` in which case it will only\n * be a label for screen readers.\n */\n title: string;\n /**\n * Controls whether the title is displayed (see `title` prop). Titles are only displayed on\n * web: on mobile, this parameter is ignored.\n */\n showTitle?: boolean;\n /**\n * Whether the menu is open.\n */\n open: boolean;\n /**\n * Event handler called when the open state of the menu changes. This includes\n * anything like clicking the trigger, selecting a menu item, or dismissing\n * the menu with the mouse or keyboard.\n */\n onOpenChange: (open: boolean) => void;\n /**\n * The button that opens the menu. This must be a component that accepts a ref\n * and spreads props.\n * https://www.radix-ui.com/primitives/docs/guides/composition\n */\n trigger: ReactNode;\n /**\n * The menu contents.\n */\n children: ReactNode;\n /**\n * The side of the trigger on which to place the menu. Note that the menu may\n * still end up on a different side than the one you request if there isn't\n * enough space.\n * @default bottom\n */\n side?: \"top\" | \"right\" | \"bottom\" | \"left\";\n /**\n * The edge along which the menu and trigger will be aligned.\n * @default center\n */\n align?: \"start\" | \"center\" | \"end\";\n}\n\nconst DropdownMenuItemWrapper: FC<MenuItemWrapperProps> = ({\n onSelect,\n children,\n}) => (\n <DropdownMenuItem onSelect={onSelect ?? undefined} asChild>\n {children}\n </DropdownMenuItem>\n);\n\n/**\n * A menu opened by pressing a button.\n */\nexport const Menu: FC<Props> = ({\n title,\n showTitle = true,\n open,\n onOpenChange,\n trigger,\n children: childrenProp,\n side = \"bottom\",\n align = \"center\",\n}) => {\n // Normally, the menu takes the form of a floating box. But on Android and\n // iOS, the menu should morph into a drawer\n const platform = getPlatform();\n const drawer = platform === \"android\" || platform === \"ios\";\n const context: MenuData = useMemo(\n () => ({\n MenuItemWrapper: drawer ? null : DropdownMenuItemWrapper,\n onOpenChange,\n }),\n [onOpenChange],\n );\n const children = (\n <MenuContext.Provider value={context}>{childrenProp}</MenuContext.Provider>\n );\n\n return drawer ? (\n <Drawer.Root open={open} onOpenChange={onOpenChange}>\n <Drawer.Trigger asChild>{trigger}</Drawer.Trigger>\n <Drawer.Portal>\n <Drawer.Overlay className={classnames(drawerMenu.bg)} />\n <Drawer.Content asChild>\n <DrawerMenu title={title}>{children}</DrawerMenu>\n </Drawer.Content>\n </Drawer.Portal>\n </Drawer.Root>\n ) : (\n <Root open={open} onOpenChange={onOpenChange}>\n <Trigger asChild>{trigger}</Trigger>\n <Portal>\n <Content
|
|
1
|
+
{"version":3,"file":"Menu.cjs","sources":["../../../src/components/Menu/Menu.tsx"],"sourcesContent":["/*\nCopyright 2023 New Vector Ltd.\n\nSPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial\nPlease see LICENSE files in the repository root for full details.\n*/\n\nimport React, { FC, ReactNode, useMemo } from \"react\";\nimport {\n Root,\n Trigger,\n Portal,\n Content,\n DropdownMenuItem,\n} from \"@radix-ui/react-dropdown-menu\";\nimport { FloatingMenu } from \"./FloatingMenu\";\nimport { Drawer } from \"vaul\";\nimport classnames from \"classnames\";\nimport drawerMenu from \"./DrawerMenu.module.css\";\nimport { MenuContext, MenuData, MenuItemWrapperProps } from \"./MenuContext\";\nimport { DrawerMenu } from \"./DrawerMenu\";\nimport { getPlatform } from \"../../utils/platform\";\n\ninterface Props {\n /**\n * The menu title. This can be hidden with `showTitle={false}` in which case it will only\n * be a label for screen readers.\n */\n title: string;\n /**\n * Controls whether the title is displayed (see `title` prop). Titles are only displayed on\n * web: on mobile, this parameter is ignored.\n */\n showTitle?: boolean;\n /**\n * Whether the menu is open.\n */\n open: boolean;\n /**\n * Event handler called when the open state of the menu changes. This includes\n * anything like clicking the trigger, selecting a menu item, or dismissing\n * the menu with the mouse or keyboard.\n */\n onOpenChange: (open: boolean) => void;\n /**\n * The button that opens the menu. This must be a component that accepts a ref\n * and spreads props.\n * https://www.radix-ui.com/primitives/docs/guides/composition\n */\n trigger: ReactNode;\n /**\n * The menu contents.\n */\n children: ReactNode;\n /**\n * The side of the trigger on which to place the menu. Note that the menu may\n * still end up on a different side than the one you request if there isn't\n * enough space.\n * @default bottom\n */\n side?: \"top\" | \"right\" | \"bottom\" | \"left\";\n /**\n * The edge along which the menu and trigger will be aligned.\n * @default center\n */\n align?: \"start\" | \"center\" | \"end\";\n}\n\nconst DropdownMenuItemWrapper: FC<MenuItemWrapperProps> = ({\n onSelect,\n children,\n}) => (\n <DropdownMenuItem onSelect={onSelect ?? undefined} asChild>\n {children}\n </DropdownMenuItem>\n);\n\n/**\n * A menu opened by pressing a button.\n */\nexport const Menu: FC<Props> = ({\n title,\n showTitle = true,\n open,\n onOpenChange,\n trigger,\n children: childrenProp,\n side = \"bottom\",\n align = \"center\",\n}) => {\n // Normally, the menu takes the form of a floating box. But on Android and\n // iOS, the menu should morph into a drawer\n const platform = getPlatform();\n const drawer = platform === \"android\" || platform === \"ios\";\n const context: MenuData = useMemo(\n () => ({\n MenuItemWrapper: drawer ? null : DropdownMenuItemWrapper,\n onOpenChange,\n }),\n [onOpenChange],\n );\n const children = (\n <MenuContext.Provider value={context}>{childrenProp}</MenuContext.Provider>\n );\n\n return drawer ? (\n <Drawer.Root open={open} onOpenChange={onOpenChange}>\n <Drawer.Trigger asChild>{trigger}</Drawer.Trigger>\n <Drawer.Portal>\n <Drawer.Overlay className={classnames(drawerMenu.bg)} />\n <Drawer.Content asChild>\n <DrawerMenu title={title}>{children}</DrawerMenu>\n </Drawer.Content>\n </Drawer.Portal>\n </Drawer.Root>\n ) : (\n <Root open={open} onOpenChange={onOpenChange}>\n <Trigger asChild>{trigger}</Trigger>\n <Portal>\n <Content asChild side={side} align={align} sideOffset={8}>\n <FloatingMenu title={title} showTitle={showTitle}>\n {children}\n </FloatingMenu>\n </Content>\n </Portal>\n </Root>\n );\n};\n"],"names":["DropdownMenuItem","platform","getPlatform","useMemo","jsx","MenuContext","jsxs","Drawer","classnames","drawerMenu","DrawerMenu","Root","Trigger","Portal","Content","FloatingMenu"],"mappings":";;;;;;;;;;;;AAoEA,MAAM,0BAAoD,CAAC;AAAA,EACzD;AAAA,EACA;AACF,qCACGA,oCAAiB,EAAA,UAAU,YAAY,QAAW,SAAO,MACvD,UACH;AAMK,MAAM,OAAkB,CAAC;AAAA,EAC9B;AAAA,EACA,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AACV,MAAM;AAGJ,QAAMC,aAAWC,SAAAA,YAAY;AACvB,QAAA,SAASD,eAAa,aAAaA,eAAa;AACtD,QAAM,UAAoBE,MAAA;AAAA,IACxB,OAAO;AAAA,MACL,iBAAiB,SAAS,OAAO;AAAA,MACjC;AAAA,IAAA;AAAA,IAEF,CAAC,YAAY;AAAA,EACf;AACA,QAAM,WACHC,+BAAAC,YAAAA,YAAY,UAAZ,EAAqB,OAAO,SAAU,UAAa,cAAA;AAGtD,SAAO,SACJC,2BAAAA,KAAAC,KAAA,OAAO,MAAP,EAAY,MAAY,cACvB,UAAA;AAAA,IAAAH,2BAAA,IAACG,KAAO,OAAA,SAAP,EAAe,SAAO,MAAE,UAAQ,SAAA;AAAA,IACjCD,2BAAAA,KAACC,KAAO,OAAA,QAAP,EACC,UAAA;AAAA,MAAAH,+BAACG,KAAAA,OAAO,SAAP,EAAe,WAAWC,WAAWC,kBAAA,QAAW,EAAE,GAAG;AAAA,MACtDL,2BAAAA,IAACG,KAAO,OAAA,SAAP,EAAe,SAAO,MACrB,UAACH,2BAAAA,IAAAM,WAAAA,YAAA,EAAW,OAAe,SAAS,CAAA,EACtC,CAAA;AAAA,IAAA,EACF,CAAA;AAAA,EAAA,EACF,CAAA,IAEAJ,2BAAAA,KAACK,kBAAAA,MAAK,EAAA,MAAY,cAChB,UAAA;AAAA,IAACP,2BAAA,IAAAQ,kBAAA,SAAA,EAAQ,SAAO,MAAE,UAAQ,SAAA;AAAA,mCACzBC,kBAAAA,QACC,EAAA,UAAAT,2BAAA,IAACU,kBAAQ,SAAA,EAAA,SAAO,MAAC,MAAY,OAAc,YAAY,GACrD,yCAACC,2BAAa,EAAA,OAAc,WACzB,UACH,GACF,EACF,CAAA;AAAA,EAAA,GACF;AAEJ;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Menu.d.ts","sourceRoot":"","sources":["../../../src/components/Menu/Menu.tsx"],"names":[],"mappings":"AAOA,OAAc,EAAE,EAAE,EAAE,SAAS,EAAW,MAAM,OAAO,CAAC;AAgBtD,UAAU,KAAK;IACb;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,IAAI,EAAE,OAAO,CAAC;IACd;;;;OAIG;IACH,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC;;;;OAIG;IACH,OAAO,EAAE,SAAS,CAAC;IACnB;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAC;IACpB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC3C;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;CACpC;AAWD;;GAEG;AACH,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"Menu.d.ts","sourceRoot":"","sources":["../../../src/components/Menu/Menu.tsx"],"names":[],"mappings":"AAOA,OAAc,EAAE,EAAE,EAAE,SAAS,EAAW,MAAM,OAAO,CAAC;AAgBtD,UAAU,KAAK;IACb;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,IAAI,EAAE,OAAO,CAAC;IACd;;;;OAIG;IACH,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC;;;;OAIG;IACH,OAAO,EAAE,SAAS,CAAC;IACnB;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAC;IACpB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC3C;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;CACpC;AAWD;;GAEG;AACH,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,KAAK,CA+C1B,CAAC"}
|
|
@@ -40,19 +40,7 @@ const Menu = ({
|
|
|
40
40
|
] })
|
|
41
41
|
] }) : /* @__PURE__ */ jsxs(Root, { open, onOpenChange, children: [
|
|
42
42
|
/* @__PURE__ */ jsx(Trigger, { asChild: true, children: trigger }),
|
|
43
|
-
/* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(
|
|
44
|
-
Content,
|
|
45
|
-
{
|
|
46
|
-
asChild: true,
|
|
47
|
-
side,
|
|
48
|
-
align,
|
|
49
|
-
sideOffset: 8,
|
|
50
|
-
onCloseAutoFocus: (event) => {
|
|
51
|
-
event.preventDefault();
|
|
52
|
-
},
|
|
53
|
-
children: /* @__PURE__ */ jsx(FloatingMenu, { title, showTitle, children })
|
|
54
|
-
}
|
|
55
|
-
) })
|
|
43
|
+
/* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(Content, { asChild: true, side, align, sideOffset: 8, children: /* @__PURE__ */ jsx(FloatingMenu, { title, showTitle, children }) }) })
|
|
56
44
|
] });
|
|
57
45
|
};
|
|
58
46
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Menu.js","sources":["../../../src/components/Menu/Menu.tsx"],"sourcesContent":["/*\nCopyright 2023 New Vector Ltd.\n\nSPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial\nPlease see LICENSE files in the repository root for full details.\n*/\n\nimport React, { FC, ReactNode, useMemo } from \"react\";\nimport {\n Root,\n Trigger,\n Portal,\n Content,\n DropdownMenuItem,\n} from \"@radix-ui/react-dropdown-menu\";\nimport { FloatingMenu } from \"./FloatingMenu\";\nimport { Drawer } from \"vaul\";\nimport classnames from \"classnames\";\nimport drawerMenu from \"./DrawerMenu.module.css\";\nimport { MenuContext, MenuData, MenuItemWrapperProps } from \"./MenuContext\";\nimport { DrawerMenu } from \"./DrawerMenu\";\nimport { getPlatform } from \"../../utils/platform\";\n\ninterface Props {\n /**\n * The menu title. This can be hidden with `showTitle={false}` in which case it will only\n * be a label for screen readers.\n */\n title: string;\n /**\n * Controls whether the title is displayed (see `title` prop). Titles are only displayed on\n * web: on mobile, this parameter is ignored.\n */\n showTitle?: boolean;\n /**\n * Whether the menu is open.\n */\n open: boolean;\n /**\n * Event handler called when the open state of the menu changes. This includes\n * anything like clicking the trigger, selecting a menu item, or dismissing\n * the menu with the mouse or keyboard.\n */\n onOpenChange: (open: boolean) => void;\n /**\n * The button that opens the menu. This must be a component that accepts a ref\n * and spreads props.\n * https://www.radix-ui.com/primitives/docs/guides/composition\n */\n trigger: ReactNode;\n /**\n * The menu contents.\n */\n children: ReactNode;\n /**\n * The side of the trigger on which to place the menu. Note that the menu may\n * still end up on a different side than the one you request if there isn't\n * enough space.\n * @default bottom\n */\n side?: \"top\" | \"right\" | \"bottom\" | \"left\";\n /**\n * The edge along which the menu and trigger will be aligned.\n * @default center\n */\n align?: \"start\" | \"center\" | \"end\";\n}\n\nconst DropdownMenuItemWrapper: FC<MenuItemWrapperProps> = ({\n onSelect,\n children,\n}) => (\n <DropdownMenuItem onSelect={onSelect ?? undefined} asChild>\n {children}\n </DropdownMenuItem>\n);\n\n/**\n * A menu opened by pressing a button.\n */\nexport const Menu: FC<Props> = ({\n title,\n showTitle = true,\n open,\n onOpenChange,\n trigger,\n children: childrenProp,\n side = \"bottom\",\n align = \"center\",\n}) => {\n // Normally, the menu takes the form of a floating box. But on Android and\n // iOS, the menu should morph into a drawer\n const platform = getPlatform();\n const drawer = platform === \"android\" || platform === \"ios\";\n const context: MenuData = useMemo(\n () => ({\n MenuItemWrapper: drawer ? null : DropdownMenuItemWrapper,\n onOpenChange,\n }),\n [onOpenChange],\n );\n const children = (\n <MenuContext.Provider value={context}>{childrenProp}</MenuContext.Provider>\n );\n\n return drawer ? (\n <Drawer.Root open={open} onOpenChange={onOpenChange}>\n <Drawer.Trigger asChild>{trigger}</Drawer.Trigger>\n <Drawer.Portal>\n <Drawer.Overlay className={classnames(drawerMenu.bg)} />\n <Drawer.Content asChild>\n <DrawerMenu title={title}>{children}</DrawerMenu>\n </Drawer.Content>\n </Drawer.Portal>\n </Drawer.Root>\n ) : (\n <Root open={open} onOpenChange={onOpenChange}>\n <Trigger asChild>{trigger}</Trigger>\n <Portal>\n <Content
|
|
1
|
+
{"version":3,"file":"Menu.js","sources":["../../../src/components/Menu/Menu.tsx"],"sourcesContent":["/*\nCopyright 2023 New Vector Ltd.\n\nSPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial\nPlease see LICENSE files in the repository root for full details.\n*/\n\nimport React, { FC, ReactNode, useMemo } from \"react\";\nimport {\n Root,\n Trigger,\n Portal,\n Content,\n DropdownMenuItem,\n} from \"@radix-ui/react-dropdown-menu\";\nimport { FloatingMenu } from \"./FloatingMenu\";\nimport { Drawer } from \"vaul\";\nimport classnames from \"classnames\";\nimport drawerMenu from \"./DrawerMenu.module.css\";\nimport { MenuContext, MenuData, MenuItemWrapperProps } from \"./MenuContext\";\nimport { DrawerMenu } from \"./DrawerMenu\";\nimport { getPlatform } from \"../../utils/platform\";\n\ninterface Props {\n /**\n * The menu title. This can be hidden with `showTitle={false}` in which case it will only\n * be a label for screen readers.\n */\n title: string;\n /**\n * Controls whether the title is displayed (see `title` prop). Titles are only displayed on\n * web: on mobile, this parameter is ignored.\n */\n showTitle?: boolean;\n /**\n * Whether the menu is open.\n */\n open: boolean;\n /**\n * Event handler called when the open state of the menu changes. This includes\n * anything like clicking the trigger, selecting a menu item, or dismissing\n * the menu with the mouse or keyboard.\n */\n onOpenChange: (open: boolean) => void;\n /**\n * The button that opens the menu. This must be a component that accepts a ref\n * and spreads props.\n * https://www.radix-ui.com/primitives/docs/guides/composition\n */\n trigger: ReactNode;\n /**\n * The menu contents.\n */\n children: ReactNode;\n /**\n * The side of the trigger on which to place the menu. Note that the menu may\n * still end up on a different side than the one you request if there isn't\n * enough space.\n * @default bottom\n */\n side?: \"top\" | \"right\" | \"bottom\" | \"left\";\n /**\n * The edge along which the menu and trigger will be aligned.\n * @default center\n */\n align?: \"start\" | \"center\" | \"end\";\n}\n\nconst DropdownMenuItemWrapper: FC<MenuItemWrapperProps> = ({\n onSelect,\n children,\n}) => (\n <DropdownMenuItem onSelect={onSelect ?? undefined} asChild>\n {children}\n </DropdownMenuItem>\n);\n\n/**\n * A menu opened by pressing a button.\n */\nexport const Menu: FC<Props> = ({\n title,\n showTitle = true,\n open,\n onOpenChange,\n trigger,\n children: childrenProp,\n side = \"bottom\",\n align = \"center\",\n}) => {\n // Normally, the menu takes the form of a floating box. But on Android and\n // iOS, the menu should morph into a drawer\n const platform = getPlatform();\n const drawer = platform === \"android\" || platform === \"ios\";\n const context: MenuData = useMemo(\n () => ({\n MenuItemWrapper: drawer ? null : DropdownMenuItemWrapper,\n onOpenChange,\n }),\n [onOpenChange],\n );\n const children = (\n <MenuContext.Provider value={context}>{childrenProp}</MenuContext.Provider>\n );\n\n return drawer ? (\n <Drawer.Root open={open} onOpenChange={onOpenChange}>\n <Drawer.Trigger asChild>{trigger}</Drawer.Trigger>\n <Drawer.Portal>\n <Drawer.Overlay className={classnames(drawerMenu.bg)} />\n <Drawer.Content asChild>\n <DrawerMenu title={title}>{children}</DrawerMenu>\n </Drawer.Content>\n </Drawer.Portal>\n </Drawer.Root>\n ) : (\n <Root open={open} onOpenChange={onOpenChange}>\n <Trigger asChild>{trigger}</Trigger>\n <Portal>\n <Content asChild side={side} align={align} sideOffset={8}>\n <FloatingMenu title={title} showTitle={showTitle}>\n {children}\n </FloatingMenu>\n </Content>\n </Portal>\n </Root>\n );\n};\n"],"names":["classnames"],"mappings":";;;;;;;;;;AAoEA,MAAM,0BAAoD,CAAC;AAAA,EACzD;AAAA,EACA;AACF,0BACG,kBAAiB,EAAA,UAAU,YAAY,QAAW,SAAO,MACvD,UACH;AAMK,MAAM,OAAkB,CAAC;AAAA,EAC9B;AAAA,EACA,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AACV,MAAM;AAGJ,QAAM,WAAW,YAAY;AACvB,QAAA,SAAS,aAAa,aAAa,aAAa;AACtD,QAAM,UAAoB;AAAA,IACxB,OAAO;AAAA,MACL,iBAAiB,SAAS,OAAO;AAAA,MACjC;AAAA,IAAA;AAAA,IAEF,CAAC,YAAY;AAAA,EACf;AACA,QAAM,WACH,oBAAA,YAAY,UAAZ,EAAqB,OAAO,SAAU,UAAa,cAAA;AAGtD,SAAO,SACJ,qBAAA,OAAO,MAAP,EAAY,MAAY,cACvB,UAAA;AAAA,IAAA,oBAAC,OAAO,SAAP,EAAe,SAAO,MAAE,UAAQ,SAAA;AAAA,IACjC,qBAAC,OAAO,QAAP,EACC,UAAA;AAAA,MAAA,oBAAC,OAAO,SAAP,EAAe,WAAWA,WAAW,WAAW,EAAE,GAAG;AAAA,MACtD,oBAAC,OAAO,SAAP,EAAe,SAAO,MACrB,UAAC,oBAAA,YAAA,EAAW,OAAe,SAAS,CAAA,EACtC,CAAA;AAAA,IAAA,EACF,CAAA;AAAA,EAAA,EACF,CAAA,IAEA,qBAAC,MAAK,EAAA,MAAY,cAChB,UAAA;AAAA,IAAC,oBAAA,SAAA,EAAQ,SAAO,MAAE,UAAQ,SAAA;AAAA,wBACzB,QACC,EAAA,UAAA,oBAAC,SAAQ,EAAA,SAAO,MAAC,MAAY,OAAc,YAAY,GACrD,8BAAC,cAAa,EAAA,OAAc,WACzB,UACH,GACF,EACF,CAAA;AAAA,EAAA,GACF;AAEJ;"}
|
package/dist/style.css.css
CHANGED
|
@@ -779,6 +779,16 @@ Please see LICENSE files in the repository root for full details.
|
|
|
779
779
|
background: var(--cpd-color-icon-secondary);
|
|
780
780
|
border-radius: var(--cpd-radius-pill-effect);
|
|
781
781
|
}
|
|
782
|
+
/*
|
|
783
|
+
* Copyright 2025 New Vector Ltd
|
|
784
|
+
*
|
|
785
|
+
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
786
|
+
* Please see LICENSE files in the repository root for full details.
|
|
787
|
+
*/
|
|
788
|
+
|
|
789
|
+
._content_vnv5k_8[data-state="closed"] {
|
|
790
|
+
animation: none;
|
|
791
|
+
}
|
|
782
792
|
/*
|
|
783
793
|
Copyright 2023 New Vector Ltd.
|
|
784
794
|
|
package/package.json
CHANGED
|
@@ -17,6 +17,7 @@ import { FloatingMenu } from "./FloatingMenu";
|
|
|
17
17
|
import { Drawer } from "vaul";
|
|
18
18
|
import classnames from "classnames";
|
|
19
19
|
import drawerStyles from "./DrawerMenu.module.css";
|
|
20
|
+
import contextStyles from "./ContextMenu.module.css";
|
|
20
21
|
import { MenuContext, MenuData, MenuItemWrapperProps } from "./MenuContext";
|
|
21
22
|
import { DrawerMenu } from "./DrawerMenu";
|
|
22
23
|
import { getPlatform } from "../../utils/platform";
|
|
@@ -130,7 +131,7 @@ export const ContextMenu: FC<Props> = ({
|
|
|
130
131
|
<Root onOpenChange={onOpenChange}>
|
|
131
132
|
{trigger}
|
|
132
133
|
<Portal>
|
|
133
|
-
<Content asChild>
|
|
134
|
+
<Content asChild className={classnames(contextStyles.content)}>
|
|
134
135
|
<FloatingMenu showTitle={showTitle} title={title}>
|
|
135
136
|
{children}
|
|
136
137
|
</FloatingMenu>
|
|
@@ -117,17 +117,7 @@ export const Menu: FC<Props> = ({
|
|
|
117
117
|
<Root open={open} onOpenChange={onOpenChange}>
|
|
118
118
|
<Trigger asChild>{trigger}</Trigger>
|
|
119
119
|
<Portal>
|
|
120
|
-
<Content
|
|
121
|
-
asChild
|
|
122
|
-
side={side}
|
|
123
|
-
align={align}
|
|
124
|
-
sideOffset={8}
|
|
125
|
-
onCloseAutoFocus={(event) => {
|
|
126
|
-
// https://www.radix-ui.com/primitives/docs/components/dropdown-menu#content => onCloseAutoFocus
|
|
127
|
-
// Prevent the default behavior of focusing the trigger when the menu closes
|
|
128
|
-
event.preventDefault();
|
|
129
|
-
}}
|
|
130
|
-
>
|
|
120
|
+
<Content asChild side={side} align={align} sideOffset={8}>
|
|
131
121
|
<FloatingMenu title={title} showTitle={showTitle}>
|
|
132
122
|
{children}
|
|
133
123
|
</FloatingMenu>
|