@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.cjs CHANGED
@@ -4222,6 +4222,50 @@ 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, 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
+ }, []);
4251
+ if (items.length === 0) return null;
4252
+ const enriched = items.map((item) => ({
4253
+ ...item,
4254
+ onClose: onRemove ? () => onRemove(item.id) : item.onClose
4255
+ }));
4256
+ return /* @__PURE__ */ jsxRuntime.jsx(
4257
+ "div",
4258
+ {
4259
+ className: cn(
4260
+ "fixed z-50 top-4",
4261
+ "md:right-4 md:w-[360px]",
4262
+ "max-md:left-1/2 max-md:-translate-x-1/2 max-md:w-[calc(100vw-32px)]",
4263
+ className
4264
+ ),
4265
+ children: /* @__PURE__ */ jsxRuntime.jsx(ToastStack, { items: enriched, renderItem })
4266
+ }
4267
+ );
4268
+ }
4225
4269
  const OptionList = React.forwardRef(
4226
4270
  function OptionList2({
4227
4271
  options,
@@ -5882,6 +5926,7 @@ exports.TextArea = TextArea;
5882
5926
  exports.TimeInput = TimeInput;
5883
5927
  exports.Toast = Toast;
5884
5928
  exports.ToastStack = ToastStack;
5929
+ exports.Toaster = Toaster;
5885
5930
  exports.Toggle = Toggle;
5886
5931
  exports.cn = cn;
5887
5932
  exports.useIsMobile = useIsMobile;