@robert-stackflow/oneui 0.6.41 → 0.6.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/CHANGELOG.md +8 -0
- package/README.md +3 -1
- package/components/Toast.d.ts +7 -2
- package/components/Toast.js +146 -98
- package/components/Toast.module.css +182 -85
- package/components/ToastProvider.js +19 -62
- package/components/ToastStack.d.ts +8 -0
- package/components/ToastStack.js +190 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## 0.6.42
|
|
2
|
+
|
|
3
|
+
- Toast 采用轻叠卡片,支持数量按钮、悬停、键盘展开和 Escape 收起;展开按实际高度排列,保留独立关闭、原位更新与异步重试。
|
|
4
|
+
- 通知组使用受视口约束的原生顶层浮层;大量消息仅在通知区域滚动,避免展开和动画撑出页面滚动条,收起与展开保持卡片宽度稳定。
|
|
5
|
+
- 修正深色通知按钮在悬停、按下和聚焦时的对比度;柔和样式使用对应的独立控件颜色。
|
|
6
|
+
- 未展开的后层消息不提前过期;暂停后保留剩余展示时长,过时异步操作不会关闭刚更新的同 id 通知。
|
|
7
|
+
- 通知层随活动弹窗迁移,避免显示在弹窗上方却无法点击;弹窗关闭时保留通知、剩余时长与进行中的操作。
|
|
8
|
+
|
|
1
9
|
## 0.6.41
|
|
2
10
|
|
|
3
11
|
- Form 支持保留现有事件处理的原生约束模式,统一行内校验、错误焦点、外部提交、重置和异步提交锁;保留 useFormState 控制器模式。
|
package/README.md
CHANGED
|
@@ -95,7 +95,9 @@ Section 支持 headingLevel(2–6,默认 2)和 contentLayout="settings";
|
|
|
95
95
|
|
|
96
96
|
提示横幅主入口改为 `Banner`,两端应用与示例均使用新名称。支持五种 tone、soft/outline/filled 变体、compact、图标、标题、操作、关闭,以及受控或内部状态的可展开 details。旧的 `Alert` 仅保留兼容别名,不维护另一套实现。
|
|
97
97
|
|
|
98
|
-
Toast
|
|
98
|
+
Toast 默认采用轻叠卡片:最新消息在前,后层仅露出边缘,悬停、键盘聚焦或点击数量按钮后展开;Escape 收起。`ToastProvider maxVisible` 默认 3,控制收起时露出的卡片层数,展开可访问整组通知。组内按实际高度排列,超出视口时只滚动通知区域,不增加页面滚动条;六个位置均使用受约束的原生顶层浮层。深色与柔和样式的按钮分别保持悬停、按下和键盘焦点对比度。
|
|
99
|
+
|
|
100
|
+
只有前台可读的消息计时;展开、悬停、聚焦及异步操作暂停计时,恢复后继续剩余时长。`notify(message,{id:"task"})` 用同一个 id 原位更新异步任务并重置该消息的时长。`createToaster().getSnapshot()` 仍返回最新一条,`getQueueSnapshot()` 返回队列;带 id 的 dismiss/clear 只影响对应消息,无参时作用于全部消息。旧关闭函数不会影响后来的其他消息。独立使用的 `Toast` 保留原生浮层与已有调用方式。
|
|
99
101
|
|
|
100
102
|
## Markdown
|
|
101
103
|
|
package/components/Toast.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ToastMessage } from "./ToastProvider";
|
|
2
|
-
export declare function Toast({ toast, position, onDismiss, stackIndex, stackOffset, stackExpanded, stackHidden, paused, onHoverChange, onHeightChange, }: {
|
|
2
|
+
export declare function Toast({ toast, position, onDismiss, stackIndex, stackOffset, stackExpanded, stackHidden, paused, onHoverChange, onHeightChange, embedded, stackHeight, stackCount, onStackToggle, }: {
|
|
3
3
|
toast: ToastMessage | null;
|
|
4
4
|
position: string;
|
|
5
5
|
onDismiss(id: number): void;
|
|
@@ -10,4 +10,9 @@ export declare function Toast({ toast, position, onDismiss, stackIndex, stackOff
|
|
|
10
10
|
paused?: boolean;
|
|
11
11
|
onHoverChange?(inside: boolean): void;
|
|
12
12
|
onHeightChange?(height: number): void;
|
|
13
|
-
|
|
13
|
+
/** Internal stack rendering; standalone Toast retains its native popover. */
|
|
14
|
+
embedded?: boolean;
|
|
15
|
+
stackHeight?: number;
|
|
16
|
+
stackCount?: number;
|
|
17
|
+
onStackToggle?(): void;
|
|
18
|
+
}): import("react").JSX.Element;
|
package/components/Toast.js
CHANGED
|
@@ -13,7 +13,9 @@ import {
|
|
|
13
13
|
Info,
|
|
14
14
|
TriangleAlert,
|
|
15
15
|
CircleX,
|
|
16
|
-
LoaderCircle
|
|
16
|
+
LoaderCircle,
|
|
17
|
+
ChevronDown,
|
|
18
|
+
ChevronUp
|
|
17
19
|
} from "lucide-react";
|
|
18
20
|
import { toastMotion, cancelMotion } from "./motion.js";
|
|
19
21
|
import s from "./Toast.module.css";
|
|
@@ -35,37 +37,51 @@ function Toast({
|
|
|
35
37
|
stackHidden = false,
|
|
36
38
|
paused = false,
|
|
37
39
|
onHoverChange,
|
|
38
|
-
onHeightChange
|
|
40
|
+
onHeightChange,
|
|
41
|
+
embedded = false,
|
|
42
|
+
stackHeight,
|
|
43
|
+
stackCount = 1,
|
|
44
|
+
onStackToggle
|
|
39
45
|
}) {
|
|
40
46
|
const { text } = useUIText();
|
|
41
|
-
const ref = useRef(null), current = useRef(toast), timer = useRef(void 0), pendingId = useRef(null);
|
|
47
|
+
const ref = useRef(null), content = useRef(null), current = useRef(toast), timer = useRef(void 0), pendingId = useRef(null);
|
|
48
|
+
const remaining = useRef(5e3), deadline = useRef(0);
|
|
49
|
+
const pausedState = useRef(paused);
|
|
50
|
+
pausedState.current = paused;
|
|
42
51
|
const [pending, setPending] = useState(false), [error, setError] = useState("");
|
|
43
52
|
current.current = toast;
|
|
44
|
-
const
|
|
53
|
+
const pauseClock = () => {
|
|
45
54
|
clearTimeout(timer.current);
|
|
55
|
+
if (deadline.current)
|
|
56
|
+
remaining.current = Math.max(0, deadline.current - performance.now());
|
|
57
|
+
deadline.current = 0;
|
|
58
|
+
};
|
|
59
|
+
const dismiss = () => {
|
|
60
|
+
pauseClock();
|
|
46
61
|
const message = current.current, node = ref.current;
|
|
47
62
|
if (!message) return;
|
|
48
63
|
void toastMotion(node, "exit", position).then((done) => {
|
|
49
|
-
if (done && current.current
|
|
64
|
+
if (done && current.current === message) {
|
|
50
65
|
if (node.matches(":popover-open")) node.hidePopover();
|
|
51
66
|
onDismiss(message.id);
|
|
52
67
|
}
|
|
53
68
|
});
|
|
54
69
|
};
|
|
55
70
|
const arm = () => {
|
|
56
|
-
|
|
71
|
+
pauseClock();
|
|
57
72
|
const message = current.current, node = ref.current;
|
|
58
|
-
if (message && !
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
);
|
|
73
|
+
if (message && !pausedState.current && !message.closing && !message.options?.persistent && pendingId.current !== message.id && !node?.matches(":hover") && !node?.contains(document.activeElement)) {
|
|
74
|
+
deadline.current = performance.now() + remaining.current;
|
|
75
|
+
timer.current = setTimeout(dismiss, remaining.current);
|
|
76
|
+
}
|
|
63
77
|
};
|
|
64
78
|
useLayoutEffect(() => {
|
|
65
79
|
const node = ref.current;
|
|
66
80
|
setPending(false);
|
|
67
81
|
setError("");
|
|
68
82
|
pendingId.current = null;
|
|
83
|
+
pauseClock();
|
|
84
|
+
remaining.current = Math.max(0, toast?.options?.duration ?? 5e3);
|
|
69
85
|
if (!toast) {
|
|
70
86
|
if (node.matches(":popover-open")) node.hidePopover();
|
|
71
87
|
return;
|
|
@@ -75,10 +91,11 @@ function Toast({
|
|
|
75
91
|
return;
|
|
76
92
|
}
|
|
77
93
|
const already = node.matches(":popover-open");
|
|
78
|
-
if (!already) node.showPopover();
|
|
79
|
-
void toastMotion(node,
|
|
94
|
+
if (!embedded && !already) node.showPopover();
|
|
95
|
+
void toastMotion(node, node.dataset.entered ? "update" : "enter", position);
|
|
96
|
+
node.dataset.entered = "true";
|
|
80
97
|
arm();
|
|
81
|
-
return
|
|
98
|
+
return pauseClock;
|
|
82
99
|
}, [toast, position]);
|
|
83
100
|
useEffect(() => {
|
|
84
101
|
const node = ref.current;
|
|
@@ -90,32 +107,39 @@ function Toast({
|
|
|
90
107
|
const heightChange = useRef(onHeightChange);
|
|
91
108
|
heightChange.current = onHeightChange;
|
|
92
109
|
useLayoutEffect(() => {
|
|
93
|
-
const node =
|
|
110
|
+
const node = content.current;
|
|
94
111
|
const observer = new ResizeObserver(
|
|
95
|
-
() => heightChange.current?.(node.offsetHeight)
|
|
112
|
+
() => heightChange.current?.(node.offsetHeight + 2)
|
|
96
113
|
);
|
|
97
114
|
observer.observe(node);
|
|
98
115
|
return () => observer.disconnect();
|
|
99
116
|
}, []);
|
|
100
117
|
useEffect(() => {
|
|
101
|
-
if (paused)
|
|
118
|
+
if (paused) pauseClock();
|
|
102
119
|
else arm();
|
|
103
120
|
}, [paused]);
|
|
104
121
|
const execute = async () => {
|
|
105
122
|
const message = current.current, action2 = message?.options?.action;
|
|
106
123
|
if (!message || !action2 || pendingId.current === message.id) return;
|
|
107
|
-
|
|
124
|
+
pauseClock();
|
|
108
125
|
pendingId.current = message.id;
|
|
109
126
|
setPending(true);
|
|
110
127
|
setError("");
|
|
111
128
|
try {
|
|
112
129
|
await action2.onClick();
|
|
113
|
-
if (current.current
|
|
130
|
+
if (current.current === message && action2.closeOnClick !== false)
|
|
114
131
|
dismiss();
|
|
115
132
|
} catch {
|
|
116
|
-
if (current.current
|
|
133
|
+
if (current.current === message)
|
|
134
|
+
setError(
|
|
135
|
+
text(
|
|
136
|
+
"\u64CD\u4F5C\u672A\u5B8C\u6210\uFF0C\u8BF7\u91CD\u8BD5",
|
|
137
|
+
"Action failed. Please retry.",
|
|
138
|
+
"\u64CD\u4F5C\u672A\u5B8C\u6210\uFF0C\u8ACB\u91CD\u8A66"
|
|
139
|
+
)
|
|
140
|
+
);
|
|
117
141
|
} finally {
|
|
118
|
-
if (current.current
|
|
142
|
+
if (current.current === message) {
|
|
119
143
|
pendingId.current = null;
|
|
120
144
|
setPending(false);
|
|
121
145
|
arm();
|
|
@@ -126,90 +150,114 @@ function Toast({
|
|
|
126
150
|
const icon = options.icon === false ? null : options.icon === true || options.icon === void 0 ? tone !== "neutral" || options.icon === true ? /* @__PURE__ */ jsx(Icon, {}) : null : options.icon;
|
|
127
151
|
const style = {
|
|
128
152
|
"--toast-stack-offset": `${stackOffset}px`,
|
|
129
|
-
"--toast-stack-scale": stackExpanded ? 1 : Math.max(0.85, 1 - stackIndex * 0.
|
|
153
|
+
"--toast-stack-scale": stackExpanded ? 1 : Math.max(0.85, 1 - stackIndex * 0.035),
|
|
154
|
+
"--toast-stack-height": stackHeight === void 0 ? void 0 : `${stackHeight}px`,
|
|
155
|
+
zIndex: 1e3 - stackIndex,
|
|
130
156
|
"--toast-icon-color": options.iconColor,
|
|
131
157
|
"--toast-text-color": options.textColor
|
|
132
158
|
};
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
159
|
+
const element = /* @__PURE__ */ jsx(
|
|
160
|
+
"div",
|
|
161
|
+
{
|
|
162
|
+
ref,
|
|
163
|
+
popover: embedded ? void 0 : "manual",
|
|
164
|
+
className: s.toast,
|
|
165
|
+
"data-position": position,
|
|
166
|
+
"data-toast": true,
|
|
167
|
+
"data-embedded": embedded,
|
|
168
|
+
"data-stack-index": stackIndex,
|
|
169
|
+
"data-stack-expanded": stackExpanded,
|
|
170
|
+
"data-stack-hidden": stackHidden,
|
|
171
|
+
inert: stackHidden || embedded && !stackExpanded && stackIndex > 0,
|
|
172
|
+
"aria-hidden": stackHidden || embedded && !stackExpanded && stackIndex > 0 || void 0,
|
|
173
|
+
"data-tone": tone,
|
|
174
|
+
"data-variant": options.variant || "solid",
|
|
175
|
+
role: "status",
|
|
176
|
+
"aria-live": "polite",
|
|
177
|
+
"aria-atomic": "true",
|
|
178
|
+
style,
|
|
179
|
+
onPointerEnter: () => {
|
|
180
|
+
pauseClock();
|
|
181
|
+
onHoverChange?.(true);
|
|
182
|
+
},
|
|
183
|
+
onPointerLeave: () => {
|
|
184
|
+
onHoverChange?.(false);
|
|
185
|
+
arm();
|
|
186
|
+
},
|
|
187
|
+
onFocus: () => {
|
|
188
|
+
pauseClock();
|
|
189
|
+
onHoverChange?.(true);
|
|
190
|
+
},
|
|
191
|
+
onBlur: (e) => {
|
|
192
|
+
if (!e.currentTarget.contains(e.relatedTarget)) {
|
|
157
193
|
onHoverChange?.(false);
|
|
158
|
-
arm
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
194
|
+
queueMicrotask(arm);
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
onKeyDown: (e) => {
|
|
198
|
+
if (e.key === "Escape" && !(embedded && stackExpanded)) {
|
|
199
|
+
e.stopPropagation();
|
|
200
|
+
dismiss();
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
children: /* @__PURE__ */ jsxs("div", { ref: content, className: s.content, children: [
|
|
204
|
+
icon && /* @__PURE__ */ jsx("span", { className: s.icon, "aria-hidden": "true", "data-toast-icon": true, children: icon }),
|
|
205
|
+
/* @__PURE__ */ jsxs("div", { className: s.copy, "data-toast-copy": true, children: [
|
|
206
|
+
options.title && /* @__PURE__ */ jsx("strong", { children: options.title }),
|
|
207
|
+
/* @__PURE__ */ jsx("span", { children: toast?.message }),
|
|
208
|
+
error && /* @__PURE__ */ jsx("small", { role: "alert", children: error })
|
|
209
|
+
] }),
|
|
210
|
+
action && /* @__PURE__ */ jsxs(
|
|
211
|
+
"button",
|
|
212
|
+
{
|
|
213
|
+
className: s.action,
|
|
214
|
+
type: "button",
|
|
215
|
+
"aria-label": action.label,
|
|
216
|
+
disabled: pending,
|
|
217
|
+
"data-icon-only": action.display === "icon",
|
|
218
|
+
onClick: () => void execute(),
|
|
219
|
+
children: [
|
|
220
|
+
pending ? /* @__PURE__ */ jsx(LoaderCircle, { className: s.spin }) : action.display !== "text" && action.icon,
|
|
221
|
+
action.display !== "icon" && /* @__PURE__ */ jsx("span", { children: action.label })
|
|
222
|
+
]
|
|
168
223
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
224
|
+
),
|
|
225
|
+
stackCount > 1 && onStackToggle && /* @__PURE__ */ jsxs(
|
|
226
|
+
"button",
|
|
227
|
+
{
|
|
228
|
+
className: s.expand,
|
|
229
|
+
type: "button",
|
|
230
|
+
"data-toast-expand": true,
|
|
231
|
+
"aria-label": stackExpanded ? text("\u6536\u8D77\u901A\u77E5", "Collapse notifications", "\u6536\u8D77\u901A\u77E5") : text(
|
|
232
|
+
`\u5C55\u5F00 ${stackCount} \u6761\u901A\u77E5`,
|
|
233
|
+
`Expand ${stackCount} notifications`,
|
|
234
|
+
`\u5C55\u958B ${stackCount} \u689D\u901A\u77E5`
|
|
235
|
+
),
|
|
236
|
+
"aria-expanded": stackExpanded,
|
|
237
|
+
onClick: onStackToggle,
|
|
238
|
+
children: [
|
|
239
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
240
|
+
"+",
|
|
241
|
+
stackCount - 1
|
|
242
|
+
] }),
|
|
243
|
+
stackExpanded ? /* @__PURE__ */ jsx(ChevronUp, {}) : /* @__PURE__ */ jsx(ChevronDown, {})
|
|
244
|
+
]
|
|
174
245
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
"aria-label": action.label,
|
|
189
|
-
disabled: pending,
|
|
190
|
-
"data-icon-only": action.display === "icon",
|
|
191
|
-
onClick: () => void execute(),
|
|
192
|
-
children: [
|
|
193
|
-
pending ? /* @__PURE__ */ jsx(LoaderCircle, { className: s.spin }) : action.display !== "text" && action.icon,
|
|
194
|
-
action.display !== "icon" && /* @__PURE__ */ jsx("span", { children: action.label })
|
|
195
|
-
]
|
|
196
|
-
}
|
|
197
|
-
),
|
|
198
|
-
options.closable !== false && /* @__PURE__ */ jsx(
|
|
199
|
-
"button",
|
|
200
|
-
{
|
|
201
|
-
className: s.close,
|
|
202
|
-
type: "button",
|
|
203
|
-
"aria-label": text("\u5173\u95ED\u63D0\u793A", "Dismiss notification", "\u95DC\u9589\u63D0\u793A"),
|
|
204
|
-
onClick: dismiss,
|
|
205
|
-
children: /* @__PURE__ */ jsx(X, {})
|
|
206
|
-
}
|
|
207
|
-
)
|
|
208
|
-
]
|
|
209
|
-
}
|
|
210
|
-
),
|
|
211
|
-
document.body
|
|
246
|
+
),
|
|
247
|
+
options.closable !== false && /* @__PURE__ */ jsx(
|
|
248
|
+
"button",
|
|
249
|
+
{
|
|
250
|
+
className: s.close,
|
|
251
|
+
type: "button",
|
|
252
|
+
"aria-label": text("\u5173\u95ED\u63D0\u793A", "Dismiss notification", "\u95DC\u9589\u63D0\u793A"),
|
|
253
|
+
onClick: dismiss,
|
|
254
|
+
children: /* @__PURE__ */ jsx(X, {})
|
|
255
|
+
}
|
|
256
|
+
)
|
|
257
|
+
] })
|
|
258
|
+
}
|
|
212
259
|
);
|
|
260
|
+
return embedded ? element : createPortal(element, document.body);
|
|
213
261
|
}
|
|
214
262
|
export {
|
|
215
263
|
Toast
|
|
@@ -1,110 +1,203 @@
|
|
|
1
|
+
.viewport {
|
|
2
|
+
position: fixed;
|
|
3
|
+
inset: 0;
|
|
4
|
+
margin: 0;
|
|
5
|
+
padding: 0;
|
|
6
|
+
border: 0;
|
|
7
|
+
width: 100%;
|
|
8
|
+
height: 100%;
|
|
9
|
+
max-width: none;
|
|
10
|
+
max-height: none;
|
|
11
|
+
background: transparent;
|
|
12
|
+
overflow: clip;
|
|
13
|
+
contain: strict;
|
|
14
|
+
pointer-events: none;
|
|
15
|
+
}
|
|
16
|
+
.viewport::backdrop {
|
|
17
|
+
background: transparent;
|
|
18
|
+
pointer-events: none;
|
|
19
|
+
}
|
|
20
|
+
.region {
|
|
21
|
+
position: absolute;
|
|
22
|
+
width: min(436px, 100%);
|
|
23
|
+
max-height: 100%;
|
|
24
|
+
box-sizing: border-box;
|
|
25
|
+
padding: 20px 16px 30px;
|
|
26
|
+
overflow-x: clip;
|
|
27
|
+
overflow-y: auto;
|
|
28
|
+
overscroll-behavior: contain;
|
|
29
|
+
scrollbar-width: thin;
|
|
30
|
+
scrollbar-gutter: stable both-edges;
|
|
31
|
+
pointer-events: none;
|
|
32
|
+
}
|
|
33
|
+
.region[data-expanded="true"] {
|
|
34
|
+
pointer-events: auto;
|
|
35
|
+
}
|
|
36
|
+
.region[data-position^="top"] {
|
|
37
|
+
top: 0;
|
|
38
|
+
}
|
|
39
|
+
.region[data-position^="bottom"] {
|
|
40
|
+
bottom: 0;
|
|
41
|
+
padding-top: 30px;
|
|
42
|
+
padding-bottom: 20px;
|
|
43
|
+
}
|
|
44
|
+
.region[data-position$="left"] {
|
|
45
|
+
left: 4px;
|
|
46
|
+
}
|
|
47
|
+
.region[data-position$="right"] {
|
|
48
|
+
right: 4px;
|
|
49
|
+
}
|
|
50
|
+
.region[data-position$="center"] {
|
|
51
|
+
left: 50%;
|
|
52
|
+
transform: translateX(-50%);
|
|
53
|
+
}
|
|
54
|
+
.stack {
|
|
55
|
+
position: relative;
|
|
56
|
+
width: 100%;
|
|
57
|
+
}
|
|
1
58
|
.toast {
|
|
59
|
+
--tone: #c4c4c4;
|
|
60
|
+
--soft-tone: #555;
|
|
61
|
+
--toast-control: #ffffff12;
|
|
62
|
+
--toast-control-hover: #ffffff24;
|
|
63
|
+
--toast-control-active: #ffffff32;
|
|
64
|
+
--toast-stack-sign: 1;
|
|
2
65
|
position: fixed;
|
|
3
66
|
inset: auto;
|
|
4
67
|
margin: 0;
|
|
5
|
-
padding:
|
|
6
|
-
border:
|
|
7
|
-
border-radius:
|
|
8
|
-
|
|
9
|
-
|
|
68
|
+
padding: 0;
|
|
69
|
+
border: 1px solid #ffffff0c;
|
|
70
|
+
border-radius: 13px;
|
|
71
|
+
box-sizing: border-box;
|
|
72
|
+
width: min(384px, calc(100vw - 32px));
|
|
73
|
+
max-width: none;
|
|
74
|
+
background: #303234;
|
|
75
|
+
color: var(--toast-text-color, #f7f7f7);
|
|
10
76
|
box-shadow:
|
|
11
|
-
0 8px
|
|
12
|
-
0 2px 6px #
|
|
13
|
-
|
|
14
|
-
max-height: min(160px, calc(100vh - 40px));
|
|
15
|
-
overflow: auto;
|
|
77
|
+
0 8px 24px #00000016,
|
|
78
|
+
0 2px 6px #0000000c;
|
|
79
|
+
overflow: clip;
|
|
16
80
|
font-size: 13px;
|
|
17
81
|
line-height: 20px;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
82
|
+
pointer-events: auto;
|
|
83
|
+
transform-origin: top center;
|
|
84
|
+
transform: translateY(
|
|
85
|
+
calc(var(--toast-stack-offset, 0px) * var(--toast-stack-sign))
|
|
86
|
+
)
|
|
87
|
+
scale(var(--toast-stack-scale, 1));
|
|
88
|
+
transition:
|
|
89
|
+
transform 340ms cubic-bezier(0.16, 1, 0.3, 1),
|
|
90
|
+
height 340ms cubic-bezier(0.16, 1, 0.3, 1);
|
|
91
|
+
will-change: transform, opacity;
|
|
92
|
+
}
|
|
93
|
+
.toast:popover-open,
|
|
94
|
+
.toast[data-embedded="true"] {
|
|
95
|
+
display: block;
|
|
21
96
|
}
|
|
22
|
-
.
|
|
97
|
+
.content {
|
|
23
98
|
display: flex;
|
|
24
99
|
align-items: center;
|
|
25
|
-
gap:
|
|
100
|
+
gap: 10px;
|
|
101
|
+
padding: 14px 16px;
|
|
102
|
+
box-sizing: border-box;
|
|
103
|
+
max-height: min(320px, calc(100dvh - 80px));
|
|
104
|
+
overflow: auto;
|
|
105
|
+
scrollbar-width: thin;
|
|
26
106
|
}
|
|
27
107
|
.copy {
|
|
108
|
+
flex: 1;
|
|
28
109
|
min-width: 0;
|
|
29
110
|
display: grid;
|
|
30
|
-
gap:
|
|
111
|
+
gap: 3px;
|
|
31
112
|
white-space: pre-wrap;
|
|
32
113
|
overflow-wrap: anywhere;
|
|
33
114
|
}
|
|
34
115
|
.copy strong {
|
|
35
|
-
font-size:
|
|
116
|
+
font-size: 13px;
|
|
36
117
|
font-weight: 600;
|
|
37
118
|
}
|
|
119
|
+
.copy:has(strong) > span {
|
|
120
|
+
opacity: 0.75;
|
|
121
|
+
}
|
|
38
122
|
.copy small {
|
|
39
123
|
color: inherit;
|
|
40
|
-
opacity: 0.
|
|
41
|
-
font-size:
|
|
124
|
+
opacity: 0.85;
|
|
125
|
+
font-size: 12px;
|
|
42
126
|
}
|
|
43
127
|
.icon {
|
|
44
128
|
display: grid;
|
|
45
129
|
place-items: center;
|
|
46
130
|
flex-shrink: 0;
|
|
47
|
-
align-self: center;
|
|
48
131
|
width: 20px;
|
|
49
132
|
height: 20px;
|
|
50
133
|
color: var(--toast-icon-color, var(--tone));
|
|
51
134
|
}
|
|
52
135
|
.icon svg {
|
|
53
136
|
display: block;
|
|
54
|
-
width:
|
|
55
|
-
height:
|
|
137
|
+
width: 19px;
|
|
138
|
+
height: 19px;
|
|
56
139
|
}
|
|
57
140
|
.toast button {
|
|
141
|
+
appearance: none;
|
|
58
142
|
display: inline-flex;
|
|
59
143
|
align-items: center;
|
|
60
144
|
justify-content: center;
|
|
61
|
-
gap:
|
|
145
|
+
gap: 4px;
|
|
62
146
|
flex-shrink: 0;
|
|
63
147
|
border: 0;
|
|
64
|
-
border-radius:
|
|
148
|
+
border-radius: 7px;
|
|
65
149
|
color: inherit;
|
|
150
|
+
font: inherit;
|
|
66
151
|
font-size: 12px;
|
|
67
152
|
line-height: 20px;
|
|
68
|
-
min-height:
|
|
153
|
+
min-height: 28px;
|
|
154
|
+
background: var(--toast-control);
|
|
155
|
+
cursor: pointer;
|
|
69
156
|
transition:
|
|
70
157
|
background-color var(--motion-hover),
|
|
71
158
|
opacity var(--motion-hover);
|
|
72
159
|
}
|
|
160
|
+
.toast button:hover:not(:disabled) {
|
|
161
|
+
background: var(--toast-control-hover);
|
|
162
|
+
}
|
|
163
|
+
.toast button:active:not(:disabled) {
|
|
164
|
+
background: var(--toast-control-active);
|
|
165
|
+
}
|
|
166
|
+
.toast button:focus-visible {
|
|
167
|
+
outline: 2px solid currentColor;
|
|
168
|
+
outline-offset: 2px;
|
|
169
|
+
}
|
|
170
|
+
.toast button:disabled {
|
|
171
|
+
opacity: 0.6;
|
|
172
|
+
cursor: wait;
|
|
173
|
+
}
|
|
73
174
|
.action {
|
|
74
|
-
|
|
75
|
-
padding: 3px 8px;
|
|
76
|
-
background: #ffffff18;
|
|
175
|
+
padding: 4px 8px;
|
|
77
176
|
white-space: nowrap;
|
|
78
177
|
}
|
|
79
|
-
.action:hover:not(:disabled) {
|
|
80
|
-
background: #ffffff2a;
|
|
81
|
-
}
|
|
82
178
|
.action[data-icon-only="true"] {
|
|
83
|
-
width:
|
|
179
|
+
width: 28px;
|
|
84
180
|
padding: 4px;
|
|
85
181
|
}
|
|
86
|
-
.action svg
|
|
87
|
-
|
|
88
|
-
|
|
182
|
+
.action svg,
|
|
183
|
+
.expand svg {
|
|
184
|
+
width: 14px;
|
|
185
|
+
height: 14px;
|
|
89
186
|
}
|
|
90
|
-
.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
padding: 3px;
|
|
94
|
-
background: transparent;
|
|
95
|
-
opacity: 0.65;
|
|
187
|
+
.expand {
|
|
188
|
+
padding: 3px 7px;
|
|
189
|
+
font-variant-numeric: tabular-nums;
|
|
96
190
|
}
|
|
97
|
-
.close
|
|
98
|
-
|
|
99
|
-
|
|
191
|
+
.toast .close {
|
|
192
|
+
width: 28px;
|
|
193
|
+
height: 28px;
|
|
194
|
+
padding: 4px;
|
|
195
|
+
background: transparent;
|
|
100
196
|
}
|
|
101
197
|
.close svg {
|
|
102
|
-
width:
|
|
103
|
-
height:
|
|
104
|
-
|
|
105
|
-
.toast button:focus-visible {
|
|
106
|
-
outline: 1px solid currentColor;
|
|
107
|
-
outline-offset: 2px;
|
|
198
|
+
width: 15px;
|
|
199
|
+
height: 15px;
|
|
200
|
+
opacity: 0.8;
|
|
108
201
|
}
|
|
109
202
|
.toast[data-tone="success"] {
|
|
110
203
|
--tone: #91d5a4;
|
|
@@ -123,25 +216,23 @@
|
|
|
123
216
|
--soft-tone: #b13d3d;
|
|
124
217
|
}
|
|
125
218
|
.toast[data-variant="soft"] {
|
|
219
|
+
--toast-control: color-mix(in srgb, var(--soft-tone) 9%, transparent);
|
|
220
|
+
--toast-control-hover: color-mix(in srgb, var(--soft-tone) 16%, transparent);
|
|
221
|
+
--toast-control-active: color-mix(in srgb, var(--soft-tone) 22%, transparent);
|
|
126
222
|
background: color-mix(in srgb, var(--soft-tone) 8%, var(--surface));
|
|
127
223
|
color: var(--toast-text-color, var(--fg));
|
|
128
|
-
|
|
129
|
-
border: 1px solid color-mix(in srgb, var(--soft-tone) 18%, var(--surface));
|
|
224
|
+
border-color: color-mix(in srgb, var(--soft-tone) 18%, var(--surface));
|
|
130
225
|
}
|
|
131
226
|
.toast[data-variant="soft"] .icon {
|
|
132
227
|
color: var(--toast-icon-color, var(--soft-tone));
|
|
133
228
|
}
|
|
134
|
-
.toast[data-variant="soft"] .action {
|
|
135
|
-
background: color-mix(in srgb, var(--soft-tone) 10%, transparent);
|
|
136
|
-
}
|
|
137
|
-
.toast[data-variant="soft"] button:hover:not(:disabled) {
|
|
138
|
-
background: color-mix(in srgb, var(--soft-tone) 18%, transparent);
|
|
139
|
-
}
|
|
140
229
|
.toast[data-position^="top"] {
|
|
141
230
|
top: 20px;
|
|
142
231
|
}
|
|
143
232
|
.toast[data-position^="bottom"] {
|
|
144
233
|
bottom: 20px;
|
|
234
|
+
--toast-stack-sign: -1;
|
|
235
|
+
transform-origin: bottom center;
|
|
145
236
|
}
|
|
146
237
|
.toast[data-position$="left"] {
|
|
147
238
|
left: 20px;
|
|
@@ -151,16 +242,39 @@
|
|
|
151
242
|
}
|
|
152
243
|
.toast[data-position$="center"] {
|
|
153
244
|
left: 50%;
|
|
154
|
-
transform: translateX(-50%)
|
|
245
|
+
transform: translateX(-50%)
|
|
246
|
+
translateY(calc(var(--toast-stack-offset, 0px) * var(--toast-stack-sign)))
|
|
247
|
+
scale(var(--toast-stack-scale, 1));
|
|
248
|
+
}
|
|
249
|
+
.toast[data-embedded="true"] {
|
|
250
|
+
position: absolute;
|
|
251
|
+
width: 100%;
|
|
252
|
+
inset: 0 0 auto;
|
|
253
|
+
height: var(--toast-stack-height, auto);
|
|
254
|
+
}
|
|
255
|
+
.toast[data-embedded="true"][data-position^="bottom"] {
|
|
256
|
+
inset: auto 0 0;
|
|
257
|
+
}
|
|
258
|
+
.toast[data-embedded="true"][data-position$="center"] {
|
|
259
|
+
transform: translateY(
|
|
260
|
+
calc(var(--toast-stack-offset, 0px) * var(--toast-stack-sign))
|
|
261
|
+
)
|
|
262
|
+
scale(var(--toast-stack-scale, 1));
|
|
263
|
+
}
|
|
264
|
+
.toast[data-embedded="true"][data-stack-expanded="false"]:not(
|
|
265
|
+
[data-stack-index="0"]
|
|
266
|
+
)
|
|
267
|
+
.content {
|
|
268
|
+
visibility: hidden;
|
|
269
|
+
}
|
|
270
|
+
.toast[data-stack-hidden="true"] {
|
|
271
|
+
visibility: hidden;
|
|
272
|
+
pointer-events: none;
|
|
155
273
|
}
|
|
156
274
|
:global([data-theme="dark"]) .toast {
|
|
157
275
|
box-shadow:
|
|
158
|
-
0 8px
|
|
159
|
-
0 2px 6px #
|
|
160
|
-
}
|
|
161
|
-
:global([data-theme="dark"]) .toast[data-variant="solid"] {
|
|
162
|
-
background: #333;
|
|
163
|
-
color: var(--toast-text-color, #f4f4f4);
|
|
276
|
+
0 8px 24px #00000038,
|
|
277
|
+
0 2px 6px #00000020;
|
|
164
278
|
}
|
|
165
279
|
:global([data-theme="dark"]) .toast[data-variant="soft"] {
|
|
166
280
|
--soft-tone: var(--tone);
|
|
@@ -173,28 +287,11 @@
|
|
|
173
287
|
transform: rotate(360deg);
|
|
174
288
|
}
|
|
175
289
|
}
|
|
176
|
-
|
|
177
|
-
.toast {
|
|
178
|
-
--toast-stack-sign: 1;
|
|
179
|
-
transform: translateY(
|
|
180
|
-
calc(var(--toast-stack-offset, 0px) * var(--toast-stack-sign))
|
|
181
|
-
);
|
|
182
|
-
transition: transform 320ms cubic-bezier(0.16, 1, 0.3, 1);
|
|
183
|
-
will-change: transform, opacity;
|
|
184
|
-
}
|
|
185
|
-
.toast[data-position^="bottom"] {
|
|
186
|
-
--toast-stack-sign: -1;
|
|
187
|
-
}
|
|
188
|
-
.toast[data-position$="center"] {
|
|
189
|
-
transform: translateX(-50%)
|
|
190
|
-
translateY(calc(var(--toast-stack-offset, 0px) * var(--toast-stack-sign)));
|
|
191
|
-
}
|
|
192
|
-
.toast[data-stack-hidden="true"] {
|
|
193
|
-
visibility: hidden;
|
|
194
|
-
pointer-events: none;
|
|
195
|
-
}
|
|
196
290
|
@media (prefers-reduced-motion: reduce) {
|
|
197
291
|
.toast {
|
|
198
292
|
transition: none;
|
|
199
293
|
}
|
|
294
|
+
.spin {
|
|
295
|
+
animation: none;
|
|
296
|
+
}
|
|
200
297
|
}
|
|
@@ -4,12 +4,10 @@ import {
|
|
|
4
4
|
createContext,
|
|
5
5
|
useContext,
|
|
6
6
|
useState,
|
|
7
|
-
useRef,
|
|
8
|
-
useEffect,
|
|
9
7
|
useSyncExternalStore
|
|
10
8
|
} from "react";
|
|
11
9
|
import { useUIConfig } from "./UIProvider.js";
|
|
12
|
-
import {
|
|
10
|
+
import { ToastStack } from "./ToastStack.js";
|
|
13
11
|
import {
|
|
14
12
|
createToaster
|
|
15
13
|
} from "./createToaster.js";
|
|
@@ -29,68 +27,27 @@ function ToastProvider({
|
|
|
29
27
|
serverSnapshot
|
|
30
28
|
);
|
|
31
29
|
const messages = Array.isArray(snapshot) ? snapshot : snapshot ? [snapshot] : [];
|
|
32
|
-
const [expanded, setExpanded] = useState([]);
|
|
33
|
-
const [heights, setHeights] = useState({});
|
|
34
|
-
const timers = useRef(/* @__PURE__ */ new Map());
|
|
35
|
-
const hover = (position, inside) => {
|
|
36
|
-
clearTimeout(timers.current.get(position));
|
|
37
|
-
if (inside)
|
|
38
|
-
setExpanded((old) => old.includes(position) ? old : [...old, position]);
|
|
39
|
-
else
|
|
40
|
-
timers.current.set(
|
|
41
|
-
position,
|
|
42
|
-
setTimeout(
|
|
43
|
-
() => setExpanded((old) => old.filter((entry) => entry !== position)),
|
|
44
|
-
140
|
|
45
|
-
)
|
|
46
|
-
);
|
|
47
|
-
};
|
|
48
|
-
useEffect(() => () => timers.current.forEach(clearTimeout), []);
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
setHeights((previous) => {
|
|
51
|
-
const ids = new Set(messages.map((message) => String(message.id)));
|
|
52
|
-
return Object.keys(previous).every((id) => ids.has(id)) ? previous : Object.fromEntries(
|
|
53
|
-
Object.entries(previous).filter(([id]) => ids.has(id))
|
|
54
|
-
);
|
|
55
|
-
});
|
|
56
|
-
}, [snapshot]);
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
setExpanded([]);
|
|
59
|
-
setHeights({});
|
|
60
|
-
}, [source.id]);
|
|
61
30
|
const limit = Number.isFinite(maxVisible) ? Math.max(1, Math.floor(maxVisible)) : 3;
|
|
62
31
|
return /* @__PURE__ */ jsxs(Context, { value: source.notify, children: [
|
|
63
32
|
children,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
stackOffset: offset,
|
|
83
|
-
stackExpanded: isExpanded,
|
|
84
|
-
stackHidden: index >= limit,
|
|
85
|
-
paused: isExpanded,
|
|
86
|
-
onHoverChange: (inside) => hover(position, inside),
|
|
87
|
-
onHeightChange: (height) => setHeights(
|
|
88
|
-
(old) => old[toast.id] === height ? old : { ...old, [toast.id]: height }
|
|
89
|
-
)
|
|
90
|
-
},
|
|
91
|
-
`${source.id}-${toast.id}`
|
|
92
|
-
);
|
|
93
|
-
})
|
|
33
|
+
[
|
|
34
|
+
...new Set(
|
|
35
|
+
messages.map(
|
|
36
|
+
(toast) => toast.options?.position || config.toastPosition
|
|
37
|
+
)
|
|
38
|
+
)
|
|
39
|
+
].map((position) => /* @__PURE__ */ jsx(
|
|
40
|
+
ToastStack,
|
|
41
|
+
{
|
|
42
|
+
position,
|
|
43
|
+
messages: messages.filter(
|
|
44
|
+
(toast) => (toast.options?.position || config.toastPosition) === position
|
|
45
|
+
).toReversed(),
|
|
46
|
+
maxVisible: limit,
|
|
47
|
+
onDismiss: source.clear
|
|
48
|
+
},
|
|
49
|
+
`${source.id}-${position}`
|
|
50
|
+
))
|
|
94
51
|
] });
|
|
95
52
|
}
|
|
96
53
|
const useToast = () => useContext(Context);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ToastMessage, ToastPosition } from "./ToastProvider";
|
|
2
|
+
/** One top-layer viewport contains all animation and scrolling for this position. */
|
|
3
|
+
export declare function ToastStack({ position, messages, maxVisible, onDismiss, }: {
|
|
4
|
+
position: ToastPosition;
|
|
5
|
+
messages: readonly ToastMessage[];
|
|
6
|
+
maxVisible: number;
|
|
7
|
+
onDismiss(id: number): void;
|
|
8
|
+
}): import("react").ReactPortal;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import {
|
|
4
|
+
useEffect,
|
|
5
|
+
useLayoutEffect,
|
|
6
|
+
useRef,
|
|
7
|
+
useState
|
|
8
|
+
} from "react";
|
|
9
|
+
import { createPortal } from "react-dom";
|
|
10
|
+
import { Toast } from "./Toast.js";
|
|
11
|
+
import { useUIText } from "./useUIText.js";
|
|
12
|
+
import s from "./Toast.module.css";
|
|
13
|
+
function ToastStack({
|
|
14
|
+
position,
|
|
15
|
+
messages,
|
|
16
|
+
maxVisible,
|
|
17
|
+
onDismiss
|
|
18
|
+
}) {
|
|
19
|
+
const { text } = useUIText();
|
|
20
|
+
const [host] = useState(() => document.createElement("div"));
|
|
21
|
+
const viewport = useRef(null);
|
|
22
|
+
const region = useRef(null);
|
|
23
|
+
const interaction = useRef({
|
|
24
|
+
pointer: false,
|
|
25
|
+
focus: false,
|
|
26
|
+
pinned: false,
|
|
27
|
+
suppressed: false
|
|
28
|
+
});
|
|
29
|
+
const timer = useRef(void 0);
|
|
30
|
+
const [expanded, setExpanded] = useState(false);
|
|
31
|
+
const [heights, setHeights] = useState({});
|
|
32
|
+
const newest = messages[0]?.id;
|
|
33
|
+
const sync = () => {
|
|
34
|
+
const state = interaction.current;
|
|
35
|
+
setExpanded(
|
|
36
|
+
state.pinned || !state.suppressed && (state.pointer || state.focus)
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
const collapse = () => {
|
|
40
|
+
interaction.current.pinned = false;
|
|
41
|
+
interaction.current.suppressed = true;
|
|
42
|
+
setExpanded(false);
|
|
43
|
+
region.current?.querySelector("[data-toast-expand]")?.focus({ preventScroll: true });
|
|
44
|
+
};
|
|
45
|
+
useLayoutEffect(() => {
|
|
46
|
+
const node = viewport.current;
|
|
47
|
+
host.dataset.toastLayer = "";
|
|
48
|
+
host.style.display = "contents";
|
|
49
|
+
const relocate = () => {
|
|
50
|
+
let dialogs;
|
|
51
|
+
try {
|
|
52
|
+
dialogs = document.querySelectorAll("dialog:modal");
|
|
53
|
+
} catch {
|
|
54
|
+
dialogs = document.querySelectorAll("dialog[open]");
|
|
55
|
+
}
|
|
56
|
+
const parent = dialogs.item(dialogs.length - 1) || document.body;
|
|
57
|
+
if (host.parentElement === parent) return;
|
|
58
|
+
if (node.matches(":popover-open")) node.hidePopover();
|
|
59
|
+
parent.append(host);
|
|
60
|
+
node.showPopover();
|
|
61
|
+
};
|
|
62
|
+
relocate();
|
|
63
|
+
const observer = new MutationObserver(relocate);
|
|
64
|
+
observer.observe(document.body, {
|
|
65
|
+
childList: true,
|
|
66
|
+
subtree: true,
|
|
67
|
+
attributes: true,
|
|
68
|
+
attributeFilter: ["open"]
|
|
69
|
+
});
|
|
70
|
+
return () => {
|
|
71
|
+
observer.disconnect();
|
|
72
|
+
host.remove();
|
|
73
|
+
};
|
|
74
|
+
}, [host]);
|
|
75
|
+
useLayoutEffect(() => {
|
|
76
|
+
const node = viewport.current;
|
|
77
|
+
if (node.matches(":popover-open")) node.hidePopover();
|
|
78
|
+
node.showPopover();
|
|
79
|
+
}, [newest]);
|
|
80
|
+
useEffect(() => () => clearTimeout(timer.current), []);
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
const ids = new Set(messages.map((message) => String(message.id)));
|
|
83
|
+
setHeights(
|
|
84
|
+
(old) => Object.keys(old).every((id) => ids.has(id)) ? old : Object.fromEntries(Object.entries(old).filter(([id]) => ids.has(id)))
|
|
85
|
+
);
|
|
86
|
+
if (messages.length < 2) {
|
|
87
|
+
interaction.current.pinned = false;
|
|
88
|
+
setExpanded(false);
|
|
89
|
+
}
|
|
90
|
+
}, [messages]);
|
|
91
|
+
let offset = 0;
|
|
92
|
+
const frontHeight = heights[newest] ?? 64;
|
|
93
|
+
const offsets = messages.map((toast) => {
|
|
94
|
+
const value = offset;
|
|
95
|
+
offset += (heights[toast.id] ?? 64) + 10;
|
|
96
|
+
return value;
|
|
97
|
+
});
|
|
98
|
+
const height = expanded ? offset - 10 : frontHeight + Math.min(messages.length - 1, maxVisible - 1) * 9;
|
|
99
|
+
useLayoutEffect(() => {
|
|
100
|
+
if (expanded && position.startsWith("bottom") && region.current) {
|
|
101
|
+
region.current.scrollTop = region.current.scrollHeight;
|
|
102
|
+
}
|
|
103
|
+
}, [expanded, position, height]);
|
|
104
|
+
return createPortal(
|
|
105
|
+
/* @__PURE__ */ jsx(
|
|
106
|
+
"div",
|
|
107
|
+
{
|
|
108
|
+
ref: viewport,
|
|
109
|
+
popover: "manual",
|
|
110
|
+
className: s.viewport,
|
|
111
|
+
"data-toast-viewport": true,
|
|
112
|
+
"data-position": position,
|
|
113
|
+
children: /* @__PURE__ */ jsx(
|
|
114
|
+
"div",
|
|
115
|
+
{
|
|
116
|
+
ref: region,
|
|
117
|
+
className: s.region,
|
|
118
|
+
"data-position": position,
|
|
119
|
+
"data-expanded": expanded,
|
|
120
|
+
role: "region",
|
|
121
|
+
"aria-label": text("\u901A\u77E5", "Notifications", "\u901A\u77E5"),
|
|
122
|
+
onPointerEnter: (event) => {
|
|
123
|
+
if (event.pointerType === "touch") return;
|
|
124
|
+
clearTimeout(timer.current);
|
|
125
|
+
interaction.current.pointer = true;
|
|
126
|
+
sync();
|
|
127
|
+
},
|
|
128
|
+
onPointerLeave: () => {
|
|
129
|
+
interaction.current.pointer = false;
|
|
130
|
+
timer.current = setTimeout(() => {
|
|
131
|
+
interaction.current.suppressed = false;
|
|
132
|
+
sync();
|
|
133
|
+
}, 140);
|
|
134
|
+
},
|
|
135
|
+
onFocus: (event) => {
|
|
136
|
+
clearTimeout(timer.current);
|
|
137
|
+
if (event.target.matches(":focus-visible")) {
|
|
138
|
+
interaction.current.focus = true;
|
|
139
|
+
sync();
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
onBlur: (event) => {
|
|
143
|
+
if (!event.currentTarget.contains(event.relatedTarget)) {
|
|
144
|
+
interaction.current.focus = false;
|
|
145
|
+
if (!interaction.current.pointer)
|
|
146
|
+
interaction.current.suppressed = false;
|
|
147
|
+
sync();
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
onKeyDown: (event) => {
|
|
151
|
+
if (event.key === "Escape" && expanded) {
|
|
152
|
+
event.stopPropagation();
|
|
153
|
+
collapse();
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
children: /* @__PURE__ */ jsx("div", { className: s.stack, style: { height }, children: messages.map((toast, index) => /* @__PURE__ */ jsx(
|
|
157
|
+
Toast,
|
|
158
|
+
{
|
|
159
|
+
embedded: true,
|
|
160
|
+
toast,
|
|
161
|
+
position,
|
|
162
|
+
onDismiss,
|
|
163
|
+
stackIndex: index,
|
|
164
|
+
stackOffset: expanded ? offsets[index] : index * 9,
|
|
165
|
+
stackExpanded: expanded && messages.length > 1,
|
|
166
|
+
stackHidden: !expanded && index >= maxVisible,
|
|
167
|
+
stackHeight: !expanded && index > 0 ? frontHeight : void 0,
|
|
168
|
+
stackCount: index === 0 ? messages.length : void 0,
|
|
169
|
+
onStackToggle: () => {
|
|
170
|
+
interaction.current.pinned = !expanded;
|
|
171
|
+
interaction.current.suppressed = expanded;
|
|
172
|
+
setExpanded(!expanded);
|
|
173
|
+
},
|
|
174
|
+
paused: expanded || index > 0,
|
|
175
|
+
onHeightChange: (value) => setHeights(
|
|
176
|
+
(old) => old[toast.id] === value ? old : { ...old, [toast.id]: value }
|
|
177
|
+
)
|
|
178
|
+
},
|
|
179
|
+
toast.id
|
|
180
|
+
)) })
|
|
181
|
+
}
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
),
|
|
185
|
+
host
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
export {
|
|
189
|
+
ToastStack
|
|
190
|
+
};
|