partey_workadventure/front/src/Components/EmoteMenu/EmoteMenu.svelte

70 lines
1.5 KiB
Svelte
Raw Normal View History

2021-09-10 16:57:21 +02:00
<script lang="typescript">
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";
2021-09-10 16:57:21 +02:00
let emojiContainer: HTMLElement;
let picker: EmojiButton;
let unsubscriber: Unsubscriber | null = null;
onMount(() => {
picker = new EmojiButton({
rootElement: emojiContainer,
styleProperties: {
'--font': 'Press Start 2P'
},
emojisPerRow: isMobile() ? 6 : 8,
autoFocusSearch: false
2021-09-10 16:57:21 +02:00
});
2021-10-04 11:23:30 +02:00
//the timeout is here to prevent the menu from flashing
setTimeout(() => picker.showPicker(emojiContainer), 100);
2021-09-10 16:57:21 +02:00
picker.on("emoji", (selection) => {
emoteStore.set(selection.emoji);
});
picker.on("hidden", () => {
emoteMenuStore.closeEmoteMenu();
2021-09-10 16:57:21 +02:00
});
})
function onKeyDown(e:KeyboardEvent) {
if (e.key === 'Escape') {
emoteMenuStore.closeEmoteMenu();
}
}
2021-09-10 16:57:21 +02:00
onDestroy(() => {
if (unsubscriber) {
unsubscriber();
}
picker.destroyPicker();
2021-09-10 16:57:21 +02:00
})
</script>
<svelte:window on:keydown={onKeyDown}/>
2021-09-10 16:57:21 +02:00
<div class="emote-menu-container">
<div class="emote-menu" bind:this={emojiContainer}></div>
</div>
<style lang="scss">
.emote-menu-container {
display: flex;
width: 100%;
height: 100%;
justify-content: center;
align-items: center;
}
.emote-menu {
pointer-events: all;
}
</style>