kitzo 2.1.30 → 2.2.0

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
@@ -13,7 +13,13 @@ npm i kitzo
13
13
  #### React APIs
14
14
 
15
15
  ```jsx
16
- import { ToastContainer, toast, Tooltip, useDebounce, useWindowSize } from 'kitzo';
16
+ import {
17
+ ToastContainer,
18
+ toast,
19
+ Tooltip,
20
+ useDebounce,
21
+ useWindowSize,
22
+ } from 'kitzo';
17
23
  ```
18
24
 
19
25
  > You can import only what you need.
@@ -23,93 +29,109 @@ import { ToastContainer, toast, Tooltip, useDebounce, useWindowSize } from 'kitz
23
29
  - Toast message
24
30
  - Tooltip
25
31
 
26
- ##### Toast API:
32
+ ##### Toast API usage:
27
33
 
28
34
  ```jsx
29
35
  import { toast } from 'kitzo';
30
36
  import MyCustomComponent from './MyCustomComponent';
31
37
 
32
- toast.success('toast message', { duration: 2000, style: {}, showIcon: true, position: 'top-center' });
33
- toast.error('toast message', { duration: 2000, style: {}, showIcon: true, position: 'top-center' });
38
+ // ---------------------
39
+ // Normal / Success / Error
40
+ // ---------------------
41
+
42
+ toast('Toast message', {
43
+ id: 'normat_toast',
44
+ duration: 2000,
45
+ showIcon: true,
46
+ position: 'top-center',
47
+ });
48
+
49
+ toast.success('Toast message', {
50
+ id: 'success_toast',
51
+ duration: 2000,
52
+ showIcon: true,
53
+ position: 'top-center',
54
+ });
55
+
56
+ toast.error('Toast message', {
57
+ id: 'error_toast',
58
+ duration: 2000,
59
+ showIcon: true,
60
+ position: 'top-center',
61
+ });
62
+
63
+ // content can be: (dismiss) => (
64
+ // <div>
65
+ // <span>any thing</span>
66
+ // <button onClick={dismiss} >❌</button>
67
+ // </div>
68
+ //)
69
+
70
+ // ---------------------
71
+ // Promise-based toast
72
+ // ---------------------
34
73
 
35
74
  toast.promise(
36
- promise(), // call a function that returns promise
75
+ promise(), // function that returns a promise
37
76
  {
38
77
  loading: 'Saving...',
39
- success: 'Saved' | (response) => 'Saved',
40
- error: 'Error occured' | (error) => 'Error occured',
78
+ success: (res) => `Saved: ${res}`, // or just 'Saved'
79
+ error: (err) => `Error occurred: ${err}`, // or just 'Error occurred'
80
+ },
81
+ {
82
+ id: 'promise_toast',
83
+ duration: 2000,
84
+ showIcon: true,
85
+ position: 'top-center',
41
86
  },
42
- { duration: 2000, style: {}, showIcon: true, position: 'top-center' },
43
87
  );
44
88
 
89
+ // ---------------------
90
+ // Custom toast
91
+ // ---------------------
92
+
45
93
  // JSX element
46
- toast.custom(<MyCustomComponent />, { duration: 2000, position: 'top-center' });
94
+ toast.custom(<MyCustomComponent />, {
95
+ id: 'custom_toast',
96
+ duration: 2000,
97
+ position: 'top-center',
98
+ });
47
99
 
48
100
  // Function that receives a dismiss handler
49
- toast.custom((dismiss) => (
50
- <div>
51
- <span>Custom toast message</span>
52
- <button onClick={dismiss}>Close</button>
53
- </div>
54
- ), { duration: 3000 | Infinity });
55
-
56
- // (and optionally)
57
- toast.custom("string");
58
- ```
59
-
60
- ##### React Toast API Usage
61
-
62
- ```jsx
63
- import { ToastContainer, toast } from 'kitzo';
64
-
65
- function App() {
66
- function fakePromise() {
67
- return new Promise((resolved, rejected) => {
68
- setTimeout(() => {
69
- Math.random() > 0.5 ? resolved('resolved') : rejected('rejected');
70
- }, 2000);
71
- });
72
- }
73
-
74
- function promiseToast() {
75
- toast.promise(
76
- fakePromise(),
77
- {
78
- loading: 'Saving data...',
79
- success: 'Data saved',
80
- error: 'Failed saving data',
81
- },
82
- { duration: 2500, position: 'top-center' },
83
- );
84
- }
85
-
86
- function customToast() {
87
- toast.custom(
88
- (dismiss) => (
89
- <div>
90
- <span>Funtion that return jsx</span>
91
- <button onClick={dismiss}>Close</button>
92
- </div>
93
- ),
94
- {
95
- duration: 2000,
96
- position: 'top-center',
97
- },
98
- );
99
- }
100
-
101
- return (
101
+ toast.custom(
102
+ (dismiss) => (
102
103
  <div>
103
- <button onClick={() => toast.success('✅ Success toast message')}>Succes</button>
104
- <button onClick={() => toast.error('❌ Error toast message')}>Error</button>
105
- <button onClick={promiseToast}>Promise</button>
106
- <button onClick={customToast}>Custom Toast</button>
107
-
108
- {/* Toast container must be placed */}
109
- <ToastContainer />
104
+ <span>Custom toast message</span>
105
+ <button onClick={dismiss}>Close</button>
110
106
  </div>
111
- );
112
- }
107
+ ),
108
+ {
109
+ id: 'custom_toast',
110
+ duration: Infinity, // or 3000
111
+ position: 'top-center',
112
+ },
113
+ );
114
+
115
+ // Simple string
116
+ toast.custom('Simple string toast', {
117
+ id: 'custom_toast',
118
+ duration: 2000,
119
+ position: 'top-center',
120
+ });
121
+
122
+ // ---------------------
123
+ // Update / Dismiss
124
+ // ---------------------
125
+ // ❗ Update is only supported on custom toasts
126
+
127
+ toast.update('my-toast', 'Updated content!', {
128
+ duration: 3000,
129
+ });
130
+
131
+ // Dismiss by id (optional)
132
+ toast.dismiss('my-toast');
133
+ // Or dismiss all toasts
134
+ toast.dismiss();
113
135
  ```
114
136
 
115
137
  > Each toast can have its own position. default position is `top-center`.
@@ -203,6 +225,7 @@ function App() {
203
225
  - copy _(Copy text to clipboard)_
204
226
 
205
227
  #### copy usage:
228
+
206
229
  ```jsx
207
230
  import { copy } from 'kitzo/fns';
208
231
  import { ToastContainer, toast } from 'kitzo';