firefish/packages/client/src/components/MkEmojiPicker.section.vue

90 lines
1.9 KiB
Vue
Raw Normal View History

2023-07-20 04:17:05 +09:00
<template>
<section>
<header class="_acrylic" @click="shown = !shown">
<i
class="toggle ph-fw ph-lg"
:class="
2023-10-17 02:12:35 +09:00
icon(shown ? 'ph-caret-down ph-lg' : 'ph-caret-up ph-lg')
2023-07-20 04:17:05 +09:00
"
></i>
<slot></slot> ({{ emojis.length }})
<span v-if="props.skinToneSelector && props.skinTones">
<button
v-for="skinTone in props.skinTones"
class="_button"
@click.stop="
applyUnicodeSkinTone(
props.skinTones.indexOf(skinTone) + 1,
)
"
>
<i
2023-10-17 02:12:35 +09:00
class="ph-circle ph-fill ph-fw"
2023-07-20 04:17:05 +09:00
:style="{ color: skinTone + ' !important' }"
:aria-label="
props.skinToneLabels
? props.skinToneLabels[
props.skinTones.indexOf(skinTone)
]
: ''
"
></i>
</button>
</span>
</header>
<div v-if="shown" class="body">
<button
v-for="emoji in localEmojis"
:key="emoji"
class="_button item"
@click="emit('chosen', emoji, $event)"
>
<MkEmoji class="emoji" :emoji="emoji" :normal="true" />
</button>
</div>
</section>
</template>
<script lang="ts" setup>
2023-09-04 17:47:24 +09:00
import { onMounted, ref, watch } from "vue";
2023-07-20 04:17:05 +09:00
import { addSkinTone } from "@/scripts/emojilist";
2023-10-17 02:12:35 +09:00
import icon from "@/scripts/icon";
2023-07-20 04:17:05 +09:00
const props = defineProps<{
emojis: string[];
initialShown?: boolean;
skinToneSelector?: boolean;
skinTones?: string[];
skinToneLabels?: string[];
}>();
const localEmojis = ref([...props.emojis]);
function applyUnicodeSkinTone(custom?: number) {
for (let i = 0; i < localEmojis.value.length; i++) {
localEmojis.value[i] = addSkinTone(localEmojis.value[i], custom);
}
}
const emit = defineEmits<{
(ev: "chosen", v: string, event: MouseEvent): void;
}>();
const shown = ref(!!props.initialShown);
onMounted(() => {
if (props.skinToneSelector) {
applyUnicodeSkinTone();
}
});
watch(
() => props.emojis,
(newVal) => {
localEmojis.value = [...newVal];
},
);
</script>
<style lang="scss" scoped></style>