kitzo 2.1.28 → 2.1.30

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
@@ -2,20 +2,7 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/kitzo)](https://www.npmjs.com/package/kitzo)
4
4
 
5
- ### A lightweight library of Vanilla js and React js
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,134 +10,24 @@
23
10
  npm i kitzo
24
11
  ```
25
12
 
26
- or
27
-
28
- ```javascript
29
- <script src="https://cdn.jsdelivr.net/npm/kitzo@2.1.28/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:
58
-
59
- ```javascript
60
- kitzo.copy(doc);
61
- ```
62
-
63
- > Copy functionality on call.
64
-
65
- ##### Tooltip API:
66
-
67
- ```javascript
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
- ```
77
-
78
- > Attach minimal tooltips to buttons for clean, helpful hover hints.
79
-
80
- ##### Ripple API:
81
-
82
- ```javascript
83
- kitzo.ripple(selectors | element | NodeList, {
84
- opacity: number,
85
- duration: number,
86
- color: string,
87
- size: number,
88
- });
89
- ```
90
-
91
- > Adds a lightweight, clean ripple effect to your elements on click.
92
-
93
- ##### Debounce API:
94
-
95
- ```javascript
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);
108
- });
109
- ```
110
-
111
- > Debounce on every call of function.
112
-
113
- ##### Clippath API:
114
-
115
- ```javascript
116
- kitzo.clippath(selectors | element | NodeList, {
117
- textOption: null | { selector: string, value: string | number },
118
- clippathSize: string | number,
119
- smooth: boolean,
120
- class: string,
121
- style: object,
122
- });
123
- ```
124
-
125
- ##### TypeCheck API:
126
-
127
- ```javascript
128
- kitzo.getType(type);
13
+ #### React APIs
129
14
 
130
- const data = [];
131
- console.log(kitzo.getType(data)); // 'array'
15
+ ```jsx
16
+ import { ToastContainer, toast, Tooltip, useDebounce, useWindowSize } from 'kitzo';
132
17
  ```
133
18
 
134
- ---
135
-
136
- ## React
137
-
138
- #### Install
19
+ > You can import only what you need.
139
20
 
140
- ```bash
141
- npm i kitzo
142
- ```
21
+ #### UI
143
22
 
144
- #### React APIs
145
-
146
- ```jsx
147
- import { ToastContainer, toast, Tooltip, ... } from 'kitzo/react';
148
- ```
23
+ - Toast message
24
+ - Tooltip
149
25
 
150
26
  ##### Toast API:
151
27
 
152
28
  ```jsx
153
- import { toast } from 'kitzo/react';
29
+ import { toast } from 'kitzo';
30
+ import MyCustomComponent from './MyCustomComponent';
154
31
 
155
32
  toast.success('toast message', { duration: 2000, style: {}, showIcon: true, position: 'top-center' });
156
33
  toast.error('toast message', { duration: 2000, style: {}, showIcon: true, position: 'top-center' });
@@ -183,7 +60,7 @@ toast.custom("string");
183
60
  ##### React Toast API Usage
184
61
 
185
62
  ```jsx
186
- import { ToastContainer, toast } from 'kitzo/react';
63
+ import { ToastContainer, toast } from 'kitzo';
187
64
 
188
65
  function App() {
189
66
  function fakePromise() {
@@ -228,7 +105,7 @@ function App() {
228
105
  <button onClick={promiseToast}>Promise</button>
229
106
  <button onClick={customToast}>Custom Toast</button>
230
107
 
231
- {/* Toast container must needed */}
108
+ {/* Toast container must be placed */}
232
109
  <ToastContainer />
233
110
  </div>
234
111
  );
@@ -237,10 +114,10 @@ function App() {
237
114
 
238
115
  > Each toast can have its own position. default position is `top-center`.
239
116
 
240
- ##### React Tooltip API:
117
+ ##### React Tooltip API usage:
241
118
 
242
119
  ```jsx
243
- import { Tooltip } from 'kitzo/react';
120
+ import { Tooltip } from 'kitzo';
244
121
 
245
122
  function App() {
246
123
  return (
@@ -261,7 +138,7 @@ function App() {
261
138
  }}
262
139
  style={{
263
140
  '--arrow-size': 6,
264
- '--arrow-color': 'red'
141
+ '--arrow-color': 'red',
265
142
  }}
266
143
  >
267
144
  <button>Hover me</button>
@@ -273,3 +150,86 @@ function App() {
273
150
  ```
274
151
 
275
152
  > You can provide your own custom jsx element as `content`. e.g. `content={<div>Custom tooltip</div>}`
153
+
154
+ ---
155
+
156
+ ### Hooks
157
+
158
+ - useDebounce
159
+ - useWindowSize
160
+
161
+ #### useDebounce usage:
162
+
163
+ ```jsx
164
+ import { useDebounce } from 'kitzo';
165
+
166
+ function App() {
167
+ const [value, setValue] = useState('');
168
+ const debouncedValue = useDebounce(value, 500);
169
+
170
+ return (
171
+ <div>
172
+ <input
173
+ value={value}
174
+ onChange={(e) => setValue(e.target.value)}
175
+ />
176
+ <p>Debounced value: {debouncedValue}</p>
177
+ </div>
178
+ );
179
+ }
180
+ ```
181
+
182
+ #### useWindowSize usage:
183
+
184
+ ```jsx
185
+ import { useWindowSize } from 'kitzo';
186
+
187
+ function App() {
188
+ const { screenWidth, screenHeight } = useWindowSize({ delay: 100 });
189
+
190
+ return (
191
+ <div>
192
+ <p>Window width: {width}</p>
193
+ <p>Window height: {height}</p>
194
+ </div>
195
+ );
196
+ }
197
+ ```
198
+
199
+ ---
200
+
201
+ ### Functions
202
+
203
+ - copy _(Copy text to clipboard)_
204
+
205
+ #### copy usage:
206
+ ```jsx
207
+ import { copy } from 'kitzo/fns';
208
+ import { ToastContainer, toast } from 'kitzo';
209
+
210
+ // copy(text: string): Promise<void>;
211
+
212
+ function App() {
213
+ async function copyText(text) {
214
+ try {
215
+ await copy(text);
216
+ toast.success('Copied to clipboard');
217
+ } catch (err) {
218
+ console.error(err);
219
+ toast.error('Failed to copy to clipboard');
220
+ }
221
+ }
222
+
223
+ return (
224
+ <div>
225
+ <button onClick={() => copyText('hello world')}>Copy text</button>
226
+ <ToastContainer />
227
+ </div>
228
+ );
229
+ }
230
+
231
+ // or just
232
+ copy('hello world');
233
+ ```
234
+
235
+ > 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