@oneplatformdev/hooks 0.1.0-15 → 0.1.0-150
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/CHANGELOG.md +585 -0
- package/index.d.ts +37 -0
- package/index.d.ts.map +1 -0
- package/package.json +14 -20
- package/useBoolean/index.d.ts +2 -0
- package/useBoolean/index.d.ts.map +1 -0
- package/useBoolean/index.js +4 -0
- package/useBoolean/useBoolean.d.ts +29 -0
- package/useBoolean/useBoolean.d.ts.map +1 -0
- package/useBoolean/useBoolean.js +16 -0
- package/useClickAnyWhere/index.d.ts +2 -0
- package/useClickAnyWhere/index.d.ts.map +1 -0
- package/useClickAnyWhere/index.js +4 -0
- package/useClickAnyWhere/useClickAnyWhere.d.ts +17 -0
- package/useClickAnyWhere/useClickAnyWhere.d.ts.map +1 -0
- package/useClickAnyWhere/useClickAnyWhere.js +9 -0
- package/useCopyToClipboard/index.d.ts +2 -0
- package/useCopyToClipboard/index.d.ts.map +1 -0
- package/useCopyToClipboard/index.js +4 -0
- package/useCopyToClipboard/useCopyToClipboard.d.ts +34 -0
- package/useCopyToClipboard/useCopyToClipboard.d.ts.map +1 -0
- package/useCopyToClipboard/useCopyToClipboard.js +16 -0
- package/useCountdown/index.d.ts +2 -0
- package/useCountdown/index.d.ts.map +1 -0
- package/useCountdown/index.js +4 -0
- package/useCountdown/useCountdown.d.ts +47 -0
- package/useCountdown/useCountdown.d.ts.map +1 -0
- package/useCountdown/useCountdown.js +33 -0
- package/useCounter/index.d.ts +2 -0
- package/useCounter/index.d.ts.map +1 -0
- package/useCounter/index.js +4 -0
- package/useCounter/useCounter.d.ts +28 -0
- package/useCounter/useCounter.d.ts.map +1 -0
- package/useCounter/useCounter.js +20 -0
- package/useDarkMode/index.d.ts +2 -0
- package/useDarkMode/index.d.ts.map +1 -0
- package/useDarkMode/index.js +4 -0
- package/useDarkMode/useDarkMode.d.ts +46 -0
- package/useDarkMode/useDarkMode.d.ts.map +1 -0
- package/useDarkMode/useDarkMode.js +38 -0
- package/useDebounceCallback/index.d.ts +3 -0
- package/useDebounceCallback/index.d.ts.map +1 -0
- package/useDebounceCallback/index.js +5 -0
- package/useDebounceCallback/useDebounceCallback.d.ts +62 -0
- package/useDebounceCallback/useDebounceCallback.d.ts.map +1 -0
- package/useDebounceCallback/useDebounceCallback.js +21 -0
- package/useDebounceValue/index.d.ts +2 -0
- package/useDebounceValue/index.d.ts.map +1 -0
- package/useDebounceValue/index.js +4 -0
- package/useDebounceValue/useDebounceValue.d.ts +40 -0
- package/useDebounceValue/useDebounceValue.d.ts.map +1 -0
- package/useDebounceValue/useDebounceValue.js +13 -0
- package/useDocumentTitle/index.d.ts +2 -0
- package/useDocumentTitle/index.d.ts.map +1 -0
- package/useDocumentTitle/index.js +4 -0
- package/useDocumentTitle/useDocumentTitle.d.ts +19 -0
- package/useDocumentTitle/useDocumentTitle.d.ts.map +1 -0
- package/useDocumentTitle/useDocumentTitle.js +16 -0
- package/useEventCallback/index.d.ts +2 -0
- package/useEventCallback/index.d.ts.map +1 -0
- package/useEventCallback/index.js +4 -0
- package/useEventCallback/useEventCallback.d.ts +18 -0
- package/useEventCallback/useEventCallback.d.ts.map +1 -0
- package/useEventCallback/useEventCallback.js +13 -0
- package/useEventListener/index.d.ts +2 -0
- package/useEventListener/index.d.ts.map +1 -0
- package/useEventListener/index.js +4 -0
- package/useEventListener/useEventListener.d.ts +9 -0
- package/useEventListener/useEventListener.d.ts.map +1 -0
- package/useEventListener/useEventListener.js +20 -0
- package/useHover/index.d.ts +2 -0
- package/useHover/index.d.ts.map +1 -0
- package/useHover/index.js +4 -0
- package/useHover/useHover.d.ts +17 -0
- package/useHover/useHover.d.ts.map +1 -0
- package/useHover/useHover.js +13 -0
- package/useIntersectionObserver/index.d.ts +2 -0
- package/useIntersectionObserver/index.d.ts.map +1 -0
- package/useIntersectionObserver/index.js +4 -0
- package/useIntersectionObserver/useIntersectionObserver.d.ts +72 -0
- package/useIntersectionObserver/useIntersectionObserver.d.ts.map +1 -0
- package/useIntersectionObserver/useIntersectionObserver.js +53 -0
- package/useInterval/index.d.ts +2 -0
- package/useInterval/index.d.ts.map +1 -0
- package/useInterval/index.js +4 -0
- package/useInterval/useInterval.d.ts +16 -0
- package/useInterval/useInterval.d.ts.map +1 -0
- package/useInterval/useInterval.js +20 -0
- package/useIsClient/index.d.ts +2 -0
- package/useIsClient/index.d.ts.map +1 -0
- package/useIsClient/index.js +4 -0
- package/useIsClient/useIsClient.d.ts +13 -0
- package/useIsClient/useIsClient.d.ts.map +1 -0
- package/useIsClient/useIsClient.js +10 -0
- package/useIsMobile/index.d.ts +3 -0
- package/useIsMobile/index.d.ts.map +1 -0
- package/useIsMobile/index.js +4 -0
- package/useIsMobile/types.d.ts +4 -0
- package/useIsMobile/types.d.ts.map +1 -0
- package/useIsMobile/types.js +1 -0
- package/useIsMobile/useIsMobile.d.ts +3 -0
- package/useIsMobile/useIsMobile.d.ts.map +1 -0
- package/useIsMobile/useIsMobile.js +16 -0
- package/useIsMounted/index.d.ts +2 -0
- package/useIsMounted/index.d.ts.map +1 -0
- package/useIsMounted/index.js +4 -0
- package/useIsMounted/useIsMounted.d.ts +2 -0
- package/useIsMounted/useIsMounted.d.ts.map +1 -0
- package/useIsMounted/useIsMounted.js +10 -0
- package/useIsomorphicLayoutEffect/index.d.ts +2 -0
- package/useIsomorphicLayoutEffect/index.d.ts.map +1 -0
- package/useIsomorphicLayoutEffect/index.js +4 -0
- package/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.ts +16 -0
- package/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.ts.map +1 -0
- package/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js +5 -0
- package/useLocalStorage/index.d.ts +2 -0
- package/useLocalStorage/index.d.ts.map +1 -0
- package/useLocalStorage/index.js +4 -0
- package/useLocalStorage/useLocalStorage.d.ts +39 -0
- package/useLocalStorage/useLocalStorage.d.ts.map +1 -0
- package/useLocalStorage/useLocalStorage.js +65 -0
- package/useLockBody/index.d.ts +2 -0
- package/useLockBody/index.d.ts.map +1 -0
- package/useLockBody/index.js +4 -0
- package/useLockBody/useLockBody.d.ts +2 -0
- package/useLockBody/useLockBody.d.ts.map +1 -0
- package/useLockBody/useLockBody.js +12 -0
- package/useMap/index.d.ts +2 -0
- package/useMap/index.d.ts.map +1 -0
- package/useMap/index.js +4 -0
- package/useMap/useMap.d.ts +48 -0
- package/useMap/useMap.d.ts.map +1 -0
- package/useMap/useMap.js +27 -0
- package/useMediaQuery/index.d.ts +2 -0
- package/useMediaQuery/index.d.ts.map +1 -0
- package/useMediaQuery/index.js +4 -0
- package/useMediaQuery/useMediaQuery.d.ts +29 -0
- package/useMediaQuery/useMediaQuery.d.ts.map +1 -0
- package/useMediaQuery/useMediaQuery.js +21 -0
- package/useOnClickOutside/index.d.ts +2 -0
- package/useOnClickOutside/index.d.ts.map +1 -0
- package/useOnClickOutside/index.js +4 -0
- package/useOnClickOutside/useOnClickOutside.d.ts +24 -0
- package/useOnClickOutside/useOnClickOutside.d.ts.map +1 -0
- package/useOnClickOutside/useOnClickOutside.js +17 -0
- package/useQueryString/index.d.ts +2 -0
- package/useQueryString/index.d.ts.map +1 -0
- package/useQueryString/index.js +4 -0
- package/useQueryString/useQueryString.d.ts +10 -0
- package/useQueryString/useQueryString.d.ts.map +1 -0
- package/useQueryString/useQueryString.js +10 -0
- package/useReadLocalStorage/index.d.ts +2 -0
- package/useReadLocalStorage/index.d.ts.map +1 -0
- package/useReadLocalStorage/index.js +4 -0
- package/useReadLocalStorage/useReadLocalStorage.d.ts +14 -0
- package/useReadLocalStorage/useReadLocalStorage.d.ts.map +1 -0
- package/useReadLocalStorage/useReadLocalStorage.js +48 -0
- package/useResizeObserver/index.d.ts +2 -0
- package/useResizeObserver/index.d.ts.map +1 -0
- package/useResizeObserver/index.js +4 -0
- package/useResizeObserver/useResizeObserver.d.ts +44 -0
- package/useResizeObserver/useResizeObserver.d.ts.map +1 -0
- package/useResizeObserver/useResizeObserver.js +31 -0
- package/useScreen/index.d.ts +2 -0
- package/useScreen/index.d.ts.map +1 -0
- package/useScreen/index.js +4 -0
- package/useScreen/useScreen.d.ts +20 -0
- package/useScreen/useScreen.d.ts.map +1 -0
- package/useScreen/useScreen.js +48 -0
- package/useScript/index.d.ts +2 -0
- package/useScript/index.d.ts.map +1 -0
- package/useScript/index.js +4 -0
- package/useScript/useScript.d.ts +24 -0
- package/useScript/useScript.d.ts.map +1 -0
- package/useScript/useScript.js +45 -0
- package/useScrollLock/index.d.ts +2 -0
- package/useScrollLock/index.d.ts.map +1 -0
- package/useScrollLock/index.js +4 -0
- package/useScrollLock/useScrollLock.d.ts +54 -0
- package/useScrollLock/useScrollLock.d.ts.map +1 -0
- package/useScrollLock/useScrollLock.js +26 -0
- package/useSessionStorage/index.d.ts +2 -0
- package/useSessionStorage/index.d.ts.map +1 -0
- package/useSessionStorage/index.js +4 -0
- package/useSessionStorage/useSessionStorage.d.ts +39 -0
- package/useSessionStorage/useSessionStorage.d.ts.map +1 -0
- package/useSessionStorage/useSessionStorage.js +65 -0
- package/useStep/index.d.ts +2 -0
- package/useStep/index.d.ts.map +1 -0
- package/useStep/index.js +4 -0
- package/useStep/useStep.d.ts +31 -0
- package/useStep/useStep.d.ts.map +1 -0
- package/useStep/useStep.js +34 -0
- package/useTernaryDarkMode/index.d.ts +2 -0
- package/useTernaryDarkMode/index.d.ts.map +1 -0
- package/useTernaryDarkMode/index.js +4 -0
- package/useTernaryDarkMode/useTernaryDarkMode.d.ts +46 -0
- package/useTernaryDarkMode/useTernaryDarkMode.d.ts.map +1 -0
- package/useTernaryDarkMode/useTernaryDarkMode.js +27 -0
- package/useTimeout/index.d.ts +2 -0
- package/useTimeout/index.d.ts.map +1 -0
- package/useTimeout/index.js +4 -0
- package/useTimeout/useTimeout.d.ts +17 -0
- package/useTimeout/useTimeout.d.ts.map +1 -0
- package/useTimeout/useTimeout.js +20 -0
- package/useToggle/index.d.ts +2 -0
- package/useToggle/index.d.ts.map +1 -0
- package/useToggle/index.js +4 -0
- package/useToggle/useToggle.d.ts +18 -0
- package/useToggle/useToggle.d.ts.map +1 -0
- package/useToggle/useToggle.js +10 -0
- package/useUnmount/index.d.ts +2 -0
- package/useUnmount/index.d.ts.map +1 -0
- package/useUnmount/index.js +4 -0
- package/useUnmount/useUnmount.d.ts +14 -0
- package/useUnmount/useUnmount.d.ts.map +1 -0
- package/useUnmount/useUnmount.js +13 -0
- package/useWindowSize/index.d.ts +2 -0
- package/useWindowSize/index.d.ts.map +1 -0
- package/useWindowSize/index.js +4 -0
- package/useWindowSize/useWindowSize.d.ts +30 -0
- package/useWindowSize/useWindowSize.d.ts.map +1 -0
- package/useWindowSize/useWindowSize.js +31 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useScript/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Script loading status. */
|
|
2
|
+
type UseScriptStatus = 'idle' | 'loading' | 'ready' | 'error';
|
|
3
|
+
/** Hook options. */
|
|
4
|
+
type UseScriptOptions = {
|
|
5
|
+
/** If `true`, prevents the script from being loaded (optional). */
|
|
6
|
+
shouldPreventLoad?: boolean;
|
|
7
|
+
/** If `true`, removes the script from the DOM when the component unmounts (optional). */
|
|
8
|
+
removeOnUnmount?: boolean;
|
|
9
|
+
/** Script's `id` (optional). */
|
|
10
|
+
id?: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Custom hook that dynamically loads scripts and tracking their loading status.
|
|
14
|
+
* @param {string | null} src - The source URL of the script to load. Set to `null` or omit to prevent loading (optional).
|
|
15
|
+
* @param {UseScriptOptions} [options] - Additional options for controlling script loading (optional).
|
|
16
|
+
* @returns {UseScriptStatus} The status of the script loading, which can be one of 'idle', 'loading', 'ready', or 'error'.
|
|
17
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-script)
|
|
18
|
+
* @example
|
|
19
|
+
* const scriptStatus = useScript('https://example.com/script.js', { removeOnUnmount: true });
|
|
20
|
+
* // Access the status of the script loading (e.g., 'loading', 'ready', 'error').
|
|
21
|
+
*/
|
|
22
|
+
export declare function useScript(src: string | null, options?: UseScriptOptions): UseScriptStatus;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=useScript.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScript.d.ts","sourceRoot":"","sources":["../../src/useScript/useScript.ts"],"names":[],"mappings":"AAEA,6BAA6B;AAC7B,KAAK,eAAe,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAA;AAE7D,oBAAoB;AACpB,KAAK,gBAAgB,GAAG;IACtB,mEAAmE;IACnE,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,yFAAyF;IACzF,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,gCAAgC;IAChC,EAAE,CAAC,EAAE,MAAM,CAAA;CACZ,CAAA;AA6BD;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,GAAG,IAAI,EAClB,OAAO,CAAC,EAAE,gBAAgB,GACzB,eAAe,CAsFjB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useState as v, useEffect as f } from "react";
|
|
2
|
+
const s = /* @__PURE__ */ new Map();
|
|
3
|
+
function m(t) {
|
|
4
|
+
const r = document.querySelector(
|
|
5
|
+
`script[src="${t}"]`
|
|
6
|
+
), u = r?.getAttribute("data-status");
|
|
7
|
+
return {
|
|
8
|
+
node: r,
|
|
9
|
+
status: u
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function p(t, r) {
|
|
13
|
+
const [u, i] = v(() => !t || r?.shouldPreventLoad ? "idle" : typeof window > "u" ? "loading" : s.get(t) ?? "loading");
|
|
14
|
+
return f(() => {
|
|
15
|
+
if (!t || r?.shouldPreventLoad)
|
|
16
|
+
return;
|
|
17
|
+
const n = s.get(t);
|
|
18
|
+
if (n === "ready" || n === "error") {
|
|
19
|
+
i(n);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const c = m(t);
|
|
23
|
+
let e = c.node;
|
|
24
|
+
if (e)
|
|
25
|
+
i(c.status ?? n ?? "loading");
|
|
26
|
+
else {
|
|
27
|
+
e = document.createElement("script"), e.src = t, e.async = !0, r?.id && (e.id = r.id), e.setAttribute("data-status", "loading"), document.body.appendChild(e);
|
|
28
|
+
const a = (o) => {
|
|
29
|
+
const l = o.type === "load" ? "ready" : "error";
|
|
30
|
+
e?.setAttribute("data-status", l);
|
|
31
|
+
};
|
|
32
|
+
e.addEventListener("load", a), e.addEventListener("error", a);
|
|
33
|
+
}
|
|
34
|
+
const d = (a) => {
|
|
35
|
+
const o = a.type === "load" ? "ready" : "error";
|
|
36
|
+
i(o), s.set(t, o);
|
|
37
|
+
};
|
|
38
|
+
return e.addEventListener("load", d), e.addEventListener("error", d), () => {
|
|
39
|
+
e && (e.removeEventListener("load", d), e.removeEventListener("error", d)), e && r?.removeOnUnmount && (e.remove(), s.delete(t));
|
|
40
|
+
};
|
|
41
|
+
}, [t, r?.shouldPreventLoad, r?.removeOnUnmount, r?.id]), u;
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
p as useScript
|
|
45
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useScrollLock/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** Hook options. */
|
|
2
|
+
type UseScrollLockOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* Whether to lock the scroll initially.
|
|
5
|
+
* @default true
|
|
6
|
+
*/
|
|
7
|
+
autoLock?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* The target element to lock the scroll (default is the body element).
|
|
10
|
+
* @default document.body
|
|
11
|
+
*/
|
|
12
|
+
lockTarget?: HTMLElement | string;
|
|
13
|
+
/**
|
|
14
|
+
* Whether to prevent width reflow when locking the scroll.
|
|
15
|
+
* @default true
|
|
16
|
+
*/
|
|
17
|
+
widthReflow?: boolean;
|
|
18
|
+
};
|
|
19
|
+
/** Hook return type. */
|
|
20
|
+
type UseScrollLockReturn = {
|
|
21
|
+
/** Whether the scroll is locked. */
|
|
22
|
+
isLocked: boolean;
|
|
23
|
+
/** Lock the scroll. */
|
|
24
|
+
lock: () => void;
|
|
25
|
+
/** Unlock the scroll. */
|
|
26
|
+
unlock: () => void;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* A custom hook that locks and unlocks scroll.
|
|
30
|
+
* @param {UseScrollLockOptions} [options] - Options to configure the hook, by default it will lock the scroll automatically.
|
|
31
|
+
* @returns {UseScrollLockReturn} - An object containing the lock and unlock functions.
|
|
32
|
+
* @public
|
|
33
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-scroll-lock)
|
|
34
|
+
* @example
|
|
35
|
+
* ```tsx
|
|
36
|
+
* // Lock the scroll when the modal is mounted, and unlock it when it's unmounted
|
|
37
|
+
* useScrollLock()
|
|
38
|
+
* ```
|
|
39
|
+
* @example
|
|
40
|
+
* ```tsx
|
|
41
|
+
* // Manually lock and unlock the scroll
|
|
42
|
+
* const { lock, unlock } = useScrollLock({ autoLock: false })
|
|
43
|
+
*
|
|
44
|
+
* return (
|
|
45
|
+
* <div>
|
|
46
|
+
* <button onClick={lock}>Lock</button>
|
|
47
|
+
* <button onClick={unlock}>Unlock</button>
|
|
48
|
+
* </div>
|
|
49
|
+
* )
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function useScrollLock(options?: UseScrollLockOptions): UseScrollLockReturn;
|
|
53
|
+
export {};
|
|
54
|
+
//# sourceMappingURL=useScrollLock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScrollLock.d.ts","sourceRoot":"","sources":["../../src/useScrollLock/useScrollLock.ts"],"names":[],"mappings":"AAIA,oBAAoB;AACpB,KAAK,oBAAoB,GAAG;IAC1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;OAGG;IACH,UAAU,CAAC,EAAE,WAAW,GAAG,MAAM,CAAA;IACjC;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAED,wBAAwB;AACxB,KAAK,mBAAmB,GAAG;IACzB,oCAAoC;IACpC,QAAQ,EAAE,OAAO,CAAA;IACjB,uBAAuB;IACvB,IAAI,EAAE,MAAM,IAAI,CAAA;IAChB,yBAAyB;IACzB,MAAM,EAAE,MAAM,IAAI,CAAA;CACnB,CAAA;AASD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,aAAa,CAC3B,OAAO,GAAE,oBAAyB,GACjC,mBAAmB,CA0ErB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useState as y, useRef as d } from "react";
|
|
2
|
+
import { useIsomorphicLayoutEffect as w } from "../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js";
|
|
3
|
+
const R = typeof window > "u";
|
|
4
|
+
function S(s = {}) {
|
|
5
|
+
const { autoLock: o = !0, lockTarget: e, widthReflow: n = !0 } = s, [l, c] = y(!1), t = d(null), r = d(null), u = () => {
|
|
6
|
+
if (t.current) {
|
|
7
|
+
const { overflow: f, paddingRight: g } = t.current.style;
|
|
8
|
+
if (r.current = { overflow: f, paddingRight: g }, n) {
|
|
9
|
+
const a = t.current === document.body ? window.innerWidth : t.current.offsetWidth, h = parseInt(window.getComputedStyle(t.current).paddingRight, 10) || 0, p = a - t.current.scrollWidth;
|
|
10
|
+
t.current.style.paddingRight = `${p + h}px`;
|
|
11
|
+
}
|
|
12
|
+
t.current.style.overflow = "hidden", c(!0);
|
|
13
|
+
}
|
|
14
|
+
}, i = () => {
|
|
15
|
+
t.current && r.current && (t.current.style.overflow = r.current.overflow, n && (t.current.style.paddingRight = r.current.paddingRight)), c(!1);
|
|
16
|
+
};
|
|
17
|
+
return w(() => {
|
|
18
|
+
if (!R)
|
|
19
|
+
return e && (t.current = typeof e == "string" ? document.querySelector(e) : e), t.current || (t.current = document.body), o && u(), () => {
|
|
20
|
+
i();
|
|
21
|
+
};
|
|
22
|
+
}, [o, e, n]), { isLocked: l, lock: u, unlock: i };
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
S as useScrollLock
|
|
26
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useSessionStorage/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
declare global {
|
|
3
|
+
interface WindowEventMap {
|
|
4
|
+
'session-storage': CustomEvent;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Represents the options for customizing the behavior of serialization and deserialization.
|
|
9
|
+
* @template T - The type of the state to be stored in session storage.
|
|
10
|
+
*/
|
|
11
|
+
type UseSessionStorageOptions<T> = {
|
|
12
|
+
/** A function to serialize the value before storing it. */
|
|
13
|
+
serializer?: (value: T) => string;
|
|
14
|
+
/** A function to deserialize the stored value. */
|
|
15
|
+
deserializer?: (value: string) => T;
|
|
16
|
+
/**
|
|
17
|
+
* If `true` (default), the hook will initialize reading the session storage. In SSR, you should set it to `false`, returning the initial value initially.
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
20
|
+
initializeWithValue?: boolean;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Custom hook that uses the [`sessionStorage API`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage) to persist state across page reloads.
|
|
24
|
+
* @template T - The type of the state to be stored in session storage.
|
|
25
|
+
* @param {string} key - The key under which the value will be stored in session storage.
|
|
26
|
+
* @param {T | (() => T)} initialValue - The initial value of the state or a function that returns the initial value.
|
|
27
|
+
* @param {?UseSessionStorageOptions<T>} [options] - Options for customizing the behavior of serialization and deserialization (optional).
|
|
28
|
+
* @returns {[T, Dispatch<SetStateAction<T>>, () => void]} A tuple containing the stored value, a function to set the value and a function to remove the key from storage.
|
|
29
|
+
* @public
|
|
30
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-session-storage)
|
|
31
|
+
* @example
|
|
32
|
+
* ```tsx
|
|
33
|
+
* const [count, setCount, removeCount] = useSessionStorage('count', 0);
|
|
34
|
+
* // Access the `count` value, the `setCount` function to update it and `removeCount` function to remove the key from storage.
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function useSessionStorage<T>(key: string, initialValue: T | (() => T), options?: UseSessionStorageOptions<T>): [T, Dispatch<SetStateAction<T>>, () => void];
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=useSessionStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSessionStorage.d.ts","sourceRoot":"","sources":["../../src/useSessionStorage/useSessionStorage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAKrD,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,cAAc;QACtB,iBAAiB,EAAE,WAAW,CAAA;KAC/B;CACF;AAED;;;GAGG;AACH,KAAK,wBAAwB,CAAC,CAAC,IAAI;IACjC,2DAA2D;IAC3D,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAA;IACjC,kDAAkD;IAClD,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,CAAC,CAAA;IACnC;;;OAGG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAC9B,CAAA;AAID;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAC3B,OAAO,GAAE,wBAAwB,CAAC,CAAC,CAAM,GACxC,CAAC,CAAC,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,CA2I9C"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { useCallback as i, useState as F, useEffect as p } from "react";
|
|
2
|
+
import { useEventCallback as u } from "../useEventCallback/useEventCallback.js";
|
|
3
|
+
import { useEventListener as w } from "../useEventListener/useEventListener.js";
|
|
4
|
+
const a = typeof window > "u";
|
|
5
|
+
function J(n, r, o = {}) {
|
|
6
|
+
const { initializeWithValue: S = !0 } = o, m = i(
|
|
7
|
+
(e) => o.serializer ? o.serializer(e) : JSON.stringify(e),
|
|
8
|
+
[o]
|
|
9
|
+
), d = i(
|
|
10
|
+
(e) => {
|
|
11
|
+
if (o.deserializer)
|
|
12
|
+
return o.deserializer(e);
|
|
13
|
+
if (e === "undefined")
|
|
14
|
+
return;
|
|
15
|
+
const t = r instanceof Function ? r() : r;
|
|
16
|
+
let g;
|
|
17
|
+
try {
|
|
18
|
+
g = JSON.parse(e);
|
|
19
|
+
} catch (z) {
|
|
20
|
+
return console.error("Error parsing JSON:", z), t;
|
|
21
|
+
}
|
|
22
|
+
return g;
|
|
23
|
+
},
|
|
24
|
+
[o, r]
|
|
25
|
+
), s = i(() => {
|
|
26
|
+
const e = r instanceof Function ? r() : r;
|
|
27
|
+
if (a)
|
|
28
|
+
return e;
|
|
29
|
+
try {
|
|
30
|
+
const t = window.sessionStorage.getItem(n);
|
|
31
|
+
return t ? d(t) : e;
|
|
32
|
+
} catch (t) {
|
|
33
|
+
return console.warn(`Error reading sessionStorage key “${n}”:`, t), e;
|
|
34
|
+
}
|
|
35
|
+
}, [r, n, d]), [h, c] = F(() => S ? s() : r instanceof Function ? r() : r), E = u((e) => {
|
|
36
|
+
a && console.warn(
|
|
37
|
+
`Tried setting sessionStorage key “${n}” even though environment is not a client`
|
|
38
|
+
);
|
|
39
|
+
try {
|
|
40
|
+
const t = e instanceof Function ? e(s()) : e;
|
|
41
|
+
window.sessionStorage.setItem(n, m(t)), c(t), window.dispatchEvent(new StorageEvent("session-storage", { key: n }));
|
|
42
|
+
} catch (t) {
|
|
43
|
+
console.warn(`Error setting sessionStorage key “${n}”:`, t);
|
|
44
|
+
}
|
|
45
|
+
}), v = u(() => {
|
|
46
|
+
a && console.warn(
|
|
47
|
+
`Tried removing sessionStorage key “${n}” even though environment is not a client`
|
|
48
|
+
);
|
|
49
|
+
const e = r instanceof Function ? r() : r;
|
|
50
|
+
window.sessionStorage.removeItem(n), c(e), window.dispatchEvent(new StorageEvent("session-storage", { key: n }));
|
|
51
|
+
});
|
|
52
|
+
p(() => {
|
|
53
|
+
c(s());
|
|
54
|
+
}, [n]);
|
|
55
|
+
const f = i(
|
|
56
|
+
(e) => {
|
|
57
|
+
e.key && e.key !== n || c(s());
|
|
58
|
+
},
|
|
59
|
+
[n, s]
|
|
60
|
+
);
|
|
61
|
+
return w("storage", f), w("session-storage", f), [h, E, v];
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
J as useSessionStorage
|
|
65
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useStep/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
|
package/useStep/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
/** Represents the second element of the output of the `useStep` hook. */
|
|
3
|
+
type UseStepActions = {
|
|
4
|
+
/** Go to the next step in the process. */
|
|
5
|
+
goToNextStep: () => void;
|
|
6
|
+
/** Go to the previous step in the process. */
|
|
7
|
+
goToPrevStep: () => void;
|
|
8
|
+
/** Reset the step to the initial step. */
|
|
9
|
+
reset: () => void;
|
|
10
|
+
/** Check if the next step is available. */
|
|
11
|
+
canGoToNextStep: boolean;
|
|
12
|
+
/** Check if the previous step is available. */
|
|
13
|
+
canGoToPrevStep: boolean;
|
|
14
|
+
/** Set the current step to a specific value. */
|
|
15
|
+
setStep: Dispatch<SetStateAction<number>>;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Custom hook that manages and navigates between steps in a multi-step process.
|
|
19
|
+
* @param {number} maxStep - The maximum step in the process.
|
|
20
|
+
* @returns {[number, UseStepActions]} An tuple containing the current step and helper functions for navigating steps.
|
|
21
|
+
* @public
|
|
22
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-step)
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* const [currentStep, { goToNextStep, goToPrevStep, reset, canGoToNextStep, canGoToPrevStep, setStep }] = useStep(3);
|
|
26
|
+
* // Access and use the current step and provided helper functions.
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function useStep(maxStep: number): [number, UseStepActions];
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=useStep.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStep.d.ts","sourceRoot":"","sources":["../../src/useStep/useStep.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAErD,yEAAyE;AACzE,KAAK,cAAc,GAAG;IACpB,0CAA0C;IAC1C,YAAY,EAAE,MAAM,IAAI,CAAA;IACxB,8CAA8C;IAC9C,YAAY,EAAE,MAAM,IAAI,CAAA;IACxB,0CAA0C;IAC1C,KAAK,EAAE,MAAM,IAAI,CAAA;IACjB,2CAA2C;IAC3C,eAAe,EAAE,OAAO,CAAA;IACxB,+CAA+C;IAC/C,eAAe,EAAE,OAAO,CAAA;IACxB,gDAAgD;IAChD,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAA;CAC1C,CAAA;AAID;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAgDjE"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useState as a, useCallback as n } from "react";
|
|
2
|
+
function l(r) {
|
|
3
|
+
const [e, o] = a(1), c = e + 1 <= r, s = e - 1 > 0, S = n(
|
|
4
|
+
(t) => {
|
|
5
|
+
const u = t instanceof Function ? t(e) : t;
|
|
6
|
+
if (u >= 1 && u <= r) {
|
|
7
|
+
o(u);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
throw new Error("Step not valid");
|
|
11
|
+
},
|
|
12
|
+
[r, e]
|
|
13
|
+
), i = n(() => {
|
|
14
|
+
c && o((t) => t + 1);
|
|
15
|
+
}, [c]), p = n(() => {
|
|
16
|
+
s && o((t) => t - 1);
|
|
17
|
+
}, [s]), f = n(() => {
|
|
18
|
+
o(1);
|
|
19
|
+
}, []);
|
|
20
|
+
return [
|
|
21
|
+
e,
|
|
22
|
+
{
|
|
23
|
+
goToNextStep: i,
|
|
24
|
+
goToPrevStep: p,
|
|
25
|
+
canGoToNextStep: c,
|
|
26
|
+
canGoToPrevStep: s,
|
|
27
|
+
setStep: S,
|
|
28
|
+
reset: f
|
|
29
|
+
}
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
l as useStep
|
|
34
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useTernaryDarkMode/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
/** Ternary dark mode options. */
|
|
3
|
+
export type TernaryDarkMode = 'system' | 'dark' | 'light';
|
|
4
|
+
/** Options for the `useTernaryDarkMode` hook. */
|
|
5
|
+
export type TernaryDarkModeOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* The default value for the dark mode.
|
|
8
|
+
* @default 'system'
|
|
9
|
+
*/
|
|
10
|
+
defaultValue?: TernaryDarkMode;
|
|
11
|
+
/**
|
|
12
|
+
* The key for storing dark mode preference in local storage.
|
|
13
|
+
* @default 'usehooks-ts-ternary-dark-mode'
|
|
14
|
+
*/
|
|
15
|
+
localStorageKey?: string;
|
|
16
|
+
/**
|
|
17
|
+
* If `true` (default), the hook will initialize reading `localStorage`. In SSR, you should set it to `false`, returning default values initially.
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
20
|
+
initializeWithValue?: boolean;
|
|
21
|
+
};
|
|
22
|
+
/** Represents the return type of the `useTernaryDarkMode` hook. */
|
|
23
|
+
export type TernaryDarkModeReturn = {
|
|
24
|
+
/** The current state of the dark mode. */
|
|
25
|
+
isDarkMode: boolean;
|
|
26
|
+
/** The current state of the dark mode. */
|
|
27
|
+
ternaryDarkMode: TernaryDarkMode;
|
|
28
|
+
/** A function to set the dark mode state. */
|
|
29
|
+
setTernaryDarkMode: Dispatch<SetStateAction<TernaryDarkMode>>;
|
|
30
|
+
/** A function to toggle the dark mode state. */
|
|
31
|
+
toggleTernaryDarkMode: () => void;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Custom hook that manages ternary (system, dark, light) dark mode with local storage support.
|
|
35
|
+
* @param {?TernaryDarkModeOptions | string} [options] - Options or the local storage key for the hook.
|
|
36
|
+
* @returns {TernaryDarkModeReturn} An object containing the dark mode state and helper functions.
|
|
37
|
+
* @public
|
|
38
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-ternary-dark-mode)
|
|
39
|
+
* @example
|
|
40
|
+
* ```tsx
|
|
41
|
+
* const { isDarkMode, ternaryDarkMode, setTernaryDarkMode, toggleTernaryDarkMode } = useTernaryDarkMode({ defaultValue: 'dark' });
|
|
42
|
+
* // Access and use the dark mode state and provided helper functions.
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function useTernaryDarkMode({ defaultValue, localStorageKey, initializeWithValue, }?: TernaryDarkModeOptions): TernaryDarkModeReturn;
|
|
46
|
+
//# sourceMappingURL=useTernaryDarkMode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTernaryDarkMode.d.ts","sourceRoot":"","sources":["../../src/useTernaryDarkMode/useTernaryDarkMode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAQrD,iCAAiC;AACjC,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;AAEzD,iDAAiD;AACjD,MAAM,MAAM,sBAAsB,GAAG;IACnC;;;OAGG;IACH,YAAY,CAAC,EAAE,eAAe,CAAA;IAC9B;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;OAGG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAC9B,CAAA;AAED,mEAAmE;AACnE,MAAM,MAAM,qBAAqB,GAAG;IAClC,0CAA0C;IAC1C,UAAU,EAAE,OAAO,CAAA;IACnB,0CAA0C;IAC1C,eAAe,EAAE,eAAe,CAAA;IAChC,6CAA6C;IAC7C,kBAAkB,EAAE,QAAQ,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC,CAAA;IAC7D,gDAAgD;IAChD,qBAAqB,EAAE,MAAM,IAAI,CAAA;CAClC,CAAA;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,YAAuB,EACvB,eAAmC,EACnC,mBAA0B,GAC3B,GAAE,sBAA2B,GAAG,qBAAqB,CAsBrD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useLocalStorage as c } from "../useLocalStorage/useLocalStorage.js";
|
|
2
|
+
import { useMediaQuery as m } from "../useMediaQuery/useMediaQuery.js";
|
|
3
|
+
const y = "(prefers-color-scheme: dark)", M = "usehooks-ts-ternary-dark-mode";
|
|
4
|
+
function f({
|
|
5
|
+
defaultValue: t = "system",
|
|
6
|
+
localStorageKey: n = M,
|
|
7
|
+
initializeWithValue: o = !0
|
|
8
|
+
} = {}) {
|
|
9
|
+
const a = m(y, { initializeWithValue: o }), [e, s] = c(n, t, {
|
|
10
|
+
initializeWithValue: o
|
|
11
|
+
});
|
|
12
|
+
return {
|
|
13
|
+
isDarkMode: e === "dark" || e === "system" && a,
|
|
14
|
+
ternaryDarkMode: e,
|
|
15
|
+
setTernaryDarkMode: s,
|
|
16
|
+
toggleTernaryDarkMode: () => {
|
|
17
|
+
const r = ["light", "system", "dark"];
|
|
18
|
+
s((d) => {
|
|
19
|
+
const k = (r.indexOf(d) + 1) % r.length;
|
|
20
|
+
return r[k];
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
f as useTernaryDarkMode
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useTimeout/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom hook that handles timeouts in React components using the [`setTimeout API`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout).
|
|
3
|
+
* @param {() => void} callback - The function to be executed when the timeout elapses.
|
|
4
|
+
* @param {number | null} delay - The duration (in milliseconds) for the timeout. Set to `null` to clear the timeout.
|
|
5
|
+
* @returns {void} This hook does not return anything.
|
|
6
|
+
* @public
|
|
7
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-timeout)
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* // Usage of useTimeout hook
|
|
11
|
+
* useTimeout(() => {
|
|
12
|
+
* // Code to be executed after the specified delay
|
|
13
|
+
* }, 1000); // Set a timeout of 1000 milliseconds (1 second)
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function useTimeout(callback: () => void, delay: number | null): void;
|
|
17
|
+
//# sourceMappingURL=useTimeout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTimeout.d.ts","sourceRoot":"","sources":["../../src/useTimeout/useTimeout.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAwB3E"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useRef as u, useEffect as f } from "react";
|
|
2
|
+
import { useIsomorphicLayoutEffect as i } from "../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js";
|
|
3
|
+
function n(e, t) {
|
|
4
|
+
const r = u(e);
|
|
5
|
+
i(() => {
|
|
6
|
+
r.current = e;
|
|
7
|
+
}, [e]), f(() => {
|
|
8
|
+
if (!t && t !== 0)
|
|
9
|
+
return;
|
|
10
|
+
const o = setTimeout(() => {
|
|
11
|
+
r.current();
|
|
12
|
+
}, t);
|
|
13
|
+
return () => {
|
|
14
|
+
clearTimeout(o);
|
|
15
|
+
};
|
|
16
|
+
}, [t]);
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
n as useTimeout
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useToggle/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Custom hook that manages a boolean toggle state in React components.
|
|
4
|
+
* @param {boolean} [defaultValue] - The initial value for the toggle state.
|
|
5
|
+
* @returns {[boolean, () => void, Dispatch<SetStateAction<boolean>>]} A tuple containing the current state,
|
|
6
|
+
* a function to toggle the state, and a function to set the state explicitly.
|
|
7
|
+
* @public
|
|
8
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-toggle)
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* const [isToggled, toggle, setToggle] = useToggle(); // Initial value is false
|
|
12
|
+
* // OR
|
|
13
|
+
* const [isToggled, toggle, setToggle] = useToggle(true); // Initial value is true
|
|
14
|
+
* // Use isToggled in your component, toggle to switch the state, setToggle to set the state explicitly.
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function useToggle(defaultValue?: boolean): [boolean, () => void, Dispatch<SetStateAction<boolean>>];
|
|
18
|
+
//# sourceMappingURL=useToggle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useToggle.d.ts","sourceRoot":"","sources":["../../src/useToggle/useToggle.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAErD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CACvB,YAAY,CAAC,EAAE,OAAO,GACrB,CAAC,OAAO,EAAE,MAAM,IAAI,EAAE,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAQ1D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useUnmount/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom hook that runs a cleanup function when the component is unmounted.
|
|
3
|
+
* @param {() => void} func - The cleanup function to be executed on unmount.
|
|
4
|
+
* @public
|
|
5
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-unmount)
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* useUnmount(() => {
|
|
9
|
+
* // Cleanup logic here
|
|
10
|
+
* });
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare function useUnmount(func: () => void): void;
|
|
14
|
+
//# sourceMappingURL=useUnmount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUnmount.d.ts","sourceRoot":"","sources":["../../src/useUnmount/useUnmount.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,IAAI,QAW1C"}
|