@akonwi/mica 0.5.0 → 0.6.0
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/mica.css +10 -10
- package/package.json +1 -1
- package/toast.js +7 -9
- package/types/react.d.ts +5 -0
package/mica.css
CHANGED
|
@@ -979,7 +979,7 @@
|
|
|
979
979
|
command="close" aria-label="Close">✕</button> (or wrap it in a
|
|
980
980
|
method=dialog form). absolute is safe: the dialog is positioned.
|
|
981
981
|
shared with toasts (popovertarget/popovertargetaction=hide there). */
|
|
982
|
-
:where(dialog, [popover]
|
|
982
|
+
:where(dialog, m-toast[popover]) > :where(button.close) {
|
|
983
983
|
position: absolute;
|
|
984
984
|
inset-block-start: var(--space-sm);
|
|
985
985
|
inset-inline-end: var(--space-sm);
|
|
@@ -1482,10 +1482,10 @@
|
|
|
1482
1482
|
}
|
|
1483
1483
|
|
|
1484
1484
|
/* --- toast: display only (queueing/auto-dismiss are Tier 2) ------- *
|
|
1485
|
-
* <
|
|
1486
|
-
*
|
|
1485
|
+
* <m-toast popover="manual" role="status"> — manual so it survives
|
|
1486
|
+
* light dismiss and other popovers; role=status announces.
|
|
1487
1487
|
* ------------------------------------------------------------------ */
|
|
1488
|
-
:where([popover]
|
|
1488
|
+
:where(m-toast[popover]) {
|
|
1489
1489
|
position-area: none; /* not anchored — pinned to the corner */
|
|
1490
1490
|
/* --m-toast-offset comes from toast.js when stacking; 0 without it */
|
|
1491
1491
|
inset: auto var(--space-lg) calc(var(--space-lg) + var(--m-toast-offset, 0px)) auto;
|
|
@@ -1504,23 +1504,23 @@
|
|
|
1504
1504
|
color: var(--color-text-muted);
|
|
1505
1505
|
}
|
|
1506
1506
|
|
|
1507
|
-
&:where([
|
|
1507
|
+
&:where([variant="success"]) {
|
|
1508
1508
|
border-inline-start: 2px solid var(--color-success);
|
|
1509
1509
|
}
|
|
1510
|
-
&:where([
|
|
1510
|
+
&:where([variant="danger"]) {
|
|
1511
1511
|
border-inline-start: 2px solid var(--color-danger);
|
|
1512
1512
|
}
|
|
1513
|
-
&:where([
|
|
1513
|
+
&:where([variant="warning"]) {
|
|
1514
1514
|
border-inline-start: 2px solid var(--color-warn);
|
|
1515
1515
|
}
|
|
1516
1516
|
}
|
|
1517
1517
|
/* restacking motion always (inset-block-end); the entrance slide/fade
|
|
1518
1518
|
only where overlay transitions work — see the base popover note. */
|
|
1519
|
-
:where([popover]
|
|
1519
|
+
:where(m-toast[popover]:popover-open) {
|
|
1520
1520
|
transition: inset-block-end 0.15s;
|
|
1521
1521
|
}
|
|
1522
1522
|
@supports (overlay: auto) {
|
|
1523
|
-
:where([popover]
|
|
1523
|
+
:where(m-toast[popover]:popover-open) {
|
|
1524
1524
|
transition:
|
|
1525
1525
|
opacity 0.1s,
|
|
1526
1526
|
translate 0.1s,
|
|
@@ -1529,7 +1529,7 @@
|
|
|
1529
1529
|
display 0.1s allow-discrete;
|
|
1530
1530
|
}
|
|
1531
1531
|
@starting-style {
|
|
1532
|
-
:where([popover]
|
|
1532
|
+
:where(m-toast[popover]:popover-open) {
|
|
1533
1533
|
translate: 0 0.75rem;
|
|
1534
1534
|
}
|
|
1535
1535
|
}
|
package/package.json
CHANGED
package/toast.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/* mica/toast.js — toast stacking, auto-dismiss, and a spawn helper.
|
|
2
2
|
* Tier 2.
|
|
3
3
|
*
|
|
4
|
-
* Enhances the Tier-1 toast recipe (corner-pinned manual popovers).
|
|
4
|
+
* Enhances the Tier-1 <m-toast> recipe (corner-pinned manual popovers).
|
|
5
5
|
* Declared toasts keep working without this module — it adds:
|
|
6
6
|
*
|
|
7
7
|
* - stacking: open toasts stack upward; JS ships one number per toast
|
|
8
8
|
* (--m-toast-offset), CSS owns the geometry and the reflow motion
|
|
9
|
-
* - auto-dismiss: `
|
|
9
|
+
* - auto-dismiss: `duration` attribute in ms (default 5000,
|
|
10
10
|
* "0" = sticky), paused while hovered
|
|
11
11
|
* - toast(title, { description, variant, duration }): spawns the same
|
|
12
12
|
* recipe markup (`variant`: success, warning, or danger), shows it,
|
|
@@ -20,7 +20,7 @@ const open = [];
|
|
|
20
20
|
const timers = new WeakMap();
|
|
21
21
|
|
|
22
22
|
const isToast = (el) =>
|
|
23
|
-
el instanceof HTMLElement && el.matches("[popover]
|
|
23
|
+
el instanceof HTMLElement && el.matches("m-toast[popover]");
|
|
24
24
|
|
|
25
25
|
function restack() {
|
|
26
26
|
let offset = 0;
|
|
@@ -31,8 +31,7 @@ function restack() {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
function startTimer(el) {
|
|
34
|
-
const duration =
|
|
35
|
-
el.getAttribute("data-duration") ?? el.getAttribute("duration");
|
|
34
|
+
const duration = el.getAttribute("duration");
|
|
36
35
|
const ms = duration !== null
|
|
37
36
|
? Number(duration)
|
|
38
37
|
: DEFAULT_DURATION;
|
|
@@ -75,13 +74,12 @@ document.addEventListener(
|
|
|
75
74
|
);
|
|
76
75
|
|
|
77
76
|
export function toast(title, { description = "", variant = "", duration } = {}) {
|
|
78
|
-
const el = document.createElement("
|
|
77
|
+
const el = document.createElement("m-toast");
|
|
79
78
|
el.popover = "manual";
|
|
80
|
-
el.
|
|
81
|
-
if (variant) el.setAttribute("data-variant", variant);
|
|
79
|
+
if (variant) el.setAttribute("variant", variant);
|
|
82
80
|
el.setAttribute("role", "status");
|
|
83
81
|
el.dataset.ephemeral = "";
|
|
84
|
-
if (duration !== undefined) el.setAttribute("
|
|
82
|
+
if (duration !== undefined) el.setAttribute("duration", String(duration));
|
|
85
83
|
|
|
86
84
|
const x = document.createElement("button");
|
|
87
85
|
x.className = "close";
|
package/types/react.d.ts
CHANGED
|
@@ -56,6 +56,11 @@ declare module 'react' {
|
|
|
56
56
|
variant?: 'primary' | 'success' | 'warning' | 'danger'
|
|
57
57
|
count?: boolean
|
|
58
58
|
}>
|
|
59
|
+
'm-toast': MicaElement<{
|
|
60
|
+
popover?: 'manual'
|
|
61
|
+
variant?: 'success' | 'warning' | 'danger'
|
|
62
|
+
duration?: string | number
|
|
63
|
+
}>
|
|
59
64
|
'm-field': MicaElement
|
|
60
65
|
'm-error': MicaElement<{ active?: boolean }>
|
|
61
66
|
'm-combobox': MicaElement
|