@vector-im/compound-web 7.6.4 → 7.7.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.
@@ -0,0 +1,23 @@
1
+ import { default as React } from 'react';
2
+ /**
3
+ * A menu item with a checkbox control.
4
+ * Must be used within a compound Menu or other `menu` or `menubar` aria role subtree.
5
+ */
6
+ export declare const CheckboxMenuItem: React.ForwardRefExoticComponent<Pick<{
7
+ as?: ("a" | "button" | "div") | undefined;
8
+ className?: string;
9
+ Icon: React.ComponentType<React.SVGAttributes<SVGElement>> | React.ReactElement;
10
+ label: string | null;
11
+ labelProps?: React.ComponentPropsWithoutRef<typeof import('../..').Text>;
12
+ onSelect: ((e: Event) => void) | null;
13
+ onClick?: (e: Event) => void;
14
+ kind?: "primary" | "critical";
15
+ disabled?: boolean;
16
+ hideChevron?: boolean;
17
+ } & Omit<Omit<React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> | Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> | Omit<React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, "ref">, "onClick" | "onSelect">, "label" | "className" | "disabled" | "onSelect"> & {
18
+ /**
19
+ * Whether the checkbox is checked.
20
+ */
21
+ checked: boolean;
22
+ } & React.RefAttributes<HTMLInputElement>>;
23
+ //# sourceMappingURL=CheckboxMenuItem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CheckboxMenuItem.d.ts","sourceRoot":"","sources":["../../../src/components/Menu/CheckboxMenuItem.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAyD,MAAM,OAAO,CAAC;AAc9E;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;IAV3B;;OAEG;aACM,OAAO;0CA2CjB,CAAC"}
@@ -19,6 +19,7 @@ const MenuItem = ({
19
19
  children,
20
20
  onClick: onClickProp,
21
21
  disabled,
22
+ hideChevron,
22
23
  ...props
23
24
  }) => {
24
25
  const Component = as ?? "button";
@@ -75,7 +76,7 @@ const MenuItem = ({
75
76
  children: label
76
77
  }
77
78
  ),
78
- (Component === "button" || Component === "a") && /* @__PURE__ */ jsxRuntime.jsx(
79
+ !hideChevron && (Component === "button" || Component === "a") && /* @__PURE__ */ jsxRuntime.jsx(
79
80
  ChevronRightIcon,
80
81
  {
81
82
  width: 8,
@@ -1 +1 @@
1
- {"version":3,"file":"MenuItem.cjs","sources":["../../../src/components/Menu/MenuItem.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 classnames from \"classnames\";\nimport React, {\n ComponentPropsWithoutRef,\n ComponentType,\n ElementType,\n isValidElement,\n ReactElement,\n SVGAttributes,\n useCallback,\n useContext,\n} from \"react\";\nimport styles from \"./MenuItem.module.css\";\nimport { Text } from \"../Typography/Text\";\nimport ChevronRightIcon from \"@vector-im/compound-design-tokens/assets/web/icons/chevron-right\";\nimport { MenuContext } from \"./MenuContext\";\nimport { Slot } from \"@radix-ui/react-slot\";\n\ntype MenuItemElement = \"button\" | \"a\" | \"div\";\n\ntype Props<C extends MenuItemElement> = {\n /**\n * The element type of this menu item.\n * @default button\n */\n as?: C;\n /**\n * The CSS class name.\n */\n className?: string;\n /**\n * The icon to show on this menu item.\n * When `Icon` is a ReactElement, it should spread the props\n */\n Icon: ComponentType<SVGAttributes<SVGElement>> | ReactElement;\n /**\n * The label to show on this menu item.\n */\n // This prop is required because it's rare to not want a label\n label: string | null;\n /**\n * Additional properties to pass to the Text label component.\n */\n labelProps?: ComponentPropsWithoutRef<typeof Text>;\n /**\n * Event callback for when the item is selected via mouse, touch, or keyboard.\n * Calling event.preventDefault in this handler will prevent the menu from\n * being dismissed.\n */\n // This prop is required because it's rare to not want a selection handler\n onSelect: ((e: Event) => void) | null;\n /**\n * The color variant of the menu item.\n * @default primary\n */\n kind?: \"primary\" | \"critical\";\n disabled?: boolean;\n} & Omit<ComponentPropsWithoutRef<C>, \"onSelect\">;\n\n/**\n * An item within a menu, acting either as a navigation button, or simply a\n * container for other interactive elements.\n * Must be used within a compound Menu or other `menu` or `menubar` aria role subtree.\n */\nexport const MenuItem = <C extends MenuItemElement = \"button\">({\n as,\n className,\n Icon,\n label,\n labelProps,\n onSelect,\n kind = \"primary\",\n children,\n onClick: onClickProp,\n disabled,\n ...props\n}: Props<C>): React.ReactElement => {\n const Component = as ?? (\"button\" as ElementType);\n const context = useContext(MenuContext);\n\n const onClick = useCallback(\n (e: Parameters<Exclude<typeof onClickProp, undefined>>[0]) => {\n (onClickProp as ((e_: typeof e) => void) | undefined)?.(e);\n // If there is no wrapper component to automatically handle onSelect, we\n // need to handle it manually, dismissing the menu as the default action\n if (onSelect !== null && context?.MenuItemWrapper == null) {\n const selectEvent = new CustomEvent(\"menu.itemSelect\", {\n bubbles: true,\n cancelable: true,\n });\n onSelect(selectEvent);\n if (!selectEvent.defaultPrevented) context?.onOpenChange(false);\n }\n },\n [context, onSelect],\n );\n\n const iconIsReactElement = isValidElement(Icon);\n const componentIcon = Icon as ReactElement;\n const SvgIcon = Icon as ComponentType<SVGAttributes<SVGElement>>;\n\n const content = (\n <Component\n role=\"menuitem\"\n {...props}\n className={classnames(className, styles.item, {\n [styles.interactive]: onSelect !== null,\n [styles[\"no-label\"]]: label === null,\n [styles[\"disabled\"]]: disabled,\n })}\n data-kind={kind}\n onClick={onClick}\n disabled={Component === \"button\" ? disabled : undefined}\n aria-disabled={Component === \"button\" ? undefined : disabled}\n >\n {iconIsReactElement ? (\n <Slot className={styles.icon}>{componentIcon}</Slot>\n ) : (\n <SvgIcon\n width={24}\n height={24}\n className={styles.icon}\n aria-hidden={true}\n />\n )}\n\n {label !== null && (\n <Text\n className={styles.label}\n size=\"md\"\n weight=\"medium\"\n as=\"span\"\n {...labelProps}\n >\n {label}\n </Text>\n )}\n {/* We use CSS to swap between this navigation hint and the provided\n children on hover - see the styles module. */}\n {(Component === \"button\" || Component === \"a\") && (\n <ChevronRightIcon\n width={8}\n height={24}\n className={styles[\"nav-hint\"]}\n aria-hidden={true}\n /* The SVG is a small icon in a large canvas. It probably ought to be\n cropped, but we can adjust the viewBox here to chop off the horizontal\n space to get it closer to the right hand edge.\n */\n viewBox=\"8 0 8 24\"\n />\n )}\n {children}\n </Component>\n );\n\n return context?.MenuItemWrapper == null || onSelect === null ? (\n content\n ) : (\n <context.MenuItemWrapper onSelect={onSelect}>\n {content}\n </context.MenuItemWrapper>\n );\n};\n"],"names":["useContext","MenuContext","useCallback","isValidElement","jsxs","classnames","styles","Slot","jsx","Text"],"mappings":";;;;;;;;;;AAsEO,MAAM,WAAW,CAAuC;AAAA,EAC7D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,OAAO;AAAA,EACP;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA,GAAG;AACL,MAAoC;AAClC,QAAM,YAAY,MAAO;AACnB,QAAA,UAAUA,iBAAWC,uBAAW;AAEtC,QAAM,UAAUC,MAAA;AAAA,IACd,CAAC,MAA6D;AAC3D,oBAAuD,CAAC;AAGzD,UAAI,aAAa,QAAQ,SAAS,mBAAmB,MAAM;AACnD,cAAA,cAAc,IAAI,YAAY,mBAAmB;AAAA,UACrD,SAAS;AAAA,UACT,YAAY;AAAA,QAAA,CACb;AACD,iBAAS,WAAW;AACpB,YAAI,CAAC,YAAY,iBAAkB,UAAS,aAAa,KAAK;AAAA,MAAA;AAAA,IAElE;AAAA,IACA,CAAC,SAAS,QAAQ;AAAA,EACpB;AAEM,QAAA,qBAAqBC,qBAAe,IAAI;AAC9C,QAAM,gBAAgB;AACtB,QAAM,UAAU;AAEhB,QAAM,UACJC,2BAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,MAAK;AAAA,MACJ,GAAG;AAAA,MACJ,WAAWC,WAAW,WAAWC,gBAAAA,QAAO,MAAM;AAAA,QAC5C,CAACA,gBAAA,QAAO,WAAW,GAAG,aAAa;AAAA,QACnC,CAACA,wBAAO,UAAU,CAAC,GAAG,UAAU;AAAA,QAChC,CAACA,gBAAAA,QAAO,UAAU,CAAC,GAAG;AAAA,MAAA,CACvB;AAAA,MACD,aAAW;AAAA,MACX;AAAA,MACA,UAAU,cAAc,WAAW,WAAW;AAAA,MAC9C,iBAAe,cAAc,WAAW,SAAY;AAAA,MAEnD,UAAA;AAAA,QAAA,oDACEC,UAAK,MAAA,EAAA,WAAWD,wBAAO,MAAO,wBAAc,CAAA,IAE7CE,2BAAA;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,OAAO;AAAA,YACP,QAAQ;AAAA,YACR,WAAWF,gBAAO,QAAA;AAAA,YAClB,eAAa;AAAA,UAAA;AAAA,QACf;AAAA,QAGD,UAAU,QACTE,2BAAA;AAAA,UAACC,KAAA;AAAA,UAAA;AAAA,YACC,WAAWH,gBAAO,QAAA;AAAA,YAClB,MAAK;AAAA,YACL,QAAO;AAAA,YACP,IAAG;AAAA,YACF,GAAG;AAAA,YAEH,UAAA;AAAA,UAAA;AAAA,QACH;AAAA,SAIA,cAAc,YAAY,cAAc,QACxCE,2BAAA;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,OAAO;AAAA,YACP,QAAQ;AAAA,YACR,WAAWF,wBAAO,UAAU;AAAA,YAC5B,eAAa;AAAA,YAKb,SAAQ;AAAA,UAAA;AAAA,QACV;AAAA,QAED;AAAA,MAAA;AAAA,IAAA;AAAA,EACH;AAGK,SAAA,SAAS,mBAAmB,QAAQ,aAAa,OACtD,UAEAE,+BAAC,QAAQ,iBAAR,EAAwB,UACtB,UACH,QAAA,CAAA;AAEJ;;"}
1
+ {"version":3,"file":"MenuItem.cjs","sources":["../../../src/components/Menu/MenuItem.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 classnames from \"classnames\";\nimport React, {\n ComponentPropsWithoutRef,\n ComponentType,\n ElementType,\n isValidElement,\n ReactElement,\n SVGAttributes,\n useCallback,\n useContext,\n} from \"react\";\nimport styles from \"./MenuItem.module.css\";\nimport { Text } from \"../Typography/Text\";\nimport ChevronRightIcon from \"@vector-im/compound-design-tokens/assets/web/icons/chevron-right\";\nimport { MenuContext } from \"./MenuContext\";\nimport { Slot } from \"@radix-ui/react-slot\";\n\ntype MenuItemElement = \"button\" | \"a\" | \"div\";\n\ntype Props<C extends MenuItemElement> = {\n /**\n * The element type of this menu item.\n * @default button\n */\n as?: C;\n /**\n * The CSS class name.\n */\n className?: string;\n /**\n * The icon to show on this menu item.\n * When `Icon` is a ReactElement, it should spread the props\n */\n Icon: ComponentType<SVGAttributes<SVGElement>> | ReactElement;\n /**\n * The label to show on this menu item.\n */\n // This prop is required because it's rare to not want a label\n label: string | null;\n /**\n * Additional properties to pass to the Text label component.\n */\n labelProps?: ComponentPropsWithoutRef<typeof Text>;\n /**\n * Event callback for when the item is selected via mouse, touch, or keyboard.\n * Calling event.preventDefault in this handler will prevent the menu from\n * being dismissed.\n */\n // This prop is required because it's rare to not want a selection handler\n onSelect: ((e: Event) => void) | null;\n /**\n * Event callback for when the item is clicked.\n * @param e\n */\n onClick?: (e: Event) => void;\n /**\n * The color variant of the menu item.\n * @default primary\n */\n kind?: \"primary\" | \"critical\";\n disabled?: boolean;\n /**\n * Whether to hide the chevron navigation hint.\n */\n hideChevron?: boolean;\n} & Omit<ComponentPropsWithoutRef<C>, \"onSelect\" | \"onClick\">;\n\n/**\n * An item within a menu, acting either as a navigation button, or simply a\n * container for other interactive elements.\n * Must be used within a compound Menu or other `menu` or `menubar` aria role subtree.\n */\nexport const MenuItem = <C extends MenuItemElement = \"button\">({\n as,\n className,\n Icon,\n label,\n labelProps,\n onSelect,\n kind = \"primary\",\n children,\n onClick: onClickProp,\n disabled,\n hideChevron,\n ...props\n}: Props<C>): React.ReactElement => {\n const Component = as ?? (\"button\" as ElementType);\n const context = useContext(MenuContext);\n\n const onClick = useCallback(\n (e: Parameters<Exclude<typeof onClickProp, undefined>>[0]) => {\n (onClickProp as ((e_: typeof e) => void) | undefined)?.(e);\n // If there is no wrapper component to automatically handle onSelect, we\n // need to handle it manually, dismissing the menu as the default action\n if (onSelect !== null && context?.MenuItemWrapper == null) {\n const selectEvent = new CustomEvent(\"menu.itemSelect\", {\n bubbles: true,\n cancelable: true,\n });\n onSelect(selectEvent);\n if (!selectEvent.defaultPrevented) context?.onOpenChange(false);\n }\n },\n [context, onSelect],\n );\n\n const iconIsReactElement = isValidElement(Icon);\n const componentIcon = Icon as ReactElement;\n const SvgIcon = Icon as ComponentType<SVGAttributes<SVGElement>>;\n\n const content = (\n <Component\n role=\"menuitem\"\n {...props}\n className={classnames(className, styles.item, {\n [styles.interactive]: onSelect !== null,\n [styles[\"no-label\"]]: label === null,\n [styles[\"disabled\"]]: disabled,\n })}\n data-kind={kind}\n onClick={onClick}\n disabled={Component === \"button\" ? disabled : undefined}\n aria-disabled={Component === \"button\" ? undefined : disabled}\n >\n {iconIsReactElement ? (\n <Slot className={styles.icon}>{componentIcon}</Slot>\n ) : (\n <SvgIcon\n width={24}\n height={24}\n className={styles.icon}\n aria-hidden={true}\n />\n )}\n\n {label !== null && (\n <Text\n className={styles.label}\n size=\"md\"\n weight=\"medium\"\n as=\"span\"\n {...labelProps}\n >\n {label}\n </Text>\n )}\n {/* We use CSS to swap between this navigation hint and the provided\n children on hover - see the styles module. */}\n {!hideChevron && (Component === \"button\" || Component === \"a\") && (\n <ChevronRightIcon\n width={8}\n height={24}\n className={styles[\"nav-hint\"]}\n aria-hidden={true}\n /* The SVG is a small icon in a large canvas. It probably ought to be\n cropped, but we can adjust the viewBox here to chop off the horizontal\n space to get it closer to the right hand edge.\n */\n viewBox=\"8 0 8 24\"\n />\n )}\n {children}\n </Component>\n );\n\n return context?.MenuItemWrapper == null || onSelect === null ? (\n content\n ) : (\n <context.MenuItemWrapper onSelect={onSelect}>\n {content}\n </context.MenuItemWrapper>\n );\n};\n"],"names":["useContext","MenuContext","useCallback","isValidElement","jsxs","classnames","styles","Slot","jsx","Text"],"mappings":";;;;;;;;;;AA+EO,MAAM,WAAW,CAAuC;AAAA,EAC7D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,OAAO;AAAA,EACP;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAoC;AAClC,QAAM,YAAY,MAAO;AACnB,QAAA,UAAUA,iBAAWC,uBAAW;AAEtC,QAAM,UAAUC,MAAA;AAAA,IACd,CAAC,MAA6D;AAC3D,oBAAuD,CAAC;AAGzD,UAAI,aAAa,QAAQ,SAAS,mBAAmB,MAAM;AACnD,cAAA,cAAc,IAAI,YAAY,mBAAmB;AAAA,UACrD,SAAS;AAAA,UACT,YAAY;AAAA,QAAA,CACb;AACD,iBAAS,WAAW;AACpB,YAAI,CAAC,YAAY,iBAAkB,UAAS,aAAa,KAAK;AAAA,MAAA;AAAA,IAElE;AAAA,IACA,CAAC,SAAS,QAAQ;AAAA,EACpB;AAEM,QAAA,qBAAqBC,qBAAe,IAAI;AAC9C,QAAM,gBAAgB;AACtB,QAAM,UAAU;AAEhB,QAAM,UACJC,2BAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,MAAK;AAAA,MACJ,GAAG;AAAA,MACJ,WAAWC,WAAW,WAAWC,gBAAAA,QAAO,MAAM;AAAA,QAC5C,CAACA,gBAAA,QAAO,WAAW,GAAG,aAAa;AAAA,QACnC,CAACA,wBAAO,UAAU,CAAC,GAAG,UAAU;AAAA,QAChC,CAACA,gBAAAA,QAAO,UAAU,CAAC,GAAG;AAAA,MAAA,CACvB;AAAA,MACD,aAAW;AAAA,MACX;AAAA,MACA,UAAU,cAAc,WAAW,WAAW;AAAA,MAC9C,iBAAe,cAAc,WAAW,SAAY;AAAA,MAEnD,UAAA;AAAA,QAAA,oDACEC,UAAK,MAAA,EAAA,WAAWD,wBAAO,MAAO,wBAAc,CAAA,IAE7CE,2BAAA;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,OAAO;AAAA,YACP,QAAQ;AAAA,YACR,WAAWF,gBAAO,QAAA;AAAA,YAClB,eAAa;AAAA,UAAA;AAAA,QACf;AAAA,QAGD,UAAU,QACTE,2BAAA;AAAA,UAACC,KAAA;AAAA,UAAA;AAAA,YACC,WAAWH,gBAAO,QAAA;AAAA,YAClB,MAAK;AAAA,YACL,QAAO;AAAA,YACP,IAAG;AAAA,YACF,GAAG;AAAA,YAEH,UAAA;AAAA,UAAA;AAAA,QACH;AAAA,QAID,CAAC,gBAAgB,cAAc,YAAY,cAAc,QACxDE,2BAAA;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,OAAO;AAAA,YACP,QAAQ;AAAA,YACR,WAAWF,wBAAO,UAAU;AAAA,YAC5B,eAAa;AAAA,YAKb,SAAQ;AAAA,UAAA;AAAA,QACV;AAAA,QAED;AAAA,MAAA;AAAA,IAAA;AAAA,EACH;AAGK,SAAA,SAAS,mBAAmB,QAAQ,aAAa,OACtD,UAEAE,+BAAC,QAAQ,iBAAR,EAAwB,UACtB,UACH,QAAA,CAAA;AAEJ;;"}
@@ -30,18 +30,27 @@ type Props<C extends MenuItemElement> = {
30
30
  * being dismissed.
31
31
  */
32
32
  onSelect: ((e: Event) => void) | null;
33
+ /**
34
+ * Event callback for when the item is clicked.
35
+ * @param e
36
+ */
37
+ onClick?: (e: Event) => void;
33
38
  /**
34
39
  * The color variant of the menu item.
35
40
  * @default primary
36
41
  */
37
42
  kind?: "primary" | "critical";
38
43
  disabled?: boolean;
39
- } & Omit<ComponentPropsWithoutRef<C>, "onSelect">;
44
+ /**
45
+ * Whether to hide the chevron navigation hint.
46
+ */
47
+ hideChevron?: boolean;
48
+ } & Omit<ComponentPropsWithoutRef<C>, "onSelect" | "onClick">;
40
49
  /**
41
50
  * An item within a menu, acting either as a navigation button, or simply a
42
51
  * container for other interactive elements.
43
52
  * Must be used within a compound Menu or other `menu` or `menubar` aria role subtree.
44
53
  */
45
- export declare const MenuItem: <C extends MenuItemElement = "button">({ as, className, Icon, label, labelProps, onSelect, kind, children, onClick: onClickProp, disabled, ...props }: Props<C>) => React.ReactElement;
54
+ export declare const MenuItem: <C extends MenuItemElement = "button">({ as, className, Icon, label, labelProps, onSelect, kind, children, onClick: onClickProp, disabled, hideChevron, ...props }: Props<C>) => React.ReactElement;
46
55
  export {};
47
56
  //# sourceMappingURL=MenuItem.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MenuItem.d.ts","sourceRoot":"","sources":["../../../src/components/Menu/MenuItem.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,EACZ,wBAAwB,EACxB,aAAa,EAGb,YAAY,EACZ,aAAa,EAGd,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAK1C,KAAK,eAAe,GAAG,QAAQ,GAAG,GAAG,GAAG,KAAK,CAAC;AAE9C,KAAK,KAAK,CAAC,CAAC,SAAS,eAAe,IAAI;IACtC;;;OAGG;IACH,EAAE,CAAC,EAAE,CAAC,CAAC;IACP;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,IAAI,EAAE,aAAa,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,GAAG,YAAY,CAAC;IAC9D;;OAEG;IAEH,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB;;OAEG;IACH,UAAU,CAAC,EAAE,wBAAwB,CAAC,OAAO,IAAI,CAAC,CAAC;IACnD;;;;OAIG;IAEH,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IACtC;;;OAGG;IACH,IAAI,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,GAAG,IAAI,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;AAElD;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,eAAe,6HAY/C,KAAK,CAAC,CAAC,CAAC,KAAG,KAAK,CAAC,YAuFnB,CAAC"}
1
+ {"version":3,"file":"MenuItem.d.ts","sourceRoot":"","sources":["../../../src/components/Menu/MenuItem.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,EACZ,wBAAwB,EACxB,aAAa,EAGb,YAAY,EACZ,aAAa,EAGd,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAK1C,KAAK,eAAe,GAAG,QAAQ,GAAG,GAAG,GAAG,KAAK,CAAC;AAE9C,KAAK,KAAK,CAAC,CAAC,SAAS,eAAe,IAAI;IACtC;;;OAGG;IACH,EAAE,CAAC,EAAE,CAAC,CAAC;IACP;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,IAAI,EAAE,aAAa,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,GAAG,YAAY,CAAC;IAC9D;;OAEG;IAEH,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB;;OAEG;IACH,UAAU,CAAC,EAAE,wBAAwB,CAAC,OAAO,IAAI,CAAC,CAAC;IACnD;;;;OAIG;IAEH,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IACtC;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC;IAC7B;;;OAGG;IACH,IAAI,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,GAAG,IAAI,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC,CAAC;AAE9D;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,eAAe,0IAa/C,KAAK,CAAC,CAAC,CAAC,KAAG,KAAK,CAAC,YAuFnB,CAAC"}
@@ -17,6 +17,7 @@ const MenuItem = ({
17
17
  children,
18
18
  onClick: onClickProp,
19
19
  disabled,
20
+ hideChevron,
20
21
  ...props
21
22
  }) => {
22
23
  const Component = as ?? "button";
@@ -73,7 +74,7 @@ const MenuItem = ({
73
74
  children: label
74
75
  }
75
76
  ),
76
- (Component === "button" || Component === "a") && /* @__PURE__ */ jsx(
77
+ !hideChevron && (Component === "button" || Component === "a") && /* @__PURE__ */ jsx(
77
78
  ChevronRightIcon,
78
79
  {
79
80
  width: 8,
@@ -1 +1 @@
1
- {"version":3,"file":"MenuItem.js","sources":["../../../src/components/Menu/MenuItem.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 classnames from \"classnames\";\nimport React, {\n ComponentPropsWithoutRef,\n ComponentType,\n ElementType,\n isValidElement,\n ReactElement,\n SVGAttributes,\n useCallback,\n useContext,\n} from \"react\";\nimport styles from \"./MenuItem.module.css\";\nimport { Text } from \"../Typography/Text\";\nimport ChevronRightIcon from \"@vector-im/compound-design-tokens/assets/web/icons/chevron-right\";\nimport { MenuContext } from \"./MenuContext\";\nimport { Slot } from \"@radix-ui/react-slot\";\n\ntype MenuItemElement = \"button\" | \"a\" | \"div\";\n\ntype Props<C extends MenuItemElement> = {\n /**\n * The element type of this menu item.\n * @default button\n */\n as?: C;\n /**\n * The CSS class name.\n */\n className?: string;\n /**\n * The icon to show on this menu item.\n * When `Icon` is a ReactElement, it should spread the props\n */\n Icon: ComponentType<SVGAttributes<SVGElement>> | ReactElement;\n /**\n * The label to show on this menu item.\n */\n // This prop is required because it's rare to not want a label\n label: string | null;\n /**\n * Additional properties to pass to the Text label component.\n */\n labelProps?: ComponentPropsWithoutRef<typeof Text>;\n /**\n * Event callback for when the item is selected via mouse, touch, or keyboard.\n * Calling event.preventDefault in this handler will prevent the menu from\n * being dismissed.\n */\n // This prop is required because it's rare to not want a selection handler\n onSelect: ((e: Event) => void) | null;\n /**\n * The color variant of the menu item.\n * @default primary\n */\n kind?: \"primary\" | \"critical\";\n disabled?: boolean;\n} & Omit<ComponentPropsWithoutRef<C>, \"onSelect\">;\n\n/**\n * An item within a menu, acting either as a navigation button, or simply a\n * container for other interactive elements.\n * Must be used within a compound Menu or other `menu` or `menubar` aria role subtree.\n */\nexport const MenuItem = <C extends MenuItemElement = \"button\">({\n as,\n className,\n Icon,\n label,\n labelProps,\n onSelect,\n kind = \"primary\",\n children,\n onClick: onClickProp,\n disabled,\n ...props\n}: Props<C>): React.ReactElement => {\n const Component = as ?? (\"button\" as ElementType);\n const context = useContext(MenuContext);\n\n const onClick = useCallback(\n (e: Parameters<Exclude<typeof onClickProp, undefined>>[0]) => {\n (onClickProp as ((e_: typeof e) => void) | undefined)?.(e);\n // If there is no wrapper component to automatically handle onSelect, we\n // need to handle it manually, dismissing the menu as the default action\n if (onSelect !== null && context?.MenuItemWrapper == null) {\n const selectEvent = new CustomEvent(\"menu.itemSelect\", {\n bubbles: true,\n cancelable: true,\n });\n onSelect(selectEvent);\n if (!selectEvent.defaultPrevented) context?.onOpenChange(false);\n }\n },\n [context, onSelect],\n );\n\n const iconIsReactElement = isValidElement(Icon);\n const componentIcon = Icon as ReactElement;\n const SvgIcon = Icon as ComponentType<SVGAttributes<SVGElement>>;\n\n const content = (\n <Component\n role=\"menuitem\"\n {...props}\n className={classnames(className, styles.item, {\n [styles.interactive]: onSelect !== null,\n [styles[\"no-label\"]]: label === null,\n [styles[\"disabled\"]]: disabled,\n })}\n data-kind={kind}\n onClick={onClick}\n disabled={Component === \"button\" ? disabled : undefined}\n aria-disabled={Component === \"button\" ? undefined : disabled}\n >\n {iconIsReactElement ? (\n <Slot className={styles.icon}>{componentIcon}</Slot>\n ) : (\n <SvgIcon\n width={24}\n height={24}\n className={styles.icon}\n aria-hidden={true}\n />\n )}\n\n {label !== null && (\n <Text\n className={styles.label}\n size=\"md\"\n weight=\"medium\"\n as=\"span\"\n {...labelProps}\n >\n {label}\n </Text>\n )}\n {/* We use CSS to swap between this navigation hint and the provided\n children on hover - see the styles module. */}\n {(Component === \"button\" || Component === \"a\") && (\n <ChevronRightIcon\n width={8}\n height={24}\n className={styles[\"nav-hint\"]}\n aria-hidden={true}\n /* The SVG is a small icon in a large canvas. It probably ought to be\n cropped, but we can adjust the viewBox here to chop off the horizontal\n space to get it closer to the right hand edge.\n */\n viewBox=\"8 0 8 24\"\n />\n )}\n {children}\n </Component>\n );\n\n return context?.MenuItemWrapper == null || onSelect === null ? (\n content\n ) : (\n <context.MenuItemWrapper onSelect={onSelect}>\n {content}\n </context.MenuItemWrapper>\n );\n};\n"],"names":["classnames"],"mappings":";;;;;;;;AAsEO,MAAM,WAAW,CAAuC;AAAA,EAC7D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,OAAO;AAAA,EACP;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA,GAAG;AACL,MAAoC;AAClC,QAAM,YAAY,MAAO;AACnB,QAAA,UAAU,WAAW,WAAW;AAEtC,QAAM,UAAU;AAAA,IACd,CAAC,MAA6D;AAC3D,oBAAuD,CAAC;AAGzD,UAAI,aAAa,QAAQ,SAAS,mBAAmB,MAAM;AACnD,cAAA,cAAc,IAAI,YAAY,mBAAmB;AAAA,UACrD,SAAS;AAAA,UACT,YAAY;AAAA,QAAA,CACb;AACD,iBAAS,WAAW;AACpB,YAAI,CAAC,YAAY,iBAAkB,UAAS,aAAa,KAAK;AAAA,MAAA;AAAA,IAElE;AAAA,IACA,CAAC,SAAS,QAAQ;AAAA,EACpB;AAEM,QAAA,qBAAqB,eAAe,IAAI;AAC9C,QAAM,gBAAgB;AACtB,QAAM,UAAU;AAEhB,QAAM,UACJ;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,MAAK;AAAA,MACJ,GAAG;AAAA,MACJ,WAAWA,WAAW,WAAW,OAAO,MAAM;AAAA,QAC5C,CAAC,OAAO,WAAW,GAAG,aAAa;AAAA,QACnC,CAAC,OAAO,UAAU,CAAC,GAAG,UAAU;AAAA,QAChC,CAAC,OAAO,UAAU,CAAC,GAAG;AAAA,MAAA,CACvB;AAAA,MACD,aAAW;AAAA,MACX;AAAA,MACA,UAAU,cAAc,WAAW,WAAW;AAAA,MAC9C,iBAAe,cAAc,WAAW,SAAY;AAAA,MAEnD,UAAA;AAAA,QAAA,yCACE,MAAK,EAAA,WAAW,OAAO,MAAO,wBAAc,CAAA,IAE7C;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,OAAO;AAAA,YACP,QAAQ;AAAA,YACR,WAAW,OAAO;AAAA,YAClB,eAAa;AAAA,UAAA;AAAA,QACf;AAAA,QAGD,UAAU,QACT;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,WAAW,OAAO;AAAA,YAClB,MAAK;AAAA,YACL,QAAO;AAAA,YACP,IAAG;AAAA,YACF,GAAG;AAAA,YAEH,UAAA;AAAA,UAAA;AAAA,QACH;AAAA,SAIA,cAAc,YAAY,cAAc,QACxC;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,OAAO;AAAA,YACP,QAAQ;AAAA,YACR,WAAW,OAAO,UAAU;AAAA,YAC5B,eAAa;AAAA,YAKb,SAAQ;AAAA,UAAA;AAAA,QACV;AAAA,QAED;AAAA,MAAA;AAAA,IAAA;AAAA,EACH;AAGK,SAAA,SAAS,mBAAmB,QAAQ,aAAa,OACtD,UAEA,oBAAC,QAAQ,iBAAR,EAAwB,UACtB,UACH,QAAA,CAAA;AAEJ;"}
1
+ {"version":3,"file":"MenuItem.js","sources":["../../../src/components/Menu/MenuItem.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 classnames from \"classnames\";\nimport React, {\n ComponentPropsWithoutRef,\n ComponentType,\n ElementType,\n isValidElement,\n ReactElement,\n SVGAttributes,\n useCallback,\n useContext,\n} from \"react\";\nimport styles from \"./MenuItem.module.css\";\nimport { Text } from \"../Typography/Text\";\nimport ChevronRightIcon from \"@vector-im/compound-design-tokens/assets/web/icons/chevron-right\";\nimport { MenuContext } from \"./MenuContext\";\nimport { Slot } from \"@radix-ui/react-slot\";\n\ntype MenuItemElement = \"button\" | \"a\" | \"div\";\n\ntype Props<C extends MenuItemElement> = {\n /**\n * The element type of this menu item.\n * @default button\n */\n as?: C;\n /**\n * The CSS class name.\n */\n className?: string;\n /**\n * The icon to show on this menu item.\n * When `Icon` is a ReactElement, it should spread the props\n */\n Icon: ComponentType<SVGAttributes<SVGElement>> | ReactElement;\n /**\n * The label to show on this menu item.\n */\n // This prop is required because it's rare to not want a label\n label: string | null;\n /**\n * Additional properties to pass to the Text label component.\n */\n labelProps?: ComponentPropsWithoutRef<typeof Text>;\n /**\n * Event callback for when the item is selected via mouse, touch, or keyboard.\n * Calling event.preventDefault in this handler will prevent the menu from\n * being dismissed.\n */\n // This prop is required because it's rare to not want a selection handler\n onSelect: ((e: Event) => void) | null;\n /**\n * Event callback for when the item is clicked.\n * @param e\n */\n onClick?: (e: Event) => void;\n /**\n * The color variant of the menu item.\n * @default primary\n */\n kind?: \"primary\" | \"critical\";\n disabled?: boolean;\n /**\n * Whether to hide the chevron navigation hint.\n */\n hideChevron?: boolean;\n} & Omit<ComponentPropsWithoutRef<C>, \"onSelect\" | \"onClick\">;\n\n/**\n * An item within a menu, acting either as a navigation button, or simply a\n * container for other interactive elements.\n * Must be used within a compound Menu or other `menu` or `menubar` aria role subtree.\n */\nexport const MenuItem = <C extends MenuItemElement = \"button\">({\n as,\n className,\n Icon,\n label,\n labelProps,\n onSelect,\n kind = \"primary\",\n children,\n onClick: onClickProp,\n disabled,\n hideChevron,\n ...props\n}: Props<C>): React.ReactElement => {\n const Component = as ?? (\"button\" as ElementType);\n const context = useContext(MenuContext);\n\n const onClick = useCallback(\n (e: Parameters<Exclude<typeof onClickProp, undefined>>[0]) => {\n (onClickProp as ((e_: typeof e) => void) | undefined)?.(e);\n // If there is no wrapper component to automatically handle onSelect, we\n // need to handle it manually, dismissing the menu as the default action\n if (onSelect !== null && context?.MenuItemWrapper == null) {\n const selectEvent = new CustomEvent(\"menu.itemSelect\", {\n bubbles: true,\n cancelable: true,\n });\n onSelect(selectEvent);\n if (!selectEvent.defaultPrevented) context?.onOpenChange(false);\n }\n },\n [context, onSelect],\n );\n\n const iconIsReactElement = isValidElement(Icon);\n const componentIcon = Icon as ReactElement;\n const SvgIcon = Icon as ComponentType<SVGAttributes<SVGElement>>;\n\n const content = (\n <Component\n role=\"menuitem\"\n {...props}\n className={classnames(className, styles.item, {\n [styles.interactive]: onSelect !== null,\n [styles[\"no-label\"]]: label === null,\n [styles[\"disabled\"]]: disabled,\n })}\n data-kind={kind}\n onClick={onClick}\n disabled={Component === \"button\" ? disabled : undefined}\n aria-disabled={Component === \"button\" ? undefined : disabled}\n >\n {iconIsReactElement ? (\n <Slot className={styles.icon}>{componentIcon}</Slot>\n ) : (\n <SvgIcon\n width={24}\n height={24}\n className={styles.icon}\n aria-hidden={true}\n />\n )}\n\n {label !== null && (\n <Text\n className={styles.label}\n size=\"md\"\n weight=\"medium\"\n as=\"span\"\n {...labelProps}\n >\n {label}\n </Text>\n )}\n {/* We use CSS to swap between this navigation hint and the provided\n children on hover - see the styles module. */}\n {!hideChevron && (Component === \"button\" || Component === \"a\") && (\n <ChevronRightIcon\n width={8}\n height={24}\n className={styles[\"nav-hint\"]}\n aria-hidden={true}\n /* The SVG is a small icon in a large canvas. It probably ought to be\n cropped, but we can adjust the viewBox here to chop off the horizontal\n space to get it closer to the right hand edge.\n */\n viewBox=\"8 0 8 24\"\n />\n )}\n {children}\n </Component>\n );\n\n return context?.MenuItemWrapper == null || onSelect === null ? (\n content\n ) : (\n <context.MenuItemWrapper onSelect={onSelect}>\n {content}\n </context.MenuItemWrapper>\n );\n};\n"],"names":["classnames"],"mappings":";;;;;;;;AA+EO,MAAM,WAAW,CAAuC;AAAA,EAC7D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,OAAO;AAAA,EACP;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAoC;AAClC,QAAM,YAAY,MAAO;AACnB,QAAA,UAAU,WAAW,WAAW;AAEtC,QAAM,UAAU;AAAA,IACd,CAAC,MAA6D;AAC3D,oBAAuD,CAAC;AAGzD,UAAI,aAAa,QAAQ,SAAS,mBAAmB,MAAM;AACnD,cAAA,cAAc,IAAI,YAAY,mBAAmB;AAAA,UACrD,SAAS;AAAA,UACT,YAAY;AAAA,QAAA,CACb;AACD,iBAAS,WAAW;AACpB,YAAI,CAAC,YAAY,iBAAkB,UAAS,aAAa,KAAK;AAAA,MAAA;AAAA,IAElE;AAAA,IACA,CAAC,SAAS,QAAQ;AAAA,EACpB;AAEM,QAAA,qBAAqB,eAAe,IAAI;AAC9C,QAAM,gBAAgB;AACtB,QAAM,UAAU;AAEhB,QAAM,UACJ;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,MAAK;AAAA,MACJ,GAAG;AAAA,MACJ,WAAWA,WAAW,WAAW,OAAO,MAAM;AAAA,QAC5C,CAAC,OAAO,WAAW,GAAG,aAAa;AAAA,QACnC,CAAC,OAAO,UAAU,CAAC,GAAG,UAAU;AAAA,QAChC,CAAC,OAAO,UAAU,CAAC,GAAG;AAAA,MAAA,CACvB;AAAA,MACD,aAAW;AAAA,MACX;AAAA,MACA,UAAU,cAAc,WAAW,WAAW;AAAA,MAC9C,iBAAe,cAAc,WAAW,SAAY;AAAA,MAEnD,UAAA;AAAA,QAAA,yCACE,MAAK,EAAA,WAAW,OAAO,MAAO,wBAAc,CAAA,IAE7C;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,OAAO;AAAA,YACP,QAAQ;AAAA,YACR,WAAW,OAAO;AAAA,YAClB,eAAa;AAAA,UAAA;AAAA,QACf;AAAA,QAGD,UAAU,QACT;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,WAAW,OAAO;AAAA,YAClB,MAAK;AAAA,YACL,QAAO;AAAA,YACP,IAAG;AAAA,YACF,GAAG;AAAA,YAEH,UAAA;AAAA,UAAA;AAAA,QACH;AAAA,QAID,CAAC,gBAAgB,cAAc,YAAY,cAAc,QACxD;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,OAAO;AAAA,YACP,QAAQ;AAAA,YACR,WAAW,OAAO,UAAU;AAAA,YAC5B,eAAa;AAAA,YAKb,SAAQ;AAAA,UAAA;AAAA,QACV;AAAA,QAED;AAAA,MAAA;AAAA,IAAA;AAAA,EACH;AAGK,SAAA,SAAS,mBAAmB,QAAQ,aAAa,OACtD,UAEA,oBAAC,QAAQ,iBAAR,EAAwB,UACtB,UACH,QAAA,CAAA;AAEJ;"}
@@ -5,7 +5,7 @@ const React = require("react");
5
5
  const MenuItem = require("./MenuItem.cjs");
6
6
  const Toggle = require("../Form/Controls/Toggle/Toggle.cjs");
7
7
  const ToggleMenuItem = React.forwardRef(
8
- function ToggleMenuItem2({ className, Icon, label, onSelect, checked, disabled }, ref) {
8
+ function ToggleMenuItem2({ className, Icon, label, onSelect, checked, disabled, onClick }, ref) {
9
9
  const toggleId = React.useId();
10
10
  const onChange = React.useCallback(() => {
11
11
  }, []);
@@ -20,6 +20,7 @@ const ToggleMenuItem = React.forwardRef(
20
20
  label,
21
21
  onSelect,
22
22
  disabled,
23
+ onClick,
23
24
  children: /* @__PURE__ */ jsxRuntime.jsx(
24
25
  Toggle.ToggleInput,
25
26
  {
@@ -1 +1 @@
1
- {"version":3,"file":"ToggleMenuItem.cjs","sources":["../../../src/components/Menu/ToggleMenuItem.tsx"],"sourcesContent":["/*\nCopyright 2023, 2024 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, { ComponentProps, forwardRef, useCallback, useId } from \"react\";\nimport { MenuItem } from \"./MenuItem\";\nimport { ToggleInput } from \"../Form/Controls/Toggle\";\n\ntype Props = Pick<\n ComponentProps<typeof MenuItem>,\n \"className\" | \"Icon\" | \"label\" | \"onSelect\" | \"disabled\"\n> & {\n /**\n * Whether the toggle is checked.\n */\n checked: boolean;\n};\n\n/**\n * A menu item with a toggle control.\n * Must be used within a compound Menu or other `menu` or `menubar` aria role subtree.\n */\nexport const ToggleMenuItem = forwardRef<HTMLInputElement, Props>(\n function ToggleMenuItem(\n { className, Icon, label, onSelect, checked, disabled },\n ref,\n ) {\n const toggleId = useId();\n // The toggle is controlled and we intend to ignore its events. We do need\n // to at least set onChange though to make React happy.\n const onChange = useCallback(() => {}, []);\n\n // <label> elements are not allowed to have a role like menuitemcheckbox, so\n // we must instead use a plain <div> for the menu item and use aria-checked\n // etc. to communicate its state.\n return (\n <MenuItem\n as=\"div\"\n role=\"menuitemcheckbox\"\n aria-checked={checked}\n className={className}\n Icon={Icon}\n label={label}\n onSelect={onSelect}\n disabled={disabled}\n >\n <ToggleInput\n id={toggleId}\n ref={ref}\n // This is purely cosmetic; really the whole MenuItem is the toggle.\n aria-hidden\n checked={checked}\n disabled={disabled}\n onChange={onChange}\n />\n </MenuItem>\n );\n },\n);\n"],"names":["forwardRef","ToggleMenuItem","useId","useCallback","jsx","MenuItem","ToggleInput"],"mappings":";;;;;;AAyBO,MAAM,iBAAiBA,MAAA;AAAA,EAC5B,SAASC,gBACP,EAAE,WAAW,MAAM,OAAO,UAAU,SAAS,SAAS,GACtD,KACA;AACA,UAAM,WAAWC,MAAAA,MAAM;AAGjB,UAAA,WAAWC,MAAAA,YAAY,MAAM;AAAA,IAAC,GAAG,EAAE;AAMvC,WAAAC,2BAAA;AAAA,MAACC,SAAA;AAAA,MAAA;AAAA,QACC,IAAG;AAAA,QACH,MAAK;AAAA,QACL,gBAAc;AAAA,QACd;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QAEA,UAAAD,2BAAA;AAAA,UAACE,OAAA;AAAA,UAAA;AAAA,YACC,IAAI;AAAA,YACJ;AAAA,YAEA,eAAW;AAAA,YACX;AAAA,YACA;AAAA,YACA;AAAA,UAAA;AAAA,QAAA;AAAA,MACF;AAAA,IACF;AAAA,EAAA;AAGN;;"}
1
+ {"version":3,"file":"ToggleMenuItem.cjs","sources":["../../../src/components/Menu/ToggleMenuItem.tsx"],"sourcesContent":["/*\nCopyright 2023, 2024 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, { ComponentProps, forwardRef, useCallback, useId } from \"react\";\nimport { MenuItem } from \"./MenuItem\";\nimport { ToggleInput } from \"../Form/Controls/Toggle\";\n\ntype Props = Pick<\n ComponentProps<typeof MenuItem>,\n \"className\" | \"Icon\" | \"label\" | \"onSelect\" | \"disabled\" | \"onClick\"\n> & {\n /**\n * Whether the toggle is checked.\n */\n checked: boolean;\n};\n\n/**\n * A menu item with a toggle control.\n * Must be used within a compound Menu or other `menu` or `menubar` aria role subtree.\n */\nexport const ToggleMenuItem = forwardRef<HTMLInputElement, Props>(\n function ToggleMenuItem(\n { className, Icon, label, onSelect, checked, disabled, onClick },\n ref,\n ) {\n const toggleId = useId();\n // The toggle is controlled and we intend to ignore its events. We do need\n // to at least set onChange though to make React happy.\n const onChange = useCallback(() => {}, []);\n\n // <label> elements are not allowed to have a role like menuitemcheckbox, so\n // we must instead use a plain <div> for the menu item and use aria-checked\n // etc. to communicate its state.\n return (\n <MenuItem\n as=\"div\"\n role=\"menuitemcheckbox\"\n aria-checked={checked}\n className={className}\n Icon={Icon}\n label={label}\n onSelect={onSelect}\n disabled={disabled}\n onClick={onClick}\n >\n <ToggleInput\n id={toggleId}\n ref={ref}\n // This is purely cosmetic; really the whole MenuItem is the toggle.\n aria-hidden\n checked={checked}\n disabled={disabled}\n onChange={onChange}\n />\n </MenuItem>\n );\n },\n);\n"],"names":["forwardRef","ToggleMenuItem","useId","useCallback","jsx","MenuItem","ToggleInput"],"mappings":";;;;;;AAyBO,MAAM,iBAAiBA,MAAA;AAAA,EAC5B,SAASC,gBACP,EAAE,WAAW,MAAM,OAAO,UAAU,SAAS,UAAU,QAAQ,GAC/D,KACA;AACA,UAAM,WAAWC,MAAAA,MAAM;AAGjB,UAAA,WAAWC,MAAAA,YAAY,MAAM;AAAA,IAAC,GAAG,EAAE;AAMvC,WAAAC,2BAAA;AAAA,MAACC,SAAA;AAAA,MAAA;AAAA,QACC,IAAG;AAAA,QACH,MAAK;AAAA,QACL,gBAAc;AAAA,QACd;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QAEA,UAAAD,2BAAA;AAAA,UAACE,OAAA;AAAA,UAAA;AAAA,YACC,IAAI;AAAA,YACJ;AAAA,YAEA,eAAW;AAAA,YACX;AAAA,YACA;AAAA,YACA;AAAA,UAAA;AAAA,QAAA;AAAA,MACF;AAAA,IACF;AAAA,EAAA;AAGN;;"}
@@ -10,9 +10,11 @@ export declare const ToggleMenuItem: React.ForwardRefExoticComponent<Pick<{
10
10
  label: string | null;
11
11
  labelProps?: React.ComponentPropsWithoutRef<typeof import('../..').Text>;
12
12
  onSelect: ((e: Event) => void) | null;
13
+ onClick?: (e: Event) => void;
13
14
  kind?: "primary" | "critical";
14
15
  disabled?: boolean;
15
- } & Omit<Omit<React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> | Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> | Omit<React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, "ref">, "onSelect">, "label" | "className" | "disabled" | "onSelect" | "Icon"> & {
16
+ hideChevron?: boolean;
17
+ } & Omit<Omit<React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> | Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> | Omit<React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, "ref">, "onClick" | "onSelect">, "label" | "className" | "disabled" | "onClick" | "onSelect" | "Icon"> & {
16
18
  /**
17
19
  * Whether the toggle is checked.
18
20
  */
@@ -1 +1 @@
1
- {"version":3,"file":"ToggleMenuItem.d.ts","sourceRoot":"","sources":["../../../src/components/Menu/ToggleMenuItem.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAyD,MAAM,OAAO,CAAC;AAc9E;;;GAGG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;IAVzB;;OAEG;aACM,OAAO;0CA2CjB,CAAC"}
1
+ {"version":3,"file":"ToggleMenuItem.d.ts","sourceRoot":"","sources":["../../../src/components/Menu/ToggleMenuItem.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAyD,MAAM,OAAO,CAAC;AAc9E;;;GAGG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;IAVzB;;OAEG;aACM,OAAO;0CA4CjB,CAAC"}
@@ -3,7 +3,7 @@ import { forwardRef, useId, useCallback } from "react";
3
3
  import { MenuItem } from "./MenuItem.js";
4
4
  import { ToggleInput } from "../Form/Controls/Toggle/Toggle.js";
5
5
  const ToggleMenuItem = forwardRef(
6
- function ToggleMenuItem2({ className, Icon, label, onSelect, checked, disabled }, ref) {
6
+ function ToggleMenuItem2({ className, Icon, label, onSelect, checked, disabled, onClick }, ref) {
7
7
  const toggleId = useId();
8
8
  const onChange = useCallback(() => {
9
9
  }, []);
@@ -18,6 +18,7 @@ const ToggleMenuItem = forwardRef(
18
18
  label,
19
19
  onSelect,
20
20
  disabled,
21
+ onClick,
21
22
  children: /* @__PURE__ */ jsx(
22
23
  ToggleInput,
23
24
  {
@@ -1 +1 @@
1
- {"version":3,"file":"ToggleMenuItem.js","sources":["../../../src/components/Menu/ToggleMenuItem.tsx"],"sourcesContent":["/*\nCopyright 2023, 2024 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, { ComponentProps, forwardRef, useCallback, useId } from \"react\";\nimport { MenuItem } from \"./MenuItem\";\nimport { ToggleInput } from \"../Form/Controls/Toggle\";\n\ntype Props = Pick<\n ComponentProps<typeof MenuItem>,\n \"className\" | \"Icon\" | \"label\" | \"onSelect\" | \"disabled\"\n> & {\n /**\n * Whether the toggle is checked.\n */\n checked: boolean;\n};\n\n/**\n * A menu item with a toggle control.\n * Must be used within a compound Menu or other `menu` or `menubar` aria role subtree.\n */\nexport const ToggleMenuItem = forwardRef<HTMLInputElement, Props>(\n function ToggleMenuItem(\n { className, Icon, label, onSelect, checked, disabled },\n ref,\n ) {\n const toggleId = useId();\n // The toggle is controlled and we intend to ignore its events. We do need\n // to at least set onChange though to make React happy.\n const onChange = useCallback(() => {}, []);\n\n // <label> elements are not allowed to have a role like menuitemcheckbox, so\n // we must instead use a plain <div> for the menu item and use aria-checked\n // etc. to communicate its state.\n return (\n <MenuItem\n as=\"div\"\n role=\"menuitemcheckbox\"\n aria-checked={checked}\n className={className}\n Icon={Icon}\n label={label}\n onSelect={onSelect}\n disabled={disabled}\n >\n <ToggleInput\n id={toggleId}\n ref={ref}\n // This is purely cosmetic; really the whole MenuItem is the toggle.\n aria-hidden\n checked={checked}\n disabled={disabled}\n onChange={onChange}\n />\n </MenuItem>\n );\n },\n);\n"],"names":["ToggleMenuItem"],"mappings":";;;;AAyBO,MAAM,iBAAiB;AAAA,EAC5B,SAASA,gBACP,EAAE,WAAW,MAAM,OAAO,UAAU,SAAS,SAAS,GACtD,KACA;AACA,UAAM,WAAW,MAAM;AAGjB,UAAA,WAAW,YAAY,MAAM;AAAA,IAAC,GAAG,EAAE;AAMvC,WAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,IAAG;AAAA,QACH,MAAK;AAAA,QACL,gBAAc;AAAA,QACd;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QAEA,UAAA;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,IAAI;AAAA,YACJ;AAAA,YAEA,eAAW;AAAA,YACX;AAAA,YACA;AAAA,YACA;AAAA,UAAA;AAAA,QAAA;AAAA,MACF;AAAA,IACF;AAAA,EAAA;AAGN;"}
1
+ {"version":3,"file":"ToggleMenuItem.js","sources":["../../../src/components/Menu/ToggleMenuItem.tsx"],"sourcesContent":["/*\nCopyright 2023, 2024 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, { ComponentProps, forwardRef, useCallback, useId } from \"react\";\nimport { MenuItem } from \"./MenuItem\";\nimport { ToggleInput } from \"../Form/Controls/Toggle\";\n\ntype Props = Pick<\n ComponentProps<typeof MenuItem>,\n \"className\" | \"Icon\" | \"label\" | \"onSelect\" | \"disabled\" | \"onClick\"\n> & {\n /**\n * Whether the toggle is checked.\n */\n checked: boolean;\n};\n\n/**\n * A menu item with a toggle control.\n * Must be used within a compound Menu or other `menu` or `menubar` aria role subtree.\n */\nexport const ToggleMenuItem = forwardRef<HTMLInputElement, Props>(\n function ToggleMenuItem(\n { className, Icon, label, onSelect, checked, disabled, onClick },\n ref,\n ) {\n const toggleId = useId();\n // The toggle is controlled and we intend to ignore its events. We do need\n // to at least set onChange though to make React happy.\n const onChange = useCallback(() => {}, []);\n\n // <label> elements are not allowed to have a role like menuitemcheckbox, so\n // we must instead use a plain <div> for the menu item and use aria-checked\n // etc. to communicate its state.\n return (\n <MenuItem\n as=\"div\"\n role=\"menuitemcheckbox\"\n aria-checked={checked}\n className={className}\n Icon={Icon}\n label={label}\n onSelect={onSelect}\n disabled={disabled}\n onClick={onClick}\n >\n <ToggleInput\n id={toggleId}\n ref={ref}\n // This is purely cosmetic; really the whole MenuItem is the toggle.\n aria-hidden\n checked={checked}\n disabled={disabled}\n onChange={onChange}\n />\n </MenuItem>\n );\n },\n);\n"],"names":["ToggleMenuItem"],"mappings":";;;;AAyBO,MAAM,iBAAiB;AAAA,EAC5B,SAASA,gBACP,EAAE,WAAW,MAAM,OAAO,UAAU,SAAS,UAAU,QAAQ,GAC/D,KACA;AACA,UAAM,WAAW,MAAM;AAGjB,UAAA,WAAW,YAAY,MAAM;AAAA,IAAC,GAAG,EAAE;AAMvC,WAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,IAAG;AAAA,QACH,MAAK;AAAA,QACL,gBAAc;AAAA,QACd;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QAEA,UAAA;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,IAAI;AAAA,YACJ;AAAA,YAEA,eAAW;AAAA,YACX;AAAA,YACA;AAAA,YACA;AAAA,UAAA;AAAA,QAAA;AAAA,MACF;AAAA,IACF;AAAA,EAAA;AAGN;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vector-im/compound-web",
3
- "version": "7.6.4",
3
+ "version": "7.7.0",
4
4
  "description": "Compound components for the Web",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -0,0 +1,62 @@
1
+ /*
2
+ * Copyright 2025 New Vector Ltd
3
+ *
4
+ * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
5
+ * Please see LICENSE files in the repository root for full details.
6
+ */
7
+
8
+ import React, { ComponentProps, forwardRef, useCallback, useId } from "react";
9
+ import { MenuItem } from "./MenuItem";
10
+ import { CheckboxInput } from "../Form";
11
+
12
+ type Props = Pick<
13
+ ComponentProps<typeof MenuItem>,
14
+ "className" | "label" | "onSelect" | "disabled"
15
+ > & {
16
+ /**
17
+ * Whether the checkbox is checked.
18
+ */
19
+ checked: boolean;
20
+ };
21
+
22
+ /**
23
+ * A menu item with a checkbox control.
24
+ * Must be used within a compound Menu or other `menu` or `menubar` aria role subtree.
25
+ */
26
+ export const CheckboxMenuItem = forwardRef<HTMLInputElement, Props>(
27
+ function CheckboxMenuItem(
28
+ { className, label, onSelect, checked, disabled },
29
+ ref,
30
+ ) {
31
+ const toggleId = useId();
32
+ // The checkbox is controlled and we intend to ignore its events. We do need
33
+ // to at least set onChange though to make React happy.
34
+ const onChange = useCallback(() => {}, []);
35
+
36
+ // <label> elements are not allowed to have a role like menuitemcheckbox, so
37
+ // we must instead use a plain <div> for the menu item and use aria-checked
38
+ // etc. to communicate its state.
39
+ return (
40
+ <MenuItem
41
+ as="div"
42
+ role="menuitemcheckbox"
43
+ aria-checked={checked}
44
+ className={className}
45
+ label={label}
46
+ onSelect={onSelect}
47
+ disabled={disabled}
48
+ Icon={
49
+ <CheckboxInput
50
+ id={toggleId}
51
+ ref={ref}
52
+ // This is purely cosmetic; really the whole MenuItem is the toggle.
53
+ aria-hidden
54
+ checked={checked}
55
+ disabled={disabled}
56
+ onChange={onChange}
57
+ />
58
+ }
59
+ />
60
+ );
61
+ },
62
+ );
@@ -55,13 +55,22 @@ type Props<C extends MenuItemElement> = {
55
55
  */
56
56
  // This prop is required because it's rare to not want a selection handler
57
57
  onSelect: ((e: Event) => void) | null;
58
+ /**
59
+ * Event callback for when the item is clicked.
60
+ * @param e
61
+ */
62
+ onClick?: (e: Event) => void;
58
63
  /**
59
64
  * The color variant of the menu item.
60
65
  * @default primary
61
66
  */
62
67
  kind?: "primary" | "critical";
63
68
  disabled?: boolean;
64
- } & Omit<ComponentPropsWithoutRef<C>, "onSelect">;
69
+ /**
70
+ * Whether to hide the chevron navigation hint.
71
+ */
72
+ hideChevron?: boolean;
73
+ } & Omit<ComponentPropsWithoutRef<C>, "onSelect" | "onClick">;
65
74
 
66
75
  /**
67
76
  * An item within a menu, acting either as a navigation button, or simply a
@@ -79,6 +88,7 @@ export const MenuItem = <C extends MenuItemElement = "button">({
79
88
  children,
80
89
  onClick: onClickProp,
81
90
  disabled,
91
+ hideChevron,
82
92
  ...props
83
93
  }: Props<C>): React.ReactElement => {
84
94
  const Component = as ?? ("button" as ElementType);
@@ -143,7 +153,7 @@ export const MenuItem = <C extends MenuItemElement = "button">({
143
153
  )}
144
154
  {/* We use CSS to swap between this navigation hint and the provided
145
155
  children on hover - see the styles module. */}
146
- {(Component === "button" || Component === "a") && (
156
+ {!hideChevron && (Component === "button" || Component === "a") && (
147
157
  <ChevronRightIcon
148
158
  width={8}
149
159
  height={24}
@@ -11,7 +11,7 @@ import { ToggleInput } from "../Form/Controls/Toggle";
11
11
 
12
12
  type Props = Pick<
13
13
  ComponentProps<typeof MenuItem>,
14
- "className" | "Icon" | "label" | "onSelect" | "disabled"
14
+ "className" | "Icon" | "label" | "onSelect" | "disabled" | "onClick"
15
15
  > & {
16
16
  /**
17
17
  * Whether the toggle is checked.
@@ -25,7 +25,7 @@ type Props = Pick<
25
25
  */
26
26
  export const ToggleMenuItem = forwardRef<HTMLInputElement, Props>(
27
27
  function ToggleMenuItem(
28
- { className, Icon, label, onSelect, checked, disabled },
28
+ { className, Icon, label, onSelect, checked, disabled, onClick },
29
29
  ref,
30
30
  ) {
31
31
  const toggleId = useId();
@@ -46,6 +46,7 @@ export const ToggleMenuItem = forwardRef<HTMLInputElement, Props>(
46
46
  label={label}
47
47
  onSelect={onSelect}
48
48
  disabled={disabled}
49
+ onClick={onClick}
49
50
  >
50
51
  <ToggleInput
51
52
  id={toggleId}