Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

menuActionItems.ts

29 lines939 Bytes

1import type { MenuAction } from "@react-native-menu/menu";
2import type { AppBarMenuItem } from "./AppBar.types";
3​
4/** Adapts a `MenuAction` tree and its selection handler to `AppBar` menu items. */
5export function appBarMenuItemsFromActions(
6 actions: ReadonlyArray<MenuAction>,
7 onSelect: (id: string) => void,
8): AppBarMenuItem[] {
9 return actions.map((action, index) => {
10 const id = action.id ?? String(index);
11 return action.subactions?.length
12 ? {
13 id,
14 title: action.title,
15 icon: action.image,
16 items: appBarMenuItemsFromActions(action.subactions, onSelect),
17 }
18 : {
19 id,
20 title: action.title,
21 subtitle: action.subtitle,
22 icon: action.image,
23 iconColor: action.imageColor,
24 selected: action.state === "on",
25 disabled: action.attributes?.disabled,
26 onPress: () => onSelect(id),
27 };
28 });