2023-05-29 10:09:44 +00:00
|
|
|
import type { Editor } from '@tiptap/core'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
2023-05-29 10:09:44 +00:00
|
|
|
import { clsx } from 'clsx'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { createSignal, Show, For } from 'solid-js'
|
|
|
|
|
2023-05-29 10:09:44 +00:00
|
|
|
import { useLocalize } from '../../../context/localize'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { Icon } from '../../_shared/Icon'
|
|
|
|
|
|
|
|
import styles from './BubbleMenu.module.scss'
|
2023-05-29 10:09:44 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
editor: Editor
|
|
|
|
ref: (el: HTMLElement) => void
|
|
|
|
}
|
|
|
|
|
|
|
|
const backgrounds = [null, 'white', 'black', 'yellow', 'pink', 'green']
|
|
|
|
|
|
|
|
export const IncutBubbleMenu = (props: Props) => {
|
|
|
|
const { t } = useLocalize()
|
|
|
|
const [substratBubbleOpen, setSubstratBubbleOpen] = createSignal(false)
|
2023-09-25 10:16:06 +00:00
|
|
|
const handleChangeBg = (bg) => {
|
|
|
|
props.editor.chain().focus().setArticleBg(bg).run()
|
|
|
|
setSubstratBubbleOpen(false)
|
|
|
|
}
|
2023-05-29 10:09:44 +00:00
|
|
|
return (
|
2023-05-29 17:14:58 +00:00
|
|
|
<div ref={props.ref} class={styles.BubbleMenu}>
|
2023-05-29 10:09:44 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
2023-06-10 14:10:05 +00:00
|
|
|
class={styles.bubbleMenuButton}
|
2023-05-29 10:09:44 +00:00
|
|
|
onClick={() => props.editor.chain().focus().setArticleFloat('half-left').run()}
|
|
|
|
>
|
|
|
|
<Icon name="editor-image-half-align-left" />
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
type="button"
|
2023-06-10 14:10:05 +00:00
|
|
|
class={styles.bubbleMenuButton}
|
2023-05-29 10:09:44 +00:00
|
|
|
onClick={() => props.editor.chain().focus().setArticleFloat(null).run()}
|
|
|
|
>
|
|
|
|
<Icon name="editor-image-align-center" />
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
|
|
|
type="button"
|
2023-06-10 14:10:05 +00:00
|
|
|
class={styles.bubbleMenuButton}
|
2023-05-29 10:09:44 +00:00
|
|
|
onClick={() => props.editor.chain().focus().setArticleFloat('half-right').run()}
|
|
|
|
>
|
|
|
|
<Icon name="editor-image-half-align-right" />
|
|
|
|
</button>
|
|
|
|
<div class={styles.delimiter} />
|
|
|
|
<div class={styles.dropDownHolder}>
|
|
|
|
<button
|
|
|
|
type="button"
|
2023-06-10 14:10:05 +00:00
|
|
|
class={styles.bubbleMenuButton}
|
2023-05-29 10:09:44 +00:00
|
|
|
onClick={() => setSubstratBubbleOpen(!substratBubbleOpen())}
|
|
|
|
>
|
|
|
|
<span style={{ color: 'white' }}>{t('Substrate')}</span>
|
|
|
|
<Icon name="down-triangle" class={styles.triangle} />
|
|
|
|
</button>
|
2023-09-25 10:16:06 +00:00
|
|
|
<Show when={substratBubbleOpen()}>
|
2023-05-29 10:09:44 +00:00
|
|
|
<div class={styles.dropDown}>
|
|
|
|
<div class={styles.actions}>
|
|
|
|
<For each={backgrounds}>
|
2023-09-25 10:16:06 +00:00
|
|
|
{(bg) => <div onClick={() => handleChangeBg(bg)} class={clsx(styles.color, styles[bg])} />}
|
2023-05-29 10:09:44 +00:00
|
|
|
</For>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Show>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|