@siberiacancode/reactuse 0.2.18 → 0.2.19

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 (51) hide show
  1. package/README.md +71 -71
  2. package/dist/cjs/hooks/useCopy/useCopy.cjs +1 -1
  3. package/dist/cjs/hooks/useCopy/useCopy.cjs.map +1 -1
  4. package/dist/cjs/hooks/useCssVar/useCssVar.cjs +1 -1
  5. package/dist/cjs/hooks/useCssVar/useCssVar.cjs.map +1 -1
  6. package/dist/cjs/hooks/useDebounceCallback/useDebounceCallback.cjs +1 -1
  7. package/dist/cjs/hooks/useDebounceCallback/useDebounceCallback.cjs.map +1 -1
  8. package/dist/cjs/hooks/useDeviceMotion/useDeviceMotion.cjs.map +1 -1
  9. package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs +1 -1
  10. package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs.map +1 -1
  11. package/dist/cjs/hooks/useHash/useHash.cjs +1 -1
  12. package/dist/cjs/hooks/useHash/useHash.cjs.map +1 -1
  13. package/dist/cjs/hooks/useQuery/useQuery.cjs.map +1 -1
  14. package/dist/cjs/hooks/useShallowEffect/useShallowEffect.cjs +2 -0
  15. package/dist/cjs/hooks/useShallowEffect/useShallowEffect.cjs.map +1 -0
  16. package/dist/cjs/hooks/useStorage/useStorage.cjs.map +1 -1
  17. package/dist/cjs/hooks/useThrottleCallback/useThrottleCallback.cjs +1 -1
  18. package/dist/cjs/hooks/useThrottleCallback/useThrottleCallback.cjs.map +1 -1
  19. package/dist/cjs/hooks/useWizard/useWizard.cjs.map +1 -1
  20. package/dist/cjs/index.cjs +1 -1
  21. package/dist/esm/hooks/useCopy/useCopy.mjs +1 -1
  22. package/dist/esm/hooks/useCopy/useCopy.mjs.map +1 -1
  23. package/dist/esm/hooks/useCssVar/useCssVar.mjs +23 -26
  24. package/dist/esm/hooks/useCssVar/useCssVar.mjs.map +1 -1
  25. package/dist/esm/hooks/useDebounceCallback/useDebounceCallback.mjs +8 -8
  26. package/dist/esm/hooks/useDebounceCallback/useDebounceCallback.mjs.map +1 -1
  27. package/dist/esm/hooks/useDeviceMotion/useDeviceMotion.mjs.map +1 -1
  28. package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs +1 -0
  29. package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs.map +1 -1
  30. package/dist/esm/hooks/useHash/useHash.mjs +9 -8
  31. package/dist/esm/hooks/useHash/useHash.mjs.map +1 -1
  32. package/dist/esm/hooks/useQuery/useQuery.mjs.map +1 -1
  33. package/dist/esm/hooks/useShallowEffect/useShallowEffect.mjs +23 -0
  34. package/dist/esm/hooks/useShallowEffect/useShallowEffect.mjs.map +1 -0
  35. package/dist/esm/hooks/useStorage/useStorage.mjs +6 -1
  36. package/dist/esm/hooks/useStorage/useStorage.mjs.map +1 -1
  37. package/dist/esm/hooks/useThrottleCallback/useThrottleCallback.mjs +13 -6
  38. package/dist/esm/hooks/useThrottleCallback/useThrottleCallback.mjs.map +1 -1
  39. package/dist/esm/hooks/useWizard/useWizard.mjs.map +1 -1
  40. package/dist/esm/index.mjs +252 -248
  41. package/dist/esm/index.mjs.map +1 -1
  42. package/dist/types/hooks/index.d.ts +1 -0
  43. package/dist/types/hooks/useCopy/useCopy.d.ts +1 -1
  44. package/dist/types/hooks/useCssVar/useCssVar.d.ts +6 -4
  45. package/dist/types/hooks/useDoubleClick/useDoubleClick.d.ts +4 -0
  46. package/dist/types/hooks/useHash/useHash.d.ts +3 -2
  47. package/dist/types/hooks/useShallowEffect/useShallowEffect.d.ts +14 -0
  48. package/dist/types/hooks/useStorage/useStorage.d.ts +1 -5
  49. package/dist/types/hooks/useThrottleCallback/useThrottleCallback.d.ts +4 -1
  50. package/dist/types/hooks/useWizard/useWizard.d.ts +1 -1
  51. package/package.json +1 -1
@@ -4,12 +4,14 @@ import { StateRef } from '../useRefState/useRefState';
4
4
  export interface UseCssVarReturn {
5
5
  /** The value of the CSS variable */
6
6
  value: string;
7
+ /** Remove the value of the CSS variable */
8
+ remove: () => void;
7
9
  /** Set the value of the CSS variable */
8
10
  set: (value: string) => void;
9
11
  }
