Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/editors/slate/edit-bar/insert.tsx
1697 views
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { useMemo } from "react";
7
8
import { DropdownMenu, Icon, IconName } from "@cocalc/frontend/components";
9
import { MenuItems } from "@cocalc/frontend/components/dropdown-menu";
10
import { formatAction } from "../format";
11
import { BUTTON_STYLE } from "./marks-bar";
12
13
const ITEMS: [string, string, IconName | React.JSX.Element][] = [
14
["link", "Link to a URL...", "link"],
15
["image", "Image...", "image"],
16
["SpecialChar", "Special symbol or emoji...", <span>Ω</span>],
17
["format_code", "Block of code (shortcut: ```␣)", "CodeOutlined"],
18
["insertunorderedlist", "Unordered list (shortcut: -␣)", "list"],
19
["insertorderedlist", "Ordered list (shortcut: 1.␣)", "list-ol"],
20
["equation", "Inline LaTeX math (shortcut: $x$␣)", <span>$</span>],
21
[
22
"display_equation",
23
"Displayed LaTeX math (shortcut: $$x$$␣)",
24
<span>$$</span>,
25
],
26
["quote", "Quote selected text (shortcut: >␣)", "quote-left"],
27
["horizontalRule", "Horizontal rule (shortcut: ---␣)", <span>&mdash;</span>],
28
["linebreak", "Line break (shortcut: <br/>␣)", <span></span>],
29
["table", "Table", "table"],
30
];
31
32
interface Props {
33
editor;
34
}
35
36
export default function InsertMenu({ editor }: Props) {
37
const items: MenuItems = useMemo(() => {
38
return ITEMS.map(([command, description, icon]) => {
39
return {
40
key: command,
41
onClick: () => formatAction(editor, command, []),
42
label: (
43
<>
44
<div style={{ display: "inline-block", width: "24px" }}>
45
{typeof icon == "string" ? <Icon name={icon} /> : icon}
46
</div>{" "}
47
{description}
48
</>
49
),
50
};
51
});
52
}, [editor]);
53
54
return (
55
<DropdownMenu
56
button={true}
57
title={<Icon name={"plus-circle"} />}
58
style={BUTTON_STYLE}
59
items={items}
60
/>
61
);
62
}
63
64