@ansiversa/components 0.0.40 → 0.0.41

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ansiversa/components",
3
- "version": "0.0.40",
3
+ "version": "0.0.41",
4
4
  "description": "Shared UI components and layouts for the Ansiversa ecosystem",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,9 +1,9 @@
1
1
  ---
2
- import AvButton from "./AvButton.astro";
2
+ import { AvButton } from "@ansiversa/components";
3
3
 
4
4
  interface Props {
5
5
  id: string;
6
- title?: string;
6
+ headline?: string;
7
7
  description?: string;
8
8
  confirmLabel?: string;
9
9
  cancelLabel?: string;
@@ -14,19 +14,23 @@ interface Props {
14
14
 
15
15
  const {
16
16
  id,
17
- title = "Confirm",
17
+ headline = "Confirm",
18
18
  description,
19
19
  confirmLabel = "Confirm",
20
20
  cancelLabel = "Cancel",
21
21
  variant = "default",
22
22
  busy = false,
23
23
  className = "",
24
- } = Astro.props as Props;
24
+ ...attrs
25
+ } = Astro.props as Props & Record<string, unknown>;
26
+
27
+ if (!id) {
28
+ throw new Error("AvConfirmDialog requires an `id` prop.");
29
+ }
25
30
 
26
31
  const labelId = `${id}-title`;
27
32
  const descId = description ? `${id}-desc` : undefined;
28
33
  const dialogClass = `av-dialog av-dialog--${variant} ${className}`.trim();
29
- const dialogIdLiteral = JSON.stringify(id);
30
34
  ---
31
35
 
32
36
  <dialog
@@ -35,10 +39,11 @@ const dialogIdLiteral = JSON.stringify(id);
35
39
  aria-modal="true"
36
40
  aria-labelledby={labelId}
37
41
  aria-describedby={description ? descId : undefined}
42
+ {...attrs}
38
43
  >
39
44
  <div class="av-dialog__panel" role="document">
40
45
  <div class="av-dialog__header">
41
- <h2 class="av-dialog__title" id={labelId}>{title}</h2>
46
+ <h2 class="av-dialog__title" id={labelId}>{headline}</h2>
42
47
  {description ? <p class="av-dialog__desc" id={descId}>{description}</p> : null}
43
48
  </div>
44
49
 
@@ -55,75 +60,65 @@ const dialogIdLiteral = JSON.stringify(id);
55
60
  className={variant === "danger" ? "av-dialog__confirm--danger" : ""}
56
61
  disabled={busy}
57
62
  >
58
- {busy ? "Working" : confirmLabel}
63
+ {busy ? "Working..." : confirmLabel}
59
64
  </AvButton>
60
65
  </div>
61
66
  </div>
62
67
  </dialog>
63
68
 
64
- <script is:inline>
65
- (() => {
66
- const dialog = document.getElementById(${dialogIdLiteral});
67
- if (!dialog || !(dialog instanceof HTMLDialogElement)) return;
68
-
69
- const confirmBtn = dialog.querySelector("[data-av-confirm]");
70
- const cancelBtn = dialog.querySelector("[data-av-cancel]");
71
-
72
- function openDialogById(targetId) {
73
- const target = document.getElementById(targetId);
74
- if (!target || !(target instanceof HTMLDialogElement)) return;
69
+ <script define:vars={{ dialogId: id }}>
70
+ (() => {
71
+ const dialog = document.getElementById(dialogId);
72
+ if (!dialog) return;
75
73
 
76
- if (!target.open && typeof target.showModal === "function") {
77
- target.showModal();
78
- }
79
- }
80
-
81
- function closeDialogById(targetId) {
82
- const target = document.getElementById(targetId);
83
- if (!target || !(target instanceof HTMLDialogElement)) return;
74
+ const confirmBtn = dialog.querySelector("[data-av-confirm]");
75
+ const cancelBtn = dialog.querySelector("[data-av-cancel]");
84
76
 
85
- if (target.open) {
86
- target.close();
87
- }
88
- }
77
+ function dispatch(name) {
78
+ dialog.dispatchEvent(
79
+ new CustomEvent(name, { bubbles: true, detail: { id: dialogId } })
80
+ );
81
+ }
89
82
 
90
- function dispatch(name) {
91
- dialog.dispatchEvent(
92
- new CustomEvent(name, {
93
- bubbles: true,
94
- detail: { id: dialog.id },
95
- })
96
- );
83
+ function open() {
84
+ if (!dialog.open && typeof dialog.showModal === "function") {
85
+ dialog.showModal();
97
86
  }
98
-
99
- const open = () => openDialogById(dialog.id);
100
- const close = () => closeDialogById(dialog.id);
101
-
102
- window.AvDialog = window.AvDialog || {};
103
- window.AvDialog.open = (targetId) => openDialogById(targetId);
104
- window.AvDialog.close = (targetId) => closeDialogById(targetId);
105
-
106
- confirmBtn?.addEventListener("click", () => {
107
- dispatch("av-confirm");
108
- close();
109
- });
110
-
111
- cancelBtn?.addEventListener("click", () => {
87
+ }
88
+
89
+ function close() {
90
+ if (dialog.open) dialog.close();
91
+ }
92
+
93
+ window.AvDialog = window.AvDialog || {};
94
+ window.AvDialog.open = (targetId) => {
95
+ if (targetId === dialogId) open();
96
+ };
97
+ window.AvDialog.close = (targetId) => {
98
+ if (targetId === dialogId) close();
99
+ };
100
+
101
+ confirmBtn?.addEventListener("click", () => {
102
+ dispatch("av-confirm");
103
+ close();
104
+ });
105
+
106
+ cancelBtn?.addEventListener("click", () => {
107
+ dispatch("av-cancel");
108
+ close();
109
+ });
110
+
111
+ dialog.addEventListener("cancel", (e) => {
112
+ e.preventDefault(); // Escape
113
+ dispatch("av-cancel");
114
+ close();
115
+ });
116
+
117
+ dialog.addEventListener("click", (e) => {
118
+ if (e.target === dialog) {
112
119
  dispatch("av-cancel");
113
120
  close();
114
- });
115
-
116
- dialog.addEventListener("cancel", (event) => {
117
- event.preventDefault();
118
- dispatch("av-cancel");
119
- close();
120
- });
121
-
122
- dialog.addEventListener("click", (event) => {
123
- if (event.target === dialog) {
124
- dispatch("av-cancel");
125
- close();
126
- }
127
- });
128
- })();
121
+ }
122
+ });
123
+ })();
129
124
  </script>
@@ -632,7 +632,7 @@
632
632
  /* Confirm Dialog --------------------------------------- */
633
633
 
634
634
  .av-dialog {
635
- @apply fixed m-0 w-[min(640px,92vw)] border-0 bg-transparent p-0 text-slate-100 inset-0;
635
+ @apply fixed inset-0 m-0 w-full max-w-none border-0 bg-transparent p-0 text-slate-100;
636
636
  }
637
637
 
638
638
  .av-dialog[open] {
@@ -644,9 +644,10 @@
644
644
  }
645
645
 
646
646
  .av-dialog__panel {
647
- @apply w-full rounded-2xl border border-slate-800/70 bg-slate-950/90 p-6 shadow-2xl flex flex-col gap-5;
647
+ @apply w-[min(640px,92vw)] rounded-2xl border border-slate-800/70 bg-slate-950/90 p-6 shadow-2xl flex flex-col gap-5;
648
648
  }
649
649
 
650
+
650
651
  .av-dialog__header {
651
652
  @apply space-y-2;
652
653
  }