kitzo 3.1.1 → 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 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): void;
93
- info: (content: ToastContent, options?: Options) => void;
94
- success: (content: ToastContent, options?: Options) => void;
95
- warning: (content: ToastContent, options?: Options) => void;
96
- error: (content: ToastContent, options?: Options) => void;
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) => void;
99
- custom: (content: ToastContent, options?: Options) => void;
100
- dismiss: (id?: string | number, toasterId?: string | number) => void;
101
- update: (id: string | number, content: ToastContent, options?: UpdateToastOptions) => void;
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 r } from "./listenars.js";
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 s = 0;
9
- const d = () => crypto.randomUUID?.() ?? ++s;
8
+ let r = 0;
9
+ const d = () => crypto.randomUUID?.() ?? ++r;
10
10
  let u = 1;
11
- function p({
11
+ function l({
12
12
  type: a,
13
13
  action: i,
14
14
  content: n,
15
- options: o
15
+ options: t
16
16
  }) {
17
- const t = typeof o == "object" && o !== null ? o : {};
17
+ const o = typeof t == "object" && t !== null ? t : {};
18
18
  return {
19
- id: `${t.id ?? d()}`,
20
- toasterId: `${t.toasterId ?? r}`,
21
- duration: t.duration ?? e.duration,
22
- showIcon: t.showIcon ?? e.showIcon,
23
- animateTransformOrigin: t.animateTransformOrigin ?? e.animateTransformOrigin,
24
- position: t.position,
25
- icon: t.icon,
26
- type: a === "default" ? t.type ?? "default" : a,
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: t.swipeToClose ?? e.swipeToClose,
32
- updateState: "initial"
31
+ swipeToClose: o.swipeToClose ?? e.swipeToClose,
32
+ updateState: "initial",
33
+ onClose: o.onClose
33
34
  };
34
35
  }
35
- function l({ id: a, content: i, options: n }) {
36
- const o = typeof n == "object" && n !== null ? n : {};
36
+ function p({ id: a, content: i, options: n }) {
37
+ const t = typeof n == "object" && n !== null ? n : {};
37
38
  return {
38
- ...o,
39
+ ...t,
39
40
  id: a,
40
41
  content: i,
41
42
  action: "update",
42
- duration: o.duration ?? e.duration,
43
- toasterId: `${o.toasterId ?? r}`
43
+ duration: t.duration ?? e.duration,
44
+ toasterId: `${t.toasterId ?? s}`
44
45
  };
45
46
  }
46
47
  export {
47
- p as createToast,
48
+ l as createToast,
48
49
  d as genId,
49
- l as updateToast
50
+ p as updateToast
50
51
  };
@@ -1,19 +1,24 @@
1
- import { LEAVE_DELAY as r, clearAllTimers as s, clearTimer as u } from "./timers.js";
2
- function a({ toast: l, setToasts: n }) {
3
- if (l.action === "dismiss" && l.id == null) {
4
- n((i) => i.map((e) => ({ ...e, status: "leaving" }))), setTimeout(() => {
5
- n((i) => i.filter((e) => e.status !== "leaving"));
6
- }, r), s();
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
- n((i) => (i.find((d) => d.id === l.id) && u(l.id), i.map(
10
- (d) => d.id === l.id ? { ...d, status: "leaving" } : d
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
- (i) => i.filter((e) => !(e.id === l.id && e.status === "leaving"))
14
- );
15
- }, r);
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
- a as default
23
+ m as default
19
24
  };
@@ -1,103 +1,92 @@
1
- import { createToast as n, updateToast as s, genId as c } from "./createToast.js";
2
- import { notify as e } from "./listenars.js";
3
- const i = (r, t) => {
4
- r != null && e(
5
- n({
6
- type: "default",
7
- action: "add",
8
- content: r,
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
- i.info = (r, t) => {
21
- r != null && e(
22
- n({
23
- action: "add",
24
- type: "info",
25
- content: r,
26
- options: t
27
- })
28
- );
29
- };
30
- i.success = (r, t) => {
31
- r != null && e(
32
- n({
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
- i.warning = (r, t) => {
41
- r != null && e(
42
- n({
43
- action: "add",
44
- type: "warning",
45
- content: r,
46
- options: t
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
- i.error = (r, t) => {
51
- r != null && e(
52
- n({
53
- action: "add",
54
- type: "error",
55
- content: r,
56
- options: t
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
- i.loading = (r, t) => {
61
- r != null && e(
62
- n({
63
- action: "add",
64
- type: "loading",
65
- content: r,
66
- options: { duration: 1 / 0, ...t }
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
- i.custom = (r, t) => {
71
- r != null && e(
72
- n({
73
- action: "add",
74
- type: "custom",
75
- content: r,
76
- options: t
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
- i.update = (r, t, o) => {
81
- r != null && t != null && e(s({ id: `${r}`, content: t, options: o }));
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
- i.promise = (async (r, t, o) => {
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
- e(
86
- n({
74
+ i(
75
+ o({
87
76
  action: "add",
88
77
  type: "loading",
89
- content: t.loading,
90
- options: { ...o, id: u, duration: 1 / 0, swipeToClose: !1 }
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, d = typeof t.success == "function" ? await t.success(a) : t.success;
95
- return i.update(u, d, { ...o, type: "success" }), a;
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 d = typeof t.error == "function" ? await t.error(a) : t.error;
98
- throw i.update(u, d, { ...o, type: "error" }), a;
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
- i as toast
91
+ e as toast
103
92
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kitzo",
3
- "version": "3.1.1",
3
+ "version": "3.1.2",
4
4
  "description": "A lightweight production-ready React micro-utility library providing essential components, hooks, and functions for modern web applications.",
5
5
  "type": "module",
6
6
  "files": [