add the shared controls
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte"
|
||||
import { animate, appear } from "./motion"
|
||||
let { title, description, confirm, danger = false, onresult }: {
|
||||
title: string; description: string; confirm: string; danger?: boolean; onresult: (accepted: boolean) => void
|
||||
} = $props()
|
||||
let node: HTMLDialogElement
|
||||
let closing = $state(false)
|
||||
const id = $props.id()
|
||||
|
||||
onMount(() => node.showModal())
|
||||
function finish(accepted: boolean) {
|
||||
if (closing) return
|
||||
closing = true
|
||||
animate(node, {
|
||||
opacity: 0,
|
||||
y: 5,
|
||||
onComplete: () => {
|
||||
node.close()
|
||||
onresult(accepted)
|
||||
},
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<dialog bind:this={node} use:appear aria-labelledby={id + "-title"} aria-describedby={id + "-description"}
|
||||
oncancel={(event) => { event.preventDefault(); finish(false) }}>
|
||||
<h2 id={id + "-title"}>{title}</h2>
|
||||
<p class="note" id={id + "-description"}>{description}</p>
|
||||
<div class="actions wrap">
|
||||
<button type="button" class="button" disabled={closing} onclick={() => finish(false)}>Cancel</button>
|
||||
<button type="button" class="button" class:danger class:primary={!danger} disabled={closing} onclick={() => finish(true)}>{confirm}</button>
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
<style>
|
||||
p { margin-top: 8px; overflow-wrap: anywhere; white-space: pre-line; }
|
||||
</style>
|
||||
Reference in New Issue
Block a user