sander-ui 0.1.18 → 0.1.20

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
@@ -5,8 +5,8 @@ import { B as f } from "./Badge-D1SsfPgP.js";
5
5
  import { B as T } from "./Breadcrumbs-u6K5JP-p.js";
6
6
  import { B as b } from "./Button-CZyNozz2.js";
7
7
  import { C as i, a as C, b as B, c as w } from "./Card-sDTrEkr0.js";
8
- import { C as S } from "./Checkbox-D-5XA5nS.js";
9
- import { C as u, M as H, a as g, b as I, c as M } from "./ConfirmModal-CVz_ziw_.js";
8
+ import { C as u } from "./Checkbox-D-5XA5nS.js";
9
+ import { C as A, M as H, a as g, b as I, c as M } from "./ConfirmModal-CVz_ziw_.js";
10
10
  import { C as y } from "./Container-ahtH8Cdw.js";
11
11
  import { D as F, a as R, b as h, c as v } from "./Drawer-DQlmckRl.js";
12
12
  import { D as L, a as j, b as q, c as z, d as E } from "./Dropdown-GLV9Ia6O.js";
@@ -23,10 +23,10 @@ import { S as po } from "./Spinner-BBsu1HN3.js";
23
23
  import { S as xo } from "./Switch-D7LlrXzk.js";
24
24
  import { T as no, a as To } from "./Tabs-CEWSRAh7.js";
25
25
  import { T as bo, a as co, b as io, c as Co, d as Bo, e as wo } from "./Table-BUCUALeG.js";
