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';
|
2021-09-16 18:20:42 +02:00
|
|
|
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'
|
|
|
|
},
|
2021-09-16 18:20:42 +02:00
|
|
|
emojisPerRow: isMobile() ? 6 : 8,
|
|
|
|
autoFocusSearch: false
|
2021-09-10 16:57:21 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
picker.on("emoji", (selection) => {
|
|
|
|
emoteStore.set(selection.emoji);
|
|
|
|
});
|
|
|
|
|
|
|
|
picker.on("hidden", () => {
|
2021-09-12 11:11:52 +02:00
|
|
|
emoteMenuStore.closeEmoteMenu();
|
2021-09-10 16:57:21 +02:00
|
|
|
});
|
|
|
|
|
2021-09-12 11:11:52 +02:00
|
|
|
unsubscriber = emoteMenuStore.subscribe((isEmoteMenuVisible) => {
|
|
|
|
if (isEmoteMenuVisible && !picker.isPickerVisible()) {
|
2021-09-10 16:57:21 +02:00
|
|
|
picker.showPicker(emojiContainer);
|
|
|
|
} else {
|
|
|
|
picker.hidePicker();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-09-16 18:20:42 +02:00
|
|
|
function onKeyDown(e:KeyboardEvent) {
|
|
|
|
if (e.key === 'Escape') {
|
|
|
|
emoteMenuStore.closeEmoteMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-10 16:57:21 +02:00
|
|
|
onDestroy(() => {
|
|
|
|
if (unsubscriber) {
|
|
|
|
unsubscriber();
|
|
|
|
}
|
2021-09-12 11:11:52 +02:00
|
|
|
|
|
|
|
picker.destroyPicker();
|
2021-09-10 16:57:21 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
2021-09-16 18:20:42 +02:00
|
|
|
<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>
|