workadventure/front/src/Components/EmoteMenu/EmoteMenu.svelte

95 lines
2.9 KiB
Svelte
Raw Normal View History

2021-09-10 16:57:21 +02:00
<script lang="typescript">
2021-12-06 16:12:37 +01:00
import type { Unsubscriber } from "svelte/store";
import { emoteStore, emoteMenuStore } from "../../Stores/EmoteStore";
import { onDestroy, onMount } from "svelte";
import { EmojiButton } from "@joeattardi/emoji-button";
import { isMobile } from "../../Enum/EnvironmentVariable";
2022-01-25 17:41:05 +01:00
import LL from "../../i18n/i18n-svelte";
2021-09-10 16:57:21 +02:00
2021-12-06 16:12:37 +01:00
let emojiContainer: HTMLElement;
let picker: EmojiButton;
2021-12-06 16:12:37 +01:00
let unsubscriber: Unsubscriber | null = null;
2021-09-10 16:57:21 +02:00
2021-12-06 16:12:37 +01:00
onMount(() => {
picker = new EmojiButton({
rootElement: emojiContainer,
styleProperties: {
"--font": "Press Start 2P",
2022-01-25 17:41:05 +01:00
"--text-color": "whitesmoke",
"--secondary-text-color": "whitesmoke",
"--category-button-color": "whitesmoke",
2021-12-06 16:12:37 +01:00
},
emojisPerRow: isMobile() ? 6 : 8,
autoFocusSearch: false,
style: "twemoji",
2022-01-25 17:41:05 +01:00
showPreview: false,
i18n: {
search: $LL.emoji.search(),
categories: {
recents: $LL.emoji.categories.recents(),
smileys: $LL.emoji.categories.smileys(),
people: $LL.emoji.categories.people(),
animals: $LL.emoji.categories.animals(),
food: $LL.emoji.categories.food(),
activities: $LL.emoji.categories.activities(),
travel: $LL.emoji.categories.travel(),
objects: $LL.emoji.categories.objects(),
symbols: $LL.emoji.categories.symbols(),
flags: $LL.emoji.categories.flags(),
custom: $LL.emoji.categories.custom(),
},
notFound: $LL.emoji.notFound(),
},
2021-12-06 16:12:37 +01:00
});
//the timeout is here to prevent the menu from flashing
setTimeout(() => picker.showPicker(emojiContainer), 100);
2021-09-10 16:57:21 +02:00
2021-12-06 16:12:37 +01:00
picker.on("emoji", (selection) => {
emoteStore.set({
unicode: selection.emoji,
url: selection.url,
name: selection.name,
});
});
2021-09-10 16:57:21 +02:00
2021-12-06 16:12:37 +01:00
picker.on("hidden", () => {
emoteMenuStore.closeEmoteMenu();
});
2021-09-10 16:57:21 +02:00
});
2021-12-06 16:12:37 +01:00
function onKeyDown(e: KeyboardEvent) {
if (e.key === "Escape") {
emoteMenuStore.closeEmoteMenu();
}
}
2021-12-06 16:12:37 +01:00
onDestroy(() => {
if (unsubscriber) {
unsubscriber();
}
2021-09-10 16:57:21 +02:00
2021-12-06 16:12:37 +01:00
picker.destroyPicker();
});
2021-09-10 16:57:21 +02:00
</script>
2021-12-06 16:12:37 +01:00
<svelte:window on:keydown={onKeyDown} />
2021-09-10 16:57:21 +02:00
<div class="emote-menu-container">
2021-12-06 16:12:37 +01:00
<div class="emote-menu" bind:this={emojiContainer} />
2021-09-10 16:57:21 +02:00
</div>
<style lang="scss">
2021-12-06 16:12:37 +01:00
.emote-menu-container {
display: flex;
width: 100%;
height: 100%;
justify-content: center;
align-items: center;
}
2021-09-10 16:57:21 +02:00
2021-12-06 16:12:37 +01:00
.emote-menu {
pointer-events: all;
}
</style>