kitzo 2.0.26 → 2.0.28

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
@@ -25,7 +25,7 @@ npm i kitzo
25
25
  or
26
26
 
27
27
  ```javascript
28
- <script src="https://cdn.jsdelivr.net/npm/kitzo@2.0.26/dist/kitzo.umd.min.js"></script>
28
+ <script src="https://cdn.jsdelivr.net/npm/kitzo@2.0.28/dist/kitzo.umd.min.js"></script>
29
29
  ```
30
30
 
31
31
  > Attach this script tag in the html head tag and you are good to go.
@@ -41,6 +41,7 @@ or
41
41
  | [`kitzo.ripple()`](#ripple-api) |
42
42
  | [`kitzo.debounce()`](#debounce-api) |
43
43
  | [`kitzo.clippath()`](#clippath-api) |
44
+ | [`kitzo.getType()`](#typecheck-api) |
44
45
 
45
46
  #### Vanilla APIs
46
47
 
@@ -53,6 +54,7 @@ kitzo.tooltip();
53
54
  kitzo.ripple();
54
55
  kitzo.debounce();
55
56
  kitzo.clippath();
57
+ kitzo.getType();
56
58
  ```
57
59
 
58
60
  > Use a modern build tool. **vite** - recommended
@@ -125,6 +127,15 @@ kitzo.clippath(selectors | element | NodeList, {
125
127
  });
126
128
  ```
127
129
 
130
+ ##### TypeCheck API:
131
+
132
+ ```javascript
133
+ kitzo.getType(type);
134
+
135
+ const data = [];
136
+ console.log(kitzo.getType(data)); // 'array'
137
+ ```
138
+
128
139
  ---
129
140
 
130
141
  ## React
@@ -146,17 +157,32 @@ import { ToastContainer, toast, ... } from 'kitzo/react';
146
157
  ```jsx
147
158
  import { toast } from 'kitzo/react';
148
159
 
149
- toast.success('toast message', {});
150
- toast.error('toast message', {});
160
+ toast.success('toast message', { duration: 2000, style: {}, showIcon: true });
161
+ toast.error('toast message', { duration: 2000, style: {}, showIcon: true });
162
+
151
163
  toast.promise(
152
- promise(),
164
+ promise(), // call a function that returns promise
153
165
  {
154
166
  loading: 'Saving...',
155
- success: 'Saved',
156
- error: 'Error occured',
167
+ success: 'Saved' | (response) => 'Saved',
168
+ error: 'Error occured' | (error) => 'Error occured',
157
169
  },
158
- { duration: 2000 }
170
+ { duration: 2000, style: {}, showIcon: true },
159
171
  );
172
+
173
+ // JSX element
174
+ toast.custom(<MyCustomComponent />, { duration: 2000 });
175
+
176
+ // Function that receives a dismiss handler
177
+ toast.custom((dismiss) => (
178
+ <div>
179
+ <span>Custom toast message</span>
180
+ <button onClick={dismiss}>Close</button>
181
+ </div>
182
+ ), { duration: 3000 | Infinity });
183
+
184
+ // (and optionally)
185
+ toast.custom("string");
160
186
  ```
161
187
 
162
188
  ##### Toast API Usage
@@ -169,29 +195,42 @@ function App() {
169
195
  return new Promise((resolved, rejected) => {
170
196
  setTimeout(() => {
171
197
  Math.random() > 0.5 ? resolved('resolved') : rejected('rejected');
172
- }, 2000)
173
- })
198
+ }, 2000);
199
+ });
200
+ }
201
+
202
+ function promiseToast() {
203
+ toast.promise(
204
+ fakePromise(),
205
+ {
206
+ loading: 'Saving data...',
207
+ success: 'Data saved',
208
+ error: 'Failed saving data',
209
+ },
210
+ { duration: 2500 },
211
+ );
212
+ }
213
+
214
+ function customToast() {
215
+ toast.custom(
216
+ (dismiss) => (
217
+ <div>
218
+ <span>Funtion that return jsx</span>
219
+ <button onClick={dismiss}>Close</button>
220
+ </div>
221
+ ),
222
+ {
223
+ duration: 2000,
224
+ },
225
+ );
174
226
  }
