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.
@@ -6,7 +6,7 @@
6
6
  children: Snippet<[string]>; // Snippet<[variant]>
7
7
  open?: boolean; // bindable (false)
8
8
  closable?: boolean; // (true)
9
- trigger?: HTMLElement; // bindable
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
- trigger?: HTMLElement; // bindable
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, trigger = $bindable(), ariaLabel, element = $bindable(), styling, variant = $bindable("") }: ModalProps = $props();
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(); } : undefined;
66
- function onclose() {
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
- <!-- svelte-ignore a11y_autofocus -->
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(html:has(dialog[open])) {
83
- overflow: hidden;
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
- trigger?: HTMLElement;
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
- * trigger?: HTMLElement; // bindable
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" | "open" | "element" | "trigger">;
30
+ declare const Modal: import("svelte").Component<ModalProps, {}, "variant" | "id" | "open" | "element">;
31
31
  type Modal = ReturnType<typeof Modal>;
32
32
  export default Modal;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svseeds",
3
- "version": "0.4.11",
3
+ "version": "0.4.12",
4
4
  "description": "Simple components for Svelte.",
5
5
  "type": "module",
6
6
  "main": "./index.js",