web/dialogs: create a container for reused code

This commit is contained in:
wukko
2024-07-27 14:24:24 +06:00
parent 0a7747c497
commit 778190b2b3
3 changed files with 48 additions and 63 deletions

View File

@@ -0,0 +1,33 @@
<script lang="ts">
import { tick } from "svelte";
import { killDialog } from "$lib/dialogs";
export let id: string;
let dialogParent: HTMLDialogElement;
let open = false;
let closing = false;
export const close = () => {
if (dialogParent) {
closing = true;
open = false;
setTimeout(() => {
dialogParent.close();
killDialog();
}, 150);
}
};
$: if (dialogParent) {
dialogParent.showModal();
tick().then(() => {
open = true;
});
}
</script>
<dialog id="dialog-{id}" bind:this={dialogParent} class:closing class:open>
<slot></slot>
</dialog>