@siberiacancode/reactuse 0.2.35 → 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/useFocusTrap/useFocusTrap.cjs +1 -1
- package/dist/cjs/hooks/useFocusTrap/useFocusTrap.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/useFocusTrap/useFocusTrap.mjs +22 -40
- package/dist/esm/hooks/useFocusTrap/useFocusTrap.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/useFocusTrap/useFocusTrap.d.ts +1 -0
- 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';
|
|
@@ -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 */
|
|
@@ -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;
|