1
0
mirror of https://github.com/elk-zone/elk synced 2024-12-01 00:08:11 +09:00
elk/components/publish/PublishEmojiPicker.client.vue
2022-12-27 13:28:02 +01:00

56 lines
1.3 KiB
Vue

<script setup lang="ts">
import type { Picker } from 'emoji-mart'
import { updateCustomEmojis } from '~/composables/emojis'
const emit = defineEmits<{
(e: 'select', code: string): void
}>()
const el = $ref<HTMLElement>()
let picker = $ref<Picker>()
async function openEmojiPicker() {
await updateCustomEmojis()
if (picker) {
picker.update({
theme: isDark.value ? 'dark' : 'light',
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(e: any) {
emit('select', e.native || e.shortcodes)
},
theme: isDark.value ? 'dark' : 'light',
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>