svseeds 0.4.11 → 0.4.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_svseeds/_Modal.svelte +13 -17
- package/_svseeds/_Modal.svelte.d.ts +3 -3
- package/package.json +1 -1
package/_svseeds/_Modal.svelte
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
children: Snippet<[string]>; // Snippet<[variant]>
|
|
7
7
|
open?: boolean; // bindable (false)
|
|
8
8
|
closable?: boolean; // (true)
|
|
9
|
-
|
|
9
|
+
id?: string; // bindable
|
|
10
10
|
ariaLabel?: string;
|
|
11
11
|
element?: HTMLDialogElement; // bindable
|
|
12
12
|
styling?: SVSClass;
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
children: Snippet<[string]>; // Snippet<[variant]>
|
|
20
20
|
open?: boolean; // bindable (false)
|
|
21
21
|
closable?: boolean; // (true)
|
|
22
|
-
|
|
22
|
+
id?: string; // bindable
|
|
23
23
|
ariaLabel?: string;
|
|
24
24
|
element?: HTMLDialogElement; // bindable
|
|
25
25
|
styling?: SVSClass;
|
|
@@ -31,23 +31,18 @@
|
|
|
31
31
|
const preset = "svs-modal";
|
|
32
32
|
|
|
33
33
|
import { type Snippet, untrack } from "svelte";
|
|
34
|
-
import { type SVSClass, VARIANT, PARTS, fnClass } from "./core";
|
|
34
|
+
import { type SVSClass, VARIANT, PARTS, elemId, fnClass } from "./core";
|
|
35
35
|
</script>
|
|
36
36
|
|
|
37
37
|
<script lang="ts">
|
|
38
|
-
let { children, open = $bindable(false), closable = true,
|
|
38
|
+
let { children, open = $bindable(false), closable = true, id = $bindable(), ariaLabel, element = $bindable(), styling, variant = $bindable("") }: ModalProps = $props();
|
|
39
39
|
|
|
40
40
|
// *** Initialize *** //
|
|
41
41
|
if (!variant) variant = VARIANT.NEUTRAL;
|
|
42
42
|
const cls = fnClass(preset, styling);
|
|
43
|
+
if (!id) id = elemId.id;
|
|
43
44
|
|
|
44
45
|
// *** Bind Handlers *** //
|
|
45
|
-
$effect(() => {
|
|
46
|
-
open;
|
|
47
|
-
untrack(() => {
|
|
48
|
-
if (!open) trigger?.focus();
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
46
|
$effect.pre(() => {
|
|
52
47
|
open;
|
|
53
48
|
untrack(() => toggle());
|
|
@@ -62,24 +57,25 @@
|
|
|
62
57
|
|
|
63
58
|
// *** Event Handlers *** //
|
|
64
59
|
const onclick = closable ? (ev: MouseEvent) => { if (ev.target === element) open = false; } : undefined;
|
|
65
|
-
const onkeydown = closable ? (ev: KeyboardEvent) => { if (ev.key === "Escape") ev.preventDefault(); }
|
|
66
|
-
function
|
|
67
|
-
open = false;
|
|
60
|
+
const onkeydown = closable ? undefined : (ev: KeyboardEvent) => { if (ev.key === "Escape") ev.preventDefault(); };
|
|
61
|
+
function ontoggle() {
|
|
62
|
+
open = element?.open ?? false;
|
|
68
63
|
}
|
|
69
64
|
$effect(() => untrack(() => { if (open) element?.showModal(); }));
|
|
70
65
|
</script>
|
|
71
66
|
|
|
72
67
|
<!---------------------------------------->
|
|
73
68
|
|
|
74
|
-
|
|
75
|
-
<dialog bind:this={element} class={cls(PARTS.WHOLE, variant)} aria-label={ariaLabel} {onclick} {onkeydown} {onclose} autofocus={true}>
|
|
69
|
+
<dialog bind:this={element} class={cls(PARTS.WHOLE, variant)} aria-label={ariaLabel} {id} {onclick} {onkeydown} {ontoggle} autofocus={true}>
|
|
76
70
|
<div class={cls(PARTS.MAIN, variant)}>
|
|
77
71
|
{@render children(variant)}
|
|
78
72
|
</div>
|
|
79
73
|
</dialog>
|
|
80
74
|
|
|
81
75
|
<style>
|
|
82
|
-
:global
|
|
83
|
-
|
|
76
|
+
:global {
|
|
77
|
+
html:has(dialog[open]) {
|
|
78
|
+
overflow: hidden;
|
|
79
|
+
}
|
|
84
80
|
}
|
|
85
81
|
</style>
|
|
@@ -2,7 +2,7 @@ export interface ModalProps {
|
|
|
2
2
|
children: Snippet<[string]>;
|
|
3
3
|
open?: boolean;
|
|
4
4
|
closable?: boolean;
|
|
5
|
-
|
|
5
|
+
id?: string;
|
|
6
6
|
ariaLabel?: string;
|
|
7
7
|
element?: HTMLDialogElement;
|
|
8
8
|
styling?: SVSClass;
|
|
@@ -19,7 +19,7 @@ import { type SVSClass } from "./core";
|
|
|
19
19
|
* children: Snippet<[string]>; // Snippet<[variant]>
|
|
20
20
|
* open?: boolean; // bindable (false)
|
|
21
21
|
* closable?: boolean; // (true)
|
|
22
|
-
*
|
|
22
|
+
* id?: string; // bindable
|
|
23
23
|
* ariaLabel?: string;
|
|
24
24
|
* element?: HTMLDialogElement; // bindable
|
|
25
25
|
* styling?: SVSClass;
|
|
@@ -27,6 +27,6 @@ import { type SVSClass } from "./core";
|
|
|
27
27
|
* }
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
|
-
declare const Modal: import("svelte").Component<ModalProps, {}, "variant" | "
|
|
30
|
+
declare const Modal: import("svelte").Component<ModalProps, {}, "variant" | "id" | "open" | "element">;
|
|
31
31
|
type Modal = ReturnType<typeof Modal>;
|
|
32
32
|
export default Modal;
|