@sarunyu/system-one 4.7.4 → 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.js CHANGED
@@ -4203,6 +4203,50 @@ 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, 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
+ }, []);
4232
+ if (items.length === 0) return null;
4233
+ const enriched = items.map((item) => ({
4234
+ ...item,
4235
+ onClose: onRemove ? () => onRemove(item.id) : item.onClose
4236
+ }));
4237
+ return /* @__PURE__ */ jsx(
4238
+ "div",
4239
+ {
4240
+ className: cn(
4241
+ "fixed z-50 top-4",
4242
+ "md:right-4 md:w-[360px]",
4243
+ "max-md:left-1/2 max-md:-translate-x-1/2 max-md:w-[calc(100vw-32px)]",
4244
+ className
4245
+ ),
4246
+ children: /* @__PURE__ */ jsx(ToastStack, { items: enriched, renderItem })
4247
+ }
4248
+ );
4249
+ }
4206
4250
  const OptionList = forwardRef(
4207
4251
  function OptionList2({
4208
4252
  options,
@@ -5864,6 +5908,7 @@ export {
5864
5908
  TimeInput,
5865
5909
  Toast,
5866
5910
  ToastStack,
5911
+ Toaster,
5867
5912
  Toggle,
5868
5913
  cn,
5869
5914
  useIsMobile