175
227
 
176
228
  return (
177
229
  <div>
178
230
  <button onClick={() => toast.success('✅ Success toast message')}>Succes</button>
179
231
  <button onClick={() => toast.error('❌ Error toast message')}>Error</button>
180
- <button
181
- onClick={() => {
182
- toast.promise(
183
- fakePromise(),
184
- {
185
- loading: 'Saving data...',
186
- success: 'Data saved',
187
- error: 'Failed saving data',
188
- },
189
- { duration: 2500 }
190
- );
191
- }}
192
- >
193
- Promise
194
- </button>
232
+ <button onClick={promiseToast}>Promise</button>
233
+ <button onClick={customToast}>Custom Toast</button>
195
234
 
196
235
  {/* Toast container must needed */}
197
236
  <ToastContainer position="top-center" />
package/dist/kitzo.esm.js CHANGED
@@ -568,6 +568,22 @@ function clippath(element, config = {}) {
568
568
  }
569
569
  }
570
570
 
571
- const kitzo = { copy, debounce, ripple, tooltip, clippath };
571
+ function getType(value) {
572
+ if (value === null) return 'null';
573
+
574
+ if (Array.isArray(value)) return 'array';
575
+
576
+ if (value instanceof Date) return 'date';
577
+
578
+ if (value instanceof RegExp) return 'regexp';
579
+
580
+ if (typeof value === 'object') return 'object';
581
+
582
+ return typeof value;
583
+ }
584
+
585
+ // button effects
586
+
587
+ const kitzo = { copy, debounce, ripple, tooltip, clippath, getType };
572
588
 
573
- export { clippath, copy, debounce, kitzo as default, ripple, tooltip };
589
+ export { clippath, copy, debounce, kitzo as default, getType, ripple, tooltip };
package/dist/kitzo.umd.js CHANGED
@@ -574,7 +574,23 @@
574
574
  }
575
575
  }
576
576
 
577
- const kitzo = { copy, debounce, ripple, tooltip, clippath };
577
+ function getType(value) {
578
+ if (value === null) return 'null';
579
+
580
+ if (Array.isArray(value)) return 'array';
581
+
582
+ if (value instanceof Date) return 'date';
583
+
584
+ if (value instanceof RegExp) return 'regexp';
585
+
586
+ if (typeof value === 'object') return 'object';
587
+
588
+ return typeof value;
589
+ }
590
+
591
+ // button effects
592
+
593
+ const kitzo = { copy, debounce, ripple, tooltip, clippath, getType };
578
594
 
579
595
  return kitzo;
580
596
 
package/dist/react.d.ts CHANGED
@@ -1,9 +1,13 @@
1
+ import React from 'react';
2
+
1
3
  export interface ToastOptions {
2
4
  duration?: number;
3
5
  style?: React.CSSProperties;
4
6
  showIcon?: boolean;
5
7
  }
6
8
 
9
+ export type CustomContent = string | React.ReactNode | ((dismiss: () => void) => React.ReactNode);
10
+
7
11
  export interface ToastAPI {
8
12
  success(text?: string, options?: ToastOptions): void;
9
13
  error(text?: string, options?: ToastOptions): void;
@@ -14,12 +18,11 @@ export interface ToastAPI {
14
18
  success?: string | ((res: T) => string);
15
19
  error?: string | ((err: Error) => string);
16
20
  },
17
- options?: ToastOptions
21
+ options?: ToastOptions,
18
22
  ): Promise<T>;
23
+ custom(content: CustomContent, options?: { duration?: number | Infinity; }): void;
19
24
  }
20
25
 
21
26
  export declare const toast: ToastAPI;
22
- export declare function ToastContainer(props: {
23
- position?: 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
24
- gap?: number;
25
- }): JSX.Element;
27
+
28
+ export declare function ToastContainer(props: { position?: 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right'; gap?: number }): JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kitzo",
3
- "version": "2.0.26",
3
+ "version": "2.0.28",
4
4
  "description": "A lightweight JavaScript UI micro-library.",
5
5
  "type": "module",
6
6
  "main": "./dist/kitzo.umd.js",