sander-ui 0.1.18 → 0.1.19

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-BX2dQTGH.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-BX2dQTGH.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,170 @@
1
+ import { useRef as I, useEffect as D, useState as M, useCallback as p, useMemo as b, createElement as y } from "react";
2
+ import { jsxs as k, jsx as u } from "react/jsx-runtime";
3
+ import { c as h } from "./index-p1eeF8LQ.js";
4
+ import { c as E } from "./createLucideIcon-CP-mMPfa.js";
5
+ import { I as w, T as x, C as z, a as R } from "./triangle-alert-CvNSSzY6.js";
6
+ import { X as j } from "./x-B9bYxG31.js";
7
+ const L = [["path", { d: "M21 12a9 9 0 1 1-6.219-8.56", key: "13zald" }]], O = E("loader-circle", L), P = "_container_d8npe_1", U = "_toast_d8npe_79", $ = "_dismissing_d8npe_95", B = "_icon_d8npe_115", V = "_iconSpin_d8npe_119", X = "_spin_d8npe_1", q = "_message_d8npe_123", F = "_dismiss_d8npe_95", G = "_success_d8npe_159", H = "_error_d8npe_165", J = "_warning_d8npe_171", K = "_info_d8npe_177", Q = "_loading_d8npe_183", r = {
8
+ container: P,
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: U,
14
+ "slide-in-bottom": "_slide-in-bottom_d8npe_1",
15
+ dismissing: $,
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: B,
20
+ iconSpin: V,
21
+ spin: X,
22
+ message: q,
23
+ dismiss: F,
24
+ default: "_default_d8npe_153",
25
+ success: G,
26
+ error: H,
27
+ warning: J,
28
+ info: K,
29
+ loading: Q,
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
+ }, W = {
35
+ default: w,
36
+ success: R,
37
+ error: z,
38
+ warning: x,
39
+ info: w,
40
+ loading: O
41
+ }, Y = ({ toast: i, onDismiss: l, onRemove: _ }) => {
42
+ const a = i.variant === "error", o = W[i.variant];
43
+ return /* @__PURE__ */ k(
44
+ "div",
45
+ {
46
+ role: a ? "alert" : "status",
47
+ "aria-atomic": "true",
48
+ className: h(
49
+ r.toast,
50
+ r[i.variant],
51
+ i.dismissing && r.dismissing
52
+ ),
53
+ onAnimationEnd: () => {
54
+ i.dismissing && _(i.id);
55
+ },
56
+ children: [
57
+ /* @__PURE__ */ u(
58
+ o,
59
+ {
60
+ size: 18,
61
+ className: h(
62
+ r.icon,
63
+ i.variant === "loading" && r.iconSpin
64
+ ),
65
+ "aria-hidden": "true"
66
+ }
67
+ ),
68
+ /* @__PURE__ */ u("p", { className: r.message, children: i.message }),
69
+ /* @__PURE__ */ u(
70
+ "button",
71
+ {
72
+ onClick: () => l(i.id),
73
+ "aria-label": "Dismiss notification",
74
+ className: r.dismiss,
75
+ children: /* @__PURE__ */ u(j, { size: 16 })
76
+ }
77
+ )
78
+ ]
79
+ }
80
+ );
81
+ }, Z = ({
82
+ toasts: i,
83
+ position: l = "top-right",
84
+ onDismiss: _,
85
+ onRemove: a
86
+ }) => {
87
+ const o = I(null), c = i.length > 0;
88
+ return D(() => {
89
+ const t = o.current;
90
+ t && (c && !t.matches(":popover-open") ? t.showPopover() : !c && t.matches(":popover-open") && t.hidePopover());
91
+ }, [c]), /* @__PURE__ */ u(
92
+ "div",
93
+ {
94
+ ref: o,
95
+ popover: "manual",
96
+ className: h(r.container, r[l]),
97
+ "aria-live": "polite",
98
+ "aria-relevant": "additions",
99
+ children: i.map((t) => /* @__PURE__ */ u(Y, { toast: t, onDismiss: _, onRemove: a }, t.id))
100
+ }
101
+ );
102
+ };
103
+ let nn = 0;
104
+ const en = () => `toast-${++nn}-${Date.now()}`, sn = 4e3, tn = {
105
+ default: !0,
106
+ success: !0,
107
+ info: !0,
108
+ warning: !0,
109
+ error: !1,
110
+ loading: !1
111
+ };
112
+ function _n(i = {}) {
113
+ const { position: l = "top-right", duration: _ = sn } = i, [a, o] = M([]), c = I(/* @__PURE__ */ new Map()), t = p((e) => {
114
+ const n = c.current.get(e);
115
+ n && (clearTimeout(n), c.current.delete(e));
116
+ }, []), f = p(
117
+ (e) => {
118
+ t(e), o(
119
+ (n) => n.map((s) => s.id === e ? { ...s, dismissing: !0 } : s)
120
+ );
121
+ },
122
+ [t]
123
+ ), T = p((e) => {
124
+ o((n) => n.filter((s) => s.id !== e));
125
+ }, []), v = p(
126
+ (e, n, s) => {
127
+ if (!tn[n] && s === void 0) return;
128
+ const N = setTimeout(() => f(e), s ?? _);
129
+ c.current.set(e, N);
130
+ },
131
+ [_, f]
132
+ ), d = p(
133
+ (e, n = {}) => {
134
+ const s = en(), g = n.variant ?? "default";
135
+ return o((m) => [...m, { id: s, message: e, variant: g }]), v(s, g, n.duration), s;
136
+ },
137
+ [v]
138
+ ), S = p(
139
+ (e, n) => {
140
+ t(e), o(
141
+ (g) => g.map((m) => m.id !== e ? m : {
142
+ ...m,
143
+ ...n.message !== void 0 && { message: n.message },
144
+ ...n.variant !== void 0 && { variant: n.variant },
145
+ dismissing: !1
146
+ })
147
+ );
148
+ const s = n.variant;
149
+ s && v(e, s, n.duration);
150
+ },
151
+ [t, v]
152
+ ), A = b(() => {
153
+ const e = (n, s) => d(n, s);
154
+ return e.success = (n, s) => d(n, { ...s, variant: "success" }), e.error = (n, s) => d(n, { ...s, variant: "error" }), e.warning = (n, s) => d(n, { ...s, variant: "warning" }), e.info = (n, s) => d(n, { ...s, variant: "info" }), e.loading = (n, s) => d(n, { ...s, variant: "loading" }), e.update = S, e;
155
+ }, [d, S]), C = b(() => {
156
+ const e = () => y(Z, {
157
+ toasts: a,
158
+ position: l,
159
+ onDismiss: f,
160
+ onRemove: T
161
+ });
162
+ return e.displayName = "Toasts", e;
163
+ }, [a, l, f, T]);
164
+ return { toasts: a, toast: A, dismiss: f, Toasts: C };
165
+ }
166
+ export {
167
+ Y as T,
168
+ Z as a,
169
+ _n as u
170
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sander-ui",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
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
- };