26
- import { T as So } from "./Text-EMaNgj_L.js";
27
- import { T as uo } from "./Textarea-Btoxtbz0.js";
28
- import { T as go, a as Io } from "./ToastContainer-hY5tgI2e.js";
29
- import { T as Po } from "./Tooltip-DENWDJQ8.js";
26
+ import { T as uo } from "./Text-EMaNgj_L.js";
27
+ import { T as Ao } from "./Textarea-Btoxtbz0.js";
28
+ import { T as go, a as Io, u as Mo } from "./useToast-BQudQhlt.js";
29
+ import { T as yo } from "./Tooltip-DENWDJQ8.js";
30
30
  export {
31
31
  r as Accordion,
32
32
  e as AccordionItem,
@@ -40,8 +40,8 @@ export {
40
40
  C as CardBody,
41
41
  B as CardFooter,
42
42
  w as CardHeader,
43
- S as Checkbox,
44
- u as ConfirmModal,
43
+ u as Checkbox,
44
+ A as ConfirmModal,
45
45
  y as Container,
46
46
  F as Drawer,
47
47
  R as DrawerBody,
@@ -75,9 +75,10 @@ export {
75
75
  Bo as TableHeader,
76
76
  wo as TableRow,
77
77
  To as Tabs,
78
- So as Text,
79
- uo as Textarea,
78
+ uo as Text,
79
+ Ao as Textarea,
80
80
  go as Toast,
81
81
  Io as ToastContainer,
82
- Po as Tooltip
82
+ yo as Tooltip,
83
+ Mo as useToast
83
84
  };
package/dist/toast.js CHANGED
@@ -1,5 +1,6 @@
1
- import { T as s, a as t } from "./ToastContainer-hY5tgI2e.js";
1
+ import { T as o, a as t, u as T } from "./useToast-BQudQhlt.js";
2
2
  export {
3
- s as Toast,
4
- t as ToastContainer
3
+ o as Toast,
4
+ t as ToastContainer,
5
+ T as useToast
5
6
  };
@@ -28,3 +28,9 @@ export type ToastContainerProps = {
28
28
  /** Callback to remove a toast from the list after the animation completes. */
29
29
  onRemove: (id: string) => void;
30
30
  };
31
+ export type UseToastOptions = {
32
+ /** Screen corner where toasts appear. @default "top-right" */
33
+ position?: ToastPosition;
34
+ /** Auto-dismiss duration in ms. @default 4000 */
35
+ duration?: number;
36
+ };
@@ -1,3 +1,5 @@
1
1
  export { Toast } from "./Toast";
2
2
  export { ToastContainer } from "./ToastContainer";
3
- export type { ToastProps, ToastContainerProps, ToastData, ToastVariant, ToastPosition } from "./Toast.types";
3
+ export { useToast } from "./useToast";
4
+ export type { ToastProps, ToastContainerProps, ToastData, ToastVariant, ToastPosition, UseToastOptions } from "./Toast.types";
5
+ export type { ToastFn, UseToastReturn } from "./useToast";
@@ -0,0 +1,28 @@
1
+ import type { FC } from "react";
2
+ import type { ToastVariant, ToastData, UseToastOptions } from "./Toast.types";
3
+ type ToastOptions = {
4
+ variant?: ToastVariant;
5
+ duration?: number;
6
+ };
7
+ type ToastUpdate = {
8
+ message?: string;
9
+ variant?: ToastVariant;
10
+ duration?: number;
11
+ };
12
+ export type ToastFn = {
13
+ (message: string, options?: ToastOptions): string;
14
+ success: (message: string, options?: Omit<ToastOptions, "variant">) => string;
15
+ error: (message: string, options?: Omit<ToastOptions, "variant">) => string;
16
+ warning: (message: string, options?: Omit<ToastOptions, "variant">) => string;
17
+ info: (message: string, options?: Omit<ToastOptions, "variant">) => string;
18
+ loading: (message: string, options?: Omit<ToastOptions, "variant">) => string;
19
+ update: (id: string, update: ToastUpdate) => void;
20
+ };
21
+ export type UseToastReturn = {
22
+ toasts: ToastData[];
23
+ toast: ToastFn;
24
+ dismiss: (id: string) => void;
25
+ Toasts: FC;
26
+ };
27
+ export declare function useToast(options?: UseToastOptions): UseToastReturn;
28
+ export {};
@@ -49,7 +49,8 @@ export { Text } from "./Text";
49
49
  export type { TextProps } from "./Text";
50
50
  export { Textarea } from "./Textarea";
51
51
  export type { TextareaProps } from "./Textarea";
52
- export { Toast, ToastContainer } from "./Toast";
53
- export type { ToastProps, ToastContainerProps, ToastData, ToastVariant, ToastPosition } from "./Toast";
52
+ export { Toast, ToastContainer, useToast } from "./Toast";
53
+ export type { ToastProps, ToastContainerProps, ToastData, ToastVariant, ToastPosition, UseToastOptions } from "./Toast";
54
+ export type { ToastFn, UseToastReturn } from "./Toast";
54
55
  export { Tooltip } from "./Tooltip";
55
56
  export type { TooltipPlacement, TooltipProps } from "./Tooltip";
@@ -0,0 +1,171 @@
1
+ import { useRef as w, useEffect as A, useSyncExternalStore as T, useMemo as S, createElement as N } from "react";
2
+ import { jsxs as C, jsx as f } from "react/jsx-runtime";
3
+ import { c as h } from "./index-p1eeF8LQ.js";
4
+ import { c as y } from "./createLucideIcon-CP-mMPfa.js";
5
+ import { I as b, T as D, C as E, a as M } from "./triangle-alert-CvNSSzY6.js";
6
+ import { X as x } from "./x-B9bYxG31.js";
7
+ const R = [["path", { d: "M21 12a9 9 0 1 1-6.219-8.56", key: "13zald" }]], k = y("loader-circle", R), z = "_container_d8npe_1", j = "_toast_d8npe_79", L = "_dismissing_d8npe_95", O = "_icon_d8npe_115", P = "_iconSpin_d8npe_119", U = "_spin_d8npe_1", $ = "_message_d8npe_123", B = "_dismiss_d8npe_95", V = "_success_d8npe_159", X = "_error_d8npe_165", q = "_warning_d8npe_171", F = "_info_d8npe_177", G = "_loading_d8npe_183", m = {
8
+ container: z,
9
+ "bottom-right": "_bottom-right_d8npe_25",
10
+ "bottom-left": "_bottom-left_d8npe_26",
11
+ "top-right": "_top-right_d8npe_30",
12
+ "top-left": "_top-left_d8npe_31",
13
+ toast: j,
14
+ "slide-in-bottom": "_slide-in-bottom_d8npe_1",
15
+ dismissing: L,
16
+ "slide-out-bottom": "_slide-out-bottom_d8npe_1",
17
+ "slide-in-top": "_slide-in-top_d8npe_1",
18
+ "slide-out-top": "_slide-out-top_d8npe_1",
19
+ icon: O,
20
+ iconSpin: P,
21
+ spin: U,
22
+ message: $,
23
+ dismiss: B,
24
+ default: "_default_d8npe_153",
25
+ success: V,
26
+ error: X,
27
+ warning: q,
28
+ info: F,
29
+ loading: G,
30
+ "slide-in-right": "_slide-in-right_d8npe_1",
31
+ "slide-out-right": "_slide-out-right_d8npe_1",
32
+ "slide-in-left": "_slide-in-left_d8npe_1",
33
+ "slide-out-left": "_slide-out-left_d8npe_1"
34
+ }, H = {
35
+ default: b,
36
+ success: M,
37
+ error: E,
38
+ warning: D,
39
+ info: b,
40
+ loading: k
41
+ }, J = ({ toast: n, onDismiss: o, onRemove: l }) => {
42
+ const d = n.variant === "error", s = H[n.variant];
43
+ return /* @__PURE__ */ C(
44
+ "div",
45
+ {
46
+ role: d ? "alert" : "status",
47
+ "aria-atomic": "true",
48
+ className: h(
49
+ m.toast,
50
+ m[n.variant],
51
+ n.dismissing && m.dismissing
52
+ ),
53
+ onAnimationEnd: () => {
54
+ n.dismissing && l(n.id);
55
+ },
56
+ children: [
57
+ /* @__PURE__ */ f(
58
+ s,
59
+ {
60
+ size: 18,
61
+ className: h(
62
+ m.icon,
63
+ n.variant === "loading" && m.iconSpin
64
+ ),
65
+ "aria-hidden": "true"
66
+ }
67
+ ),
68
+ /* @__PURE__ */ f("p", { className: m.message, children: n.message }),
69
+ /* @__PURE__ */ f(
70
+ "button",
71
+ {
72
+ onClick: () => o(n.id),
73
+ "aria-label": "Dismiss notification",
74
+ className: m.dismiss,
75
+ children: /* @__PURE__ */ f(x, { size: 16 })
76
+ }
77
+ )
78
+ ]
79
+ }
80
+ );
81
+ }, K = ({
82
+ toasts: n,
83
+ position: o = "top-right",
84
+ onDismiss: l,
85
+ onRemove: d
86
+ }) => {
87
+ const s = w(null), u = n.length > 0;
88
+ return A(() => {
89
+ const r = s.current;
90
+ r && (u && !r.matches(":popover-open") ? r.showPopover() : !u && r.matches(":popover-open") && r.hidePopover());
91
+ }, [u]), /* @__PURE__ */ f(
92
+ "div",
93
+ {
94
+ ref: s,
95
+ popover: "manual",
96
+ className: h(m.container, m[o]),
97
+ "aria-live": "polite",
98
+ "aria-relevant": "additions",
99
+ children: n.map((r) => /* @__PURE__ */ f(J, { toast: r, onDismiss: l, onRemove: d }, r.id))
100
+ }
101
+ );
102
+ };
103
+ let Q = 0;
104
+ const W = () => `toast-${++Q}-${Date.now()}`, Y = 4e3, Z = {
105
+ default: !0,
106
+ success: !0,
107
+ info: !0,
108
+ warning: !0,
109
+ error: !1,
110
+ loading: !1
111
+ };
112
+ function ss(n) {
113
+ let o = [];
114
+ const l = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Map(), s = () => l.forEach((e) => e()), u = (e) => (l.add(e), () => {
115
+ l.delete(e);
116
+ }), r = () => o, g = (e) => {
117
+ const t = d.get(e);
118
+ t && (clearTimeout(t), d.delete(e));
119
+ }, v = (e) => {
120
+ g(e), o = o.map(
121
+ (t) => t.id === e ? { ...t, dismissing: !0 } : t
122
+ ), s();
123
+ }, a = (e) => {
124
+ o = o.filter((t) => t.id !== e), s();
125
+ }, i = (e, t, _) => {
126
+ if (!Z[t] && _ === void 0) return;
127
+ const I = setTimeout(() => v(e), _ ?? n);
128
+ d.set(e, I);
129
+ };
130
+ return { subscribe: u, getSnapshot: r, addToast: (e, t = {}) => {
131
+ const _ = W(), p = t.variant ?? "default";
132
+ return o = [...o, { id: _, message: e, variant: p }], s(), i(_, p, t.duration), _;
133
+ }, dismiss: v, remove: a, update: (e, t) => {
134
+ g(e), o = o.map((p) => p.id !== e ? p : {
135
+ ...p,
136
+ ...t.message !== void 0 && { message: t.message },
137
+ ...t.variant !== void 0 && { variant: t.variant },
138
+ dismissing: !1
139
+ }), s();
140
+ const _ = t.variant;
141
+ _ && i(e, _, t.duration);
142
+ } };
143
+ }
144
+ function ds(n = {}) {
145
+ const { position: o = "top-right", duration: l = Y } = n, d = w(null);
146
+ d.current || (d.current = ss(l));
147
+ const s = d.current, u = T(s.subscribe, s.getSnapshot), r = s.dismiss, g = S(() => {
148
+ const a = (i, c) => s.addToast(i, c);
149
+ return a.success = (i, c) => s.addToast(i, { ...c, variant: "success" }), a.error = (i, c) => s.addToast(i, { ...c, variant: "error" }), a.warning = (i, c) => s.addToast(i, { ...c, variant: "warning" }), a.info = (i, c) => s.addToast(i, { ...c, variant: "info" }), a.loading = (i, c) => s.addToast(i, { ...c, variant: "loading" }), a.update = s.update, a;
150
+ }, [s]), v = S(() => {
151
+ const a = () => {
152
+ const i = T(
153
+ s.subscribe,
154
+ s.getSnapshot
155
+ );
156
+ return N(K, {
157
+ toasts: i,
158
+ position: o,
159
+ onDismiss: s.dismiss,
160
+ onRemove: s.remove
161
+ });
162
+ };
163
+ return a.displayName = "Toasts", a;
164
+ }, [s, o]);
165
+ return { toasts: u, toast: g, dismiss: r, Toasts: v };
166
+ }
167
+ export {
168
+ J as T,
169
+ K as a,
170
+ ds as u
171
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sander-ui",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "type": "module",
5
5
  "description": "A modern React component library built with TypeScript and CSS Modules",
6
6
  "main": "./dist/index.js",
@@ -1,103 +0,0 @@
1
- import { jsxs as l, jsx as s } from "react/jsx-runtime";
2
- import { c as a } from "./index-p1eeF8LQ.js";
3
- import { useRef as p, useEffect as m } from "react";
4
- import { c as g } from "./createLucideIcon-CP-mMPfa.js";
5
- import { I as c, T as f, C as u, a as h } from "./triangle-alert-CvNSSzY6.js";
6
- import { X as v } from "./x-B9bYxG31.js";
7
- const b = [["path", { d: "M21 12a9 9 0 1 1-6.219-8.56", key: "13zald" }]], C = g("loader-circle", b), N = "_container_d8npe_1", T = "_toast_d8npe_79", w = "_dismissing_d8npe_95", I = "_icon_d8npe_115", S = "_iconSpin_d8npe_119", k = "_spin_d8npe_1", x = "_message_d8npe_123", z = "_dismiss_d8npe_95", A = "_success_d8npe_159", E = "_error_d8npe_165", j = "_warning_d8npe_171", y = "_info_d8npe_177", L = "_loading_d8npe_183", n = {
8
- container: N,
9
- "bottom-right": "_bottom-right_d8npe_25",
10
- "bottom-left": "_bottom-left_d8npe_26",
11
- "top-right": "_top-right_d8npe_30",
12
- "top-left": "_top-left_d8npe_31",
13
- toast: T,
14
- "slide-in-bottom": "_slide-in-bottom_d8npe_1",
15
- dismissing: w,
16
- "slide-out-bottom": "_slide-out-bottom_d8npe_1",
17
- "slide-in-top": "_slide-in-top_d8npe_1",
18
- "slide-out-top": "_slide-out-top_d8npe_1",
19
- icon: I,
20
- iconSpin: S,
21
- spin: k,
22
- message: x,
23
- dismiss: z,
24
- default: "_default_d8npe_153",
25
- success: A,
26
- error: E,
27
- warning: j,
28
- info: y,
29
- loading: L,
30
- "slide-in-right": "_slide-in-right_d8npe_1",
31
- "slide-out-right": "_slide-out-right_d8npe_1",
32
- "slide-in-left": "_slide-in-left_d8npe_1",
33
- "slide-out-left": "_slide-out-left_d8npe_1"
34
- }, P = {
35
- default: c,
36
- success: h,
37
- error: u,
38
- warning: f,
39
- info: c,
40
- loading: C
41
- }, B = ({ toast: i, onDismiss: t, onRemove: r }) => {
42
- const d = i.variant === "error", o = P[i.variant];
43
- return /* @__PURE__ */ l(
44
- "div",
45
- {
46
- role: d ? "alert" : "status",
47
- "aria-atomic": "true",
48
- className: a(
49
- n.toast,
50
- n[i.variant],
51
- i.dismissing && n.dismissing
52
- ),
53
- onAnimationEnd: () => {
54
- i.dismissing && r(i.id);
55
- },
56
- children: [
57
- /* @__PURE__ */ s(
58
- o,
59
- {
60
- size: 18,
61
- className: a(n.icon, i.variant === "loading" && n.iconSpin),
62
- "aria-hidden": "true"
63
- }
64
- ),
65
- /* @__PURE__ */ s("p", { className: n.message, children: i.message }),
66
- /* @__PURE__ */ s(
67
- "button",
68
- {
69
- onClick: () => t(i.id),
70
- "aria-label": "Dismiss notification",
71
- className: n.dismiss,
72
- children: /* @__PURE__ */ s(v, { size: 16 })
73
- }
74
- )
75
- ]
76
- }
77
- );
78
- }, G = ({
79
- toasts: i,
80
- position: t = "top-right",
81
- onDismiss: r,
82
- onRemove: d
83
- }) => {
84
- const o = p(null), _ = i.length > 0;
85
- return m(() => {
86
- const e = o.current;
87
- e && (_ && !e.matches(":popover-open") ? e.showPopover() : !_ && e.matches(":popover-open") && e.hidePopover());
88
- }, [_]), /* @__PURE__ */ s(
89
- "div",
90
- {
91
- ref: o,
92
- popover: "manual",
93
- className: a(n.container, n[t]),
94
- "aria-live": "polite",
95
- "aria-relevant": "additions",
96
- children: i.map((e) => /* @__PURE__ */ s(B, { toast: e, onDismiss: r, onRemove: d }, e.id))
97
- }
98
- );
99
- };
100
- export {
101
- B as T,
102
- G as a
103
- };