@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 CHANGED
@@ -4222,20 +4222,47 @@ function ToastStack({ items, className, renderItem }) {
4222
4222
  (item) => renderItem ? /* @__PURE__ */ jsxRuntime.jsx("div", { children: renderItem(item) }, item.id) : /* @__PURE__ */ jsxRuntime.jsx(Toast, { ...item }, item.id)
4223
4223
  ) });
4224
4224
  }
4225
- function Toaster({ items, renderItem, className }) {
4225
+ function Toaster({ items, renderItem, className, duration = 4e3, onRemove }) {
4226
+ const timers = React.useRef(/* @__PURE__ */ new Map());
4227
+ React.useEffect(() => {
4228
+ if (!onRemove || duration === 0) return;
4229
+ items.forEach((item) => {
4230
+ if (!timers.current.has(item.id)) {
4231
+ const t = setTimeout(() => {
4232
+ onRemove(item.id);
4233
+ timers.current.delete(item.id);
4234
+ }, duration);
4235
+ timers.current.set(item.id, t);
4236
+ }
4237
+ });
4238
+ const live = new Set(items.map((i) => i.id));
4239
+ timers.current.forEach((t, id) => {
4240
+ if (!live.has(id)) {
4241
+ clearTimeout(t);
4242
+ timers.current.delete(id);
4243
+ }
4244
+ });
4245
+ });
4246
+ React.useEffect(() => {
4247
+ return () => {
4248
+ timers.current.forEach(clearTimeout);
4249
+ };
4250
+ }, []);
4226
4251
  if (items.length === 0) return null;
4252
+ const enriched = items.map((item) => ({
4253
+ ...item,
4254
+ onClose: onRemove ? () => onRemove(item.id) : item.onClose
4255
+ }));
4227
4256
  return /* @__PURE__ */ jsxRuntime.jsx(
4228
4257
  "div",
4229
4258
  {
4230
4259
  className: cn(
4231
4260
  "fixed z-50 top-4",
4232
- // desktop: top-right, fixed width
4233
4261
  "md:right-4 md:w-[360px]",
4234
- // tablet & mobile: horizontally centered, full width minus padding
4235
4262
  "max-md:left-1/2 max-md:-translate-x-1/2 max-md:w-[calc(100vw-32px)]",
4236
4263
  className
4237
4264
  ),
4238
- children: /* @__PURE__ */ jsxRuntime.jsx(ToastStack, { items, renderItem })
4265
+ children: /* @__PURE__ */ jsxRuntime.jsx(ToastStack, { items: enriched, renderItem })
4239
4266
  }
4240
4267
  );
4241
4268
  }