webapp/src/components/Editor/BubbleMenu/IncutBubbleMenu.tsx

77 lines
2.3 KiB
TypeScript
Raw Normal View History

import type { Editor } from '@tiptap/core'
import { clsx } from 'clsx'
2024-02-04 11:25:21 +00:00
import { For, Show, createSignal } from 'solid-js'
import { useLocalize } from '../../../context/localize'
import { Icon } from '../../_shared/Icon'
import styles from './BubbleMenu.module.scss'
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)
2024-06-24 17:50:27 +00:00
const handleChangeBg = (bg: string | null) => {
2023-09-25 10:16:06 +00:00
props.editor.chain().focus().setArticleBg(bg).run()
setSubstratBubbleOpen(false)
}
return (
2023-05-29 17:14:58 +00:00
<div ref={props.ref} class={styles.BubbleMenu}>
<button
type="button"
class={styles.bubbleMenuButton}
onClick={() => props.editor.chain().focus().setArticleFloat('half-left').run()}
>
<Icon name="editor-image-half-align-left" />
</button>
<button
type="button"
class={styles.bubbleMenuButton}
onClick={() => props.editor.chain().focus().setArticleFloat(null).run()}
>
<Icon name="editor-image-align-center" />
</button>
<button
type="button"
class={styles.bubbleMenuButton}
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"
class={styles.bubbleMenuButton}
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()}>
<div class={styles.dropDown}>
<div class={styles.actions}>
<For each={backgrounds}>
2024-06-24 17:50:27 +00:00
{(bg) => (
<div
onClick={() => handleChangeBg(bg)}
class={clsx(styles.color, styles[bg as keyof typeof styles])}
/>
)}
</For>
</div>
</div>
</Show>
</div>
</div>
)
}