Skip to content

Commit

Permalink
feat: add key option and shouldShow option to menus (fix ueberdosis#1480
Browse files Browse the repository at this point in the history
, fix ueberdosis#1043, fix ueberdosis#1268, fix ueberdosis#1503)

* 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
  • Loading branch information
philippkuehn authored Aug 11, 2021
1 parent 27a3292 commit 4ab829f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
13 changes: 10 additions & 3 deletions src/BubbleMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useRef } from 'react'
import { BubbleMenuPlugin, BubbleMenuPluginKey, BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu'
import { BubbleMenuPlugin, BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu'

export type BubbleMenuProps = Omit<BubbleMenuPluginProps, 'element'> & {
className?: string,
Expand All @@ -9,16 +9,23 @@ export const BubbleMenu: React.FC<BubbleMenuProps> = props => {
const element = useRef<HTMLDivElement>(null)

useEffect(() => {
const { editor, tippyOptions } = props
const {
key,
editor,
tippyOptions,
shouldShow,
} = props

editor.registerPlugin(BubbleMenuPlugin({
key,
editor,
element: element.current as HTMLElement,
tippyOptions,
shouldShow,
}))

return () => {
editor.unregisterPlugin(BubbleMenuPluginKey)
editor.unregisterPlugin(key)
}
}, [])

Expand Down
13 changes: 10 additions & 3 deletions src/FloatingMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useRef } from 'react'
import { FloatingMenuPlugin, FloatingMenuPluginKey, FloatingMenuPluginProps } from '@tiptap/extension-floating-menu'
import { FloatingMenuPlugin, FloatingMenuPluginProps } from '@tiptap/extension-floating-menu'

export type FloatingMenuProps = Omit<FloatingMenuPluginProps, 'element'> & {
className?: string,
Expand All @@ -9,16 +9,23 @@ export const FloatingMenu: React.FC<FloatingMenuProps> = props => {
const element = useRef<HTMLDivElement>(null)

useEffect(() => {
const { editor, tippyOptions } = props
const {
key,
editor,
tippyOptions,
shouldShow,
} = props

editor.registerPlugin(FloatingMenuPlugin({
key,
editor,
element: element.current as HTMLElement,
tippyOptions,
shouldShow,
}))

return () => {
editor.unregisterPlugin(FloatingMenuPluginKey)
editor.unregisterPlugin(key)
}
}, [])

Expand Down

0 comments on commit 4ab829f

Please sign in to comment.