Initial commit

This commit is contained in:
thiloho
2023-05-18 17:31:16 +02:00
parent 88bab1f351
commit b3f4c79763
28 changed files with 1248 additions and 31 deletions

View File

@@ -0,0 +1,49 @@
<script lang="ts">
export let shortcut: string;
const possibleShortcuts = ["S", "T"];
let detailsElement: HTMLDetailsElement;
let summaryElement: HTMLElement;
function openMenu() {
detailsElement.setAttribute("open", "");
}
export function closeMenu() {
detailsElement.removeAttribute("open");
}
function handleKeydown(event: KeyboardEvent) {
if (event.key === "Escape") closeMenu();
if (event.key === shortcut) {
summaryElement.focus();
openMenu();
} else if (possibleShortcuts.includes(event.key) && event.key !== shortcut) {
closeMenu();
}
}
function handleClick(event: MouseEvent) {
if (!detailsElement.contains(event.target as Node)) {
closeMenu();
}
}
</script>
<svelte:window on:keydown={handleKeydown} on:click={handleClick} />
<details bind:this={detailsElement}>
<summary bind:this={summaryElement}>
<slot name="icon" />
</summary>
<slot />
</details>
<style>
summary {
display: grid;
padding: 0.5rem;
}
</style>