10
12
  export interface UseCssVar {
11
- (key: string, initialValue?: string): UseCssVarReturn & {
12
- ref: StateRef<Element>;
13
+ <Target extends HTMLElement>(key: string, initialValue?: string): UseCssVarReturn & {
14
+ ref: StateRef<Target>;
13
15
  };
14
16
  (target: HookTarget, key: string, initialValue?: string): UseCssVarReturn;
15
17
  }
@@ -24,7 +26,7 @@ export interface UseCssVar {
24
26
  * @returns {UseCssVarReturn & { ref: StateRef<Element> }} The object containing the value of the CSS variable and ref
25
27
  *
26
28
  * @example
27
- * const { ref, value, set } = useCssVar('--color', 'red');
29
+ * const { ref, value, set, remove } = useCssVar('--color', 'red');
28
30
  *
29
31
  * @overload
30
32
  * @param {HookTarget} target The target element
@@ -33,6 +35,6 @@ export interface UseCssVar {
33
35
  * @returns {UseCssVarReturn} The object containing the value of the CSS variable
34
36
  *
35
37
  * @example
36
- * const { value, set } = useCssVar(ref, '--color', 'red');
38
+ * const { value, set, remove } = useCssVar(ref, '--color', 'red');
37
39
  */
38
40
  export declare const useCssVar: UseCssVar;
@@ -1,14 +1,18 @@
1
1
  import { HookTarget } from '../../utils/helpers';
2
2
  import { StateRef } from '../useRefState/useRefState';
3
3
  export type DoubleClickEvents = MouseEvent | TouchEvent;
4
+ /** The use double click options type */
4
5
  export interface UseDoubleClickOptions {
6
+ /** The threshold time in milliseconds between clicks */
5
7
  threshold?: number;
8
+ /** The callback function to be invoked on single click */
6
9
  onSingleClick?: (event: DoubleClickEvents) => void;
7
10
  }
8
11
  export interface UseDoubleClick {
9
12
  (target: HookTarget, callback: (event: DoubleClickEvents) => void, options?: UseDoubleClickOptions): boolean;
10
13
  <Target extends Element>(callback: (event: DoubleClickEvents) => void, options?: UseDoubleClickOptions, target?: never): StateRef<Target>;
11
14
  }
15
+ export declare const DEFAULT_THRESHOLD_TIME = 300;
12
16
  /**
13
17
  * @name useDoubleClick
14
18
  * @description - Hook that defines the logic when double clicking an element
@@ -5,10 +5,11 @@ type UseHashReturn = [string, (value: string) => void];
5
5
  * @description - Hook that manages the hash value
6
6
  * @category Browser
7
7
  *
8
+ * @param {string} [initialValue] The initial hash value if no hash exists
8
9
  * @returns {UseHashReturn} An array containing the hash value and a function to set the hash value
9
10
  *
10
11
  * @example
11
- * const [hash, setHash] = useHash();
12
+ * const [hash, setHash] = useHash("initial");
12
13
  */
13
- export declare const useHash: () => UseHashReturn;
14
+ export declare const useHash: (initialValue?: string, mode?: "initial" | "replace") => UseHashReturn;
14
15
  export {};
@@ -0,0 +1,14 @@
1
+ import { DependencyList, EffectCallback } from 'react';
2
+ export declare const deepEqual: (a: any, b: any) => boolean;
3
+ /**
4
+ * @name useShallowEffect
5
+ * @description - Hook that executes an effect only when dependencies change shallowly or deeply.
6
+ * @category Lifecycle
7
+ *
8
+ * @param {EffectCallback} effect The effect callback
9
+ * @param {DependencyList} [deps] The dependencies list for the effect
10
+ *
11
+ * @example
12
+ * useShallowEffect(() => console.log("effect"), [user]);
13
+ */
14
+ export declare const useShallowEffect: (effect: EffectCallback, deps?: DependencyList) => void;
@@ -11,12 +11,8 @@ export interface UseStorageReturn<Value> {
11
11
  set: (value: Value) => void;
12
12
  }
13
13
  export interface UseStorage {
14
- <Value>(key: string, options: UseStorageOptions<Value> & {
15
- initialValue: UseStorageInitialValue<Value>;
16
- }): UseStorageReturn<Value>;
17
14
  <Value>(key: string, options?: UseStorageOptions<Value>): UseStorageReturn<Value | undefined>;
18
- <Value>(key: string, initialValue: UseStorageInitialValue<Value>): UseStorageReturn<Value>;
19
- <Value>(key: string): UseStorageReturn<Value | undefined>;
15
+ <Value>(key: string, initialValue?: UseStorageInitialValue<Value>): UseStorageReturn<Value | undefined>;
20
16
  }
21
17
  export declare const STORAGE_EVENT = "reactuse-storage";
22
18
  export declare const dispatchStorageEvent: (params: Partial<StorageEvent>) => boolean;
@@ -1,3 +1,6 @@
1
+ export type ThrottledCallback<Params extends unknown[]> = ((...args: Params) => void) & {
2
+ cancel: () => void;
3
+ };
1
4
  /**
2
5
  * @name useThrottleCallback
3
6
  * @description - Hook that creates a throttled callback
@@ -12,4 +15,4 @@
12
15
  * @example
13
16
  * const throttled = useThrottleCallback(() => console.log('callback'), 500);
14
17
  */
15
- export declare const useThrottleCallback: <Params extends unknown[], Return>(callback: (...args: Params) => Return, delay: number) => (...args: Params) => void;
18
+ export declare const useThrottleCallback: <Params extends unknown[], Return>(callback: (...args: Params) => Return, delay: number) => ThrottledCallback<Params>;
@@ -12,7 +12,7 @@ export interface WizardItem<WizardStepId> {
12
12
  * @returns {UseWizardReturn<WizardStepId>} An object containing the current step id and functions to interact with the wizard
13
13
  *
14
14
  * @example
15
- * const { currentStepId, set, reset, back, history } = useWizard([
15
+ * const { currentStepId, set, reset, back, next, history } = useWizard([
16
16
  * { id: 'step1', nodes: ['step2', 'step3'] },
17
17
  * { id: 'step2', nodes: ['step3'] },
18
18
  * { id: 'step3', nodes: [] },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@siberiacancode/reactuse",
3
- "version": "0.2.18",
3
+ "version": "0.2.19",
4
4
  "description": "The ultimate collection of react hooks",
5
5
  "author": {
6
6
  "name": "SIBERIA CAN CODE 🧊",