@siberiacancode/reactuse 0.2.34 → 0.3.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/dist/cjs/hooks/useActiveElement/useActiveElement.cjs.map +1 -1
- package/dist/cjs/hooks/useDeviceMotion/useDeviceMotion.cjs +1 -1
- package/dist/cjs/hooks/useDeviceMotion/useDeviceMotion.cjs.map +1 -1
- package/dist/cjs/hooks/useFocusTrap/useFocusTrap.cjs +1 -1
- package/dist/cjs/hooks/useFocusTrap/useFocusTrap.cjs.map +1 -1
- package/dist/cjs/hooks/useHash/useHash.cjs +1 -1
- package/dist/cjs/hooks/useHash/useHash.cjs.map +1 -1
- package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs +1 -1
- package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs.map +1 -1
- package/dist/cjs/hooks/useUrlSearchParams/useUrlSearchParams.cjs +1 -1
- package/dist/cjs/hooks/useUrlSearchParams/useUrlSearchParams.cjs.map +1 -1
- package/dist/cjs/hooks/useVisibility/useVisibility.cjs +2 -0
- package/dist/cjs/hooks/useVisibility/useVisibility.cjs.map +1 -0
- package/dist/cjs/index.cjs +1 -1
- package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
- package/dist/esm/hooks/useDeviceMotion/useDeviceMotion.mjs +21 -21
- package/dist/esm/hooks/useDeviceMotion/useDeviceMotion.mjs.map +1 -1
- package/dist/esm/hooks/useFocusTrap/useFocusTrap.mjs +22 -40
- package/dist/esm/hooks/useFocusTrap/useFocusTrap.mjs.map +1 -1
- package/dist/esm/hooks/useHash/useHash.mjs +17 -17
- package/dist/esm/hooks/useHash/useHash.mjs.map +1 -1
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs +15 -23
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs.map +1 -1
- package/dist/esm/hooks/useUrlSearchParams/useUrlSearchParams.mjs +14 -14
- package/dist/esm/hooks/useUrlSearchParams/useUrlSearchParams.mjs.map +1 -1
- package/dist/esm/hooks/useVisibility/useVisibility.mjs +34 -0
- package/dist/esm/hooks/useVisibility/useVisibility.mjs.map +1 -0
- package/dist/esm/index.mjs +269 -266
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/hooks/sensors.d.ts +1 -0
- package/dist/types/hooks/useDeviceMotion/useDeviceMotion.d.ts +25 -4
- package/dist/types/hooks/useFocusTrap/useFocusTrap.d.ts +1 -0
- package/dist/types/hooks/useHash/useHash.d.ts +3 -1
- package/dist/types/hooks/useIntersectionObserver/useIntersectionObserver.d.ts +7 -9
- package/dist/types/hooks/useVisibility/useVisibility.d.ts +77 -0
- package/package.json +1 -1
|
@@ -28,6 +28,7 @@ export * from './useScroll/useScroll';
|
|
|
28
28
|
export * from './useScrollIntoView/useScrollIntoView';
|
|
29
29
|
export * from './useScrollTo/useScrollTo';
|
|
30
30
|
export * from './useTextSelection/useTextSelection';
|
|
31
|
+
export * from './useVisibility/useVisibility';
|
|
31
32
|
export * from './useWindowEvent/useWindowEvent';
|
|
32
33
|
export * from './useWindowFocus/useWindowFocus';
|
|
33
34
|
export * from './useWindowScroll/useWindowScroll';
|
|
@@ -4,13 +4,17 @@ export interface UseDeviceMotionReturn {
|
|
|
4
4
|
interval: DeviceMotionEvent['interval'];
|
|
5
5
|
rotationRate: DeviceMotionEventRotationRate;
|
|
6
6
|
}
|
|
7
|
-
export interface
|
|
7
|
+
export interface UseDeviceMotionOptions {
|
|
8
8
|
/** The delay in milliseconds */
|
|
9
9
|
delay?: number;
|
|
10
10
|
/** Whether to enable the hook */
|
|
11
11
|
enabled?: boolean;
|
|
12
12
|
/** The callback function to be invoked */
|
|
13
|
-
|
|
13
|
+
onChange?: (event: DeviceMotionEvent) => void;
|
|
14
|
+
}
|
|
15
|
+
export interface UseDeviceMotion {
|
|
16
|
+
(callback?: (event: DeviceMotionEvent) => void, delay?: number): UseDeviceMotionReturn;
|
|
17
|
+
(options?: UseDeviceMotionOptions): UseDeviceMotionReturn;
|
|
14
18
|
}
|
|
15
19
|
/**
|
|
16
20
|
* @name useDeviceMotion
|
|
@@ -20,12 +24,29 @@ export interface UseDeviceMotionParams {
|
|
|
20
24
|
*
|
|
21
25
|
* @browserapi DeviceMotionEvent https://developer.mozilla.org/en-US/docs/Web/API/Window/DeviceMotionEvent
|
|
22
26
|
*
|
|
27
|
+
* @overload
|
|
23
28
|
* @param {number} [delay=1000] The delay in milliseconds
|
|
24
29
|
* @param {(event: DeviceMotionEvent) => void} [callback] The callback function to be invoked
|
|
25
|
-
* @
|
|
30
|
+
* @returns {UseDeviceMotionReturn} The device motion data and interval
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const { interval, rotationRate, acceleration, accelerationIncludingGravity } = useDeviceMotion(500, (event) => console.log(event));
|
|
34
|
+
*
|
|
35
|
+
* @overload
|
|
36
|
+
* @param {(event: DeviceMotionEvent) => void} [callback] The callback function to be invoked
|
|
37
|
+
* @returns {UseDeviceMotionReturn} The device motion data and interval
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* const { interval, rotationRate, acceleration, accelerationIncludingGravity } = useDeviceMotion((event) => console.log(event));
|
|
41
|
+
*
|
|
42
|
+
* @overload
|
|
43
|
+
* @param {UseDeviceMotionOptions} [options] Configuration options
|
|
44
|
+
* @param {number} [options.delay] The delay in milliseconds
|
|
45
|
+
* @param {boolean} [options.enabled] Whether to enable the hook
|
|
46
|
+
* @param {(event: DeviceMotionEvent) => void} [options.onChange] The callback function to be invoked
|
|
26
47
|
* @returns {UseDeviceMotionReturn} The device motion data and interval
|
|
27
48
|
*
|
|
28
49
|
* @example
|
|
29
50
|
* const { interval, rotationRate, acceleration, accelerationIncludingGravity } = useDeviceMotion();
|
|
30
51
|
*/
|
|
31
|
-
export declare const useDeviceMotion:
|
|
52
|
+
export declare const useDeviceMotion: UseDeviceMotion;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { HookTarget } from '../../utils/helpers';
|
|
2
2
|
import { StateRef } from '../useRefState/useRefState';
|
|
3
|
+
export declare const FOCUS_SELECTOR = "a, input, select, textarea, button, object, [tabindex]";
|
|
3
4
|
/** The use focus trap return type */
|
|
4
5
|
export interface UseFocusTrapReturn {
|
|
5
6
|
/** Whether focus trap is active */
|
|
@@ -12,7 +12,9 @@ export interface UseHashOptions {
|
|
|
12
12
|
type UseHashReturn = [string, (value: string) => void];
|
|
13
13
|
export interface UseHash {
|
|
14
14
|
(initialValue?: string, options?: UseHashOptions): UseHashReturn;
|
|
15
|
+
(options?: UseHashOptions): UseHashReturn;
|
|
15
16
|
(initialValue?: string, callback?: (hash: string) => void): UseHashReturn;
|
|
17
|
+
(callback?: (hash: string) => void): UseHashReturn;
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
18
20
|
* @name useHash
|
|
@@ -41,7 +43,7 @@ export interface UseHash {
|
|
|
41
43
|
* @returns {UseHashReturn} An array containing the hash value and a function to set the hash value
|
|
42
44
|
*
|
|
43
45
|
* @example
|
|
44
|
-
* const [hash, setHash] = useHash("initial", (newHash) => console.log('
|
|
46
|
+
* const [hash, setHash] = useHash("initial", (newHash) => console.log('callback'));
|
|
45
47
|
*/
|
|
46
48
|
export declare const useHash: UseHash;
|
|
47
49
|
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { HookTarget } from '../../utils/helpers';
|
|
2
2
|
import { StateRef } from '../useRefState/useRefState';
|
|
3
3
|
/** The intersection observer callback type */
|
|
4
|
-
export type UseIntersectionObserverCallback = (
|
|
4
|
+
export type UseIntersectionObserverCallback = (entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void;
|
|
5
5
|
/** The intersection observer options type */
|
|
6
|
-
export interface UseIntersectionObserverOptions extends Omit<IntersectionObserverInit,
|
|
6
|
+
export interface UseIntersectionObserverOptions extends Omit<IntersectionObserverInit, 'root'> {
|
|
7
7
|
/** The enabled state of the intersection observer */
|
|
8
8
|
enabled?: boolean;
|
|
9
9
|
/** The callback to execute when intersection is detected */
|
|
@@ -14,9 +14,7 @@ export interface UseIntersectionObserverOptions extends Omit<IntersectionObserve
|
|
|
14
14
|
/** The intersection observer return type */
|
|
15
15
|
export interface UseIntersectionObserverReturn {
|
|
16
16
|
/** The intersection observer entry */
|
|
17
|
-
|
|
18
|
-
/** The in view state of the intersection observer */
|
|
19
|
-
inView: boolean;
|
|
17
|
+
entries?: IntersectionObserverEntry[];
|
|
20
18
|
/** The intersection observer instance */
|
|
21
19
|
observer?: IntersectionObserver;
|
|
22
20
|
}
|
|
@@ -46,7 +44,7 @@ export interface UseIntersectionObserver {
|
|
|
46
44
|
* @returns {UseIntersectionObserverReturn} An object containing the state
|
|
47
45
|
*
|
|
48
46
|
* @example
|
|
49
|
-
* const { ref,
|
|
47
|
+
* const { ref, entries, observer } = useIntersectionObserver();
|
|
50
48
|
*
|
|
51
49
|
* @overload
|
|
52
50
|
* @template Target The target element
|
|
@@ -56,7 +54,7 @@ export interface UseIntersectionObserver {
|
|
|
56
54
|
* @returns {UseIntersectionObserverReturn & { ref: StateRef<Target> }} A React ref to attach to the target element
|
|
57
55
|
*
|
|
58
56
|
* @example
|
|
59
|
-
* const {
|
|
57
|
+
* const { entries, observer } = useIntersectionObserver(ref);
|
|
60
58
|
*
|
|
61
59
|
* @overload
|
|
62
60
|
* @template Target The target element
|
|
@@ -64,7 +62,7 @@ export interface UseIntersectionObserver {
|
|
|
64
62
|
* @returns {UseIntersectionObserverReturn & { ref: StateRef<Target> }} A React ref to attach to the target element
|
|
65
63
|
*
|
|
66
64
|
* @example
|
|
67
|
-
* const { ref,
|
|
65
|
+
* const { ref, entries, observer } = useIntersectionObserver(() => console.log('callback'));
|
|
68
66
|
*
|
|
69
67
|
* @overload
|
|
70
68
|
* @param {UseIntersectionObserverCallback} callback The callback to execute when intersection is detected
|
|
@@ -72,6 +70,6 @@ export interface UseIntersectionObserver {
|
|
|
72
70
|
* @returns {UseIntersectionObserverReturn} An object containing the state
|
|
73
71
|
*
|
|
74
72
|
* @example
|
|
75
|
-
* const {
|
|
73
|
+
* const { entries, observer } = useIntersectionObserver(ref, () => console.log('callback'));
|
|
76
74
|
*/
|
|
77
75
|
export declare const useIntersectionObserver: UseIntersectionObserver;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { HookTarget } from '../../utils/helpers';
|
|
2
|
+
import { StateRef } from '../useRefState/useRefState';
|
|
3
|
+
/** The visibility callback type */
|
|
4
|
+
export type UseVisibilityCallback = (entry: IntersectionObserverEntry, observer: IntersectionObserver) => void;
|
|
5
|
+
/** The visibility options type */
|
|
6
|
+
export interface UseVisibilityOptions extends Omit<IntersectionObserverInit, 'root'> {
|
|
7
|
+
/** The enabled state of the intersection */
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
/** The callback to execute when intersection is detected */
|
|
10
|
+
onChange?: UseVisibilityCallback;
|
|
11
|
+
/** The root element to observe */
|
|
12
|
+
root?: HookTarget;
|
|
13
|
+
}
|
|
14
|
+
/** The intersection observer return type */
|
|
15
|
+
export interface UseVisibilityReturn {
|
|
16
|
+
/** The intersection observer entry */
|
|
17
|
+
entry?: IntersectionObserverEntry;
|
|
18
|
+
/** The intersection observer in view */
|
|
19
|
+
inView?: boolean;
|
|
20
|
+
/** The intersection observer instance */
|
|
21
|
+
observer?: IntersectionObserver;
|
|
22
|
+
}
|
|
23
|
+
export interface UseVisibility {
|
|
24
|
+
<Target extends Element>(options?: UseVisibilityOptions, target?: never): UseVisibilityReturn & {
|
|
25
|
+
ref: StateRef<Target>;
|
|
26
|
+
};
|
|
27
|
+
(target: HookTarget, options?: UseVisibilityOptions): UseVisibilityReturn;
|
|
28
|
+
<Target extends Element>(callback: UseVisibilityCallback, target?: never): UseVisibilityReturn & {
|
|
29
|
+
ref: StateRef<Target>;
|
|
30
|
+
};
|
|
31
|
+
(target: HookTarget, callback: UseVisibilityCallback): UseVisibilityReturn;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @name useVisibility
|
|
35
|
+
* @description - Hook that gives you visibility observer state
|
|
36
|
+
* @category Sensors
|
|
37
|
+
* @usage medium
|
|
38
|
+
*
|
|
39
|
+
* @browserapi IntersectionObserver https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver
|
|
40
|
+
*
|
|
41
|
+
* @overload
|
|
42
|
+
* @param {HookTarget} target The target element to detect intersection
|
|
43
|
+
* @param {boolean} [options.enabled=true] The Intersection options
|
|
44
|
+
* @param {((entries: IntersectionEntry[], observer: Intersection) => void) | undefined} [options.onChange] The callback to execute when intersection is detected
|
|
45
|
+
* @param {HookTarget} [options.root=document] The root element to observe
|
|
46
|
+
* @returns {UseVisibilityReturn} An object containing the state
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const { ref, entries, observer } = useVisibility();
|
|
50
|
+
*
|
|
51
|
+
* @overload
|
|
52
|
+
* @template Target The target element
|
|
53
|
+
* @param {boolean} [options.enabled=true] The Intersection options
|
|
54
|
+
* @param {((entries: IntersectionEntry[], observer: Intersection) => void) | undefined} [options.onChange] The callback to execute when intersection is detected
|
|
55
|
+
* @param {HookTarget} [options.root=document] The root element to observe
|
|
56
|
+
* @returns {UseVisibilityReturn & { ref: StateRef<Target> }} A React ref to attach to the target element
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* const { entries, observer } = useVisibility(ref);
|
|
60
|
+
*
|
|
61
|
+
* @overload
|
|
62
|
+
* @template Target The target element
|
|
63
|
+
* @param {UseVisibilityCallback} callback The callback to execute when intersection is detected
|
|
64
|
+
* @returns {UseVisibilityReturn & { ref: StateRef<Target> }} A React ref to attach to the target element
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* const { ref, entries, observer } = useVisibility(() => console.log('callback'));
|
|
68
|
+
*
|
|
69
|
+
* @overload
|
|
70
|
+
* @param {UseVisibilityCallback} callback The callback to execute when intersection is detected
|
|
71
|
+
* @param {HookTarget} target The target element to detect intersection
|
|
72
|
+
* @returns {UseVisibilityReturn} An object containing the state
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* const { entries, observer } = useVisibility(ref, () => console.log('callback'));
|
|
76
|
+
*/
|
|
77
|
+
export declare const useVisibility: UseVisibility;
|