@oneplatformdev/hooks 0.0.1-beta.7 → 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.
Files changed (181) hide show
  1. package/README.md +2 -2
  2. package/package.json +29 -30
  3. package/index.d.ts +0 -35
  4. package/index.mjs +0 -72
  5. package/useBoolean/index.d.ts +0 -1
  6. package/useBoolean/index.mjs +0 -4
  7. package/useBoolean/package.json +0 -7
  8. package/useBoolean/useBoolean.d.ts +0 -29
  9. package/useBoolean/useBoolean.mjs +0 -16
  10. package/useClickAnyWhere/index.d.ts +0 -1
  11. package/useClickAnyWhere/index.mjs +0 -4
  12. package/useClickAnyWhere/package.json +0 -7
  13. package/useClickAnyWhere/useClickAnyWhere.d.ts +0 -16
  14. package/useClickAnyWhere/useClickAnyWhere.mjs +0 -9
  15. package/useCopyToClipboard/index.d.ts +0 -1
  16. package/useCopyToClipboard/index.mjs +0 -4
  17. package/useCopyToClipboard/package.json +0 -7
  18. package/useCopyToClipboard/useCopyToClipboard.d.ts +0 -33
  19. package/useCopyToClipboard/useCopyToClipboard.mjs +0 -16
  20. package/useCountdown/index.d.ts +0 -1
  21. package/useCountdown/index.mjs +0 -4
  22. package/useCountdown/package.json +0 -7
  23. package/useCountdown/useCountdown.d.ts +0 -46
  24. package/useCountdown/useCountdown.mjs +0 -33
  25. package/useCounter/index.d.ts +0 -1
  26. package/useCounter/index.mjs +0 -4
  27. package/useCounter/package.json +0 -7
  28. package/useCounter/useCounter.d.ts +0 -28
  29. package/useCounter/useCounter.mjs +0 -20
  30. package/useDarkMode/index.d.ts +0 -1
  31. package/useDarkMode/index.mjs +0 -4
  32. package/useDarkMode/package.json +0 -7
  33. package/useDarkMode/useDarkMode.d.ts +0 -45
  34. package/useDarkMode/useDarkMode.mjs +0 -38
  35. package/useDebounceCallback/index.d.ts +0 -2
  36. package/useDebounceCallback/index.mjs +0 -5
  37. package/useDebounceCallback/package.json +0 -7
  38. package/useDebounceCallback/useDebounceCallback.d.ts +0 -61
  39. package/useDebounceCallback/useDebounceCallback.mjs +0 -101
  40. package/useDebounceValue/index.d.ts +0 -1
  41. package/useDebounceValue/index.mjs +0 -4
  42. package/useDebounceValue/package.json +0 -7
  43. package/useDebounceValue/useDebounceValue.d.ts +0 -40
  44. package/useDebounceValue/useDebounceValue.mjs +0 -13
  45. package/useDocumentTitle/index.d.ts +0 -1
  46. package/useDocumentTitle/index.mjs +0 -4
  47. package/useDocumentTitle/package.json +0 -7
  48. package/useDocumentTitle/useDocumentTitle.d.ts +0 -18
  49. package/useDocumentTitle/useDocumentTitle.mjs +0 -16
  50. package/useEventCallback/index.d.ts +0 -1
  51. package/useEventCallback/index.mjs +0 -4
  52. package/useEventCallback/package.json +0 -7
  53. package/useEventCallback/useEventCallback.d.ts +0 -17
  54. package/useEventCallback/useEventCallback.mjs +0 -16
  55. package/useEventListener/index.d.ts +0 -1
  56. package/useEventListener/index.mjs +0 -4
  57. package/useEventListener/package.json +0 -7
  58. package/useEventListener/useEventListener.d.ts +0 -7
  59. package/useEventListener/useEventListener.mjs +0 -20
  60. package/useHover/index.d.ts +0 -1
  61. package/useHover/index.mjs +0 -4
  62. package/useHover/package.json +0 -7
  63. package/useHover/useHover.d.ts +0 -17
  64. package/useHover/useHover.mjs +0 -13
  65. package/useIntersectionObserver/index.d.ts +0 -1
  66. package/useIntersectionObserver/index.mjs +0 -4
  67. package/useIntersectionObserver/package.json +0 -7
  68. package/useIntersectionObserver/useIntersectionObserver.d.ts +0 -71
  69. package/useIntersectionObserver/useIntersectionObserver.mjs +0 -55
  70. package/useInterval/index.d.ts +0 -1
  71. package/useInterval/index.mjs +0 -4
  72. package/useInterval/package.json +0 -7
  73. package/useInterval/useInterval.d.ts +0 -15
  74. package/useInterval/useInterval.mjs +0 -20
  75. package/useIsClient/index.d.ts +0 -1
  76. package/useIsClient/index.mjs +0 -4
  77. package/useIsClient/package.json +0 -7
  78. package/useIsClient/useIsClient.d.ts +0 -12
  79. package/useIsClient/useIsClient.mjs +0 -10
  80. package/useIsMobile/index.d.ts +0 -2
  81. package/useIsMobile/index.mjs +0 -4
  82. package/useIsMobile/package.json +0 -7
  83. package/useIsMobile/types.d.ts +0 -3
  84. package/useIsMobile/types.mjs +0 -1
  85. package/useIsMobile/useIsMobile.d.ts +0 -3
  86. package/useIsMobile/useIsMobile.mjs +0 -16
  87. package/useIsMounted/index.d.ts +0 -1
  88. package/useIsMounted/index.mjs +0 -4
  89. package/useIsMounted/package.json +0 -7
  90. package/useIsMounted/useIsMounted.d.ts +0 -1
  91. package/useIsMounted/useIsMounted.mjs +0 -10
  92. package/useIsomorphicLayoutEffect/index.d.ts +0 -1
  93. package/useIsomorphicLayoutEffect/index.mjs +0 -4
  94. package/useIsomorphicLayoutEffect/package.json +0 -7
  95. package/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.ts +0 -16
  96. package/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs +0 -5
  97. package/useLocalStorage/index.d.ts +0 -1
  98. package/useLocalStorage/index.mjs +0 -4
  99. package/useLocalStorage/package.json +0 -7
  100. package/useLocalStorage/useLocalStorage.d.ts +0 -39
  101. package/useLocalStorage/useLocalStorage.mjs +0 -65
  102. package/useLockBody/index.d.ts +0 -1
  103. package/useLockBody/index.mjs +0 -4
  104. package/useLockBody/package.json +0 -7
  105. package/useLockBody/useLockBody.d.ts +0 -1
  106. package/useLockBody/useLockBody.mjs +0 -12
  107. package/useMap/index.d.ts +0 -1
  108. package/useMap/index.mjs +0 -4
  109. package/useMap/package.json +0 -7
  110. package/useMap/useMap.d.ts +0 -47
  111. package/useMap/useMap.mjs +0 -27
  112. package/useMediaQuery/index.d.ts +0 -1
  113. package/useMediaQuery/index.mjs +0 -4
  114. package/useMediaQuery/package.json +0 -7
  115. package/useMediaQuery/useMediaQuery.d.ts +0 -28
  116. package/useMediaQuery/useMediaQuery.mjs +0 -21
  117. package/useOnClickOutside/index.d.ts +0 -1
  118. package/useOnClickOutside/index.mjs +0 -4
  119. package/useOnClickOutside/package.json +0 -7
  120. package/useOnClickOutside/useOnClickOutside.d.ts +0 -24
  121. package/useOnClickOutside/useOnClickOutside.mjs +0 -17
  122. package/useReadLocalStorage/index.d.ts +0 -1
  123. package/useReadLocalStorage/index.mjs +0 -4
  124. package/useReadLocalStorage/package.json +0 -7
  125. package/useReadLocalStorage/useReadLocalStorage.d.ts +0 -13
  126. package/useReadLocalStorage/useReadLocalStorage.mjs +0 -48
  127. package/useResizeObserver/index.d.ts +0 -1
  128. package/useResizeObserver/index.mjs +0 -4
  129. package/useResizeObserver/package.json +0 -7
  130. package/useResizeObserver/useResizeObserver.d.ts +0 -44
  131. package/useResizeObserver/useResizeObserver.mjs +0 -31
  132. package/useScreen/index.d.ts +0 -1
  133. package/useScreen/index.mjs +0 -4
  134. package/useScreen/package.json +0 -7
  135. package/useScreen/useScreen.d.ts +0 -19
  136. package/useScreen/useScreen.mjs +0 -48
  137. package/useScript/index.d.ts +0 -1
  138. package/useScript/index.mjs +0 -4
  139. package/useScript/package.json +0 -7
  140. package/useScript/useScript.d.ts +0 -23
  141. package/useScript/useScript.mjs +0 -45
  142. package/useScrollLock/index.d.ts +0 -1
  143. package/useScrollLock/index.mjs +0 -4
  144. package/useScrollLock/package.json +0 -7
  145. package/useScrollLock/useScrollLock.d.ts +0 -53
  146. package/useScrollLock/useScrollLock.mjs +0 -26
  147. package/useSessionStorage/index.d.ts +0 -1
  148. package/useSessionStorage/index.mjs +0 -4
  149. package/useSessionStorage/package.json +0 -7
  150. package/useSessionStorage/useSessionStorage.d.ts +0 -39
  151. package/useSessionStorage/useSessionStorage.mjs +0 -65
  152. package/useStep/index.d.ts +0 -1
  153. package/useStep/index.mjs +0 -4
  154. package/useStep/package.json +0 -7
  155. package/useStep/useStep.d.ts +0 -31
  156. package/useStep/useStep.mjs +0 -34
  157. package/useTernaryDarkMode/index.d.ts +0 -1
  158. package/useTernaryDarkMode/index.mjs +0 -4
  159. package/useTernaryDarkMode/package.json +0 -7
  160. package/useTernaryDarkMode/useTernaryDarkMode.d.ts +0 -46
  161. package/useTernaryDarkMode/useTernaryDarkMode.mjs +0 -27
  162. package/useTimeout/index.d.ts +0 -1
  163. package/useTimeout/index.mjs +0 -4
  164. package/useTimeout/package.json +0 -7
  165. package/useTimeout/useTimeout.d.ts +0 -16
  166. package/useTimeout/useTimeout.mjs +0 -20
  167. package/useToggle/index.d.ts +0 -1
  168. package/useToggle/index.mjs +0 -4
  169. package/useToggle/package.json +0 -7
  170. package/useToggle/useToggle.d.ts +0 -18
  171. package/useToggle/useToggle.mjs +0 -10
  172. package/useUnmount/index.d.ts +0 -1
  173. package/useUnmount/index.mjs +0 -4
  174. package/useUnmount/package.json +0 -7
  175. package/useUnmount/useUnmount.d.ts +0 -13
  176. package/useUnmount/useUnmount.mjs +0 -13
  177. package/useWindowSize/index.d.ts +0 -1
  178. package/useWindowSize/index.mjs +0 -4
  179. package/useWindowSize/package.json +0 -7
  180. package/useWindowSize/useWindowSize.d.ts +0 -29
  181. 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
