1
0
Fork 1
mirror of https://github.com/elk-zone/elk.git synced 2024-11-09 10:29:57 +00:00
elk/components/publish/PublishEmojiPicker.client.vue

62 lines
1.4 KiB
Vue
Raw Normal View History

2022-12-23 19:15:19 +00:00
<script setup lang="ts">
import type { Picker } from 'emoji-mart'
const emit = defineEmits<{
(e: 'select', code: string): void
(e: 'selectCustom', image: any): void
2022-12-23 19:15:19 +00:00
}>()
const el = $ref<HTMLElement>()
let picker = $ref<Picker>()
const colorMode = useColorMode()
2022-12-23 19:15:19 +00:00
async function openEmojiPicker() {
await updateCustomEmojis()
if (picker) {
picker.update({
theme: colorMode.value,
custom: customEmojisData.value,
})
}
else {
const promise = import('@emoji-mart/data/sets/14/twitter.json').then(r => r.default)
2022-12-23 19:15:19 +00:00
const { Picker } = await import('emoji-mart')
picker = new Picker({
2022-12-23 22:56:16 +00:00
data: () => promise,
onEmojiSelect({ native, src, alt, name }: any) {
native
? emit('select', native)
: emit('selectCustom', { src, alt, 'data-emoji-id': name })
2022-12-23 19:15:19 +00:00
},
set: 'twitter',
theme: colorMode.value,
2022-12-23 22:56:16 +00:00
custom: customEmojisData.value,
2022-12-23 19:15:19 +00:00
})
}
2022-12-25 16:58:00 +00:00
await nextTick()
// TODO: custom picker
el?.appendChild(picker as any as HTMLElement)
}
const hideEmojiPicker = () => {
2022-12-25 16:58:00 +00:00
if (picker)
el?.removeChild(picker as any as HTMLElement)
2022-12-23 19:15:19 +00:00
}
</script>
<template>
<CommonTooltip :content="$t('tooltip.add_emojis')">
2023-01-04 10:41:19 +00:00
<VDropdown
auto-boundary-max-size
@apply-show="openEmojiPicker()"
@apply-hide="hideEmojiPicker()"
>
<slot />
<template #popper>
<div ref="el" min-w-10 min-h-10 />
</template>
</VDropdown>
</CommonTooltip>
2022-12-23 19:15:19 +00:00
</template>