mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-23 00:27:49 +08:00
9ba61c1582
* add key option to bubble menu * ignore react for now * add shouldShow option to bubble menu extension * improve types * remove BubbleMenuPluginKey * add key and shouldShow option to floating menu extension * fix: don’t show floating menu within code block * docs: add new menu options
38 lines
844 B
TypeScript
38 lines
844 B
TypeScript
import React, { useEffect, useRef } from 'react'
|
|
import { FloatingMenuPlugin, FloatingMenuPluginProps } from '@tiptap/extension-floating-menu'
|
|
|
|
export type FloatingMenuProps = Omit<FloatingMenuPluginProps, 'element'> & {
|
|
className?: string,
|
|
}
|
|
|
|
export const FloatingMenu: React.FC<FloatingMenuProps> = props => {
|
|
const element = useRef<HTMLDivElement>(null)
|
|
|
|
useEffect(() => {
|
|
const {
|
|
key,
|
|
editor,
|
|
tippyOptions,
|
|
shouldShow,
|
|
} = props
|
|
|
|
editor.registerPlugin(FloatingMenuPlugin({
|
|
key,
|
|
editor,
|
|
element: element.current as HTMLElement,
|
|
tippyOptions,
|
|
shouldShow,
|
|
}))
|
|
|
|
return () => {
|
|
editor.unregisterPlugin(key)
|
|
}
|
|
}, [])
|
|
|
|
return (
|
|
<div ref={element} className={props.className} style={{ visibility: 'hidden' }}>
|
|
{props.children}
|
|
</div>
|
|
)
|
|
}
|