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