kitzo 2.1.29 → 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 +182 -199
- package/dist/functions/index.js +36 -0
- package/dist/functions/index.js.map +1 -0
- package/dist/functions/types.d.ts +0 -0
- package/dist/react/index.js +894 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/types/functions.d.ts +2 -0
- package/dist/react/types/hooks.d.ts +14 -0
- package/dist/react/types/toast.d.ts +25 -19
- package/dist/react/{index.d.ts → types.d.ts} +1 -0
- package/package.json +75 -73
- package/dist/react/react.esm.js +0 -859
- package/dist/vanilla/vanilla.d.ts +0 -95
- package/dist/vanilla/vanilla.esm.js +0 -589
- package/dist/vanilla/vanilla.umd.js +0 -597
package/README.md
CHANGED
|
@@ -2,20 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/kitzo)
|
|
4
4
|
|
|
5
|
-
### A lightweight
|
|
6
|
-
|
|
7
|
-
##### [Vanilla js](#quick-usage-overview-vanilla-js)
|
|
8
|
-
|
|
9
|
-
- Copy on click
|
|
10
|
-
- Tooltip on mouseover
|
|
11
|
-
- Ripple effect on mousedown
|
|
12
|
-
- Debounce function
|
|
13
|
-
- Hover clip-path effect
|
|
14
|
-
|
|
15
|
-
##### [React js](#react)
|
|
16
|
-
|
|
17
|
-
- React Toast notifications
|
|
18
|
-
- Tooltip wrapper component
|
|
5
|
+
### A lightweight React micro-utility.
|
|
19
6
|
|
|
20
7
|
#### Install
|
|
21
8
|
|
|
@@ -23,224 +10,136 @@
|
|
|
23
10
|
npm i kitzo
|
|
24
11
|
```
|
|
25
12
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
```javascript
|
|
29
|
-
<script src="https://cdn.jsdelivr.net/npm/kitzo@2.1.29/dist/kitzo.umd.min.js"></script>
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
> Vanilla: Attach this script tag in the html head tag and you are good to go.
|
|
33
|
-
|
|
34
|
-
---
|
|
35
|
-
|
|
36
|
-
#### API links
|
|
37
|
-
|
|
38
|
-
- **Vanilla**: [copy](#copy-api), [Tooltip](#tooltip-api), [Ripple](#ripple-api), [Debounce](#debounce-api), [Clippath](#clippath-api), [Get type](#typecheck-api)
|
|
39
|
-
- **React**: [Toast](#react-toast-api-usage), [Tooltip](#react-tooltip-api)
|
|
40
|
-
|
|
41
|
-
#### Vanilla APIs
|
|
42
|
-
|
|
43
|
-
```javascript
|
|
44
|
-
// NPM usage
|
|
45
|
-
import kitzo from 'kitzo';
|
|
46
|
-
|
|
47
|
-
kitzo.copy();
|
|
48
|
-
kitzo.tooltip();
|
|
49
|
-
kitzo.ripple();
|
|
50
|
-
kitzo.debounce();
|
|
51
|
-
kitzo.clippath();
|
|
52
|
-
kitzo.getType();
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
> Use a modern build tool. **vite** - recommended
|
|
56
|
-
|
|
57
|
-
##### Copy API:
|
|
13
|
+
#### React APIs
|
|
58
14
|
|
|
59
|
-
```
|
|
60
|
-
|
|
15
|
+
```jsx
|
|
16
|
+
import {
|
|
17
|
+
ToastContainer,
|
|
18
|
+
toast,
|
|
19
|
+
Tooltip,
|
|
20
|
+
useDebounce,
|
|
21
|
+
useWindowSize,
|
|
22
|
+
} from 'kitzo';
|
|
61
23
|
```
|
|
62
24
|
|
|
63
|
-
>
|
|
64
|
-
|
|
65
|
-
##### Tooltip API:
|
|
25
|
+
> You can import only what you need.
|
|
66
26
|
|
|
67
|
-
|
|
68
|
-
kitzo.tooltip(selectors | element | NodeList, {
|
|
69
|
-
tooltip: string,
|
|
70
|
-
direction: 'top' | 'right' | 'bottom' | 'left',
|
|
71
|
-
arrow: 'on' | 'off',
|
|
72
|
-
offset: number,
|
|
73
|
-
customClass: string,
|
|
74
|
-
style: object,
|
|
75
|
-
});
|
|
76
|
-
```
|
|
27
|
+
#### UI
|
|
77
28
|
|
|
78
|
-
|
|
29
|
+
- Toast message
|
|
30
|
+
- Tooltip
|
|
79
31
|
|
|
80
|
-
#####
|
|
32
|
+
##### Toast API usage:
|
|
81
33
|
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
34
|
+
```jsx
|
|
35
|
+
import { toast } from 'kitzo';
|
|
36
|
+
import MyCustomComponent from './MyCustomComponent';
|
|
37
|
+
|
|
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',
|
|
88
47
|
});
|
|
89
|
-
```
|
|
90
48
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
kitzo.debounce(callback, delayInMilliseconds);
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
```javascript
|
|
100
|
-
// Log only after typing stops for 500ms
|
|
101
|
-
const logSearch = kitzo.debounce((text) => {
|
|
102
|
-
console.log('Searching for:', text);
|
|
103
|
-
}, 500);
|
|
104
|
-
|
|
105
|
-
// Attach to input
|
|
106
|
-
document.querySelector('#search').addEventListener('input', (e) => {
|
|
107
|
-
logSearch(e.target.value);
|
|
49
|
+
toast.success('Toast message', {
|
|
50
|
+
id: 'success_toast',
|
|
51
|
+
duration: 2000,
|
|
52
|
+
showIcon: true,
|
|
53
|
+
position: 'top-center',
|
|
108
54
|
});
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
> Debounce on every call of function.
|
|
112
|
-
|
|
113
|
-
##### Clippath API:
|
|
114
55
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
class: string,
|
|
121
|
-
style: object,
|
|
56
|
+
toast.error('Toast message', {
|
|
57
|
+
id: 'error_toast',
|
|
58
|
+
duration: 2000,
|
|
59
|
+
showIcon: true,
|
|
60
|
+
position: 'top-center',
|
|
122
61
|
});
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
##### TypeCheck API:
|
|
126
|
-
|
|
127
|
-
```javascript
|
|
128
|
-
kitzo.getType(type);
|
|
129
|
-
|
|
130
|
-
const data = [];
|
|
131
|
-
console.log(kitzo.getType(data)); // 'array'
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
---
|
|
135
|
-
|
|
136
|
-
## React
|
|
137
|
-
|
|
138
|
-
#### Install
|
|
139
|
-
|
|
140
|
-
```bash
|
|
141
|
-
npm i kitzo
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
#### React APIs
|
|
145
62
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
```jsx
|
|
153
|
-
import { toast } from 'kitzo/react';
|
|
63
|
+
// content can be: (dismiss) => (
|
|
64
|
+
// <div>
|
|
65
|
+
// <span>any thing</span>
|
|
66
|
+
// <button onClick={dismiss} >❌</button>
|
|
67
|
+
// </div>
|
|
68
|
+
//)
|
|
154
69
|
|
|
155
|
-
|
|
156
|
-
|
|
70
|
+
// ---------------------
|
|
71
|
+
// Promise-based toast
|
|
72
|
+
// ---------------------
|
|
157
73
|
|
|
158
74
|
toast.promise(
|
|
159
|
-
promise(), //
|
|
75
|
+
promise(), // function that returns a promise
|
|
160
76
|
{
|
|
161
77
|
loading: 'Saving...',
|
|
162
|
-
success:
|
|
163
|
-
error:
|
|
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',
|
|
164
86
|
},
|
|
165
|
-
{ duration: 2000, style: {}, showIcon: true, position: 'top-center' },
|
|
166
87
|
);
|
|
167
88
|
|
|
89
|
+
// ---------------------
|
|
90
|
+
// Custom toast
|
|
91
|
+
// ---------------------
|
|
92
|
+
|
|
168
93
|
// JSX element
|
|
169
|
-
toast.custom(<MyCustomComponent />, {
|
|
94
|
+
toast.custom(<MyCustomComponent />, {
|
|
95
|
+
id: 'custom_toast',
|
|
96
|
+
duration: 2000,
|
|
97
|
+
position: 'top-center',
|
|
98
|
+
});
|
|
170
99
|
|
|
171
100
|
// Function that receives a dismiss handler
|
|
172
|
-
toast.custom(
|
|
173
|
-
|
|
174
|
-
<
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
```jsx
|
|
186
|
-
import { ToastContainer, toast } from 'kitzo/react';
|
|
187
|
-
|
|
188
|
-
function App() {
|
|
189
|
-
function fakePromise() {
|
|
190
|
-
return new Promise((resolved, rejected) => {
|
|
191
|
-
setTimeout(() => {
|
|
192
|
-
Math.random() > 0.5 ? resolved('resolved') : rejected('rejected');
|
|
193
|
-
}, 2000);
|
|
194
|
-
});
|
|
195
|
-
}
|
|
101
|
+
toast.custom(
|
|
102
|
+
(dismiss) => (
|
|
103
|
+
<div>
|
|
104
|
+
<span>Custom toast message</span>
|
|
105
|
+
<button onClick={dismiss}>Close</button>
|
|
106
|
+
</div>
|
|
107
|
+
),
|
|
108
|
+
{
|
|
109
|
+
id: 'custom_toast',
|
|
110
|
+
duration: Infinity, // or 3000
|
|
111
|
+
position: 'top-center',
|
|
112
|
+
},
|
|
113
|
+
);
|
|
196
114
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
error: 'Failed saving data',
|
|
204
|
-
},
|
|
205
|
-
{ duration: 2500, position: 'top-center' },
|
|
206
|
-
);
|
|
207
|
-
}
|
|
115
|
+
// Simple string
|
|
116
|
+
toast.custom('Simple string toast', {
|
|
117
|
+
id: 'custom_toast',
|
|
118
|
+
duration: 2000,
|
|
119
|
+
position: 'top-center',
|
|
120
|
+
});
|
|
208
121
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
<span>Funtion that return jsx</span>
|
|
214
|
-
<button onClick={dismiss}>Close</button>
|
|
215
|
-
</div>
|
|
216
|
-
),
|
|
217
|
-
{
|
|
218
|
-
duration: 2000,
|
|
219
|
-
position: 'top-center',
|
|
220
|
-
},
|
|
221
|
-
);
|
|
222
|
-
}
|
|
122
|
+
// ---------------------
|
|
123
|
+
// Update / Dismiss
|
|
124
|
+
// ---------------------
|
|
125
|
+
// ❗ Update is only supported on custom toasts
|
|
223
126
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
<button onClick={() => toast.error('❌ Error toast message')}>Error</button>
|
|
228
|
-
<button onClick={promiseToast}>Promise</button>
|
|
229
|
-
<button onClick={customToast}>Custom Toast</button>
|
|
127
|
+
toast.update('my-toast', 'Updated content!', {
|
|
128
|
+
duration: 3000,
|
|
129
|
+
});
|
|
230
130
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
131
|
+
// Dismiss by id (optional)
|
|
132
|
+
toast.dismiss('my-toast');
|
|
133
|
+
// Or dismiss all toasts
|
|
134
|
+
toast.dismiss();
|
|
236
135
|
```
|
|
237
136
|
|
|
238
137
|
> Each toast can have its own position. default position is `top-center`.
|
|
239
138
|
|
|
240
|
-
##### React Tooltip API:
|
|
139
|
+
##### React Tooltip API usage:
|
|
241
140
|
|
|
242
141
|
```jsx
|
|
243
|
-
import { Tooltip } from 'kitzo
|
|
142
|
+
import { Tooltip } from 'kitzo';
|
|
244
143
|
|
|
245
144
|
function App() {
|
|
246
145
|
return (
|
|
@@ -261,7 +160,7 @@ function App() {
|
|
|
261
160
|
}}
|
|
262
161
|
style={{
|
|
263
162
|
'--arrow-size': 6,
|
|
264
|
-
'--arrow-color': 'red'
|
|
163
|
+
'--arrow-color': 'red',
|
|
265
164
|
}}
|
|
266
165
|
>
|
|
267
166
|
<button>Hover me</button>
|
|
@@ -273,3 +172,87 @@ function App() {
|
|
|
273
172
|
```
|
|
274
173
|
|
|
275
174
|
> You can provide your own custom jsx element as `content`. e.g. `content={<div>Custom tooltip</div>}`
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
### Hooks
|
|
179
|
+
|
|
180
|
+
- useDebounce
|
|
181
|
+
- useWindowSize
|
|
182
|
+
|
|
183
|
+
#### useDebounce usage:
|
|
184
|
+
|
|
185
|
+
```jsx
|
|
186
|
+
import { useDebounce } from 'kitzo';
|
|
187
|
+
|
|
188
|
+
function App() {
|
|
189
|
+
const [value, setValue] = useState('');
|
|
190
|
+
const debouncedValue = useDebounce(value, 500);
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<div>
|
|
194
|
+
<input
|
|
195
|
+
value={value}
|
|
196
|
+
onChange={(e) => setValue(e.target.value)}
|
|
197
|
+
/>
|
|
198
|
+
<p>Debounced value: {debouncedValue}</p>
|
|
199
|
+
</div>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
#### useWindowSize usage:
|
|
205
|
+
|
|
206
|
+
```jsx
|
|
207
|
+
import { useWindowSize } from 'kitzo';
|
|
208
|
+
|
|
209
|
+
function App() {
|
|
210
|
+
const { screenWidth, screenHeight } = useWindowSize({ delay: 100 });
|
|
211
|
+
|
|
212
|
+
return (
|
|
213
|
+
<div>
|
|
214
|
+
<p>Window width: {width}</p>
|
|
215
|
+
<p>Window height: {height}</p>
|
|
216
|
+
</div>
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
### Functions
|
|
224
|
+
|
|
225
|
+
- copy _(Copy text to clipboard)_
|
|
226
|
+
|
|
227
|
+
#### copy usage:
|
|
228
|
+
|
|
229
|
+
```jsx
|
|
230
|
+
import { copy } from 'kitzo/fns';
|
|
231
|
+
import { ToastContainer, toast } from 'kitzo';
|
|
232
|
+
|
|
233
|
+
// copy(text: string): Promise<void>;
|
|
234
|
+
|
|
235
|
+
function App() {
|
|
236
|
+
async function copyText(text) {
|
|
237
|
+
try {
|
|
238
|
+
await copy(text);
|
|
239
|
+
toast.success('Copied to clipboard');
|
|
240
|
+
} catch (err) {
|
|
241
|
+
console.error(err);
|
|
242
|
+
toast.error('Failed to copy to clipboard');
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return (
|
|
247
|
+
<div>
|
|
248
|
+
<button onClick={() => copyText('hello world')}>Copy text</button>
|
|
249
|
+
<ToastContainer />
|
|
250
|
+
</div>
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// or just
|
|
255
|
+
copy('hello world');
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
> Use `copy` function to copy text to clipboard.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//! Copy function
|
|
2
|
+
function legacyCopy(text) {
|
|
3
|
+
const textarea = document.createElement('textarea');
|
|
4
|
+
textarea.value = text;
|
|
5
|
+
|
|
6
|
+
document.body.appendChild(textarea);
|
|
7
|
+
textarea.select();
|
|
8
|
+
document.execCommand('copy');
|
|
9
|
+
document.body.removeChild(textarea);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async function writeToClipboard(text) {
|
|
13
|
+
if (!navigator.clipboard?.writeText) {
|
|
14
|
+
legacyCopy(text);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
await navigator.clipboard.writeText(text);
|
|
20
|
+
} catch (err) {
|
|
21
|
+
legacyCopy(text);
|
|
22
|
+
console.error(err);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function copy(doc) {
|
|
27
|
+
if (doc == null) throw new Error('[kitzo/copy] expected a value to copy, got null or undefined.');
|
|
28
|
+
|
|
29
|
+
const text =
|
|
30
|
+
typeof doc === 'string' || typeof doc === 'number' ? String(doc) : JSON.stringify(doc);
|
|
31
|
+
|
|
32
|
+
await writeToClipboard(text);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { copy };
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/kitzo/functions/copy.js"],"sourcesContent":["//! Copy function\r\nfunction legacyCopy(text) {\r\n const textarea = document.createElement('textarea');\r\n textarea.value = text;\r\n\r\n document.body.appendChild(textarea);\r\n textarea.select();\r\n document.execCommand('copy');\r\n document.body.removeChild(textarea);\r\n}\r\n\r\nasync function writeToClipboard(text) {\r\n if (!navigator.clipboard?.writeText) {\r\n legacyCopy(text);\r\n return;\r\n }\r\n\r\n try {\r\n await navigator.clipboard.writeText(text);\r\n } catch (err) {\r\n legacyCopy(text);\r\n console.error(err);\r\n }\r\n}\r\n\r\nexport default async function copy(doc) {\r\n if (doc == null) throw new Error('[kitzo/copy] expected a value to copy, got null or undefined.');\r\n\r\n const text =\r\n typeof doc === 'string' || typeof doc === 'number' ? String(doc) : JSON.stringify(doc);\r\n\r\n await writeToClipboard(text);\r\n}\r\n"],"names":[],"mappings":"AAAA;AACA,SAAS,UAAU,CAAC,IAAI,EAAE;AAC1B,EAAE,MAAM,QAAQ,GAAG,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;AACtD,EAAE,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC;AACxB;AACA,EAAE,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;AACtC,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;AACpB,EAAE,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AAC/B,EAAE,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;AACtC,CAAC;AACD;AACA,eAAe,gBAAgB,CAAC,IAAI,EAAE;AACtC,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,SAAS,EAAE;AACvC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;AACrB,IAAI,OAAO;AACX,EAAE,CAAC;AACH;AACA,EAAE,IAAI;AACN,IAAI,MAAM,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAC9C,EAAE,CAAC,CAAC,OAAO,GAAG,EAAE;AAChB,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;AACrB,IAAI,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AACvB,EAAE,CAAC;AACH,CAAC;AACD;AACe,eAAe,IAAI,CAAC,GAAG,EAAE;AACxC,EAAE,IAAI,GAAG,IAAI,IAAI,EAAE,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;AACpG;AACA,EAAE,MAAM,IAAI;AACZ,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,KAAK,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;AAC3F;AACA,EAAE,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC;AAC/B;;;;"}
|
|
File without changes
|