- };
@@ -1 +0,0 @@
1
- export * from './useTimeout';
@@ -1,4 +0,0 @@
1
- import { useTimeout as m } from "./useTimeout.mjs";
2
- export {
3
- m as useTimeout
4
- };
@@ -1,7 +0,0 @@
1
- {
2
- "sideEffects": false,
3
- "main": "./index.mjs",
4
- "module": "./index.mjs",
5
- "default": "./index.mjs",
6
- "types": "./index.d.ts"
7
- }
@@ -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
- };
@@ -1 +0,0 @@
1
- export * from './useToggle';
@@ -1,4 +0,0 @@
1
- import { useToggle as g } from "./useToggle.mjs";
2
- export {
3
- g as useToggle
4
- };
@@ -1,7 +0,0 @@
1
- {
2
- "sideEffects": false,
3
- "main": "./index.mjs",
4
- "module": "./index.mjs",
5
- "default": "./index.mjs",
6
- "types": "./index.d.ts"
7
- }
@@ -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>>];
@@ -1,10 +0,0 @@
1
- import { useState as s, useCallback as a } from "react";
2
- function r(t) {
3
- const [o, e] = s(!!t), u = a(() => {
4
- e((l) => !l);
5
- }, []);
6
- return [o, u, e];
7
- }
8
- export {
9
- r as useToggle
10
- };
@@ -1 +0,0 @@
1
- export * from './useUnmount';
@@ -1,4 +0,0 @@
1
- import { useUnmount as m } from "./useUnmount.mjs";
2
- export {
3
- m as useUnmount
4
- };
@@ -1,7 +0,0 @@
1
- {
2
- "sideEffects": false,
3
- "main": "./index.mjs",
4
- "module": "./index.mjs",
5
- "default": "./index.mjs",
6
- "types": "./index.d.ts"
7
- }
@@ -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;
@@ -1,13 +0,0 @@
1
- import { useRef as n, useEffect as r } from "react";
2
- function f(e) {
3
- const t = n(e);
4
- t.current = e, r(
5
- () => () => {
6
- t.current();
7
- },
8
- []
9
- );
10
- }
11
- export {
12
- f as useUnmount
13
- };
@@ -1 +0,0 @@
1
- export * from './useWindowSize';
@@ -1,4 +0,0 @@
1
- import { useWindowSize as i } from "./useWindowSize.mjs";
2
- export {
3
- i as useWindowSize
4
- };
@@ -1,7 +0,0 @@
1
- {
2
- "sideEffects": false,
3
- "main": "./index.mjs",
4
- "module": "./index.mjs",
5
- "default": "./index.mjs",
6
- "types": "./index.d.ts"
7
- }
@@ -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
- };