@sarunyu/system-one 4.7.5 → 4.7.6
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/dist/index.cjs +31 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +31 -4
- package/dist/index.js.map +1 -1
- package/dist/src/components/toast.d.ts +13 -1
- package/dist/src/components/toast.d.ts.map +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4203,20 +4203,47 @@ function ToastStack({ items, className, renderItem }) {
|
|
|
4203
4203
|
(item) => renderItem ? /* @__PURE__ */ jsx("div", { children: renderItem(item) }, item.id) : /* @__PURE__ */ jsx(Toast, { ...item }, item.id)
|
|
4204
4204
|
) });
|
|
4205
4205
|
}
|
|
4206
|
-
function Toaster({ items, renderItem, className }) {
|
|
4206
|
+
function Toaster({ items, renderItem, className, duration = 4e3, onRemove }) {
|
|
4207
|
+
const timers = useRef(/* @__PURE__ */ new Map());
|
|
4208
|
+
useEffect(() => {
|
|
4209
|
+
if (!onRemove || duration === 0) return;
|
|
4210
|
+
items.forEach((item) => {
|
|
4211
|
+
if (!timers.current.has(item.id)) {
|
|
4212
|
+
const t = setTimeout(() => {
|
|
4213
|
+
onRemove(item.id);
|
|
4214
|
+
timers.current.delete(item.id);
|
|
4215
|
+
}, duration);
|
|
4216
|
+
timers.current.set(item.id, t);
|
|
4217
|
+
}
|
|
4218
|
+
});
|
|
4219
|
+
const live = new Set(items.map((i) => i.id));
|
|
4220
|
+
timers.current.forEach((t, id) => {
|
|
4221
|
+
if (!live.has(id)) {
|
|
4222
|
+
clearTimeout(t);
|
|
4223
|
+
timers.current.delete(id);
|
|
4224
|
+
}
|
|
4225
|
+
});
|
|
4226
|
+
});
|
|
4227
|
+
useEffect(() => {
|
|
4228
|
+
return () => {
|
|
4229
|
+
timers.current.forEach(clearTimeout);
|
|
4230
|
+
};
|
|
4231
|
+
}, []);
|
|
4207
4232
|
if (items.length === 0) return null;
|
|
4233
|
+
const enriched = items.map((item) => ({
|
|
4234
|
+
...item,
|
|
4235
|
+
onClose: onRemove ? () => onRemove(item.id) : item.onClose
|
|
4236
|
+
}));
|
|
4208
4237
|
return /* @__PURE__ */ jsx(
|
|
4209
4238
|
"div",
|
|
4210
4239
|
{
|
|
4211
4240
|
className: cn(
|
|
4212
4241
|
"fixed z-50 top-4",
|
|
4213
|
-
// desktop: top-right, fixed width
|
|
4214
4242
|
"md:right-4 md:w-[360px]",
|
|
4215
|
-
// tablet & mobile: horizontally centered, full width minus padding
|
|
4216
4243
|
"max-md:left-1/2 max-md:-translate-x-1/2 max-md:w-[calc(100vw-32px)]",
|
|
4217
4244
|
className
|
|
4218
4245
|
),
|
|
4219
|
-
children: /* @__PURE__ */ jsx(ToastStack, { items, renderItem })
|
|
4246
|
+
children: /* @__PURE__ */ jsx(ToastStack, { items: enriched, renderItem })
|
|
4220
4247
|
}
|
|
4221
4248
|
);
|
|
4222
4249
|
}
|