kitzo 3.1.0 → 3.1.2
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 +23 -24
- package/dist/index.d.ts +10 -9
- 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/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,44 +1,43 @@
|
|
|
1
1
|
# Kitzo
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Lightweight, production-ready React micro-utilities for modern web applications. Focus on simplicity, performance, and minimal footprint.
|
|
4
|
+
|
|
5
|
+
[Full Documentation & Demos](https://kitzo.vercel.app)
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
9
|
```bash
|
|
8
10
|
npm install kitzo
|
|
11
|
+
# or
|
|
12
|
+
pnpm add kitzo
|
|
9
13
|
```
|
|
10
14
|
|
|
11
|
-
##
|
|
12
|
-
|
|
13
|
-
### React Components
|
|
14
|
-
|
|
15
|
-
Essential, accessible, and performance-optimized UI components:
|
|
16
|
-
|
|
17
|
-
- **Toast**: A flexible notification system with support for custom positions, animations, and interaction patterns.
|
|
18
|
-
- **Tooltip**: A contextual information component with smart positioning and customizable delay and animations.
|
|
15
|
+
## Features
|
|
19
16
|
|
|
20
|
-
###
|
|
17
|
+
### Components
|
|
21
18
|
|
|
22
|
-
|
|
19
|
+
- **Toast**: Smart notification system with flexible positioning.
|
|
20
|
+
- **Tooltip**: Contextual information with auto-positioning logic.
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
- **useDebouncedCallback**: Returns a debounced version of a callback function.
|
|
26
|
-
- **useThrottle**: Limits the execution rate of a frequently changing value.
|
|
27
|
-
- **useLocalStorage**: Synchronizes state with browser local storage.
|
|
28
|
-
- **useWindowSize**: Provides real-time window dimensions.
|
|
29
|
-
- **useCopy**: Simplifies clipboard operations within components.
|
|
22
|
+
### Hooks
|
|
30
23
|
|
|
31
|
-
|
|
24
|
+
- **useCopy**: Easy clipboard management.
|
|
25
|
+
- **useDebounce**: Debounc any value.
|
|
26
|
+
- **useDebouncedCallback**: Debounce function calls.
|
|
27
|
+
- **useLocalStorage**: State persistence via storage.
|
|
28
|
+
- **useOverlay**: History-synchronized overlay management.
|
|
29
|
+
- **useThrottle**: Limit execution rate.
|
|
30
|
+
- **useWindowSize**: Real-time window dimensions.
|
|
32
31
|
|
|
33
|
-
|
|
32
|
+
### Utilities
|
|
34
33
|
|
|
35
|
-
|
|
34
|
+
- **copy**: Standalone programmatic clipboard copy.
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
[https://kitzo.vercel.app](https://kitzo.vercel.app)
|
|
36
|
+
## See Also
|
|
39
37
|
|
|
40
|
-
|
|
38
|
+
- [Root Repository](https://github.com/riyad-96/kitzo)
|
|
39
|
+
- [Documentation](https://github.com/riyad-96/kitzo/tree/main/apps/docs)
|
|
41
40
|
|
|
42
41
|
## License
|
|
43
42
|
|
|
44
|
-
|
|
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'>;
|
|
@@ -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