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";
|
2022-01-25 17:41:05 +01:00
|
|
|
import LL from "../../i18n/i18n-svelte";
|
2022-01-05 10:27:40 +01:00
|
|
|
import { isMediaBreakpointUp } from "../../Utils/BreakpointsUtils";
|
2021-09-10 16:57:21 +02:00
|
|
|
|
2021-12-06 16:12:37 +01:00
|
|
|
let emojiContainer: HTMLElement;
|
|
|
|
let picker: EmojiButton;
|
2021-09-16 18:20:42 +02:00
|
|
|
|
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
|
|
|
},
|
2022-01-05 10:27:40 +01:00
|
|
|
emojisPerRow: isMediaBreakpointUp("md") ? 6 : 8,
|
2021-12-06 16:12:37 +01:00
|
|
|
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-09-16 18:20:42 +02:00
|
|
|
}
|
|
|
|
|
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-16 18:20:42 +02:00
|
|
|
|
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;
|
2022-01-05 10:27:40 +01:00
|
|
|
position: absolute;
|
2022-01-05 10:30:27 +01:00
|
|
|
z-index: 300;
|
2021-12-06 16:12:37 +01:00
|
|
|
}
|
2021-09-10 16:57:21 +02:00
|
|
|
|
2021-12-06 16:12:37 +01:00
|
|
|
.emote-menu {
|
|
|
|
pointer-events: all;
|
|
|
|
}
|
|
|
|
</style>
|