import { FC, memo, useEffect, useRef } from 'react' import useDropdown from '../../../../shared/hooks/use-dropdown' import OLListGroup from '@/features/ui/components/ol/ol-list-group' import OLTooltip from '@/features/ui/components/ol/ol-tooltip' import OLOverlay from '@/features/ui/components/ol/ol-overlay' import OLPopover from '@/features/ui/components/ol/ol-popover' import { EditorView } from '@codemirror/view' import { emitToolbarEvent } from '../../extensions/toolbar/utils/analytics' import { useCodeMirrorViewContext } from '../codemirror-context' export const ToolbarButtonMenu: FC< React.PropsWithChildren<{ id: string label: string icon: React.ReactNode disablePopover?: boolean altCommand?: (view: EditorView) => void }> > = memo(function ButtonMenu({ icon, id, label, altCommand, disablePopover, children, }) { const target = useRef(null) const { open, onToggle, ref } = useDropdown() const view = useCodeMirrorViewContext() useEffect(() => { if (disablePopover && open) { onToggle(false) } }, [open, disablePopover, onToggle]) const button = ( ) const overlay = ( onToggle(false)} > { onToggle(false) }} > {children} ) if (!label) { return ( <> {button} {overlay} ) } return ( <> {overlay} ) })