@oneplatformdev/hooks 0.0.1-beta.6 → 0.1.1-1
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 +2 -2
- package/package.json +29 -30
- package/index.d.ts +0 -35
- package/index.mjs +0 -72
- package/useBoolean/index.d.ts +0 -1
- package/useBoolean/index.mjs +0 -4
- package/useBoolean/package.json +0 -7
- package/useBoolean/useBoolean.d.ts +0 -29
- package/useBoolean/useBoolean.mjs +0 -16
- package/useClickAnyWhere/index.d.ts +0 -1
- package/useClickAnyWhere/index.mjs +0 -4
- package/useClickAnyWhere/package.json +0 -7
- package/useClickAnyWhere/useClickAnyWhere.d.ts +0 -16
- package/useClickAnyWhere/useClickAnyWhere.mjs +0 -9
- package/useCopyToClipboard/index.d.ts +0 -1
- package/useCopyToClipboard/index.mjs +0 -4
- package/useCopyToClipboard/package.json +0 -7
- package/useCopyToClipboard/useCopyToClipboard.d.ts +0 -33
- package/useCopyToClipboard/useCopyToClipboard.mjs +0 -16
- package/useCountdown/index.d.ts +0 -1
- package/useCountdown/index.mjs +0 -4
- package/useCountdown/package.json +0 -7
- package/useCountdown/useCountdown.d.ts +0 -46
- package/useCountdown/useCountdown.mjs +0 -33
- package/useCounter/index.d.ts +0 -1
- package/useCounter/index.mjs +0 -4
- package/useCounter/package.json +0 -7
- package/useCounter/useCounter.d.ts +0 -28
- package/useCounter/useCounter.mjs +0 -20
- package/useDarkMode/index.d.ts +0 -1
- package/useDarkMode/index.mjs +0 -4
- package/useDarkMode/package.json +0 -7
- package/useDarkMode/useDarkMode.d.ts +0 -45
- package/useDarkMode/useDarkMode.mjs +0 -38
- package/useDebounceCallback/index.d.ts +0 -2
- package/useDebounceCallback/index.mjs +0 -5
- package/useDebounceCallback/package.json +0 -7
- package/useDebounceCallback/useDebounceCallback.d.ts +0 -61
- package/useDebounceCallback/useDebounceCallback.mjs +0 -101
- package/useDebounceValue/index.d.ts +0 -1
- package/useDebounceValue/index.mjs +0 -4
- package/useDebounceValue/package.json +0 -7
- package/useDebounceValue/useDebounceValue.d.ts +0 -40
- package/useDebounceValue/useDebounceValue.mjs +0 -13
- package/useDocumentTitle/index.d.ts +0 -1
- package/useDocumentTitle/index.mjs +0 -4
- package/useDocumentTitle/package.json +0 -7
- package/useDocumentTitle/useDocumentTitle.d.ts +0 -18
- package/useDocumentTitle/useDocumentTitle.mjs +0 -16
- package/useEventCallback/index.d.ts +0 -1
- package/useEventCallback/index.mjs +0 -4
- package/useEventCallback/package.json +0 -7
- package/useEventCallback/useEventCallback.d.ts +0 -17
- package/useEventCallback/useEventCallback.mjs +0 -16
- package/useEventListener/index.d.ts +0 -1
- package/useEventListener/index.mjs +0 -4
- package/useEventListener/package.json +0 -7
- package/useEventListener/useEventListener.d.ts +0 -7
- package/useEventListener/useEventListener.mjs +0 -20
- package/useHover/index.d.ts +0 -1
- package/useHover/index.mjs +0 -4
- package/useHover/package.json +0 -7
- package/useHover/useHover.d.ts +0 -17
- package/useHover/useHover.mjs +0 -13
- package/useIntersectionObserver/index.d.ts +0 -1
- package/useIntersectionObserver/index.mjs +0 -4
- package/useIntersectionObserver/package.json +0 -7
- package/useIntersectionObserver/useIntersectionObserver.d.ts +0 -71
- package/useIntersectionObserver/useIntersectionObserver.mjs +0 -55
- package/useInterval/index.d.ts +0 -1
- package/useInterval/index.mjs +0 -4
- package/useInterval/package.json +0 -7
- package/useInterval/useInterval.d.ts +0 -15
- package/useInterval/useInterval.mjs +0 -20
- package/useIsClient/index.d.ts +0 -1
- package/useIsClient/index.mjs +0 -4
- package/useIsClient/package.json +0 -7
- package/useIsClient/useIsClient.d.ts +0 -12
- package/useIsClient/useIsClient.mjs +0 -10
- package/useIsMobile/index.d.ts +0 -2
- package/useIsMobile/index.mjs +0 -4
- package/useIsMobile/package.json +0 -7
- package/useIsMobile/types.d.ts +0 -3
- package/useIsMobile/types.mjs +0 -1
- package/useIsMobile/useIsMobile.d.ts +0 -3
- package/useIsMobile/useIsMobile.mjs +0 -16
- package/useIsMounted/index.d.ts +0 -1
- package/useIsMounted/index.mjs +0 -4
- package/useIsMounted/package.json +0 -7
- package/useIsMounted/useIsMounted.d.ts +0 -1
- package/useIsMounted/useIsMounted.mjs +0 -10
- package/useIsomorphicLayoutEffect/index.d.ts +0 -1
- package/useIsomorphicLayoutEffect/index.mjs +0 -4
- package/useIsomorphicLayoutEffect/package.json +0 -7
- package/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.ts +0 -16
- package/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs +0 -5
- package/useLocalStorage/index.d.ts +0 -1
- package/useLocalStorage/index.mjs +0 -4
- package/useLocalStorage/package.json +0 -7
- package/useLocalStorage/useLocalStorage.d.ts +0 -39
- package/useLocalStorage/useLocalStorage.mjs +0 -65
- package/useLockBody/index.d.ts +0 -1
- package/useLockBody/index.mjs +0 -4
- package/useLockBody/package.json +0 -7
- package/useLockBody/useLockBody.d.ts +0 -1
- package/useLockBody/useLockBody.mjs +0 -12
- package/useMap/index.d.ts +0 -1
- package/useMap/index.mjs +0 -4
- package/useMap/package.json +0 -7
- package/useMap/useMap.d.ts +0 -47
- package/useMap/useMap.mjs +0 -27
- package/useMediaQuery/index.d.ts +0 -1
- package/useMediaQuery/index.mjs +0 -4
- package/useMediaQuery/package.json +0 -7
- package/useMediaQuery/useMediaQuery.d.ts +0 -28
- package/useMediaQuery/useMediaQuery.mjs +0 -21
- package/useOnClickOutside/index.d.ts +0 -1
- package/useOnClickOutside/index.mjs +0 -4
- package/useOnClickOutside/package.json +0 -7
- package/useOnClickOutside/useOnClickOutside.d.ts +0 -24
- package/useOnClickOutside/useOnClickOutside.mjs +0 -17
- package/useReadLocalStorage/index.d.ts +0 -1
- package/useReadLocalStorage/index.mjs +0 -4
- package/useReadLocalStorage/package.json +0 -7
- package/useReadLocalStorage/useReadLocalStorage.d.ts +0 -13
- package/useReadLocalStorage/useReadLocalStorage.mjs +0 -48
- package/useResizeObserver/index.d.ts +0 -1
- package/useResizeObserver/index.mjs +0 -4
- package/useResizeObserver/package.json +0 -7
- package/useResizeObserver/useResizeObserver.d.ts +0 -44
- package/useResizeObserver/useResizeObserver.mjs +0 -31
- package/useScreen/index.d.ts +0 -1
- package/useScreen/index.mjs +0 -4
- package/useScreen/package.json +0 -7
- package/useScreen/useScreen.d.ts +0 -19
- package/useScreen/useScreen.mjs +0 -48
- package/useScript/index.d.ts +0 -1
- package/useScript/index.mjs +0 -4
- package/useScript/package.json +0 -7
- package/useScript/useScript.d.ts +0 -23
- package/useScript/useScript.mjs +0 -45
- package/useScrollLock/index.d.ts +0 -1
- package/useScrollLock/index.mjs +0 -4
- package/useScrollLock/package.json +0 -7
- package/useScrollLock/useScrollLock.d.ts +0 -53
- package/useScrollLock/useScrollLock.mjs +0 -26
- package/useSessionStorage/index.d.ts +0 -1
- package/useSessionStorage/index.mjs +0 -4
- package/useSessionStorage/package.json +0 -7
- package/useSessionStorage/useSessionStorage.d.ts +0 -39
- package/useSessionStorage/useSessionStorage.mjs +0 -65
- package/useStep/index.d.ts +0 -1
- package/useStep/index.mjs +0 -4
- package/useStep/package.json +0 -7
- package/useStep/useStep.d.ts +0 -31
- package/useStep/useStep.mjs +0 -34
- package/useTernaryDarkMode/index.d.ts +0 -1
- package/useTernaryDarkMode/index.mjs +0 -4
- package/useTernaryDarkMode/package.json +0 -7
- package/useTernaryDarkMode/useTernaryDarkMode.d.ts +0 -46
- package/useTernaryDarkMode/useTernaryDarkMode.mjs +0 -27
- package/useTimeout/index.d.ts +0 -1
- package/useTimeout/index.mjs +0 -4
- package/useTimeout/package.json +0 -7
- package/useTimeout/useTimeout.d.ts +0 -16
- package/useTimeout/useTimeout.mjs +0 -20
- package/useToggle/index.d.ts +0 -1
- package/useToggle/index.mjs +0 -4
- package/useToggle/package.json +0 -7
- package/useToggle/useToggle.d.ts +0 -18
- package/useToggle/useToggle.mjs +0 -10
- package/useUnmount/index.d.ts +0 -1
- package/useUnmount/index.mjs +0 -4
- package/useUnmount/package.json +0 -7
- package/useUnmount/useUnmount.d.ts +0 -13
- package/useUnmount/useUnmount.mjs +0 -13
- package/useWindowSize/index.d.ts +0 -1
- package/useWindowSize/index.mjs +0 -4
- package/useWindowSize/package.json +0 -7
- package/useWindowSize/useWindowSize.d.ts +0 -29
- package/useWindowSize/useWindowSize.mjs +0 -31
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
-
|
|
3
|
-
/** Ternary dark mode options. */
|
|
4
|
-
export type TernaryDarkMode = 'system' | 'dark' | 'light';
|
|
5
|
-
/** Options for the `useTernaryDarkMode` hook. */
|
|
6
|
-
export type TernaryDarkModeOptions = {
|
|
7
|
-
/**
|
|
8
|
-
* The default value for the dark mode.
|
|
9
|
-
* @default 'system'
|
|
10
|
-
*/
|
|
11
|
-
defaultValue?: TernaryDarkMode;
|
|
12
|
-
/**
|
|
13
|
-
* The key for storing dark mode preference in local storage.
|
|
14
|
-
* @default 'usehooks-ts-ternary-dark-mode'
|
|
15
|
-
*/
|
|
16
|
-
localStorageKey?: string;
|
|
17
|
-
/**
|
|
18
|
-
* If `true` (default), the hook will initialize reading `localStorage`. In SSR, you should set it to `false`, returning default values initially.
|
|
19
|
-
* @default true
|
|
20
|
-
*/
|
|
21
|
-
initializeWithValue?: boolean;
|
|
22
|
-
};
|
|
23
|
-
/** Represents the return type of the `useTernaryDarkMode` hook. */
|
|
24
|
-
export type TernaryDarkModeReturn = {
|
|
25
|
-
/** The current state of the dark mode. */
|
|
26
|
-
isDarkMode: boolean;
|
|
27
|
-
/** The current state of the dark mode. */
|
|
28
|
-
ternaryDarkMode: TernaryDarkMode;
|
|
29
|
-
/** A function to set the dark mode state. */
|
|
30
|
-
setTernaryDarkMode: Dispatch<SetStateAction<TernaryDarkMode>>;
|
|
31
|
-
/** A function to toggle the dark mode state. */
|
|
32
|
-
toggleTernaryDarkMode: () => void;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Custom hook that manages ternary (system, dark, light) dark mode with local storage support.
|
|
36
|
-
* @param {?TernaryDarkModeOptions | string} [options] - Options or the local storage key for the hook.
|
|
37
|
-
* @returns {TernaryDarkModeReturn} An object containing the dark mode state and helper functions.
|
|
38
|
-
* @public
|
|
39
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-ternary-dark-mode)
|
|
40
|
-
* @example
|
|
41
|
-
* ```tsx
|
|
42
|
-
* const { isDarkMode, ternaryDarkMode, setTernaryDarkMode, toggleTernaryDarkMode } = useTernaryDarkMode({ defaultValue: 'dark' });
|
|
43
|
-
* // Access and use the dark mode state and provided helper functions.
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
export declare function useTernaryDarkMode({ defaultValue, localStorageKey, initializeWithValue, }?: TernaryDarkModeOptions): TernaryDarkModeReturn;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { useLocalStorage as c } from "../useLocalStorage/useLocalStorage.mjs";
|
|
2
|
-
import { useMediaQuery as m } from "../useMediaQuery/useMediaQuery.mjs";
|
|
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
|
-
};
|
package/useTimeout/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useTimeout';
|
package/useTimeout/index.mjs
DELETED
package/useTimeout/package.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { useRef as u, useEffect as f } from "react";
|
|
2
|
-
import { useIsomorphicLayoutEffect as i } from "../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs";
|
|
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
|
-
};
|
package/useToggle/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useToggle';
|
package/useToggle/index.mjs
DELETED
package/useToggle/package.json
DELETED
package/useToggle/useToggle.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Custom hook that manages a boolean toggle state in React components.
|
|
5
|
-
* @param {boolean} [defaultValue] - The initial value for the toggle state.
|
|
6
|
-
* @returns {[boolean, () => void, Dispatch<SetStateAction<boolean>>]} A tuple containing the current state,
|
|
7
|
-
* a function to toggle the state, and a function to set the state explicitly.
|
|
8
|
-
* @public
|
|
9
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-toggle)
|
|
10
|
-
* @example
|
|
11
|
-
* ```tsx
|
|
12
|
-
* const [isToggled, toggle, setToggle] = useToggle(); // Initial value is false
|
|
13
|
-
* // OR
|
|
14
|
-
* const [isToggled, toggle, setToggle] = useToggle(true); // Initial value is true
|
|
15
|
-
* // Use isToggled in your component, toggle to switch the state, setToggle to set the state explicitly.
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export declare function useToggle(defaultValue?: boolean): [boolean, () => void, Dispatch<SetStateAction<boolean>>];
|
package/useToggle/useToggle.mjs
DELETED
package/useUnmount/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useUnmount';
|
package/useUnmount/index.mjs
DELETED
package/useUnmount/package.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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;
|
package/useWindowSize/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useWindowSize';
|
package/useWindowSize/index.mjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represent the dimension of the window.
|
|
3
|
-
* @template T - The type of the dimension (number or undefined).
|
|
4
|
-
*/
|
|
5
|
-
type WindowSize<T extends number | undefined = number | undefined> = {
|
|
6
|
-
/** The width of the window. */
|
|
7
|
-
width: T;
|
|
8
|
-
/** The height of the window. */
|
|
9
|
-
height: T;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Hook options.
|
|
13
|
-
* @template InitializeWithValue - If `true` (default), the hook will initialize reading the window size. In SSR, you should set it to `false`, returning `undefined` initially.
|
|
14
|
-
*/
|
|
15
|
-
type UseWindowSizeOptions<InitializeWithValue extends boolean | undefined> = {
|
|
16
|
-
/**
|
|
17
|
-
* If `true` (default), the hook will initialize reading the window size. In SSR, you should set it to `false`, returning `undefined` initially.
|
|
18
|
-
* @default true
|
|
19
|
-
*/
|
|
20
|
-
initializeWithValue: InitializeWithValue;
|
|
21
|
-
/**
|
|
22
|
-
* The delay in milliseconds before the state is updated (disabled by default for retro-compatibility).
|
|
23
|
-
* @default undefined
|
|
24
|
-
*/
|
|
25
|
-
debounceDelay?: number;
|
|
26
|
-
};
|
|
27
|
-
export declare function useWindowSize(options: UseWindowSizeOptions<false>): WindowSize;
|
|
28
|
-
export declare function useWindowSize(options?: Partial<UseWindowSizeOptions<true>>): WindowSize<number>;
|
|
29
|
-
export {};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { useState as r } from "react";
|
|
2
|
-
import { useDebounceCallback as u } from "../useDebounceCallback/useDebounceCallback.mjs";
|
|
3
|
-
import { useEventListener as w } from "../useEventListener/useEventListener.mjs";
|
|
4
|
-
import { useIsomorphicLayoutEffect as h } from "../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs";
|
|
5
|
-
const f = typeof window > "u";
|
|
6
|
-
function m(e = {}) {
|
|
7
|
-
let { initializeWithValue: i = !0 } = e;
|
|
8
|
-
f && (i = !1);
|
|
9
|
-
const [o, n] = r(() => i ? {
|
|
10
|
-
width: window.innerWidth,
|
|
11
|
-
height: window.innerHeight
|
|
12
|
-
} : {
|
|
13
|
-
width: void 0,
|
|
14
|
-
height: void 0
|
|
15
|
-
}), d = u(
|
|
16
|
-
n,
|
|
17
|
-
e.debounceDelay
|
|
18
|
-
);
|
|
19
|
-
function t() {
|
|
20
|
-
(e.debounceDelay ? d : n)({
|
|
21
|
-
width: window.innerWidth,
|
|
22
|
-
height: window.innerHeight
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
return w("resize", t), h(() => {
|
|
26
|
-
t();
|
|
27
|
-
}, []), o;
|
|
28
|
-
}
|
|
29
|
-
export {
|
|
30
|
-
m as useWindowSize
|
|
31
|
-
};
|