@doscientos/ui 0.1.12 → 0.1.13

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.d.cts CHANGED
@@ -566,13 +566,12 @@ type ToastPromiseOptions<T> = {
566
566
  description?: string;
567
567
  position?: ToastPosition;
568
568
  };
569
- declare function dismiss(id: string): void;
570
569
  declare const toast: ((options: ToastOptions) => string) & {
571
570
  success: (title: string, options?: Omit<ToastOptions, "title" | "variant">) => string;
572
571
  error: (title: string, options?: Omit<ToastOptions, "title" | "variant">) => string;
573
572
  warning: (title: string, options?: Omit<ToastOptions, "title" | "variant">) => string;
574
573
  info: (title: string, options?: Omit<ToastOptions, "title" | "variant">) => string;
575
- dismiss: typeof dismiss;
574
+ dismiss: (id: string) => void;
576
575
  promise: <T>(promise: Promise<T>, options: ToastPromiseOptions<T>) => Promise<T>;
577
576
  };
578
577
  declare function useToast(): ((options: ToastOptions) => string) & {
@@ -580,7 +579,7 @@ declare function useToast(): ((options: ToastOptions) => string) & {
580
579
  error: (title: string, options?: Omit<ToastOptions, "title" | "variant">) => string;
581
580
  warning: (title: string, options?: Omit<ToastOptions, "title" | "variant">) => string;
582
581
  info: (title: string, options?: Omit<ToastOptions, "title" | "variant">) => string;
583
- dismiss: typeof dismiss;
582
+ dismiss: (id: string) => void;
584
583
  promise: <T>(promise: Promise<T>, options: ToastPromiseOptions<T>) => Promise<T>;
585
584
  };
586
585
  declare function ToastProvider({ children }: {
@@ -594,9 +593,9 @@ declare function ToastViewport({ position, visiblePosition, className }: {
594
593
  visiblePosition?: ToastPosition;
595
594
  className?: string;
596
595
  }): React$1.JSX.Element | null;
597
- declare function Toast({ id, title, description, variant, action, state, duration, onDismiss }: ToastData & {
596
+ declare function Toast({ id, title, description, variant, action, state, duration, position, onDismiss }: ToastData & {
598
597
  onDismiss?: () => void;
599
- }): React$1.JSX.Element;
598
+ }): null;
600
599
 
601
600
  declare function Toolbar({ className, ...props }: React$1.ComponentProps<"div">): React$1.JSX.Element;
602
601
  declare function ToolbarGroup({ className, ...props }: React$1.ComponentProps<"div">): React$1.JSX.Element;
package/dist/index.d.ts CHANGED
@@ -566,13 +566,12 @@ type ToastPromiseOptions<T> = {
566
566
  description?: string;
567
567
  position?: ToastPosition;
568
568
  };
569
- declare function dismiss(id: string): void;
570
569
  declare const toast: ((options: ToastOptions) => string) & {
571
570
  success: (title: string, options?: Omit<ToastOptions, "title" | "variant">) => string;
572
571
  error: (title: string, options?: Omit<ToastOptions, "title" | "variant">) => string;
573
572
  warning: (title: string, options?: Omit<ToastOptions, "title" | "variant">) => string;
574
573
  info: (title: string, options?: Omit<ToastOptions, "title" | "variant">) => string;
575
- dismiss: typeof dismiss;
574
+ dismiss: (id: string) => void;
576
575
  promise: <T>(promise: Promise<T>, options: ToastPromiseOptions<T>) => Promise<T>;
577
576
  };
578
577
  declare function useToast(): ((options: ToastOptions) => string) & {
@@ -580,7 +579,7 @@ declare function useToast(): ((options: ToastOptions) => string) & {
580
579
  error: (title: string, options?: Omit<ToastOptions, "title" | "variant">) => string;
581
580
  warning: (title: string, options?: Omit<ToastOptions, "title" | "variant">) => string;
582
581
  info: (title: string, options?: Omit<ToastOptions, "title" | "variant">) => string;
583
- dismiss: typeof dismiss;
582
+ dismiss: (id: string) => void;
584
583
  promise: <T>(promise: Promise<T>, options: ToastPromiseOptions<T>) => Promise<T>;
585
584
  };
586
585
  declare function ToastProvider({ children }: {
@@ -594,9 +593,9 @@ declare function ToastViewport({ position, visiblePosition, className }: {
594
593
  visiblePosition?: ToastPosition;
595
594
  className?: string;
596
595
  }): React$1.JSX.Element | null;
597
- declare function Toast({ id, title, description, variant, action, state, duration, onDismiss }: ToastData & {
596
+ declare function Toast({ id, title, description, variant, action, state, duration, position, onDismiss }: ToastData & {
598
597
  onDismiss?: () => void;
599
- }): React$1.JSX.Element;
598
+ }): null;
600
599
 
601
600
  declare function Toolbar({ className, ...props }: React$1.ComponentProps<"div">): React$1.JSX.Element;
602
601
  declare function ToolbarGroup({ className, ...props }: React$1.ComponentProps<"div">): React$1.JSX.Element;
package/dist/index.js CHANGED
@@ -32,12 +32,12 @@ function useAutosave({
32
32
  }, []);
33
33
  useEffect(() => {
34
34
  if (!enabled) return;
35
- const snapshot2 = serializeRef.current(data);
35
+ const snapshot = serializeRef.current(data);
36
36
  if (lastSaved.current === null) {
37
- lastSaved.current = snapshot2;
37
+ lastSaved.current = snapshot;
38
38
  return;
39
39
  }
40
- if (snapshot2 === lastSaved.current) return;
40
+ if (snapshot === lastSaved.current) return;
41
41
  const timeout = window.setTimeout(() => void save(data), debounceMs);
42
42
  return () => window.clearTimeout(timeout);
43
43
  }, [data, debounceMs, enabled, save]);
@@ -2609,47 +2609,41 @@ function TabsContent({ className, ...props }) {
2609
2609
  }
2610
2610
 
2611
2611
  // src/ui/toast/toast.tsx
2612
- import { useEffect as useEffect5, useSyncExternalStore } from "react";
2613
- import { CheckCircle as CheckCircle2, Info, CircleAlert as CircleAlert2, XCircle, X as X3 } from "lucide-react";
2612
+ import { useEffect as useEffect5 } from "react";
2613
+ import { sileo, Toaster as SileoToaster } from "sileo";
2614
2614
  import { Fragment as Fragment11, jsx as jsx45, jsxs as jsxs21 } from "react/jsx-runtime";
2615
- var records = [];
2616
- var listeners = /* @__PURE__ */ new Set();
2617
- var snapshot = () => records;
2618
- var emit = () => listeners.forEach((listener) => listener());
2619
- var subscribe = (listener) => {
2620
- listeners.add(listener);
2621
- return () => listeners.delete(listener);
2622
- };
2623
- var remove = (id) => {
2624
- records = records.filter((record) => record.id !== id);
2625
- emit();
2626
- };
2627
- function create(options) {
2628
- const id = `${Date.now()}-${Math.random().toString(36).slice(2)}`;
2629
- records = [...records, { ...options, id, state: "open", variant: options.variant ?? "default", duration: options.duration ?? 5e3, position: options.position ?? "bottom-right" }];
2630
- emit();
2631
- return id;
2632
- }
2633
- function dismiss(id) {
2634
- if (!records.some((record) => record.id === id && record.state === "open")) return;
2635
- records = records.map((record) => record.id === id ? { ...record, state: "closing" } : record);
2636
- emit();
2637
- window.setTimeout(() => remove(id), 180);
2615
+ function toSileoOptions({ title, description, duration, position, action }) {
2616
+ return {
2617
+ title,
2618
+ description,
2619
+ duration: duration === 0 ? null : duration,
2620
+ position,
2621
+ button: action ? { title: action.label, onClick: action.onPress } : void 0
2622
+ };
2638
2623
  }
2639
- function update(id, patch) {
2640
- records = records.map((record) => record.id === id ? { ...record, ...patch, state: "open" } : record);
2641
- emit();
2624
+ function create(options) {
2625
+ const sileoOptions = toSileoOptions(options);
2626
+ if (options.action) return sileo.action(sileoOptions);
2627
+ if (options.variant === "success") return sileo.success(sileoOptions);
2628
+ if (options.variant === "error") return sileo.error(sileoOptions);
2629
+ if (options.variant === "warning") return sileo.warning(sileoOptions);
2630
+ if (options.variant === "info") return sileo.info(sileoOptions);
2631
+ return sileo.show(sileoOptions);
2642
2632
  }
2643
2633
  var toast = Object.assign((options) => create(options), {
2644
2634
  success: (title, options) => create({ ...options, title, variant: "success" }),
2645
2635
  error: (title, options) => create({ ...options, title, variant: "error" }),
2646
2636
  warning: (title, options) => create({ ...options, title, variant: "warning" }),
2647
2637
  info: (title, options) => create({ ...options, title, variant: "info" }),
2648
- dismiss,
2638
+ dismiss: (id) => sileo.dismiss(id),
2649
2639
  promise: (promise, options) => {
2650
- const id = create({ title: options.loading, description: options.description, variant: "default", duration: 0, position: options.position });
2651
- promise.then((value) => update(id, { title: typeof options.success === "function" ? options.success(value) : options.success, variant: "success", duration: 4e3 })).catch((error) => update(id, { title: typeof options.error === "function" ? options.error(error) : options.error, variant: "error", duration: 6e3 }));
2652
- return promise;
2640
+ const shared = { description: options.description, position: options.position };
2641
+ return sileo.promise(promise, {
2642
+ loading: { ...shared, title: options.loading },
2643
+ success: (value) => ({ ...shared, title: typeof options.success === "function" ? options.success(value) : options.success }),
2644
+ error: (error) => ({ ...shared, title: typeof options.error === "function" ? options.error(error) : options.error }),
2645
+ position: options.position
2646
+ });
2653
2647
  }
2654
2648
  });
2655
2649
  function useToast() {
@@ -2661,38 +2655,24 @@ function ToastProvider({ children }) {
2661
2655
  /* @__PURE__ */ jsx45(Toaster, {})
2662
2656
  ] });
2663
2657
  }
2664
- var positionClasses = {
2665
- "top-left": "top-4 left-4 items-start",
2666
- "top-center": "top-4 left-1/2 -translate-x-1/2 items-center",
2667
- "top-right": "top-4 right-4 items-end",
2668
- "bottom-left": "bottom-4 left-4 items-start",
2669
- "bottom-center": "bottom-4 left-1/2 -translate-x-1/2 items-center",
2670
- "bottom-right": "bottom-4 right-4 items-end"
2671
- };
2672
- function Toaster({ position = "bottom-right" }) {
2673
- return /* @__PURE__ */ jsx45(Fragment11, { children: Object.keys(positionClasses).map((item) => /* @__PURE__ */ jsx45(ToastViewport, { position: item, visiblePosition: position }, item)) });
2658
+ function Toaster({ position }) {
2659
+ return /* @__PURE__ */ jsx45(SileoToaster, { position });
2674
2660
  }
2675
2661
  function ToastViewport({ position, visiblePosition, className }) {
2676
- const toasts = useSyncExternalStore(subscribe, snapshot, snapshot).filter((item) => item.position === position);
2677
- if (visiblePosition && position !== visiblePosition && toasts.length === 0) return null;
2678
- return /* @__PURE__ */ jsx45("div", { "aria-label": `Notificaciones ${position}`, className: cn("pointer-events-none fixed z-50 flex w-[min(24rem,calc(100vw-2rem))] flex-col gap-2", positionClasses[position], className), children: toasts.map((item) => /* @__PURE__ */ jsx45(Toast, { ...item, onDismiss: () => dismiss(item.id) }, item.id)) });
2662
+ void className;
2663
+ if (visiblePosition && visiblePosition !== position) return null;
2664
+ return /* @__PURE__ */ jsx45(Toaster, { position });
2679
2665
  }
2680
- function Toast({ id, title, description, variant = "default", action, state = "open", duration = 0, onDismiss }) {
2666
+ function Toast({ id, title, description, variant = "default", action, state = "open", duration = 0, position, onDismiss }) {
2681
2667
  useEffect5(() => {
2682
- if (state !== "open" || duration <= 0) return;
2683
- const timeout = window.setTimeout(() => dismiss(id), duration);
2684
- return () => window.clearTimeout(timeout);
2685
- }, [duration, id, state]);
2686
- const Icon = variant === "success" ? CheckCircle2 : variant === "error" ? XCircle : variant === "warning" ? CircleAlert2 : variant === "info" ? Info : Info;
2687
- return /* @__PURE__ */ jsx45("div", { role: variant === "error" ? "alert" : "status", "data-state": state, className: cn("pointer-events-auto w-full overflow-hidden rounded-xl border border-border/80 bg-background/95 p-3.5 text-foreground shadow-xl shadow-black/10 backdrop-blur-md animate-ui-toast-in", "data-[state=closing]:animate-ui-toast-out motion-reduce:animate-none", variant === "success" && "border-success/30", variant === "error" && "border-destructive/30", variant === "warning" && "border-warning/40"), children: /* @__PURE__ */ jsxs21("div", { className: "flex items-start gap-3", children: [
2688
- /* @__PURE__ */ jsx45(Icon, { "aria-hidden": "true", className: cn("mt-0.5 size-5 shrink-0", variant === "success" && "text-success", variant === "error" && "text-destructive", variant === "warning" && "text-warning", variant === "info" && "text-primary") }),
2689
- /* @__PURE__ */ jsxs21("div", { className: "min-w-0 flex-1", children: [
2690
- /* @__PURE__ */ jsx45("p", { className: "animate-ui-toast-title text-sm font-semibold", children: title }),
2691
- description && /* @__PURE__ */ jsx45("p", { className: "mt-1 max-h-20 animate-ui-toast-description overflow-hidden text-sm leading-5 text-muted-foreground data-[state=closing]:max-h-0", "data-state": state, children: description }),
2692
- action && /* @__PURE__ */ jsx45(Button, { size: "sm", variant: "link", onPress: action.onPress, className: "mt-1 h-auto px-0", children: action.label })
2693
- ] }),
2694
- /* @__PURE__ */ jsx45(Button, { "aria-label": "Cerrar notificaci\xF3n", onPress: onDismiss, size: "icon", variant: "ghost", className: "-mr-2 -mt-2 size-7", children: /* @__PURE__ */ jsx45(X3, {}) })
2695
- ] }) });
2668
+ if (state !== "open") return;
2669
+ const toastId = create({ title, description, variant, action, duration, position });
2670
+ return () => {
2671
+ sileo.dismiss(toastId);
2672
+ onDismiss?.();
2673
+ };
2674
+ }, [action, description, duration, id, onDismiss, position, state, title, variant]);
2675
+ return null;
2696
2676
  }
2697
2677
 
2698
2678
  // src/ui/toolbar/toolbar.tsx