CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/components/antd-menu-items.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import type { MenuProps } from "antd";
7
import { ReactNode } from "react";
8
9
import AIAvatar from "@cocalc/frontend/components/ai-avatar";
10
import { Icon, isIconName } from "@cocalc/frontend/components/icon";
11
12
export type MenuItem = Required<MenuProps>["items"][number];
13
export type MenuItems = MenuItem[];
14
15
export function menuItem(
16
key: React.Key,
17
label: React.ReactNode,
18
icon?: React.ReactNode | string,
19
children?: MenuItem[],
20
danger?: boolean,
21
): MenuItem {
22
if (typeof icon === "string") {
23
if (isIconName(icon)) {
24
icon = <Icon name={icon} />;
25
} else if (icon === "ai") {
26
icon = (
27
<AIAvatar size={18} style={{ position: "relative", top: "-12px" }} />
28
);
29
}
30
}
31
return {
32
key,
33
icon,
34
children,
35
label,
36
danger,
37
} as MenuItem;
38
}
39
40
export function menuGroup(
41
key: React.Key,
42
label: React.ReactNode,
43
children: MenuItem[],
44
icon?: ReactNode,
45
): MenuItem {
46
return {
47
key,
48
children,
49
label,
50
type: "group",
51
icon,
52
} as MenuItem;
53
}
54
55