2023-05-04 12:16:39 +00:00
|
|
|
import type { Editor } from '@tiptap/core'
|
2023-05-29 17:14:58 +00:00
|
|
|
import styles from './BubbleMenu.module.scss'
|
2023-05-04 13:36:53 +00:00
|
|
|
import { clsx } from 'clsx'
|
|
|
|
import { Icon } from '../../_shared/Icon'
|
2023-05-29 10:09:44 +00:00
|
|
|
import { useLocalize } from '../../../context/localize'
|
2023-05-29 17:14:58 +00:00
|
|
|
import { Popover } from '../../_shared/Popover'
|
2023-05-04 12:16:39 +00:00
|
|
|
|
2023-05-29 10:09:44 +00:00
|
|
|
type Props = {
|
2023-05-04 12:16:39 +00:00
|
|
|
editor: Editor
|
2023-05-29 10:09:44 +00:00
|
|
|
ref: (el: HTMLElement) => void
|
2023-05-04 12:16:39 +00:00
|
|
|
}
|
|
|
|
|
2023-05-29 10:09:44 +00:00
|
|
|
export const FigureBubbleMenu = (props: Props) => {
|
|
|
|
const { t } = useLocalize()
|
2023-05-04 12:16:39 +00:00
|
|
|
return (
|
2023-05-29 17:14:58 +00:00
|
|
|
<div ref={props.ref} class={styles.BubbleMenu}>
|
|
|
|
<Popover content={t('Alignment left')}>
|
|
|
|
{(triggerRef: (el) => void) => (
|
|
|
|
<button
|
|
|
|
ref={triggerRef}
|
|
|
|
type="button"
|
|
|
|
class={clsx(styles.bubbleMenuButton)}
|
|
|
|
onClick={() => props.editor.chain().focus().setImageFloat('left').run()}
|
|
|
|
>
|
|
|
|
<Icon name="editor-image-align-left" />
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</Popover>
|
|
|
|
<Popover content={t('Alignment center')}>
|
|
|
|
{(triggerRef: (el) => void) => (
|
|
|
|
<button
|
|
|
|
ref={triggerRef}
|
|
|
|
type="button"
|
|
|
|
class={clsx(styles.bubbleMenuButton)}
|
|
|
|
onClick={() => props.editor.chain().focus().setImageFloat(null).run()}
|
|
|
|
>
|
|
|
|
<Icon name="editor-image-align-center" />
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</Popover>
|
|
|
|
<Popover content={t('Alignment right')}>
|
|
|
|
{(triggerRef: (el) => void) => (
|
|
|
|
<button
|
|
|
|
ref={triggerRef}
|
|
|
|
type="button"
|
|
|
|
class={clsx(styles.bubbleMenuButton)}
|
|
|
|
onClick={() => props.editor.chain().focus().setImageFloat('right').run()}
|
|
|
|
>
|
|
|
|
<Icon name="editor-image-align-right" />
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</Popover>
|
2023-05-04 13:36:53 +00:00
|
|
|
<div class={styles.delimiter} />
|
2023-05-07 13:16:03 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
class={clsx(styles.bubbleMenuButton)}
|
|
|
|
onClick={() => {
|
|
|
|
props.editor.chain().focus().imageToFigure().run()
|
|
|
|
}}
|
|
|
|
>
|
2023-05-29 10:09:44 +00:00
|
|
|
<span style={{ color: 'white' }}>{t('Add signature')}</span>
|
2023-05-07 13:16:03 +00:00
|
|
|
</button>
|
|
|
|
<div class={styles.delimiter} />
|
2023-05-29 17:14:58 +00:00
|
|
|
<Popover content={t('Add image')}>
|
|
|
|
{(triggerRef: (el) => void) => (
|
|
|
|
<button type="button" ref={triggerRef} class={clsx(styles.bubbleMenuButton)}>
|
|
|
|
<Icon name="editor-image-add" />
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</Popover>
|
2023-05-04 12:16:39 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|