kitzo 3.0.0 → 3.1.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
@@ -37,7 +37,7 @@ A collection of hooks to simplify common React application logic:
37
37
  For full usage guides, API references, and live demonstrations, visit the documentation site:
38
38
  [https://kitzo.vercel.app](https://kitzo.vercel.app)
39
39
 
40
- Check out the [root project](file:///home/riyad/Desktop/kitzo-monorepo/README.md) for project-wide information.
40
+ Check out the [root project](https://github.com/riyad-96/kitzo) for project-wide information.
41
41
 
42
42
  ## License
43
43
 
package/dist/index.d.ts CHANGED
@@ -188,11 +188,27 @@ export declare function useDebouncedCallback<Args extends unknown[]>(callback: (
188
188
  */
189
189
  export declare function useLocalStorage<T>(key: string, initialValue: T, options?: Options_2<T>): [T, Dispatch<SetStateAction<T>>];
190
190
 
191
- export declare function useThrottle<T>(value: T, delay?: number): T;
191
+ /**
192
+ * A React hook that manages UI overlays (modal, drawer, popover, etc.)
193
+ * and synchronizes them with the browser navigation history.
194
+ *
195
+ * @param id - A stable unique identifier for the overlay.
196
+ * Required to maintain history state across navigations.
197
+ * Recommendation: Use page-scoped names like 'login-page:otp-modal'.
198
+ *
199
+ * @returns {isOpen: boolean, open: () => void, close: () => void}
200
+ */
201
+ export declare function useOverlay(id: string): {
202
+ isOpen: boolean;
203
+ open: () => void;
204
+ close: () => void;
205
+ };
192
206
 
193
- export declare function useWindowSize(updateDelay?: number): {
194
- screenWidth: number;
195
- screenHeight: number;
196
- };
207
+ export declare function useThrottle<T>(value: T, delay?: number): T;
208
+
209
+ export declare function useWindowSize(updateDelay?: number): {
210
+ screenWidth: number;
211
+ screenHeight: number;
212
+ };
197
213
 
198
- export { }
214
+ export { }
package/dist/index.js CHANGED
@@ -5,8 +5,9 @@ import { useCopy as s } from "./react/hooks/useCopy.js";
5
5
  import { useDebounce as a } from "./react/hooks/useDebounce.js";
6
6
  import { useDebouncedCallback as c } from "./react/hooks/useDebouncedCallback.js";
7
7
  import { useLocalStorage as i } from "./react/hooks/useLocalStorage.js";
8
- import { useThrottle as T } from "./react/hooks/useThrottle.js";
9
- import { useWindowSize as C } from "./react/hooks/useWindowSize.js";
8
+ import { useOverlay as T } from "./react/hooks/useOverlay.js";
9
+ import { useThrottle as y } from "./react/hooks/useThrottle.js";
10
+ import { useWindowSize as D } from "./react/hooks/useWindowSize.js";
10
11
  export {
11
12
  r as Toaster,
12
13
  p as Tooltip,
@@ -15,6 +16,7 @@ export {
15
16
  a as useDebounce,
16
17
  c as useDebouncedCallback,
17
18
  i as useLocalStorage,
18
- T as useThrottle,
19
- C as useWindowSize
19
+ T as useOverlay,
20
+ y as useThrottle,
21
+ D as useWindowSize
20
22
  };
@@ -0,0 +1,43 @@
1
+ import { useState as w, useEffect as d } from "react";
2
+ const n = "__kitzo_overlays";
3
+ let o = [];
4
+ const a = /* @__PURE__ */ new Set();
5
+ if (typeof window < "u") {
6
+ const e = () => {
7
+ o = window.history.state?.[n] || [], a.forEach((r) => r(o));
8
+ };
9
+ window.addEventListener("popstate", e), window.history.state && (o = window.history.state[n] || []);
10
+ }
11
+ function f(e) {
12
+ if (!e)
13
+ throw new Error(
14
+ `useOverlay requires a unique "id" parameter to manage history state correctly. Recommendation: Use a page-scoped name like 'login-page:my-modal'.`
15
+ );
16
+ const [c, r] = w(() => o.includes(e));
17
+ return d(() => {
18
+ const t = (s) => {
19
+ r(s.includes(e));
20
+ };
21
+ return a.add(t), t(o), () => {
22
+ a.delete(t);
23
+ };
24
+ }, [e]), {
25
+ isOpen: c,
26
+ open: () => {
27
+ const t = window.history.state || {}, s = t[n] || [];
28
+ if (!s.includes(e)) {
29
+ const i = [...s, e];
30
+ window.history.pushState(
31
+ { ...t, [n]: i },
32
+ ""
33
+ ), o = i, a.forEach((l) => l(o));
34
+ }
35
+ },
36
+ close: () => {
37
+ ((window.history.state || {})[n] || []).includes(e) ? window.history.back() : r(!1);
38
+ }
39
+ };
40
+ }
41
+ export {
42
+ f as useOverlay
43
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kitzo",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
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": [