@dxos/react-ui-menu 0.8.4-main.f9ba587 → 0.8.4-main.fcfe5033a5
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/lib/browser/index.mjs +558 -391
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +558 -391
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/builder.d.ts +28 -3
- package/dist/types/src/builder.d.ts.map +1 -1
- package/dist/types/src/builder.test.d.ts +2 -0
- package/dist/types/src/builder.test.d.ts.map +1 -0
- package/dist/types/src/components/ActionLabel.d.ts +3 -3
- package/dist/types/src/components/ActionLabel.d.ts.map +1 -1
- package/dist/types/src/components/DropdownMenu.d.ts +4 -2
- package/dist/types/src/components/DropdownMenu.d.ts.map +1 -1
- package/dist/types/src/components/Menu.d.ts +50 -0
- package/dist/types/src/components/Menu.d.ts.map +1 -0
- package/dist/types/src/components/Menu.stories.d.ts +21 -0
- package/dist/types/src/components/Menu.stories.d.ts.map +1 -0
- package/dist/types/src/components/Menu.test.d.ts +2 -0
- package/dist/types/src/components/Menu.test.d.ts.map +1 -0
- package/dist/types/src/components/ToolbarMenu.d.ts +7 -6
- package/dist/types/src/components/ToolbarMenu.d.ts.map +1 -1
- package/dist/types/src/components/ToolbarMenu.stories.d.ts +22 -0
- package/dist/types/src/components/ToolbarMenu.stories.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +1 -3
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useMenuActions.d.ts +8 -7
- package/dist/types/src/hooks/useMenuActions.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/testing/generator.d.ts +19 -13
- package/dist/types/src/testing/generator.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +37 -26
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +14 -5
- package/dist/types/src/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +36 -29
- package/src/builder.test.ts +224 -0
- package/src/builder.ts +76 -26
- package/src/components/ActionLabel.tsx +6 -6
- package/src/components/DropdownMenu.tsx +17 -8
- package/src/components/Menu.stories.tsx +265 -0
- package/src/components/Menu.test.tsx +447 -0
- package/src/components/Menu.tsx +348 -0
- package/src/components/ToolbarMenu.stories.tsx +82 -0
- package/src/components/ToolbarMenu.tsx +157 -98
- package/src/components/index.ts +1 -3
- package/src/hooks/useMenuActions.ts +30 -53
- package/src/index.ts +1 -3
- package/src/testing/generator.ts +74 -64
- package/src/translations.ts +1 -1
- package/src/types.ts +39 -27
- package/src/util.ts +34 -15
- package/dist/types/src/components/MenuContext.d.ts +0 -13
- package/dist/types/src/components/MenuContext.d.ts.map +0 -1
- package/dist/types/src/components/Menus.stories.d.ts +0 -25
- package/dist/types/src/components/Menus.stories.d.ts.map +0 -1
- package/src/components/MenuContext.tsx +0 -50
- package/src/components/Menus.stories.tsx +0 -69
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Atom, RegistryContext, useAtomValue } from '@effect-atom/atom-react';
|
|
6
|
+
import { type Scope, createContextScope } from '@radix-ui/react-context';
|
|
7
|
+
import { useControllableState } from '@radix-ui/react-use-controllable-state';
|
|
8
|
+
import React, { createContext, type MouseEvent, type PropsWithChildren, useCallback, useContext, useMemo } from 'react';
|
|
9
|
+
|
|
10
|
+
import { log } from '@dxos/log';
|
|
11
|
+
import { type DropdownMenuRootProps, Icon, DropdownMenu as NaturalDropdownMenu } from '@dxos/react-ui';
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
type AddMenuItemsProps,
|
|
15
|
+
type MenuAction,
|
|
16
|
+
type MenuContextValue,
|
|
17
|
+
type MenuItem,
|
|
18
|
+
type MenuItemGroup,
|
|
19
|
+
type MenuItems,
|
|
20
|
+
type MenuItemsAccessor,
|
|
21
|
+
type MenuItemsMap,
|
|
22
|
+
} from '../types';
|
|
23
|
+
import { executeMenuAction } from '../util';
|
|
24
|
+
import { ActionLabel } from './ActionLabel';
|
|
25
|
+
import { ToolbarMenu } from './ToolbarMenu';
|
|
26
|
+
|
|
27
|
+
//
|
|
28
|
+
// Scoped context.
|
|
29
|
+
//
|
|
30
|
+
|
|
31
|
+
type MenuScopedProps<P> = P & { __menuScope?: Scope };
|
|
32
|
+
|
|
33
|
+
const MENU_NAME = 'Menu';
|
|
34
|
+
|
|
35
|
+
const [createMenuContext, createMenuScope] = createContextScope(MENU_NAME, []);
|
|
36
|
+
|
|
37
|
+
const nullItemsAtom = Atom.make<MenuItem[] | null>(null);
|
|
38
|
+
const defaultItemsAccessor: MenuItemsAccessor = () => nullItemsAtom;
|
|
39
|
+
|
|
40
|
+
const menuContextDefaults: MenuContextValue = {
|
|
41
|
+
iconSize: 5,
|
|
42
|
+
items: defaultItemsAccessor,
|
|
43
|
+
onAction: undefined,
|
|
44
|
+
menuItemsAtom: Atom.make<MenuItemsMap>(new Map()),
|
|
45
|
+
addMenuItems: () => {},
|
|
46
|
+
removeMenuItems: () => {},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const [MenuContextProvider, useMenuScoped] = createMenuContext<MenuContextValue>(MENU_NAME, menuContextDefaults);
|
|
50
|
+
|
|
51
|
+
const useMenuScope = createMenuScope();
|
|
52
|
+
|
|
53
|
+
//
|
|
54
|
+
// Dropdown context (internal) — allows Menu.Content to close the parent dropdown.
|
|
55
|
+
//
|
|
56
|
+
|
|
57
|
+
type MenuDropdownContextValue = {
|
|
58
|
+
closeMenu: () => void;
|
|
59
|
+
caller?: string;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const MenuDropdownContext = createContext<MenuDropdownContextValue>({
|
|
63
|
+
closeMenu: () => {},
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
//
|
|
67
|
+
// MenuProvider (internal) — the context provider used by Menu.Root.
|
|
68
|
+
//
|
|
69
|
+
|
|
70
|
+
const DEFAULT_PRIORITY = 100;
|
|
71
|
+
|
|
72
|
+
const sortMenuItems = (items: MenuItems[]) =>
|
|
73
|
+
[...items].sort((a, b) => {
|
|
74
|
+
if (a.priority !== b.priority) {
|
|
75
|
+
return a.priority - b.priority;
|
|
76
|
+
}
|
|
77
|
+
return a.id.localeCompare(b.id);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
type MenuProviderProps = PropsWithChildren<Partial<MenuContextValue>>;
|
|
81
|
+
|
|
82
|
+
const MenuProvider = ({
|
|
83
|
+
children,
|
|
84
|
+
items = menuContextDefaults.items,
|
|
85
|
+
iconSize = menuContextDefaults.iconSize,
|
|
86
|
+
attendableId,
|
|
87
|
+
alwaysActive,
|
|
88
|
+
onAction,
|
|
89
|
+
}: MenuProviderProps) => {
|
|
90
|
+
const { scope } = useMenuScope(undefined);
|
|
91
|
+
const registry = useContext(RegistryContext);
|
|
92
|
+
const menuItemsAtom = useMemo(() => Atom.make<MenuItemsMap>(new Map()).pipe(Atom.keepAlive), []);
|
|
93
|
+
|
|
94
|
+
const addMenuItems = useCallback(
|
|
95
|
+
(props: AddMenuItemsProps) => {
|
|
96
|
+
const priority = props.priority ?? DEFAULT_PRIORITY;
|
|
97
|
+
const prev = registry.get(menuItemsAtom);
|
|
98
|
+
const next = new Map(prev);
|
|
99
|
+
next.set(props.id, { ...props, priority });
|
|
100
|
+
registry.set(menuItemsAtom, next);
|
|
101
|
+
},
|
|
102
|
+
[registry, menuItemsAtom],
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const removeMenuItems = useCallback(
|
|
106
|
+
(id: string) => {
|
|
107
|
+
const prev = registry.get(menuItemsAtom);
|
|
108
|
+
const next = new Map(prev);
|
|
109
|
+
next.delete(id);
|
|
110
|
+
registry.set(menuItemsAtom, next);
|
|
111
|
+
},
|
|
112
|
+
[registry, menuItemsAtom],
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<MenuContextProvider
|
|
117
|
+
items={items}
|
|
118
|
+
iconSize={iconSize}
|
|
119
|
+
attendableId={attendableId}
|
|
120
|
+
alwaysActive={alwaysActive}
|
|
121
|
+
menuItemsAtom={menuItemsAtom}
|
|
122
|
+
addMenuItems={addMenuItems}
|
|
123
|
+
removeMenuItems={removeMenuItems}
|
|
124
|
+
onAction={onAction}
|
|
125
|
+
scope={scope}
|
|
126
|
+
>
|
|
127
|
+
{children}
|
|
128
|
+
</MenuContextProvider>
|
|
129
|
+
);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
//
|
|
133
|
+
// Item resolution.
|
|
134
|
+
//
|
|
135
|
+
|
|
136
|
+
const resolveItems = (
|
|
137
|
+
baseItems: MenuItem[] | null,
|
|
138
|
+
group: MenuItemGroup | undefined,
|
|
139
|
+
entries: ReadonlyMap<string, MenuItems>,
|
|
140
|
+
): MenuItem[] | null => {
|
|
141
|
+
const applicable = [...entries.values()].filter((entry) => !entry.groupFilter || entry.groupFilter(group));
|
|
142
|
+
if (applicable.length === 0) {
|
|
143
|
+
return baseItems;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const sorted = sortMenuItems(applicable);
|
|
147
|
+
|
|
148
|
+
const replacements = sorted.filter((entry) => entry.mode === 'replacement');
|
|
149
|
+
if (replacements.length > 0) {
|
|
150
|
+
if (replacements.length > 1) {
|
|
151
|
+
log.warn('multiple replacement entries found', {
|
|
152
|
+
ids: replacements.map((r) => r.id).join(', '),
|
|
153
|
+
using: replacements[0].id,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return replacements[0].items;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const additive = sorted.filter((entry) => entry.mode === 'additive');
|
|
160
|
+
const additiveItems = additive.flatMap((entry) => entry.items);
|
|
161
|
+
|
|
162
|
+
if (!baseItems || baseItems.length === 0) {
|
|
163
|
+
return additiveItems.length > 0 ? additiveItems : null;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return [...baseItems, ...additiveItems];
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
//
|
|
170
|
+
// Public hooks.
|
|
171
|
+
//
|
|
172
|
+
|
|
173
|
+
const useMenuItems = (
|
|
174
|
+
group?: MenuItemGroup,
|
|
175
|
+
propsItems?: MenuItem[],
|
|
176
|
+
consumerName: string = 'useMenuItemConsumer',
|
|
177
|
+
__menuScope?: Scope,
|
|
178
|
+
) => {
|
|
179
|
+
const { items, menuItemsAtom } = useMenuScoped(consumerName, __menuScope);
|
|
180
|
+
const groupItems = useAtomValue(items(group));
|
|
181
|
+
const entries = useAtomValue(menuItemsAtom) ?? new Map();
|
|
182
|
+
|
|
183
|
+
const baseItems = useMemo(() => propsItems ?? groupItems ?? null, [propsItems, groupItems]);
|
|
184
|
+
|
|
185
|
+
const resolved = useMemo(
|
|
186
|
+
() => resolveItems(baseItems, group, entries as ReadonlyMap<string, MenuItems>),
|
|
187
|
+
[baseItems, group, entries],
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
return resolved ?? undefined;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
/** Returns the menu context without Radix scope. */
|
|
194
|
+
const useMenu = (consumerName: string): MenuContextValue => {
|
|
195
|
+
return useMenuScoped(consumerName, undefined);
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
//
|
|
199
|
+
// Menu.Root
|
|
200
|
+
//
|
|
201
|
+
|
|
202
|
+
type MenuRootProps = MenuProviderProps &
|
|
203
|
+
Pick<DropdownMenuRootProps, 'children' | 'open' | 'defaultOpen' | 'onOpenChange'> & {
|
|
204
|
+
/** Identifies the component that owns this menu (passed to action handlers). */
|
|
205
|
+
caller?: string;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Menu context boundary.
|
|
210
|
+
*
|
|
211
|
+
* NOTE: This component is headless since it's root div has `contents`.
|
|
212
|
+
*
|
|
213
|
+
* Provides the menu context (action dispatch, contribution registry, icon size, etc.)
|
|
214
|
+
* and an optional dropdown root for use with `Menu.Trigger` + `Menu.Content`.
|
|
215
|
+
*/
|
|
216
|
+
const MenuRoot = ({ children, open, defaultOpen, onOpenChange, caller, ...props }: MenuRootProps) => {
|
|
217
|
+
const [menuOpen, setMenuOpen] = useControllableState({
|
|
218
|
+
prop: open,
|
|
219
|
+
defaultProp: defaultOpen,
|
|
220
|
+
onChange: onOpenChange,
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
const closeMenu = useCallback(() => setMenuOpen(false), [setMenuOpen]);
|
|
224
|
+
|
|
225
|
+
return (
|
|
226
|
+
<MenuProvider {...props}>
|
|
227
|
+
<MenuDropdownContext.Provider value={{ closeMenu, caller }}>
|
|
228
|
+
<NaturalDropdownMenu.Root open={menuOpen} onOpenChange={setMenuOpen}>
|
|
229
|
+
{children}
|
|
230
|
+
</NaturalDropdownMenu.Root>
|
|
231
|
+
</MenuDropdownContext.Provider>
|
|
232
|
+
</MenuProvider>
|
|
233
|
+
);
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
//
|
|
237
|
+
// Menu.Content
|
|
238
|
+
//
|
|
239
|
+
|
|
240
|
+
type MenuContentProps = {
|
|
241
|
+
group?: MenuItemGroup;
|
|
242
|
+
items?: MenuItem[];
|
|
243
|
+
caller?: string;
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
const MenuContentItem = ({
|
|
247
|
+
item,
|
|
248
|
+
onClick,
|
|
249
|
+
__menuScope,
|
|
250
|
+
}: MenuScopedProps<{
|
|
251
|
+
item: MenuItem;
|
|
252
|
+
onClick: (action: MenuAction, event: MouseEvent) => void;
|
|
253
|
+
}>) => {
|
|
254
|
+
const action = item as MenuAction;
|
|
255
|
+
const handleClick = useCallback((event: MouseEvent) => onClick(action, event), [action, onClick]);
|
|
256
|
+
const { iconSize } = useMenuScoped('MenuContentItem', __menuScope);
|
|
257
|
+
return (
|
|
258
|
+
<NaturalDropdownMenu.Item
|
|
259
|
+
onClick={handleClick}
|
|
260
|
+
classNames='gap-2'
|
|
261
|
+
disabled={action.properties?.disabled}
|
|
262
|
+
{...(action.properties?.testId && { 'data-testid': action.properties.testId })}
|
|
263
|
+
>
|
|
264
|
+
{action.properties?.icon && <Icon icon={action.properties!.icon} size={iconSize} />}
|
|
265
|
+
<ActionLabel action={action} />
|
|
266
|
+
</NaturalDropdownMenu.Item>
|
|
267
|
+
);
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Renders the dropdown menu portal, content, and graph-backed items.
|
|
272
|
+
*
|
|
273
|
+
* Must be a descendant of `Menu.Root`. Reads items via `useMenuItems` from the
|
|
274
|
+
* nearest menu context, with optional `group`/`items` prop overrides.
|
|
275
|
+
*/
|
|
276
|
+
const MenuContent = ({
|
|
277
|
+
group,
|
|
278
|
+
items: propsItems,
|
|
279
|
+
caller: callerOverride,
|
|
280
|
+
__menuScope,
|
|
281
|
+
}: MenuScopedProps<MenuContentProps>) => {
|
|
282
|
+
const { closeMenu, caller: contextCaller } = useContext(MenuDropdownContext);
|
|
283
|
+
const caller = callerOverride ?? contextCaller;
|
|
284
|
+
const { onAction } = useMenuScoped('MenuContent', __menuScope);
|
|
285
|
+
const resolvedItems = useMenuItems(group, propsItems, 'MenuContent', __menuScope);
|
|
286
|
+
|
|
287
|
+
const handleActionClick = useCallback(
|
|
288
|
+
(action: MenuAction, event: MouseEvent) => {
|
|
289
|
+
if (action.properties?.disabled) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
event.stopPropagation();
|
|
293
|
+
closeMenu();
|
|
294
|
+
if (onAction) {
|
|
295
|
+
onAction(action, { parent: group, caller });
|
|
296
|
+
} else {
|
|
297
|
+
void executeMenuAction(action, { parent: group, caller });
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
[group, caller, onAction, closeMenu],
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
return (
|
|
304
|
+
<NaturalDropdownMenu.Portal>
|
|
305
|
+
<NaturalDropdownMenu.Content>
|
|
306
|
+
<NaturalDropdownMenu.Viewport>
|
|
307
|
+
{resolvedItems?.map((item) => (
|
|
308
|
+
<MenuContentItem key={item.id} item={item} onClick={handleActionClick} />
|
|
309
|
+
))}
|
|
310
|
+
</NaturalDropdownMenu.Viewport>
|
|
311
|
+
<NaturalDropdownMenu.Arrow />
|
|
312
|
+
</NaturalDropdownMenu.Content>
|
|
313
|
+
</NaturalDropdownMenu.Portal>
|
|
314
|
+
);
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
//
|
|
318
|
+
// Namespace.
|
|
319
|
+
//
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Primary namespace export for the menu system.
|
|
323
|
+
*
|
|
324
|
+
* - `Menu.Root` — context boundary (replaces `MenuProvider`); also provides a dropdown root.
|
|
325
|
+
* - `Menu.Trigger` / `Menu.VirtualTrigger` — dropdown trigger (use with `Menu.Content`).
|
|
326
|
+
* - `Menu.Content` — renders graph-backed dropdown items inside a portal.
|
|
327
|
+
* - `Menu.Toolbar` — flat toolbar component with graph-backed item rendering.
|
|
328
|
+
*/
|
|
329
|
+
const Menu = {
|
|
330
|
+
Root: MenuRoot,
|
|
331
|
+
Trigger: NaturalDropdownMenu.Trigger,
|
|
332
|
+
Content: MenuContent,
|
|
333
|
+
VirtualTrigger: NaturalDropdownMenu.VirtualTrigger,
|
|
334
|
+
Toolbar: ToolbarMenu,
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
export { Menu, menuContextDefaults, useMenu, useMenuItems, useMenuScoped };
|
|
338
|
+
|
|
339
|
+
export type { MenuContentProps, MenuRootProps, MenuScopedProps };
|
|
340
|
+
|
|
341
|
+
export type {
|
|
342
|
+
ToolbarMenuProps,
|
|
343
|
+
ToolbarMenuActionGroupProperties,
|
|
344
|
+
ToolbarMenuActionGroupProps,
|
|
345
|
+
ToolbarMenuActionProps,
|
|
346
|
+
ToolbarMenuDropdownMenuActionGroup,
|
|
347
|
+
ToolbarMenuToggleGroupActionGroup,
|
|
348
|
+
} from './ToolbarMenu';
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Atom, RegistryContext } from '@effect-atom/atom-react';
|
|
6
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
7
|
+
import React, { useContext, useMemo } from 'react';
|
|
8
|
+
|
|
9
|
+
import { random } from '@dxos/random';
|
|
10
|
+
import { IconButton } from '@dxos/react-ui';
|
|
11
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
12
|
+
import { withRegistry } from '@dxos/storybook-utils';
|
|
13
|
+
|
|
14
|
+
import { Menu } from '../components';
|
|
15
|
+
import { type ActionGraphProps, useMenuActions } from '../hooks';
|
|
16
|
+
import { createActions, createNestedActions, createNestedActionsResolver, useMutateActions } from '../testing';
|
|
17
|
+
import { translations } from '../translations';
|
|
18
|
+
|
|
19
|
+
random.seed(1234);
|
|
20
|
+
|
|
21
|
+
const meta = {
|
|
22
|
+
title: 'ui/react-ui-menu/ToolbarMenu',
|
|
23
|
+
component: Menu.Toolbar,
|
|
24
|
+
decorators: [withTheme(), withRegistry],
|
|
25
|
+
parameters: {
|
|
26
|
+
translations,
|
|
27
|
+
},
|
|
28
|
+
} satisfies Meta<typeof Menu.Toolbar>;
|
|
29
|
+
|
|
30
|
+
export default meta;
|
|
31
|
+
|
|
32
|
+
type Story = StoryObj<typeof meta>;
|
|
33
|
+
|
|
34
|
+
export const DropdownMenu: Story = {
|
|
35
|
+
render: () => {
|
|
36
|
+
const actions = useMemo(() => {
|
|
37
|
+
const actions = createActions();
|
|
38
|
+
return Atom.make<ActionGraphProps>({
|
|
39
|
+
nodes: actions,
|
|
40
|
+
edges: actions.map((action) => ({ source: 'root', target: action.id, relation: 'child' })),
|
|
41
|
+
}).pipe(Atom.keepAlive);
|
|
42
|
+
}, []);
|
|
43
|
+
|
|
44
|
+
useMutateActions(actions);
|
|
45
|
+
const menuActions = useMenuActions(actions);
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<Menu.Root {...menuActions}>
|
|
49
|
+
<Menu.Trigger asChild>
|
|
50
|
+
<IconButton icon='ph--list-checks--regular' label='Options' />
|
|
51
|
+
</Menu.Trigger>
|
|
52
|
+
<Menu.Content />
|
|
53
|
+
</Menu.Root>
|
|
54
|
+
);
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const Toolbar: Story = {
|
|
59
|
+
render: () => {
|
|
60
|
+
const registry = useContext(RegistryContext);
|
|
61
|
+
const nestedMenuActions = useMemo(() => createNestedActionsResolver({ registry }), [registry]);
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<Menu.Root {...nestedMenuActions}>
|
|
65
|
+
<Menu.Toolbar />
|
|
66
|
+
</Menu.Root>
|
|
67
|
+
);
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const UseMenuActionsToolbar: Story = {
|
|
72
|
+
render: () => {
|
|
73
|
+
useMutateActions(createNestedActions);
|
|
74
|
+
const menuActions = useMenuActions(createNestedActions);
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<Menu.Root {...menuActions}>
|
|
78
|
+
<Menu.Toolbar />
|
|
79
|
+
</Menu.Root>
|
|
80
|
+
);
|
|
81
|
+
},
|
|
82
|
+
};
|