@ansiversa/components 0.0.40 → 0.0.42
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 +1 -1
- package/src/AvConfirmDialog.astro +61 -66
- package/src/AvEmptyState.astro +43 -10
- package/src/styles/global.css +3 -2
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
---
|
|
2
|
-
import AvButton from "
|
|
2
|
+
import { AvButton } from "@ansiversa/components";
|
|
3
3
|
|
|
4
4
|
interface Props {
|
|
5
5
|
id: string;
|
|
6
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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}>{
|
|
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
|
|
63
|
+
{busy ? "Working..." : confirmLabel}
|
|
59
64
|
</AvButton>
|
|
60
65
|
</div>
|
|
61
66
|
</div>
|
|
62
67
|
</dialog>
|
|
63
68
|
|
|
64
|
-
<script
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
77
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
77
|
+
function dispatch(name) {
|
|
78
|
+
dialog.dispatchEvent(
|
|
79
|
+
new CustomEvent(name, { bubbles: true, detail: { id: dialogId } })
|
|
80
|
+
);
|
|
81
|
+
}
|
|
89
82
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
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>
|
package/src/AvEmptyState.astro
CHANGED
|
@@ -3,23 +3,56 @@ import AvButton from "./AvButton.astro";
|
|
|
3
3
|
import AvCard from "./AvCard.astro";
|
|
4
4
|
|
|
5
5
|
interface Props {
|
|
6
|
-
|
|
6
|
+
// preferred Ansiversa naming
|
|
7
|
+
headline?: string;
|
|
8
|
+
|
|
9
|
+
// current naming (keep for backward compatibility)
|
|
10
|
+
title?: string;
|
|
11
|
+
|
|
7
12
|
description?: string;
|
|
13
|
+
|
|
14
|
+
// CTA
|
|
8
15
|
ctaLabel?: string;
|
|
9
|
-
ctaHref?: string;
|
|
16
|
+
ctaHref?: string; // if provided => link CTA
|
|
17
|
+
ctaDisabled?: boolean; // if button CTA
|
|
18
|
+
className?: string;
|
|
10
19
|
}
|
|
11
20
|
|
|
12
|
-
const {
|
|
21
|
+
const {
|
|
22
|
+
headline,
|
|
23
|
+
title,
|
|
24
|
+
description,
|
|
25
|
+
ctaLabel,
|
|
26
|
+
ctaHref,
|
|
27
|
+
ctaDisabled = false,
|
|
28
|
+
className = "",
|
|
29
|
+
...attrs
|
|
30
|
+
} = Astro.props as Props & Record<string, any>;
|
|
31
|
+
|
|
32
|
+
const resolvedTitle = headline ?? title ?? "Empty";
|
|
13
33
|
---
|
|
14
34
|
|
|
15
|
-
<AvCard className=
|
|
35
|
+
<AvCard className={`av-empty-state ${className}`.trim()} {...attrs}>
|
|
16
36
|
<div class="av-empty-state__body">
|
|
17
|
-
<h3 class="av-empty-state__title">{
|
|
37
|
+
<h3 class="av-empty-state__title">{resolvedTitle}</h3>
|
|
38
|
+
|
|
18
39
|
{description && <p class="av-empty-state__description">{description}</p>}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
40
|
+
|
|
41
|
+
{ctaLabel ? (
|
|
42
|
+
ctaHref ? (
|
|
43
|
+
<AvButton href={ctaHref} variant="primary">
|
|
44
|
+
{ctaLabel}
|
|
45
|
+
</AvButton>
|
|
46
|
+
) : (
|
|
47
|
+
<AvButton
|
|
48
|
+
type="button"
|
|
49
|
+
variant="primary"
|
|
50
|
+
disabled={ctaDisabled}
|
|
51
|
+
onclick="this.dispatchEvent(new CustomEvent('cta', { bubbles: true }))"
|
|
52
|
+
>
|
|
53
|
+
{ctaLabel}
|
|
54
|
+
</AvButton>
|
|
55
|
+
)
|
|
56
|
+
) : null}
|
|
24
57
|
</div>
|
|
25
58
|
</AvCard>
|
package/src/styles/global.css
CHANGED
|
@@ -632,7 +632,7 @@
|
|
|
632
632
|
/* Confirm Dialog --------------------------------------- */
|
|
633
633
|
|
|
634
634
|
.av-dialog {
|
|
635
|
-
@apply fixed m-0 w-
|
|
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-
|
|
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
|
}
|