kitzo 3.1.1 → 3.1.3
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/README.md +5 -2
- package/dist/index.d.ts +12 -9
- package/dist/index.js +12 -10
- package/dist/react/components/toast/service/createToast.js +24 -23
- package/dist/react/components/toast/service/manageToasts/dismissToasts.js +18 -13
- package/dist/react/components/toast/service/triggerToasts.js +73 -84
- package/dist/react/hooks/useMounted.js +10 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,10 +15,12 @@ pnpm add kitzo
|
|
|
15
15
|
## Features
|
|
16
16
|
|
|
17
17
|
### Components
|
|
18
|
+
|
|
18
19
|
- **Toast**: Smart notification system with flexible positioning.
|
|
19
20
|
- **Tooltip**: Contextual information with auto-positioning logic.
|
|
20
21
|
|
|
21
22
|
### Hooks
|
|
23
|
+
|
|
22
24
|
- **useCopy**: Easy clipboard management.
|
|
23
25
|
- **useDebounce**: Debounc any value.
|
|
24
26
|
- **useDebouncedCallback**: Debounce function calls.
|
|
@@ -28,13 +30,14 @@ pnpm add kitzo
|
|
|
28
30
|
- **useWindowSize**: Real-time window dimensions.
|
|
29
31
|
|
|
30
32
|
### Utilities
|
|
33
|
+
|
|
31
34
|
- **copy**: Standalone programmatic clipboard copy.
|
|
32
35
|
|
|
33
36
|
## See Also
|
|
37
|
+
|
|
34
38
|
- [Root Repository](https://github.com/riyad-96/kitzo)
|
|
35
39
|
- [Documentation](https://github.com/riyad-96/kitzo/tree/main/apps/docs)
|
|
36
40
|
|
|
37
41
|
## License
|
|
38
|
-
MIT
|
|
39
|
-
|
|
40
42
|
|
|
43
|
+
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -89,16 +89,16 @@ export declare type ToasterProps = {
|
|
|
89
89
|
};
|
|
90
90
|
|
|
91
91
|
declare type ToastFn = {
|
|
92
|
-
(content: ToastContent, options?: ToastOptions):
|
|
93
|
-
info: (content: ToastContent, options?: Options) =>
|
|
94
|
-
success: (content: ToastContent, options?: Options) =>
|
|
95
|
-
warning: (content: ToastContent, options?: Options) =>
|
|
96
|
-
error: (content: ToastContent, options?: Options) =>
|
|
92
|
+
(content: ToastContent, options?: ToastOptions): string | number;
|
|
93
|
+
info: (content: ToastContent, options?: Options) => string | number;
|
|
94
|
+
success: (content: ToastContent, options?: Options) => string | number;
|
|
95
|
+
warning: (content: ToastContent, options?: Options) => string | number;
|
|
96
|
+
error: (content: ToastContent, options?: Options) => string | number;
|
|
97
97
|
promise: PromiseToastFn;
|
|
98
|
-
loading: (content: ToastContent, options?: Options) =>
|
|
99
|
-
custom: (content: ToastContent, options?: Options) =>
|
|
100
|
-
dismiss: (id?: string | number, toasterId?: string | number) =>
|
|
101
|
-
update: (id: string | number, content: ToastContent, options?: UpdateToastOptions) =>
|
|
98
|
+
loading: (content: ToastContent, options?: Options) => string | number;
|
|
99
|
+
custom: (content: ToastContent, options?: Options) => string | number;
|
|
100
|
+
dismiss: (id?: string | number, toasterId?: string | number) => string | number | undefined;
|
|
101
|
+
update: (id: string | number, content: ToastContent, options?: UpdateToastOptions) => string | number;
|
|
102
102
|
};
|
|
103
103
|
|
|
104
104
|
declare type ToastOptions = {
|
|
@@ -111,6 +111,7 @@ declare type ToastOptions = {
|
|
|
111
111
|
type?: ToastType;
|
|
112
112
|
swipeToClose?: boolean;
|
|
113
113
|
toasterId?: string | number;
|
|
114
|
+
onClose?: (id: string | number) => void;
|
|
114
115
|
};
|
|
115
116
|
|
|
116
117
|
declare type ToastOptionsWithoutType = Omit<ToastOptions, 'type'>;
|
|
@@ -188,6 +189,8 @@ export declare function useDebouncedCallback<Args extends unknown[]>(callback: (
|
|
|
188
189
|
*/
|
|
189
190
|
export declare function useLocalStorage<T>(key: string, initialValue: T, options?: Options_2<T>): [T, Dispatch<SetStateAction<T>>];
|
|
190
191
|
|
|
192
|
+
export declare function useMounted(): boolean;
|
|
193
|
+
|
|
191
194
|
/**
|
|
192
195
|
* A React hook that manages UI overlays (modal, drawer, popover, etc.)
|
|
193
196
|
* and synchronizes them with the browser navigation history.
|
package/dist/index.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { Toaster as r } from "./react/components/toast/Toaster.js";
|
|
2
2
|
import { Tooltip as p } from "./react/components/tooltip/Tooltip.js";
|
|
3
3
|
import { toast as m } from "./react/components/toast/service/triggerToasts.js";
|
|
4
|
-
import { useCopy as
|
|
4
|
+
import { useCopy as x } from "./react/hooks/useCopy.js";
|
|
5
5
|
import { useDebounce as a } from "./react/hooks/useDebounce.js";
|
|
6
6
|
import { useDebouncedCallback as c } from "./react/hooks/useDebouncedCallback.js";
|
|
7
|
-
import { useLocalStorage as
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
7
|
+
import { useLocalStorage as b } from "./react/hooks/useLocalStorage.js";
|
|
8
|
+
import { useMounted as i } from "./react/hooks/useMounted.js";
|
|
9
|
+
import { useOverlay as y } from "./react/hooks/useOverlay.js";
|
|
10
|
+
import { useThrottle as D } from "./react/hooks/useThrottle.js";
|
|
11
|
+
import { useWindowSize as g } from "./react/hooks/useWindowSize.js";
|
|
11
12
|
export {
|
|
12
13
|
r as Toaster,
|
|
13
14
|
p as Tooltip,
|
|
14
15
|
m as toast,
|
|
15
|
-
|
|
16
|
+
x as useCopy,
|
|
16
17
|
a as useDebounce,
|
|
17
18
|
c as useDebouncedCallback,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
y as
|
|
21
|
-
D as
|
|
19
|
+
b as useLocalStorage,
|
|
20
|
+
i as useMounted,
|
|
21
|
+
y as useOverlay,
|
|
22
|
+
D as useThrottle,
|
|
23
|
+
g as useWindowSize
|
|
22
24
|
};
|
|
@@ -1,50 +1,51 @@
|
|
|
1
|
-
import { DEFAULT_TOASTER_ID as
|
|
1
|
+
import { DEFAULT_TOASTER_ID as s } from "./listenars.js";
|
|
2
2
|
const e = {
|
|
3
3
|
duration: 2800,
|
|
4
4
|
showIcon: !0,
|
|
5
5
|
animateTransformOrigin: void 0,
|
|
6
6
|
swipeToClose: void 0
|
|
7
7
|
};
|
|
8
|
-
let
|
|
9
|
-
const d = () => crypto.randomUUID?.() ?? ++
|
|
8
|
+
let r = 0;
|
|
9
|
+
const d = () => crypto.randomUUID?.() ?? ++r;
|
|
10
10
|
let u = 1;
|
|
11
|
-
function
|
|
11
|
+
function l({
|
|
12
12
|
type: a,
|
|
13
13
|
action: i,
|
|
14
14
|
content: n,
|
|
15
|
-
options:
|
|
15
|
+
options: t
|
|
16
16
|
}) {
|
|
17
|
-
const
|
|
17
|
+
const o = typeof t == "object" && t !== null ? t : {};
|
|
18
18
|
return {
|
|
19
|
-
id: `${
|
|
20
|
-
toasterId: `${
|
|
21
|
-
duration:
|
|
22
|
-
showIcon:
|
|
23
|
-
animateTransformOrigin:
|
|
24
|
-
position:
|
|
25
|
-
icon:
|
|
26
|
-
type: a === "default" ?
|
|
19
|
+
id: `${o.id ?? d()}`,
|
|
20
|
+
toasterId: `${o.toasterId ?? s}`,
|
|
21
|
+
duration: o.duration ?? e.duration,
|
|
22
|
+
showIcon: o.showIcon ?? e.showIcon,
|
|
23
|
+
animateTransformOrigin: o.animateTransformOrigin ?? e.animateTransformOrigin,
|
|
24
|
+
position: o.position,
|
|
25
|
+
icon: o.icon,
|
|
26
|
+
type: a === "default" ? o.type ?? "default" : a,
|
|
27
27
|
status: "entering",
|
|
28
28
|
zIndex: ++u,
|
|
29
29
|
content: n,
|
|
30
30
|
action: i,
|
|
31
|
-
swipeToClose:
|
|
32
|
-
updateState: "initial"
|
|
31
|
+
swipeToClose: o.swipeToClose ?? e.swipeToClose,
|
|
32
|
+
updateState: "initial",
|
|
33
|
+
onClose: o.onClose
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
|
-
function
|
|
36
|
-
const
|
|
36
|
+
function p({ id: a, content: i, options: n }) {
|
|
37
|
+
const t = typeof n == "object" && n !== null ? n : {};
|
|
37
38
|
return {
|
|
38
|
-
...
|
|
39
|
+
...t,
|
|
39
40
|
id: a,
|
|
40
41
|
content: i,
|
|
41
42
|
action: "update",
|
|
42
|
-
duration:
|
|
43
|
-
toasterId: `${
|
|
43
|
+
duration: t.duration ?? e.duration,
|
|
44
|
+
toasterId: `${t.toasterId ?? s}`
|
|
44
45
|
};
|
|
45
46
|
}
|
|
46
47
|
export {
|
|
47
|
-
|
|
48
|
+
l as createToast,
|
|
48
49
|
d as genId,
|
|
49
|
-
|
|
50
|
+
p as updateToast
|
|
50
51
|
};
|
|
@@ -1,19 +1,24 @@
|
|
|
1
|
-
import { LEAVE_DELAY as
|
|
2
|
-
function
|
|
3
|
-
if (
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { LEAVE_DELAY as l, clearAllTimers as u, clearTimer as r } from "./timers.js";
|
|
2
|
+
function m({ toast: s, setToasts: d }) {
|
|
3
|
+
if (s.action === "dismiss" && s.id == null) {
|
|
4
|
+
d((n) => n.map((i) => ({ ...i, status: "leaving" }))), setTimeout(() => {
|
|
5
|
+
d((n) => (n.forEach((i) => {
|
|
6
|
+
i.status === "leaving" && setTimeout(() => i.onClose?.(i.id), 0);
|
|
7
|
+
}), n.filter((i) => i.status !== "leaving")));
|
|
8
|
+
}, l), u();
|
|
7
9
|
return;
|
|
8
10
|
}
|
|
9
|
-
|
|
10
|
-
(
|
|
11
|
+
d((n) => (n.find((e) => e.id === s.id) && r(s.id), n.map(
|
|
12
|
+
(e) => e.id === s.id ? { ...e, status: "leaving" } : e
|
|
11
13
|
))), setTimeout(() => {
|
|
12
|
-
n
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
d((n) => {
|
|
15
|
+
const i = n.find(
|
|
16
|
+
(e) => e.id === s.id && e.status === "leaving"
|
|
17
|
+
);
|
|
18
|
+
return i && setTimeout(() => i.onClose?.(i.id), 0), n.filter((e) => !(e.id === s.id && e.status === "leaving"));
|
|
19
|
+
});
|
|
20
|
+
}, l);
|
|
16
21
|
}
|
|
17
22
|
export {
|
|
18
|
-
|
|
23
|
+
m as default
|
|
19
24
|
};
|
|
@@ -1,103 +1,92 @@
|
|
|
1
|
-
import { createToast as
|
|
2
|
-
import { notify as
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
options: t
|
|
10
|
-
})
|
|
11
|
-
);
|
|
12
|
-
};
|
|
13
|
-
i.dismiss = (r, t) => {
|
|
14
|
-
e({
|
|
15
|
-
action: "dismiss",
|
|
16
|
-
id: r,
|
|
17
|
-
toasterId: t
|
|
1
|
+
import { createToast as o, updateToast as d, genId as c } from "./createToast.js";
|
|
2
|
+
import { notify as i } from "./listenars.js";
|
|
3
|
+
const e = (r, n) => {
|
|
4
|
+
const t = o({
|
|
5
|
+
type: "default",
|
|
6
|
+
action: "add",
|
|
7
|
+
content: r,
|
|
8
|
+
options: n
|
|
18
9
|
});
|
|
10
|
+
return r == null || i(t), t.id;
|
|
19
11
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
action: "add",
|
|
34
|
-
type: "success",
|
|
35
|
-
content: r,
|
|
36
|
-
options: t
|
|
37
|
-
})
|
|
38
|
-
);
|
|
12
|
+
e.dismiss = (r, n) => (i({
|
|
13
|
+
action: "dismiss",
|
|
14
|
+
id: r,
|
|
15
|
+
toasterId: n
|
|
16
|
+
}), r);
|
|
17
|
+
e.info = (r, n) => {
|
|
18
|
+
const t = o({
|
|
19
|
+
action: "add",
|
|
20
|
+
type: "info",
|
|
21
|
+
content: r,
|
|
22
|
+
options: n
|
|
23
|
+
});
|
|
24
|
+
return r == null || i(t), t.id;
|
|
39
25
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
);
|
|
26
|
+
e.success = (r, n) => {
|
|
27
|
+
const t = o({
|
|
28
|
+
action: "add",
|
|
29
|
+
type: "success",
|
|
30
|
+
content: r,
|
|
31
|
+
options: n
|
|
32
|
+
});
|
|
33
|
+
return r == null || i(t), t.id;
|
|
49
34
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
);
|
|
35
|
+
e.warning = (r, n) => {
|
|
36
|
+
const t = o({
|
|
37
|
+
action: "add",
|
|
38
|
+
type: "warning",
|
|
39
|
+
content: r,
|
|
40
|
+
options: n
|
|
41
|
+
});
|
|
42
|
+
return r == null || i(t), t.id;
|
|
59
43
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
);
|
|
44
|
+
e.error = (r, n) => {
|
|
45
|
+
const t = o({
|
|
46
|
+
action: "add",
|
|
47
|
+
type: "error",
|
|
48
|
+
content: r,
|
|
49
|
+
options: n
|
|
50
|
+
});
|
|
51
|
+
return r == null || i(t), t.id;
|
|
69
52
|
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
);
|
|
53
|
+
e.loading = (r, n) => {
|
|
54
|
+
const t = o({
|
|
55
|
+
action: "add",
|
|
56
|
+
type: "loading",
|
|
57
|
+
content: r,
|
|
58
|
+
options: { duration: 1 / 0, ...n }
|
|
59
|
+
});
|
|
60
|
+
return r == null || i(t), t.id;
|
|
79
61
|
};
|
|
80
|
-
|
|
81
|
-
|
|
62
|
+
e.custom = (r, n) => {
|
|
63
|
+
const t = o({
|
|
64
|
+
action: "add",
|
|
65
|
+
type: "custom",
|
|
66
|
+
content: r,
|
|
67
|
+
options: n
|
|
68
|
+
});
|
|
69
|
+
return r == null || i(t), t.id;
|
|
82
70
|
};
|
|
83
|
-
|
|
71
|
+
e.update = (r, n, t) => r == null ? "" : (n == null || i(d({ id: `${r}`, content: n, options: t })), r);
|
|
72
|
+
e.promise = (async (r, n, t) => {
|
|
84
73
|
const u = c();
|
|
85
|
-
|
|
86
|
-
|
|
74
|
+
i(
|
|
75
|
+
o({
|
|
87
76
|
action: "add",
|
|
88
77
|
type: "loading",
|
|
89
|
-
content:
|
|
90
|
-
options: { ...
|
|
78
|
+
content: n.loading,
|
|
79
|
+
options: { ...t, id: u, duration: 1 / 0, swipeToClose: !1 }
|
|
91
80
|
})
|
|
92
81
|
);
|
|
93
82
|
try {
|
|
94
|
-
const a = await r,
|
|
95
|
-
return
|
|
83
|
+
const a = await r, s = typeof n.success == "function" ? await n.success(a) : n.success;
|
|
84
|
+
return e.update(u, s, { ...t, type: "success" }), a;
|
|
96
85
|
} catch (a) {
|
|
97
|
-
const
|
|
98
|
-
throw
|
|
86
|
+
const s = typeof n.error == "function" ? await n.error(a) : n.error;
|
|
87
|
+
throw e.update(u, s, { ...t, type: "error" }), a;
|
|
99
88
|
}
|
|
100
89
|
});
|
|
101
90
|
export {
|
|
102
|
-
|
|
91
|
+
e as toast
|
|
103
92
|
};
|
package/package.json
CHANGED