@dxos/react-ui-menu 0.8.2-main.f11618f → 0.8.2-main.fbd8ed0

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.
Files changed (51) hide show
  1. package/dist/lib/browser/index.mjs +58 -63
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node/index.cjs +53 -58
  5. package/dist/lib/node/index.cjs.map +4 -4
  6. package/dist/lib/node/meta.json +1 -1
  7. package/dist/lib/node-esm/index.mjs +58 -63
  8. package/dist/lib/node-esm/index.mjs.map +4 -4
  9. package/dist/lib/node-esm/meta.json +1 -1
  10. package/dist/types/src/components/ActionLabel.d.ts +8 -4
  11. package/dist/types/src/components/ActionLabel.d.ts.map +1 -1
  12. package/dist/types/src/components/DropdownMenu.d.ts +3 -2
  13. package/dist/types/src/components/DropdownMenu.d.ts.map +1 -1
  14. package/dist/types/src/components/MenuContext.d.ts +4 -13
  15. package/dist/types/src/components/MenuContext.d.ts.map +1 -1
  16. package/dist/types/src/{testing → components}/Menus.stories.d.ts +1 -1
  17. package/dist/types/src/components/Menus.stories.d.ts.map +1 -0
  18. package/dist/types/src/components/ToolbarMenu.d.ts +5 -1
  19. package/dist/types/src/components/ToolbarMenu.d.ts.map +1 -1
  20. package/dist/types/src/hooks/index.d.ts +2 -0
  21. package/dist/types/src/hooks/index.d.ts.map +1 -0
  22. package/dist/types/src/hooks/useMenuActions.d.ts +12 -0
  23. package/dist/types/src/hooks/useMenuActions.d.ts.map +1 -0
  24. package/dist/types/src/index.d.ts +1 -1
  25. package/dist/types/src/index.d.ts.map +1 -1
  26. package/dist/types/src/testing/generator.d.ts +26 -0
  27. package/dist/types/src/testing/generator.d.ts.map +1 -0
  28. package/dist/types/src/testing/index.d.ts +1 -25
  29. package/dist/types/src/testing/index.d.ts.map +1 -1
  30. package/dist/types/src/{defs.d.ts → types.d.ts} +3 -5
  31. package/dist/types/src/types.d.ts.map +1 -0
  32. package/dist/types/src/util.d.ts +2 -2
  33. package/dist/types/src/util.d.ts.map +1 -1
  34. package/dist/types/tsconfig.tsbuildinfo +1 -1
  35. package/package.json +18 -12
  36. package/src/components/ActionLabel.tsx +11 -8
  37. package/src/components/DropdownMenu.tsx +5 -5
  38. package/src/components/MenuContext.tsx +11 -26
  39. package/src/{testing → components}/Menus.stories.tsx +13 -13
  40. package/src/components/ToolbarMenu.tsx +27 -29
  41. package/src/hooks/index.ts +5 -0
  42. package/src/{hooks.ts → hooks/useMenuActions.ts} +20 -20
  43. package/src/index.ts +1 -1
  44. package/src/testing/generator.ts +115 -0
  45. package/src/testing/index.ts +1 -107
  46. package/src/{defs.ts → types.ts} +2 -5
  47. package/src/util.ts +7 -7
  48. package/dist/types/src/defs.d.ts.map +0 -1
  49. package/dist/types/src/hooks.d.ts +0 -17
  50. package/dist/types/src/hooks.d.ts.map +0 -1
  51. package/dist/types/src/testing/Menus.stories.d.ts.map +0 -1
@@ -2,7 +2,7 @@ import '@dxos-theme';
2
2
  import React from 'react';
