mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-22 17:35:28 +03:00
58 lines
1.4 KiB
Vue
58 lines
1.4 KiB
Vue
<script setup lang="ts">
|
|
import type { Picker } from 'emoji-mart'
|
|
|
|
const emit = defineEmits<{
|
|
(e: 'select', code: string): void
|
|
(e: 'selectCustom', image: any): void
|
|
}>()
|
|
|
|
const el = $ref<HTMLElement>()
|
|
let picker = $ref<Picker>()
|
|
const colorMode = useColorMode()
|
|
|
|
async function openEmojiPicker() {
|
|
await updateCustomEmojis()
|
|
if (picker) {
|
|
picker.update({
|
|
theme: colorMode.value,
|
|
custom: customEmojisData.value,
|
|
})
|
|
}
|
|
else {
|
|
const promise = import('@emoji-mart/data').then(r => r.default)
|
|
const { Picker } = await import('emoji-mart')
|
|
picker = new Picker({
|
|
data: () => promise,
|
|
onEmojiSelect({ native, src, alt, name }: any) {
|
|
native
|
|
? emit('select', native)
|
|
: emit('selectCustom', { src, alt, 'data-emoji-id': name })
|
|
},
|
|
theme: colorMode.value,
|
|
custom: customEmojisData.value,
|
|
})
|
|
}
|
|
await nextTick()
|
|
// TODO: custom picker
|
|
el?.appendChild(picker as any as HTMLElement)
|
|
}
|
|
|
|
const hideEmojiPicker = () => {
|
|
if (picker)
|
|
el?.removeChild(picker as any as HTMLElement)
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<VDropdown
|
|
@apply-show="openEmojiPicker()"
|
|
@apply-hide="hideEmojiPicker()"
|
|
>
|
|
<button btn-action-icon :title="$t('tooltip.emoji')">
|
|
<div i-ri:emotion-line />
|
|
</button>
|
|
<template #popper>
|
|
<div ref="el" min-w-10 min-h-10 />
|
|
</template>
|
|
</VDropdown>
|
|
</template>
|