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

91 lines
1.9 KiB
Vue
Raw Normal View History

2021-02-27 11:53:20 +01:00
<template>
2023-04-08 02:01:42 +02:00
<section>
<header class="_acrylic" @click="shown = !shown">
<i
class="toggle ph-fw ph-lg"
:class="
shown
? 'ph-caret-down ph-bold ph-lg'
2023-04-08 02:01:42 +02:00
: 'ph-caret-up ph-bold ph-lg'
"
></i>
<slot></slot> ({{ emojis.length }})
<span v-if="props.skinToneSelector && props.skinTones">
<button
v-for="skinTone in props.skinTones"
class="_button"
@click.stop="
applyUnicodeSkinTone(
2023-07-06 03:28:27 +02:00
props.skinTones.indexOf(skinTone) + 1,
)
"
>
<i
class="ph-circle ph-fill ph-fw ph-lg"
:style="{ color: skinTone + ' !important' }"
:aria-label="
props.skinToneLabels
? props.skinToneLabels[
props.skinTones.indexOf(skinTone)
]
: ''
"
></i>
</button>
</span>
2023-04-08 02:01:42 +02:00
</header>
<div v-if="shown" class="body">
<button
v-for="emoji in localEmojis"
2023-04-08 02:01:42 +02:00
:key="emoji"
class="_button item"
@click="emit('chosen', emoji, $event)"
>
<MkEmoji class="emoji" :emoji="emoji" :normal="true" />
</button>
</div>
</section>
2021-02-27 11:53:20 +01:00
</template>
<script lang="ts" setup>
import { ref, watch, onMounted } from "vue";
import { addSkinTone } from "@/scripts/emojilist";
2021-02-27 11:53:20 +01:00
const props = defineProps<{
emojis: string[];
initialShown?: boolean;
skinToneSelector?: boolean;
skinTones?: string[];
skinToneLabels?: string[];
}>();
2021-02-27 11:53:20 +01:00
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<{
2023-04-08 02:01:42 +02:00
(ev: "chosen", v: string, event: MouseEvent): void;
}>();
2021-02-27 11:53:20 +01:00
const shown = ref(!!props.initialShown);
onMounted(() => {
if (props.skinToneSelector) {
applyUnicodeSkinTone();
}
});
watch(
() => props.emojis,
(newVal) => {
localEmojis.value = [...newVal];
2023-07-06 03:28:27 +02:00
},
);
2021-02-27 11:53:20 +01:00
</script>
2023-04-08 02:01:42 +02:00
<style lang="scss" scoped></style>