-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathconfirm.svelte
66 lines (59 loc) · 2.01 KB
/
confirm.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<script lang="ts">
import { Button, Form, InputCheckbox } from '$lib/elements/forms';
import { Alert, Dialog, Layout } from '@appwrite.io/pink-svelte';
export let open: boolean;
export let title: string;
export let error: string = null;
export let action: string = 'Delete';
export let canDelete: boolean = true;
export let disabled: boolean = false;
export let confirmDeletion: boolean = false;
export let onSubmit: (e: SubmitEvent) => Promise<void> | void = function () {
return;
};
let confirm = false;
let checkboxId = `delete_${title.replaceAll(' ', '_').toLowerCase()}`;
// reset checkbox status
$: if (open && confirmDeletion) {
confirm = false;
}
</script>
<Form isModal {onSubmit}>
<Dialog {title} bind:open>
{#if error}
<Alert.Inline
dismissible
status="error"
on:dismiss={() => {
error = null;
}}>
{error}
</Alert.Inline>
{/if}
<Layout.Stack gap="l">
<slot />
{#if confirmDeletion}
<InputCheckbox
size="s"
required
id={checkboxId}
bind:checked={confirm}
label="I understand and confirm" />
{/if}
</Layout.Stack>
<svelte:fragment slot="footer">
<Layout.Stack direction="row" gap="s" justifyContent="flex-end">
<slot name="footer">
<Button text on:click={() => (open = false)}>Cancel</Button>
{#if canDelete}
<Button
danger
submit
disabled={disabled || (confirmDeletion ? !confirm : false)}
>{action}</Button>
{/if}
</slot>
</Layout.Stack>
</svelte:fragment>
</Dialog>
</Form>