-
-
Notifications
You must be signed in to change notification settings - Fork 93
/
alert-dialog.svelte
61 lines (54 loc) · 1.66 KB
/
alert-dialog.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
<script lang="ts">
import { derived } from "svelte/store";
import { setCtx } from "../ctx.js";
import type { Props } from "../types.js";
type $$Props = Props;
export let preventScroll: $$Props["preventScroll"] = undefined;
export let closeOnEscape: $$Props["closeOnEscape"] = undefined;
export let closeOnOutsideClick: $$Props["closeOnOutsideClick"] = false;
export let portal: $$Props["portal"] = undefined;
export let open: $$Props["open"] = undefined;
export let onOpenChange: $$Props["onOpenChange"] = undefined;
export let openFocus: $$Props["openFocus"] = undefined;
export let closeFocus: $$Props["closeFocus"] = undefined;
export let onOutsideClick: $$Props["onOutsideClick"] = undefined;
const {
states: { open: localOpen },
updateOption,
ids
} = setCtx({
closeOnEscape,
preventScroll,
closeOnOutsideClick,
portal,
forceVisible: true,
defaultOpen: open,
openFocus,
closeFocus,
onOutsideClick,
onOpenChange: ({ next }) => {
if (open !== next) {
onOpenChange?.(next);
open = next;
}
return next;
}
});
const idValues = derived(
[ids.content, ids.description, ids.title],
([$contentId, $descriptionId, $titleId]) => ({
content: $contentId,
description: $descriptionId,
title: $titleId
})
);
$: open !== undefined && localOpen.set(open);
$: updateOption("preventScroll", preventScroll);
$: updateOption("closeOnEscape", closeOnEscape);
$: updateOption("closeOnOutsideClick", closeOnOutsideClick);
$: updateOption("portal", portal);
$: updateOption("openFocus", openFocus);
$: updateOption("closeFocus", closeFocus);
$: updateOption("onOutsideClick", onOutsideClick);
</script>
<slot ids={$idValues} />