import { FC, memo, useRef } from 'react' import { Button, ListGroup, Overlay, Popover } from 'react-bootstrap' import Icon from '../../../../shared/components/icon' import useDropdown from '../../../../shared/hooks/use-dropdown' import Tooltip from '../../../../shared/components/tooltip' import { EditorView } from '@codemirror/view' import { emitToolbarEvent } from '../../extensions/toolbar/utils/analytics' import { useCodeMirrorViewContext } from '../codemirror-editor' import MaterialIcon from '../../../../shared/components/material-icon' export const ToolbarButtonMenu: FC<{ id: string label: string icon: string materialIcon?: boolean altCommand?: (view: EditorView) => void }> = memo(function ButtonMenu({ icon, id, label, materialIcon, altCommand, children, }) { const target = useRef(null) const { open, onToggle, ref } = useDropdown() const view = useCodeMirrorViewContext() const button = ( ) const overlay = ( onToggle(false)} > { onToggle(false) }} > {children} ) if (!label) { return ( <> {button} {overlay} ) } return ( <> {overlay} ) })