@trackunit/react-components 1.10.40 → 1.10.43
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/index.cjs.js +224 -116
- package/index.esm.js +228 -120
- package/package.json +5 -7
- package/src/components/HorizontalOverflowScroller/HorizontalOverflowScroller.d.ts +8 -3
- package/src/hooks/index.d.ts +2 -3
- package/src/hooks/{useMeasure/useMeasure.d.ts → useMeasure.d.ts} +15 -3
- package/src/hooks/useMergeRefs.d.ts +23 -0
- package/src/hooks/useScrollDetection.d.ts +14 -4
- package/src/hooks/useMeasure/useMeasureElement.d.ts +0 -19
- package/src/hooks/useMeasure/useMeasureShared.d.ts +0 -19
package/src/hooks/index.d.ts
CHANGED
|
@@ -11,9 +11,8 @@ export * from "./useInfiniteScroll";
|
|
|
11
11
|
export * from "./useIsFirstRender";
|
|
12
12
|
export * from "./useIsFullScreen";
|
|
13
13
|
export * from "./useIsTextTruncated";
|
|
14
|
-
export * from "./useMeasure
|
|
15
|
-
export * from "./
|
|
16
|
-
export type { Geometry } from "./useMeasure/useMeasureShared";
|
|
14
|
+
export * from "./useMeasure";
|
|
15
|
+
export * from "./useMergeRefs";
|
|
17
16
|
export * from "./useModifierKey";
|
|
18
17
|
export * from "./useRelayPagination";
|
|
19
18
|
export * from "./useResize";
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import { RefCallback } from "react";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
export type Geometry = {
|
|
3
|
+
readonly height: number;
|
|
4
|
+
readonly width: number;
|
|
5
|
+
readonly x: number;
|
|
6
|
+
readonly y: number;
|
|
7
|
+
readonly bottom: number;
|
|
8
|
+
readonly left: number;
|
|
9
|
+
readonly right: number;
|
|
10
|
+
readonly top: number;
|
|
11
|
+
};
|
|
12
|
+
type UseMeasureOptions = {
|
|
13
|
+
skip?: boolean;
|
|
14
|
+
onChange?: (geometry: Geometry) => void;
|
|
15
|
+
};
|
|
4
16
|
type UseMeasureResult<TElement extends HTMLElement = HTMLElement> = {
|
|
5
17
|
geometry: Geometry | undefined;
|
|
6
18
|
ref: RefCallback<TElement>;
|
|
@@ -10,8 +22,8 @@ type UseMeasureResult<TElement extends HTMLElement = HTMLElement> = {
|
|
|
10
22
|
* Custom hook to measure the geometry of an element using a callback ref.
|
|
11
23
|
* Measures the size and position of the element relative to the viewport.
|
|
12
24
|
*
|
|
13
|
-
* @returns {UseMeasureResult<HTMLElement>} An object containing `geometry`, `ref` callback, and `element`.
|
|
14
25
|
* @template TElement extends HTMLElement
|
|
26
|
+
* @returns {UseMeasureResult<HTMLElement>} An object containing `geometry`, `ref` callback, and `element`.
|
|
15
27
|
* @example
|
|
16
28
|
* ```tsx
|
|
17
29
|
* const { geometry, ref } = useMeasure();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Ref, type RefCallback, type RefObject } from "react";
|
|
2
|
+
type MergeableRef<TInstance> = Exclude<Ref<TInstance>, RefObject<TInstance>> | {
|
|
3
|
+
current: TInstance | null;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Merges an array of refs into a single memoized callback ref or `null`.
|
|
7
|
+
* Useful when you need to attach multiple refs to the same element,
|
|
8
|
+
* such as when composing multiple hooks that each need a ref.
|
|
9
|
+
*
|
|
10
|
+
* @template TInstance - The type of the element instance
|
|
11
|
+
* @param {ReadonlyArray<MergeableRef<TInstance> | undefined>} refs - Array of refs to merge (can be RefObjects, RefCallbacks, or undefined)
|
|
12
|
+
* @returns {null | RefCallback<TInstance>} A single ref callback that will update all provided refs, or null if all refs are null
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* const { ref: measureRef } = useMeasure();
|
|
16
|
+
* const { ref: scrollRef } = useScrollDetection();
|
|
17
|
+
* const mergedRef = useMergeRefs([measureRef, scrollRef]);
|
|
18
|
+
*
|
|
19
|
+
* return <div ref={mergedRef}>Content</div>;
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function useMergeRefs<TInstance>(refs: ReadonlyArray<MergeableRef<TInstance> | undefined>): null | RefCallback<TInstance>;
|
|
23
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type RefCallback } from "react";
|
|
2
2
|
type ScrollDirection = "horizontal" | "vertical";
|
|
3
3
|
type ScrollState = {
|
|
4
4
|
isScrollable: boolean;
|
|
@@ -14,12 +14,22 @@ type UseScrollDetectionOptions = {
|
|
|
14
14
|
onScrollStateChange?: (state: ScrollState) => void;
|
|
15
15
|
skip?: boolean;
|
|
16
16
|
};
|
|
17
|
+
type UseScrollDetectionResult<TElement extends HTMLElement = HTMLElement> = ScrollState & {
|
|
18
|
+
ref: RefCallback<TElement>;
|
|
19
|
+
element: TElement | null;
|
|
20
|
+
};
|
|
17
21
|
/**
|
|
18
22
|
* Hook for detecting scroll values in horizontal or vertical direction.
|
|
23
|
+
* Returns a ref callback to attach to the element you want to observe.
|
|
19
24
|
*
|
|
20
|
-
* @param {useRef} elementRef - Ref hook holding the element that needs to be observed during scrolling
|
|
21
25
|
* @param {object} options - Options object containing direction, onScrollStateChange callback, and skip
|
|
22
|
-
* @returns {object} An object containing
|
|
26
|
+
* @returns {object} An object containing ref callback, element, and scroll state (isScrollable, isAtBeginning, isAtEnd, scrollPosition)
|
|
27
|
+
* @template TElement extends HTMLElement
|
|
28
|
+
* @example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* const { ref, isScrollable, isAtBeginning } = useScrollDetection({ direction: "horizontal" });
|
|
31
|
+
* return <div ref={ref}>Scrollable content</div>;
|
|
32
|
+
* ```
|
|
23
33
|
*/
|
|
24
|
-
export declare const useScrollDetection:
|
|
34
|
+
export declare const useScrollDetection: <TElement extends HTMLElement = HTMLElement>(options?: UseScrollDetectionOptions) => UseScrollDetectionResult<TElement>;
|
|
25
35
|
export {};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { RefObject } from "react";
|
|
2
|
-
import { Geometry, UseMeasureSharedOptions } from "./useMeasureShared";
|
|
3
|
-
type UseMeasureElementOptions = UseMeasureSharedOptions;
|
|
4
|
-
/**
|
|
5
|
-
* Custom hook to measure the geometry of an element from a RefObject.
|
|
6
|
-
* Use this when you already have a ref (e.g., from useRef or for composition with other hooks).
|
|
7
|
-
* Measures the size and position of the element relative to the viewport.
|
|
8
|
-
*
|
|
9
|
-
* @param ref - RefObject pointing to the element to measure
|
|
10
|
-
* @returns {Geometry} The geometry of the element
|
|
11
|
-
* @example
|
|
12
|
-
* ```tsx
|
|
13
|
-
* const ref = useRef<HTMLDivElement>(null);
|
|
14
|
-
* const geometry = useMeasureElement(ref);
|
|
15
|
-
* return <div ref={ref}>Width: {geometry.width}</div>;
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export declare const useMeasureElement: <TElement extends HTMLElement = HTMLElement>(ref: RefObject<TElement | null>, { skip, onChange }?: UseMeasureElementOptions) => Geometry | undefined;
|
|
19
|
-
export {};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export type Geometry = {
|
|
2
|
-
readonly height: number;
|
|
3
|
-
readonly width: number;
|
|
4
|
-
readonly x: number;
|
|
5
|
-
readonly y: number;
|
|
6
|
-
readonly bottom: number;
|
|
7
|
-
readonly left: number;
|
|
8
|
-
readonly right: number;
|
|
9
|
-
readonly top: number;
|
|
10
|
-
};
|
|
11
|
-
export type UseMeasureSharedOptions = {
|
|
12
|
-
skip?: boolean;
|
|
13
|
-
onChange?: (geometry: Geometry) => void;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Shared measurement logic used by both useMeasure and useMeasureElement.
|
|
17
|
-
* This hook observes an element and measures its geometry.
|
|
18
|
-
*/
|
|
19
|
-
export declare const useMeasureShared: <TElement extends HTMLElement>(element: TElement | null, { skip, onChange }?: UseMeasureSharedOptions) => Geometry | undefined;
|