3
3
  declare const _default: {
4
4
  title: string;
5
- component: ({ __menuScope, classNames, ...props }: import("..").MenuScopedProps<import("..").ToolbarMenuProps>) => React.JSX.Element;
5
+ component: ({ __menuScope, classNames, ...props }: import("./MenuContext").MenuScopedProps<import("./ToolbarMenu").ToolbarMenuProps>) => React.JSX.Element;
6
6
  decorators: import("@storybook/react").Decorator[];
7
7
  parameters: {
8
8
  translations: readonly [{
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Menus.stories.d.ts","sourceRoot":"","sources":["../../../../src/components/Menus.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AACrB,OAAO,KAA+B,MAAM,OAAO,CAAC;;;;;;;;;;;;;AAcpD,wBAKE;AAEF,eAAO,MAAM,YAAY;;CAgBxB,CAAC;AAEF,eAAO,MAAM,OAAO;;CAUnB,CAAC;AAEF,eAAO,MAAM,qBAAqB;;CAUjC,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { type ToolbarRootProps } from '@dxos/react-ui';
3
3
  import { type MenuScopedProps } from './MenuContext';
4
- import { type MenuItem, type MenuItemGroup, type MenuActionProperties, type MenuMultipleSelectActionGroup, type MenuSingleSelectActionGroup } from '../defs';
4
+ import { type MenuAction, type MenuItem, type MenuItemGroup, type MenuActionProperties, type MenuMultipleSelectActionGroup, type MenuSingleSelectActionGroup } from '../types';
5
5
  export type ToolbarMenuDropdownMenuActionGroup = Omit<MenuActionProperties, 'variant' | 'icon'> & {
6
6
  variant: 'dropdownMenu';
7
7
  icon: string;
@@ -16,5 +16,9 @@ export type ToolbarMenuActionGroupProps = {
16
16
  group: MenuItemGroup<ToolbarMenuActionGroupProperties>;
17
17
  items?: MenuItem[];
18
18
  };
19
+ export type ToolbarMenuActionProps = {
20
+ group: MenuItemGroup<ToolbarMenuActionGroupProperties>;
21
+ action: MenuAction;
22
+ };
19
23
  export declare const ToolbarMenu: ({ __menuScope, classNames, ...props }: MenuScopedProps<ToolbarMenuProps>) => React.JSX.Element;
20
24
  //# sourceMappingURL=ToolbarMenu.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ToolbarMenu.d.ts","sourceRoot":"","sources":["../../../../src/components/ToolbarMenu.tsx"],"names":[],"mappings":"AAIA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAEnD,OAAO,EAAyD,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAK9G,OAAO,EAAE,KAAK,eAAe,EAAyB,MAAM,eAAe,CAAC;AAC5E,OAAO,EAEL,KAAK,QAAQ,EAGb,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,6BAA6B,EAClC,KAAK,2BAA2B,EACjC,MAAM,SAAS,CAAC;AAEjB,MAAM,MAAM,kCAAkC,GAAG,IAAI,CAAC,oBAAoB,EAAE,SAAS,GAAG,MAAM,CAAC,GAAG;IAChG,OAAO,EAAE,cAAc,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,GAAG;IACtF,OAAO,EAAE,aAAa,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG,CAC3C,kCAAkC,GAClC,iCAAiC,CACpC,GACC,CAAC,2BAA2B,GAAG,6BAA6B,CAAC,CAAC;AAEhE,MAAM,MAAM,gBAAgB,GAAG,gBAAgB,CAAC;AAEhD,MAAM,MAAM,2BAA2B,GAAG;IACxC,KAAK,EAAE,aAAa,CAAC,gCAAgC,CAAC,CAAC;IACvD,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;CACpB,CAAC;AAiHF,eAAO,MAAM,WAAW,0CAA2C,eAAe,CAAC,gBAAgB,CAAC,sBA2BnG,CAAC"}
1
+ {"version":3,"file":"ToolbarMenu.d.ts","sourceRoot":"","sources":["../../../../src/components/ToolbarMenu.tsx"],"names":[],"mappings":"AAIA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAEnD,OAAO,EAAmC,KAAK,gBAAgB,EAAkB,MAAM,gBAAgB,CAAC;AAKxG,OAAO,EAAE,KAAK,eAAe,EAAyB,MAAM,eAAe,CAAC;AAE5E,OAAO,EACL,KAAK,UAAU,EACf,KAAK,QAAQ,EAGb,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,6BAA6B,EAClC,KAAK,2BAA2B,EACjC,MAAM,UAAU,CAAC;AAElB,MAAM,MAAM,kCAAkC,GAAG,IAAI,CAAC,oBAAoB,EAAE,SAAS,GAAG,MAAM,CAAC,GAAG;IAChG,OAAO,EAAE,cAAc,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,GAAG;IACtF,OAAO,EAAE,aAAa,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG,CAC3C,kCAAkC,GAClC,iCAAiC,CACpC,GACC,CAAC,2BAA2B,GAAG,6BAA6B,CAAC,CAAC;AAEhE,MAAM,MAAM,gBAAgB,GAAG,gBAAgB,CAAC;AAEhD,MAAM,MAAM,2BAA2B,GAAG;IACxC,KAAK,EAAE,aAAa,CAAC,gCAAgC,CAAC,CAAC;IACvD,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,KAAK,EAAE,aAAa,CAAC,gCAAgC,CAAC,CAAC;IACvD,MAAM,EAAE,UAAU,CAAC;CACpB,CAAC;AAyGF,eAAO,MAAM,WAAW,GAAI,uCAAuC,eAAe,CAAC,gBAAgB,CAAC,sBA2BnG,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './useMenuActions';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/index.ts"],"names":[],"mappings":"AAIA,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { type Edge, type NodeArg } from '@dxos/app-graph';
2
+ import { type MenuItem, type MenuItemGroup } from '../types';
3
+ export type ActionGraphNodes = NodeArg<any>[];
4
+ export type ActionGraphEdges = Edge[];
5
+ export type ActionGraphProps = {
6
+ nodes: ActionGraphNodes;
7
+ edges: ActionGraphEdges;
8
+ };
9
+ export declare const useMenuActions: (actionCreator: () => ActionGraphProps) => {
10
+ useGroupItems: (sourceNode?: MenuItemGroup) => MenuItem[];
11
+ };
12
+ //# sourceMappingURL=useMenuActions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMenuActions.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useMenuActions.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,IAAI,EAAqB,KAAK,OAAO,EAAsB,MAAM,iBAAiB,CAAC;AAEjG,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AA6B7D,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;AAC9C,MAAM,MAAM,gBAAgB,GAAG,IAAI,EAAE,CAAC;AACtC,MAAM,MAAM,gBAAgB,GAAG;IAAE,KAAK,EAAE,gBAAgB,CAAC;IAAC,KAAK,EAAE,gBAAgB,CAAA;CAAE,CAAC;AAEpF,eAAO,MAAM,cAAc,GAAI,eAAe,MAAM,gBAAgB;iCAoBlD,aAAa;CAQ9B,CAAC"}
@@ -1,5 +1,5 @@
1
1
  export * from './components';
2
- export * from './defs';
3
2
  export * from './hooks';
3
+ export * from './types';
4
4
  export { createMenuAction, createMenuItemGroup, createLineSeparator, createGapSeparator } from './util';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { type Action, ACTION_TYPE, ACTION_GROUP_TYPE } from '@dxos/app-graph';
2
+ import { type ActionGraphProps } from '../hooks/useMenuActions';
3
+ import { type MenuAction, type MenuItemGroup, type MenuItem } from '../types';
4
+ export type CreateActionsParams = Partial<{
5
+ type?: typeof ACTION_TYPE | typeof ACTION_GROUP_TYPE;
6
+ callback: () => void;
7
+ count: number;
8
+ }>;
9
+ export declare const createActions: (params?: CreateActionsParams) => import("@dxos/live-object").Live<{
10
+ id: string;
11
+ type: "dxos.org/type/GraphActionGroup" | "dxos.org/type/GraphAction";
12
+ data: symbol | (() => void);
13
+ properties: {
14
+ variant?: string | undefined;
15
+ label: string;
16
+ icon: string;
17
+ disabled: boolean;
18
+ };
19
+ }>[];
20
+ export declare const createNestedActions: () => ActionGraphProps;
21
+ export declare const createNestedActionsResolver: (groupParams?: CreateActionsParams, params?: CreateActionsParams) => {
22
+ resolveGroupItems: (groupNode?: MenuItemGroup) => MenuItem[] | null;
23
+ };
24
+ export declare const mutateActionsOnInterval: (actions: Action[]) => NodeJS.Timeout;
25
+ export declare const useMutateActions: (actions: MenuAction[]) => void;
26
+ //# sourceMappingURL=generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../../src/testing/generator.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,KAAK,MAAM,EAGX,WAAW,EACX,iBAAiB,EAGlB,MAAM,iBAAiB,CAAC;AAKzB,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,aAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAE9E,MAAM,MAAM,mBAAmB,GAAG,OAAO,CAAC;IACxC,IAAI,CAAC,EAAE,OAAO,WAAW,GAAG,OAAO,iBAAiB,CAAC;IACrD,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC,CAAC;AAqBH,eAAO,MAAM,aAAa,GAAI,SAAS,mBAAmB;;;0BAvBxC,IAAI;;;;;;;IAyCrB,CAAC;AAEF,eAAO,MAAM,mBAAmB,wBAY/B,CAAC;AAEF,eAAO,MAAM,2BAA2B,GAAI,cAAc,mBAAmB,EAAE,SAAS,mBAAmB;oCAYlE,aAAa,KACM,QAAQ,EAAE,GAAG,IAAI;CAE5E,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAI,SAAS,MAAM,EAAE,mBAUxD,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,SAAS,UAAU,EAAE,SAI9C,CAAC"}
@@ -1,26 +1,2 @@
1
- import { type Action, ACTION_TYPE, ACTION_GROUP_TYPE } from '@dxos/app-graph';
2
- import { type MenuAction, type MenuItemGroup, type MenuItem } from '../defs';
3
- import { type ActionGraphProps } from '../hooks';
4
- export type CreateActionsParams = Partial<{
5
- type?: typeof ACTION_TYPE | typeof ACTION_GROUP_TYPE;
6
- callback: () => void;
7
- count: number;
8
- }>;
9
- export declare const createActions: (params?: CreateActionsParams) => import("@dxos/live-object").Live<{
10
- id: string;
11
- type: "dxos.org/type/GraphActionGroup" | "dxos.org/type/GraphAction";
12
- data: symbol | (() => void);
13
- properties: {
14
- variant?: string | undefined;
15
- label: string;
16
- icon: string;
17
- disabled: boolean;
18
- };
19
- }>[];
20
- export declare const createNestedActions: () => ActionGraphProps;
21
- export declare const createNestedActionsResolver: (groupParams?: CreateActionsParams, params?: CreateActionsParams) => {
22
- resolveGroupItems: (groupNode?: MenuItemGroup) => MenuItem[] | null;
23
- };
24
- export declare const mutateActionsOnInterval: (actions: Action[]) => NodeJS.Timeout;
25
- export declare const useMutateActions: (actions: MenuAction[]) => void;
1
+ export * from './generator';
26
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,MAAM,EAAuB,WAAW,EAAE,iBAAiB,EAAqB,MAAM,iBAAiB,CAAC;AAKtH,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,aAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD,MAAM,MAAM,mBAAmB,GAAG,OAAO,CAAC;IACxC,IAAI,CAAC,EAAE,OAAO,WAAW,GAAG,OAAO,iBAAiB,CAAC;IACrD,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC,CAAC;AAqBH,eAAO,MAAM,aAAa,YAAa,mBAAmB;;;0BAvBxC,IAAI;;;;;;;IAyCrB,CAAC;AAEF,eAAO,MAAM,mBAAmB,wBAY/B,CAAC;AAEF,eAAO,MAAM,2BAA2B,iBAAkB,mBAAmB,WAAW,mBAAmB;oCAgBlE,aAAa,KACE,QAAQ,EAAE,GAAG,IAAI;CAExE,CAAC;AAEF,eAAO,MAAM,uBAAuB,YAAa,MAAM,EAAE,mBAUxD,CAAC;AAEF,eAAO,MAAM,gBAAgB,YAAa,UAAU,EAAE,SAI9C,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAIA,cAAc,aAAa,CAAC"}
@@ -18,7 +18,6 @@ export type MenuItemGroupProperties = {
18
18
  iconOnly?: boolean;
19
19
  };
20
20
  export type MenuAction<P extends {} = {}> = Action<P & MenuActionProperties>;
21
- export type MenuActionHandler<A extends Node = MenuAction> = (action: A) => void;
22
21
  export declare const MenuSeparatorType: "@dxos/react-ui-toolbar/separator";
23
22
  export type MenuSeparator = Node<never, Pick<ToolbarSeparatorProps, 'variant'>> & {
24
23
  type: typeof MenuSeparatorType;
@@ -36,10 +35,9 @@ export type MenuItemGroup<P extends Record<string, any> = Record<string, any>> =
36
35
  export declare const isMenuGroup: (node: Node) => node is MenuItemGroup;
37
36
  export type MenuItem = MenuSeparator | MenuAction | MenuItemGroup;
38
37
  export type MenuItemsResolver = (group?: MenuItemGroup) => MenuItem[] | null;
39
- export type MenuContextValue<A extends Node = MenuAction> = {
40
- resolveGroupItems: MenuItemsResolver;
38
+ export type MenuContextValue = {
39
+ useGroupItems: MenuItemsResolver;
41
40
  iconSize: IconButtonProps['size'];
42
- onAction: MenuActionHandler<A>;
43
41
  attendableId?: string;
44
42
  };
45
- //# sourceMappingURL=defs.d.ts.map
43
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,MAAM,EAAE,KAAK,WAAW,EAAqB,MAAM,iBAAiB,CAAC;AAC9F,OAAO,EAAE,KAAK,qBAAqB,EAAE,KAAK,KAAK,EAAE,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEnH,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,MAAM,CAAC,CAAC,GAAG,oBAAoB,CAAC,CAAC;AAE7E,eAAO,MAAM,iBAAiB,EAAG,kCAA2C,CAAC;AAE7E,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,qBAAqB,EAAE,SAAS,CAAC,CAAC,GAAG;IAChF,IAAI,EAAE,OAAO,iBAAiB,CAAC;CAChC,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,MAAM,IAAI,KAAG,IAAI,IAAI,aAAgD,CAAC;AAElG,MAAM,MAAM,2BAA2B,GAAG;IAAE,iBAAiB,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AACzF,MAAM,MAAM,6BAA6B,GAAG;IAAE,iBAAiB,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAE/F,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC;AAEhG,eAAO,MAAM,WAAW,GAAI,MAAM,IAAI,KAAG,IAAI,IAAI,aAAgD,CAAC;AAElG,MAAM,MAAM,QAAQ,GAAG,aAAa,GAAG,UAAU,GAAG,aAAa,CAAC;AAElE,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,CAAC,EAAE,aAAa,KAAK,QAAQ,EAAE,GAAG,IAAI,CAAC;AAE7E,MAAM,MAAM,gBAAgB,GAAG;IAC7B,aAAa,EAAE,iBAAiB,CAAC;IACjC,QAAQ,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC"}
@@ -1,8 +1,8 @@
1
1
  import { actionGroupSymbol, type ActionLike } from '@dxos/app-graph';
2
- import { type MenuActionProperties, type MenuItemGroupProperties } from './defs';
2
+ import { type MenuActionProperties, type MenuItemGroupProperties } from './types';
3
3
  export declare const getShortcut: (action: ActionLike) => any;
4
4
  export declare const fallbackIcon = "ph--placeholder--regular";
5
- export declare const createMenuAction: <P extends {} = {}>(id: string, properties: P & MenuActionProperties) => {
5
+ export declare const createMenuAction: <P extends {} = {}>(id: string, invoke: () => void, properties: P & MenuActionProperties) => {
6
6
  id: string;
7
7
  type: string;
8
8
  properties: P & MenuActionProperties;
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/util.ts"],"names":[],"mappings":"AAIA,OAAO,EAAkC,iBAAiB,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGrG,OAAO,EAEL,KAAK,oBAAoB,EAEzB,KAAK,uBAAuB,EAE7B,MAAM,QAAQ,CAAC;AAEhB,eAAO,MAAM,WAAW,WAAY,UAAU,QAI7C,CAAC;AAEF,eAAO,MAAM,YAAY,6BAA6B,CAAC;AAMvD,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,EAAE,WAAW,MAAM,cAAc,CAAC,GAAG,oBAAoB;;;;;CAM3E,CAAC;AAE1B,eAAO,MAAM,mBAAmB,GAC9B,CAAC,SAAS,uBAAuB,gEAE7B,MAAM,cACE,CAAC;;;;;CAOa,CAAC;AAE7B,eAAO,MAAM,kBAAkB,QAAQ,MAAM,WAAkB,MAAM;;;;;;;cAM5C,KAAK;;;;;;CAI5B,CAAC;AAEH,eAAO,MAAM,mBAAmB,QAAQ,MAAM,WAAmB,MAAM;;;;;;;cAM9C,KAAK;;;;;;CAI5B,CAAC"}
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/util.ts"],"names":[],"mappings":"AAIA,OAAO,EAAkC,iBAAiB,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGrG,OAAO,EAEL,KAAK,oBAAoB,EAEzB,KAAK,uBAAuB,EAE7B,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,WAAW,GAAI,QAAQ,UAAU,QAI7C,CAAC;AAEF,eAAO,MAAM,YAAY,6BAA6B,CAAC;AAEvD,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,EAAE,GAAG,EAAE,EAChD,IAAI,MAAM,EACV,QAAQ,MAAM,IAAI,EAClB,YAAY,CAAC,GAAG,oBAAoB;;;;gBADtB,IAAI;CAQK,CAAC;AAE1B,eAAO,MAAM,mBAAmB,GAC9B,CAAC,SAAS,uBAAuB,GAAG,uBAAuB,GAAG,OAAO,CAAC,oBAAoB,CAAC,EAE3F,IAAI,MAAM,EACV,YAAY,CAAC;;;;;CAOa,CAAC;AAE7B,eAAO,MAAM,kBAAkB,GAAI,KAAI,MAAc,EAAE,SAAQ,MAAe;;;;;;;cAMrD,KAAK;;;;;;CAI5B,CAAC;AAEH,eAAO,MAAM,mBAAmB,GAAI,KAAI,MAAe,EAAE,SAAQ,MAAe;;;;;;;cAMvD,KAAK;;;;;;CAI5B,CAAC"}
@@ -1 +1 @@
1
- {"version":"5.7.3"}
1
+ {"version":"5.8.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-menu",
3
- "version": "0.8.2-main.f11618f",
3
+ "version": "0.8.2-main.fbd8ed0",
4
4
  "description": "Components for facilitating reactive and consistent menus.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -27,28 +27,34 @@
27
27
  "@preact/signals-react": "^1.3.8",
28
28
  "@radix-ui/react-context": "1.1.1",
29
29
  "@radix-ui/react-use-controllable-state": "1.1.0",
30
- "@dxos/app-graph": "0.8.2-main.f11618f",
31
- "@dxos/keyboard": "0.8.2-main.f11618f",
32
- "@dxos/react-ui-attention": "0.8.2-main.f11618f",
33
- "@dxos/util": "0.8.2-main.f11618f"
30
+ "@dxos/app-graph": "0.8.2-main.fbd8ed0",
31
+ "@dxos/keyboard": "0.8.2-main.fbd8ed0",
32
+ "@dxos/react-ui-attention": "0.8.2-main.fbd8ed0",
33
+ "@dxos/util": "0.8.2-main.fbd8ed0"
34
34
  },
35
35
  "devDependencies": {
36
+ "@effect-rx/rx-react": "^0.34.1",
37
+ "@effect/platform": "0.80.12",
36
38
  "@types/react": "~18.2.0",
37
39
  "@types/react-dom": "~18.2.0",
40
+ "effect": "3.14.21",
38
41
  "react": "~18.2.0",
39
42
  "react-dom": "~18.2.0",
40
43
  "vite": "5.4.7",
41
- "@dxos/live-object": "0.8.2-main.f11618f",
42
- "@dxos/random": "0.8.2-main.f11618f",
43
- "@dxos/react-ui": "0.8.2-main.f11618f",
44
- "@dxos/react-ui-theme": "0.8.2-main.f11618f",
45
- "@dxos/storybook-utils": "0.8.2-main.f11618f"
44
+ "@dxos/live-object": "0.8.2-main.fbd8ed0",
45
+ "@dxos/react-ui": "0.8.2-main.fbd8ed0",
46
+ "@dxos/random": "0.8.2-main.fbd8ed0",
47
+ "@dxos/react-ui-theme": "0.8.2-main.fbd8ed0",
48
+ "@dxos/storybook-utils": "0.8.2-main.fbd8ed0"
46
49
  },
47
50
  "peerDependencies": {
51
+ "@effect-rx/rx-react": "^0.34.1",
52
+ "@effect/platform": "0.80.12",
53
+ "effect": "^3.13.3",
48
54
  "react": "~18.2.0",
49
55
  "react-dom": "~18.2.0",
50
- "@dxos/react-ui": "0.8.2-main.f11618f",
51
- "@dxos/react-ui-theme": "0.8.2-main.f11618f"
56
+ "@dxos/react-ui-theme": "0.8.2-main.fbd8ed0",
57
+ "@dxos/react-ui": "0.8.2-main.fbd8ed0"
52
58
  },
53
59
  "publishConfig": {
54
60
  "access": "public"
@@ -4,20 +4,18 @@
4
4
 
5
5
  import React from 'react';
6
6
 
7
- import { type Action, type ActionGroup } from '@dxos/app-graph';
7
+ import { type Action as GraphAction, type ActionGroup } from '@dxos/app-graph';
8
8
  import { keySymbols } from '@dxos/keyboard';
9
- import { toLocalizedString, useTranslation } from '@dxos/react-ui';
9
+ import { toLocalizedString, useTranslation, type TFunction } from '@dxos/react-ui';
10
10
  import { mx, descriptionText } from '@dxos/react-ui-theme';
11
11
 
12
- import { type MenuActionProperties } from '../defs';
13
12
  import { translationKey } from '../translations';
13
+ import { type MenuActionProperties } from '../types';
14
14
  import { getShortcut } from '../util';
15
15
 
16
- export const ActionLabel = ({
17
- action,
18
- }: {
19
- action: Action<MenuActionProperties> | ActionGroup<Omit<MenuActionProperties, 'variant'>>;
20
- }) => {
16
+ type Action = GraphAction<MenuActionProperties> | ActionGroup<Omit<MenuActionProperties, 'variant'>>;
17
+
18
+ export const ActionLabel = ({ action }: { action: Action }) => {
21
19
  const shortcut = getShortcut(action);
22
20
  const { t } = useTranslation(translationKey);
23
21
 
@@ -28,3 +26,8 @@ export const ActionLabel = ({
28
26
  </>
29
27
  );
30
28
  };
29
+
30
+ export const actionLabel = (action: Action, t: TFunction) => {
31
+ const shortcut = getShortcut(action);
32
+ return `${toLocalizedString(action.properties!.label, t)}${shortcut ? ` (${keySymbols(shortcut).join('')})` : ''}`;
33
+ };
@@ -9,12 +9,13 @@ import { DropdownMenu as NaturalDropdownMenu, Icon, type DropdownMenuRootProps }
9
9
 
10
10
  import { ActionLabel } from './ActionLabel';
11
11
  import { type MenuScopedProps, useMenu, useMenuItems } from './MenuContext';
12
- import { type MenuAction, type MenuItem, type MenuItemGroup } from '../defs';
12
+ import { type MenuAction, type MenuItem, type MenuItemGroup } from '../types';
13
13
 
14
14
  export type DropdownMenuProps = DropdownMenuRootProps & {
15
15
  group?: MenuItemGroup;
16
16
  items?: MenuItem[];
17
17
  suppressNextTooltip?: MutableRefObject<boolean>;
18
+ caller?: string;
18
19
  };
19
20
 
20
21
  const DropdownMenuItem = ({
@@ -49,6 +50,7 @@ const DropdownMenuRoot = ({
49
50
  defaultOpen,
50
51
  onOpenChange,
51
52
  suppressNextTooltip,
53
+ caller,
52
54
  children,
53
55
  __menuScope,
54
56
  ...naturalProps
@@ -59,8 +61,6 @@ const DropdownMenuRoot = ({
59
61
  onChange: onOpenChange,
60
62
  });
61
63
 
62
- const { onAction } = useMenu('DropdownMenuRoot', __menuScope);
63
-
64
64
  const handleActionClick = useCallback(
65
65
  (action: MenuAction, event: MouseEvent) => {
66
66
  if (action.properties?.disabled) {
@@ -72,9 +72,9 @@ const DropdownMenuRoot = ({
72
72
  suppressNextTooltip.current = true;
73
73
  }
74
74
  setOptionsMenuOpen(false);
75
- onAction?.(action);
75
+ void action.data?.({ parent: group, caller });
76
76
  },
77
- [onAction],
77
+ [suppressNextTooltip, group, caller],
78
78
  );
79
79
 
80
80
  const items = useMenuItems(group, propsItems);
@@ -5,15 +5,7 @@
5
5
  import { createContextScope, type Scope } from '@radix-ui/react-context';
6
6
  import React, { type PropsWithChildren, useMemo } from 'react';
7
7
 
8
- import { type Node } from '@dxos/app-graph';
9
-
10
- import {
11
- type MenuActionHandler,
12
- type MenuAction,
13
- type MenuContextValue,
14
- type MenuItem,
15
- type MenuItemGroup,
16
- } from '../defs';
8
+ import { type MenuContextValue, type MenuItem, type MenuItemGroup } from '../types';
17
9
 
18
10
  export type MenuScopedProps<P> = P & { __menuScope?: Scope };
19
11
 
@@ -21,32 +13,24 @@ const MENU_NAME = 'GraphMenu';
21
13
 
22
14
  const [createMenuContext, createMenuScope] = createContextScope(MENU_NAME, []);
23
15
 
24
- const [MenuContextProvider, useMenu] = createMenuContext<MenuContextValue<any>>(MENU_NAME);
16
+ const [MenuContextProvider, useMenu] = createMenuContext<MenuContextValue>(MENU_NAME);
25
17
 
26
- export const menuContextDefaults: MenuContextValue<MenuAction> = {
18
+ export const menuContextDefaults: MenuContextValue = {
27
19
  iconSize: 5,
28
- onAction: () => {},
29
- resolveGroupItems: () => null,
20
+ useGroupItems: () => null,
30
21
  };
31
22
 
32
23
  const useMenuScope = createMenuScope();
33
24
 
34
- const MenuProvider = <A extends Node = MenuAction>({
25
+ const MenuProvider = ({
35
26
  children,
36
- resolveGroupItems = menuContextDefaults.resolveGroupItems,
37
- onAction = menuContextDefaults.onAction as MenuActionHandler<A>,
27
+ useGroupItems = menuContextDefaults.useGroupItems,
38
28
  iconSize = menuContextDefaults.iconSize,
39
29
  attendableId,
40
- }: PropsWithChildren<Partial<MenuContextValue<A>>>) => {
30
+ }: PropsWithChildren<Partial<MenuContextValue>>) => {
41
31
  const { scope } = useMenuScope(undefined);
42
32
  return (
43
- <MenuContextProvider
44
- resolveGroupItems={resolveGroupItems}
45
- onAction={onAction}
46
- iconSize={iconSize}
47
- attendableId={attendableId}
48
- scope={scope}
49
- >
33
+ <MenuContextProvider useGroupItems={useGroupItems} iconSize={iconSize} attendableId={attendableId} scope={scope}>
50
34
  {children}
51
35
  </MenuContextProvider>
52
36
  );
@@ -58,8 +42,9 @@ export const useMenuItems = (
58
42
  consumerName: string = 'useMenuItemConsumer',
59
43
  __menuScope?: Scope,
60
44
  ) => {
61
- const { resolveGroupItems } = useMenu(consumerName, __menuScope);
62
- return useMemo(() => propsItems ?? resolveGroupItems?.(group) ?? undefined, [propsItems, group, resolveGroupItems]);
45
+ const { useGroupItems } = useMenu(consumerName, __menuScope);
46
+ const groupItems = useGroupItems(group);
47
+ return useMemo(() => propsItems ?? groupItems ?? undefined, [propsItems, groupItems]);
63
48
  };
64
49
 
65
50
  export { useMenu, createMenuScope, MenuProvider };
@@ -3,38 +3,35 @@
3
3
  //
4
4
 
5
5
  import '@dxos-theme';
6
- import React, { useCallback } from 'react';
6
+ import React, { useCallback, useMemo } from 'react';
7
7
 
8
8
  import { faker } from '@dxos/random';
9
9
  import { IconButton } from '@dxos/react-ui';
10
10
  import { withLayout, withSignals, withTheme } from '@dxos/storybook-utils';
11
11
 
12
- import { createActions, createNestedActions, createNestedActionsResolver, useMutateActions } from './index';
13
12
  import { DropdownMenu as NaturalDropdownMenu, ToolbarMenu, MenuProvider } from '../components';
14
- import { type MenuAction, type MenuActionHandler } from '../defs';
15
13
  import { useMenuActions } from '../hooks';
14
+ import { createActions, createNestedActions, createNestedActionsResolver, useMutateActions } from '../testing';
16
15
  import translations from '../translations';
16
+ import { type MenuAction } from '../types';
17
17
 
18
18
  faker.seed(1234);
19
19
 
20
20
  export default {
21
21
  title: 'ui/react-ui-menu/Menus',
22
22
  component: ToolbarMenu,
23
- decorators: [withTheme, withLayout({ tooltips: true }), withSignals],
23
+ decorators: [withTheme, withLayout(), withSignals],
24
24
  parameters: { translations },
25
25
  };
26
26
 
27
- const menuActions = createActions() as MenuAction[];
28
- const nestedMenuActions = createNestedActionsResolver();
29
-
30
- const handleAction = (action: MenuAction) => console.log('[on action]', action);
31
-
32
27
  export const DropdownMenu = {
33
28
  render: () => {
29
+ const menuActions = useMemo(() => createActions() as MenuAction[], []);
30
+ const resolveGroupItems = useCallback(() => menuActions, [menuActions]);
34
31
  useMutateActions(menuActions);
35
- const resolveGroupItems = useCallback(() => menuActions, []);
32
+
36
33
  return (
37
- <MenuProvider resolveGroupItems={resolveGroupItems} onAction={handleAction as MenuActionHandler}>
34
+ <MenuProvider useGroupItems={resolveGroupItems}>
38
35
  <NaturalDropdownMenu.Root>
39
36
  <NaturalDropdownMenu.Trigger asChild>
40
37
  <IconButton icon='ph--list-checks--regular' size={5} label='Options' />
@@ -47,8 +44,10 @@ export const DropdownMenu = {
47
44
 
48
45
  export const Toolbar = {
49
46
  render: () => {
47
+ const nestedMenuActions = useMemo(() => createNestedActionsResolver(), []);
48
+
50
49
  return (
51
- <MenuProvider onAction={handleAction as MenuActionHandler} {...nestedMenuActions}>
50
+ <MenuProvider {...nestedMenuActions}>
52
51
  <ToolbarMenu />
53
52
  </MenuProvider>
54
53
  );
@@ -58,8 +57,9 @@ export const Toolbar = {
58
57
  export const UseMenuActionsToolbar = {
59
58
  render: () => {
60
59
  const menu = useMenuActions(createNestedActions);
60
+
61
61
  return (
62
- <MenuProvider onAction={handleAction as MenuActionHandler} {...menu}>
62
+ <MenuProvider {...menu}>
63
63
  <ToolbarMenu />
64
64
  </MenuProvider>
65
65
  );
@@ -4,12 +4,13 @@
4
4
 
5
5
  import React, { useCallback, useRef } from 'react';
6
6
 
7
- import { Icon, type IconButtonProps, Toolbar as NaturalToolbar, type ToolbarRootProps } from '@dxos/react-ui';
7
+ import { Icon, Toolbar as NaturalToolbar, type ToolbarRootProps, useTranslation } from '@dxos/react-ui';
8
8
  import { useAttention } from '@dxos/react-ui-attention';
9
9
 
10
- import { ActionLabel } from './ActionLabel';
10
+ import { actionLabel, ActionLabel } from './ActionLabel';
11
11
  import { DropdownMenu } from './DropdownMenu';
12
12
  import { type MenuScopedProps, useMenu, useMenuItems } from './MenuContext';
13
+ import { translationKey } from '../translations';
13
14
  import {
14
15
  type MenuAction,
15
16
  type MenuItem,
@@ -19,7 +20,7 @@ import {
19
20
  type MenuActionProperties,
20
21
  type MenuMultipleSelectActionGroup,
21
22
  type MenuSingleSelectActionGroup,
22
- } from '../defs';
23
+ } from '../types';
23
24
 
24
25
  export type ToolbarMenuDropdownMenuActionGroup = Omit<MenuActionProperties, 'variant' | 'icon'> & {
25
26
  variant: 'dropdownMenu';
@@ -44,15 +45,19 @@ export type ToolbarMenuActionGroupProps = {
44
45
  items?: MenuItem[];
45
46
  };
46
47
 
48
+ export type ToolbarMenuActionProps = {
49
+ group: MenuItemGroup<ToolbarMenuActionGroupProperties>;
50
+ action: MenuAction;
51
+ };
52
+
47
53
  const ActionToolbarItem = ({ action, __menuScope }: MenuScopedProps<{ action: MenuAction }>) => {
48
- const { onAction, iconSize } = useMenu('ActionToolbarItem', __menuScope);
49
- const handleClick = useCallback(() => {
50
- onAction?.(action);
51
- }, [action, onAction]);
54
+ const { iconSize } = useMenu('ActionToolbarItem', __menuScope);
55
+ const { t } = useTranslation(translationKey);
56
+ const handleClick = useCallback(() => action.data?.(), [action]);
52
57
  const { icon, iconOnly = true, disabled, testId, hidden, classNames } = action.properties;
53
58
  const Root = icon ? NaturalToolbar.IconButton : NaturalToolbar.Button;
54
59
  const rootProps = icon
55
- ? { icon, size: iconSize, iconOnly, label: <ActionLabel action={action} /> }
60
+ ? { icon, size: iconSize, iconOnly, label: actionLabel(action, t) }
56
61
  : { children: <ActionLabel action={action} /> };
57
62
  return hidden ? null : (
58
63
  <Root
@@ -61,7 +66,7 @@ const ActionToolbarItem = ({ action, __menuScope }: MenuScopedProps<{ action: Me
61
66
  onClick={handleClick}
62
67
  variant='ghost'
63
68
  {...(testId && { 'data-testid': testId })}
64
- {...(rootProps as IconButtonProps)}
69
+ {...(rootProps as any)}
65
70
  classNames={classNames}
66
71
  />
67
72
  );
@@ -74,6 +79,7 @@ const DropdownMenuToolbarItem = ({
74
79
  }: MenuScopedProps<ToolbarMenuActionGroupProps>) => {
75
80
  const { iconOnly, disabled, testId } = group.properties;
76
81
  const suppressNextTooltip = useRef(false);
82
+ const { t } = useTranslation(translationKey);
77
83
  const { iconSize } = useMenu('DropdownMenuToolbarItem', __menuScope);
78
84
  const items = useMenuItems(group, propsItems, 'DropdownMenuToolbarItem', __menuScope);
79
85
  const activeItem = items?.find((item) => !!(item as MenuAction).properties.checked);
@@ -83,15 +89,13 @@ const DropdownMenuToolbarItem = ({
83
89
  (activeItem as MenuAction)?.properties.icon) ||
84
90
  group.properties.icon;
85
91
  const Root = icon ? NaturalToolbar.IconButton : NaturalToolbar.Button;
86
- const label = (
87
- <ActionLabel action={(group.properties as any).applyActive && activeItem ? (activeItem as MenuAction) : group} />
88
- );
92
+ const labelAction = (group.properties as any).applyActive && activeItem ? (activeItem as MenuAction) : group;
89
93
  const rootProps = icon
90
- ? { icon, size: iconSize, iconOnly, label, caretDown: true, suppressNextTooltip }
94
+ ? { icon, size: iconSize, iconOnly, label: actionLabel(labelAction, t), caretDown: true, suppressNextTooltip }
91
95
  : {
92
96
  children: (
93
97
  <>
94
- {label}
98
+ <ActionLabel action={labelAction} />
95
99
  <Icon size={3} icon='ph--caret-down--bold' classNames='mis-1' />
96
100
  </>
97
101
  ),
@@ -99,26 +103,20 @@ const DropdownMenuToolbarItem = ({
99
103
  return (
100
104
  <DropdownMenu.Root group={group} items={items} suppressNextTooltip={suppressNextTooltip}>
101
105
  <DropdownMenu.Trigger asChild>
102
- <Root
103
- variant='ghost'
104
- disabled={disabled}
105
- {...(rootProps as IconButtonProps)}
106
- {...(testId && { 'data-testid': testId })}
107
- />
106
+ <Root variant='ghost' disabled={disabled} {...(rootProps as any)} {...(testId && { 'data-testid': testId })} />
108
107
  </DropdownMenu.Trigger>
109
108
  </DropdownMenu.Root>
110
109
  );
111
110
  };
112
111
 
113
- const ToggleGroupItem = ({ action, __menuScope }: MenuScopedProps<{ action: MenuAction }>) => {
114
- const { iconSize, onAction } = useMenu('ToggleGroupItem', __menuScope);
112
+ const ToggleGroupItem = ({ group, action, __menuScope }: MenuScopedProps<ToolbarMenuActionProps>) => {
113
+ const { iconSize } = useMenu('ToggleGroupItem', __menuScope);
114
+ const { t } = useTranslation(translationKey);
115
115
  const { icon, iconOnly = true, disabled, testId, hidden, classNames } = action.properties;
116
- const handleClick = useCallback(() => {
117
- onAction?.(action);
118
- }, [action, onAction]);
116
+ const handleClick = useCallback(() => action.data?.({ parent: group }), [action, group]);
119
117
  const Root = icon ? NaturalToolbar.ToggleGroupIconItem : NaturalToolbar.ToggleGroupItem;
120
118
  const rootProps = icon
121
- ? { icon, size: iconSize, iconOnly, label: <ActionLabel action={action} /> }
119
+ ? { icon, size: iconSize, iconOnly, label: actionLabel(action, t) }
122
120
  : { children: <ActionLabel action={action} /> };
123
121
  return hidden ? null : (
124
122
  <Root
@@ -128,7 +126,7 @@ const ToggleGroupItem = ({ action, __menuScope }: MenuScopedProps<{ action: Menu
128
126
  onClick={handleClick}
129
127
  variant='ghost'
130
128
  {...(testId && { 'data-testid': testId })}
131
- {...(rootProps as IconButtonProps)}
129
+ {...(rootProps as any)}
132
130
  classNames={classNames}
133
131
  />
134
132
  );
@@ -148,7 +146,7 @@ const ToggleGroupToolbarItem = ({
148
146
  {
149
147
  // TODO(thure): Handle other menu item types.
150
148
  (items as MenuAction[]).map((action) => (
151
- <ToggleGroupItem key={action.id} action={action} />
149
+ <ToggleGroupItem key={action.id} group={group} action={action} />
152
150
  ))
153
151
  }
154
152
  </NaturalToolbar.ToggleGroup>
@@ -162,7 +160,7 @@ export const ToolbarMenu = ({ __menuScope, classNames, ...props }: MenuScopedPro
162
160
  return (
163
161
  <NaturalToolbar.Root
164
162
  {...props}
165
- classNames={['p-0 pointer-fine:p-1 attention-surface', !hasAttention && 'opacity-20', classNames]}
163
+ classNames={['p-1', !hasAttention && '[&>*]:opacity-20 !bg-transparent', classNames]}
166
164
  >
167
165
  {items?.map((item: MenuItem, i: number) =>
168
166
  isSeparator(item) ? (
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './useMenuActions';