kitzo 2.5.4 → 3.0.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 +24 -20
- package/dist/index.d.ts +16 -2
- package/dist/react/hooks/useLocalStorage.js +29 -20
- package/package.json +3 -12
package/README.md
CHANGED
|
@@ -1,40 +1,44 @@
|
|
|
1
1
|
# Kitzo
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A lightweight, production-ready React micro-utility library providing essential components, hooks, and functions for modern web applications.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
### Installation
|
|
5
|
+
## Installation
|
|
8
6
|
|
|
9
7
|
```bash
|
|
10
8
|
npm install kitzo
|
|
11
9
|
```
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
## Core Features
|
|
12
|
+
|
|
13
|
+
### React Components
|
|
14
|
+
|
|
15
|
+
Essential, accessible, and performance-optimized UI components:
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
- **Toast**: A flexible notification system with support for custom positions, animations, and interaction patterns.
|
|
18
|
+
- **Tooltip**: A contextual information component with smart positioning and customizable delay and animations.
|
|
16
19
|
|
|
17
|
-
|
|
20
|
+
### React Hooks
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
- **Tooltip** — Smart-positioned contextual labels.
|
|
22
|
+
A collection of hooks to simplify common React application logic:
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
- **useDebounce**: Delays value updates until a specified time has passed.
|
|
25
|
+
- **useDebouncedCallback**: Returns a debounced version of a callback function.
|
|
26
|
+
- **useThrottle**: Limits the execution rate of a frequently changing value.
|
|
27
|
+
- **useLocalStorage**: Synchronizes state with browser local storage.
|
|
28
|
+
- **useWindowSize**: Provides real-time window dimensions.
|
|
29
|
+
- **useCopy**: Simplifies clipboard operations within components.
|
|
23
30
|
|
|
24
|
-
|
|
25
|
-
- **useWindowSize** — Real-time viewport dimensions.
|
|
26
|
-
- **useCopy** — Simple "copy to clipboard" functionality.
|
|
27
|
-
- **useThrottle** — Limits how often a value can change within a specified time interval.
|
|
31
|
+
### Utility Functions
|
|
28
32
|
|
|
29
|
-
|
|
33
|
+
- **copy**: A standalone function for programmatically interacting with the system clipboard.
|
|
30
34
|
|
|
31
|
-
|
|
35
|
+
## Documentation
|
|
32
36
|
|
|
33
|
-
For usage guides and live
|
|
37
|
+
For full usage guides, API references, and live demonstrations, visit the documentation site:
|
|
34
38
|
[https://kitzo.vercel.app](https://kitzo.vercel.app)
|
|
35
39
|
|
|
36
|
-
|
|
40
|
+
Check out the [root project](file:///home/riyad/Desktop/kitzo-monorepo/README.md) for project-wide information.
|
|
37
41
|
|
|
38
|
-
|
|
42
|
+
## License
|
|
39
43
|
|
|
40
|
-
MIT
|
|
44
|
+
This project is licensed under the MIT License.
|
package/dist/index.d.ts
CHANGED
|
@@ -51,6 +51,13 @@ declare type DebounceOptions = {
|
|
|
51
51
|
|
|
52
52
|
declare type Options = ToastOptionsWithoutType;
|
|
53
53
|
|
|
54
|
+
declare type Options_2<T> = {
|
|
55
|
+
/** Milliseconds to debounce writes to localStorage (default: 0 — no debounce). */
|
|
56
|
+
debounceMs?: number;
|
|
57
|
+
/** Called once after the first value is read from localStorage on mount. */
|
|
58
|
+
onMount?: (value: T) => void;
|
|
59
|
+
};
|
|
60
|
+
|
|
54
61
|
declare type PromiseToastFn = <T, E = unknown>(promise: Promise<T>, msgs: PromiseToastMsgs<T, E>, options?: PromiseToastOptions) => Promise<T>;
|
|
55
62
|
|
|
56
63
|
declare type PromiseToastMsgs<T, E = unknown> = {
|
|
@@ -167,12 +174,19 @@ export declare function useDebouncedCallback<Args extends unknown[]>(callback: (
|
|
|
167
174
|
* always use `initialValue` (preventing hydration mismatches), and the
|
|
168
175
|
* real localStorage value is synced in after mount.
|
|
169
176
|
*
|
|
177
|
+
* - State is updated immediately on every `setValue` call for a responsive UI.
|
|
178
|
+
* - Writes to `localStorage` are debounced by `options.debounceMs` ms.
|
|
179
|
+
* - `options.onMount` is called exactly once with the first value read from storage.
|
|
180
|
+
*
|
|
170
181
|
* @example
|
|
171
|
-
* const [theme, setTheme] = useLocalStorage<'light' | 'dark'>('ui-theme', 'light'
|
|
182
|
+
* const [theme, setTheme] = useLocalStorage<'light' | 'dark'>('ui-theme', 'light', {
|
|
183
|
+
* debounceMs: 300,
|
|
184
|
+
* onMount: (v) => console.log('loaded from storage:', v),
|
|
185
|
+
* });
|
|
172
186
|
* // Supports functional updates:
|
|
173
187
|
* setTheme(prev => prev === 'light' ? 'dark' : 'light');
|
|
174
188
|
*/
|
|
175
|
-
export declare function useLocalStorage<T>(key: string, initialValue: T): [T, Dispatch<SetStateAction<T>>];
|
|
189
|
+
export declare function useLocalStorage<T>(key: string, initialValue: T, options?: Options_2<T>): [T, Dispatch<SetStateAction<T>>];
|
|
176
190
|
|
|
177
191
|
export declare function useThrottle<T>(value: T, delay?: number): T;
|
|
178
192
|
|
|
@@ -1,33 +1,42 @@
|
|
|
1
|
-
import
|
|
2
|
-
function
|
|
3
|
-
const
|
|
1
|
+
import o from "react";
|
|
2
|
+
function E(r, c, f) {
|
|
3
|
+
const g = f ?? {}, { debounceMs: s = 0, onMount: l } = g, i = o.useRef(l);
|
|
4
|
+
o.useEffect(() => {
|
|
5
|
+
i.current = l;
|
|
6
|
+
});
|
|
7
|
+
const [a, u] = o.useState(c), d = o.useCallback(() => {
|
|
4
8
|
try {
|
|
5
|
-
const e = window.localStorage.getItem(
|
|
6
|
-
return e ? JSON.parse(e) :
|
|
9
|
+
const e = window.localStorage.getItem(r);
|
|
10
|
+
return e ? JSON.parse(e) : c;
|
|
7
11
|
} catch (e) {
|
|
8
|
-
return console.warn(`Error reading localStorage key "${
|
|
12
|
+
return console.warn(`Error reading localStorage key "${r}":`, e), c;
|
|
9
13
|
}
|
|
10
|
-
}, [
|
|
14
|
+
}, [r, c]), n = o.useRef(
|
|
15
|
+
null
|
|
16
|
+
), S = o.useCallback(
|
|
11
17
|
(e) => {
|
|
12
18
|
try {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
const t = e instanceof Function ? e(a) : e;
|
|
20
|
+
u(t), typeof window < "u" && (n.current !== null && clearTimeout(n.current), s > 0 ? n.current = setTimeout(() => {
|
|
21
|
+
window.localStorage.setItem(r, JSON.stringify(t)), window.dispatchEvent(new Event("local-storage-update")), n.current = null;
|
|
22
|
+
}, s) : (window.localStorage.setItem(r, JSON.stringify(t)), window.dispatchEvent(new Event("local-storage-update"))));
|
|
23
|
+
} catch (t) {
|
|
24
|
+
console.warn(`Error setting localStorage key "${r}":`, t);
|
|
17
25
|
}
|
|
18
26
|
},
|
|
19
|
-
[
|
|
27
|
+
[r, a, s]
|
|
20
28
|
);
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
return o.useEffect(() => {
|
|
30
|
+
const e = d();
|
|
31
|
+
u(e), i.current?.(e);
|
|
32
|
+
const t = (w) => {
|
|
33
|
+
w.key && w.key !== r || u(d());
|
|
25
34
|
};
|
|
26
|
-
return window.addEventListener("storage",
|
|
27
|
-
window.removeEventListener("storage",
|
|
35
|
+
return window.addEventListener("storage", t), window.addEventListener("local-storage-update", t), () => {
|
|
36
|
+
n.current !== null && clearTimeout(n.current), window.removeEventListener("storage", t), window.removeEventListener("local-storage-update", t);
|
|
28
37
|
};
|
|
29
|
-
}, [
|
|
38
|
+
}, [r]), [a, S];
|
|
30
39
|
}
|
|
31
40
|
export {
|
|
32
|
-
|
|
41
|
+
E as useLocalStorage
|
|
33
42
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kitzo",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "A lightweight React micro-utility.",
|
|
3
|
+
"version": "3.0.0",
|
|
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": [
|
|
7
7
|
"dist"
|
|
@@ -44,24 +44,14 @@
|
|
|
44
44
|
"react-dom": ">=19"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@changesets/cli": "^2.29.8",
|
|
48
47
|
"@eslint/js": "^9.39.2",
|
|
49
48
|
"@tailwindcss/vite": "^4.1.18",
|
|
50
|
-
"@types/node": "^25.0.6",
|
|
51
|
-
"@types/react": "^19.2.8",
|
|
52
|
-
"@types/react-dom": "^19.2.3",
|
|
53
49
|
"@vitejs/plugin-react-swc": "^4.2.2",
|
|
54
|
-
"daisyui": "^5.5.14",
|
|
55
|
-
"eslint": "^9.39.2",
|
|
56
50
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
57
51
|
"eslint-plugin-react-refresh": "^0.4.26",
|
|
58
52
|
"globals": "^17.0.0",
|
|
59
|
-
"prettier": "^3.7.4",
|
|
60
|
-
"prettier-plugin-tailwindcss": "^0.7.2",
|
|
61
53
|
"react": "^19.2.3",
|
|
62
54
|
"react-dom": "^19.2.3",
|
|
63
|
-
"tailwindcss": "^4.1.18",
|
|
64
|
-
"typescript": "~5.8.2",
|
|
65
55
|
"typescript-eslint": "^8.52.0",
|
|
66
56
|
"vite": "^7.3.1",
|
|
67
57
|
"vite-plugin-dts": "^4.5.4"
|
|
@@ -70,6 +60,7 @@
|
|
|
70
60
|
"dev": "vite",
|
|
71
61
|
"dev:host": "vite --host",
|
|
72
62
|
"build": "tsc -b && vite build",
|
|
63
|
+
"type-check": "tsc --noEmit",
|
|
73
64
|
"lint": "eslint .",
|
|
74
65
|
"preview": "vite preview",
|
|
75
66
|
"cs": "changeset"
|