mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-01 23:27:51 +08:00
30 lines
756 B
TypeScript
30 lines
756 B
TypeScript
import React, { useEffect, useRef } from 'react'
|
|
import { BubbleMenuPlugin, BubbleMenuPluginKey, BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu'
|
|
|
|
export type BubbleMenuProps = Omit<BubbleMenuPluginProps, 'element'> & {
|
|
className?: string,
|
|
}
|
|
|
|
export const BubbleMenu: React.FC<BubbleMenuProps> = props => {
|
|
const element = useRef<HTMLDivElement>(null)
|
|
|
|
useEffect(() => {
|
|
const { editor } = props
|
|
|
|
editor.registerPlugin(BubbleMenuPlugin({
|
|
editor,
|
|
element: element.current as HTMLElement,
|
|
}))
|
|
|
|
return () => {
|
|
editor.unregisterPlugin(BubbleMenuPluginKey)
|
|
}
|
|
}, [])
|
|
|
|
return (
|
|
<div ref={element} className={props.className} style={{ visibility: 'hidden' }}>
|
|
{props.children}
|
|
</div>
|
|
)
|
|
}
|