import { ExpandedIcon } from "outline-icons"; import * as React from "react"; import { useMenuState } from "reakit"; import { MenuButton } from "reakit/Menu"; import styled from "styled-components"; import { MenuItem } from "@shared/editor/types"; import { s } from "@shared/styles"; import ContextMenu from "~/components/ContextMenu"; import Template from "~/components/ContextMenu/Template"; import { MenuItem as TMenuItem } from "~/types"; import { useEditor } from "./EditorContext"; import ToolbarButton from "./ToolbarButton"; import ToolbarSeparator from "./ToolbarSeparator"; import Tooltip from "./Tooltip"; type Props = { items: MenuItem[]; }; /* * Renders a dropdown menu in the floating toolbar. */ function ToolbarDropdown(props: { item: MenuItem }) { const menu = useMenuState(); const { commands, view } = useEditor(); const { item } = props; const { state } = view; const items: TMenuItem[] = React.useMemo(() => { const handleClick = (item: MenuItem) => () => { if (!item.name) { return; } commands[item.name]( typeof item.attrs === "function" ? item.attrs(state) : item.attrs ); }; return item.children ? item.children.map((child) => ({ type: "button", title: child.label, icon: child.icon, selected: child.active ? child.active(state) : false, onClick: handleClick(child), })) : []; }, [item.children, commands, state]); return ( <> {(props) => ( {item.label && } )}