2023-03-08 16:35:13 +00:00
|
|
|
import type { Editor } from '@tiptap/core'
|
2023-03-08 17:44:09 +00:00
|
|
|
import styles from './EditorBubbleMenu.module.scss'
|
|
|
|
import { Icon } from '../_shared/Icon'
|
|
|
|
import { clsx } from 'clsx'
|
2023-03-13 12:26:25 +00:00
|
|
|
import { createEditorTransaction } from 'solid-tiptap'
|
2023-03-08 16:35:13 +00:00
|
|
|
|
|
|
|
type BubbleMenuProps = {
|
|
|
|
editor: Editor
|
|
|
|
ref: (el: HTMLDivElement) => void
|
|
|
|
}
|
|
|
|
|
|
|
|
export const EditorBubbleMenu = (props: BubbleMenuProps) => {
|
2023-03-13 12:26:25 +00:00
|
|
|
const isBold = createEditorTransaction(
|
|
|
|
() => props.editor,
|
|
|
|
(editor) => editor && editor.isActive('bold')
|
|
|
|
)
|
|
|
|
|
2023-03-08 16:35:13 +00:00
|
|
|
return (
|
2023-03-08 17:44:09 +00:00
|
|
|
<div ref={props.ref} class={styles.bubbleMenu}>
|
2023-03-13 12:26:25 +00:00
|
|
|
<button class={clsx(styles.bubbleMenuButton)}>
|
2023-03-08 17:44:09 +00:00
|
|
|
<Icon name="editor-text-size" />
|
|
|
|
</button>
|
2023-03-13 12:26:25 +00:00
|
|
|
<button
|
|
|
|
class={clsx(styles.bubbleMenuButton, {
|
|
|
|
[styles.bubbleMenuButtonActive]: isBold()
|
|
|
|
})}
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault()
|
|
|
|
props.editor.commands.toggleBold()
|
|
|
|
}}
|
|
|
|
>
|
2023-03-08 17:44:09 +00:00
|
|
|
<Icon name="editor-bold" />
|
|
|
|
</button>
|
|
|
|
<button class={styles.bubbleMenuButton}>
|
|
|
|
<Icon name="editor-italic" />
|
|
|
|
</button>
|
|
|
|
<div class={styles.delimiter}></div>
|
|
|
|
<button class={styles.bubbleMenuButton}>
|
|
|
|
<Icon name="editor-link" />
|
|
|
|
</button>
|
|
|
|
<button class={styles.bubbleMenuButton}>
|
|
|
|
<Icon name="editor-footnote" />
|
|
|
|
</button>
|
|
|
|
<div class={styles.delimiter}></div>
|
|
|
|
<button class={styles.bubbleMenuButton}>
|
|
|
|
<Icon name="editor-ul" />
|
|
|
|
</button>
|
2023-03-08 16:35:13 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|