react-detect-overflow 1.0.0 → 1.1.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/README.md CHANGED
@@ -2,16 +2,6 @@
2
2
 
3
3
  React hooks for detecting horizontal and vertical overflow on DOM elements. Reactively updates when the element is resized.
4
4
 
5
- ## Installation
6
-
7
- ```bash
8
- npm install react-detect-overflow
9
- ```
10
-
11
- ## Requirements
12
-
13
- - React `v16.8.0` or later
14
-
15
5
  ---
16
6
 
17
7
  ## Usage
package/dist/index.cjs CHANGED
@@ -1,20 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let e = require("react");
3
3
  //#region src/overflow.tsx
4
- /**
5
- * Base hook for detecting overflow on a DOM element given axis.
6
- * Observes the element for size changes and recomputes overflow reactively.
7
- *
8
- * @param getSizes - A function that extracts scroll and client sizes from the element
9
- * @param externRef - An optional external ref to attach to the element. If not provided, an internal ref is created.
10
- * @returns An object containing overflow state and the ref to attach to the element
11
- *
12
- * @example
13
- * // Custom axis (e.g. both dimensions summed)
14
- * const { isOverflowing, ref } = useDetectOverflow(
15
- * (el) => ({ scrollSize: el.scrollWidth, clientSize: el.clientWidth }),
16
- * );
17
- */
18
4
  function t(t, n) {
19
5
  let r = (0, e.useRef)(null), i = (0, e.useRef)(t), a = n ?? r;
20
6
  (0, e.useLayoutEffect)(() => {
@@ -46,44 +32,16 @@ function t(t, n) {
46
32
  }
47
33
  //#endregion
48
34
  //#region src/index.tsx
49
- /**
50
- * Detects horizontal (X-axis) overflow on a DOM element.
51
- * Reactively updates when the element is resized.
52
- *
53
- * @param externRef - An optional external ref. If not provided, an internal ref is created.
54
- * @returns `isOverflowing` — whether the element overflows horizontally
55
- * @returns `amount` — the number of overflowing pixels
56
- * @returns `ratio` — `scrollWidth / clientWidth` (1 means no overflow)
57
- * @returns `ref` — attach this to the element you want to observe
58
- *
59
- * @example
60
- * const { isOverflowing, amount, ratio, ref } = useDetectOverflowX();
61
- * return <div ref={ref}>...</div>;
62
- */
63
35
  function n(e) {
64
36
  return t((e) => ({
65
37
  scrollSize: e.scrollWidth,
66
38
  clientSize: e.clientWidth
67
39
  }), e);
68
40
  }
69
- /**
70
- * Detects vertical (Y-axis) overflow on a DOM element.
71
- * Reactively updates when the element is resized.
72
- *
73
- * @param externRef - An optional external ref. If not provided, an internal ref is created.
74
- * @returns `isOverflowing` — whether the element overflows vertically
75
- * @returns `amount` — the number of overflowing pixels
76
- * @returns `ratio` — `scrollHeight / clientHeight` (1 means no overflow)
77
- * @returns `ref` — attach this to the element you want to observe
78
- *
79
- * @example
80
- * const { isOverflowing, amount, ratio, ref } = useDetectOverflowY();
81
- * return <div ref={ref}>...</div>;
82
- */
83
41
  function r(e) {
84
42
  return t((e) => ({
85
43
  scrollSize: e.scrollHeight,
86
44
  clientSize: e.clientHeight
87
45
  }), e);
88
46
  }
89
- exports.useDetectOverflowX = n, exports.useDetectOverflowY = r;
47
+ exports.useDetectOverflow = t, exports.useDetectOverflowX = n, exports.useDetectOverflowY = r;
package/dist/index.d.cts CHANGED
@@ -7,6 +7,35 @@ type DetectOverflow<T> = {
7
7
  ratio: number;
8
8
  ref: RefObject<T | null>;
9
9
  };
10
+ /**
11
+ * A function that extracts the scroll and client sizes from a DOM element,
12
+ * used to determine the axis of overflow detection.
13
+ *
14
+ * @example
15
+ * // Horizontal axis
16
+ * const getSizes: GetSizes = (el) => ({ scrollSize: el.scrollWidth, clientSize: el.clientWidth });
17
+ */
18
+ type GetSizes = (element: Element) => {
19
+ scrollSize: number;
20
+ clientSize: number;
21
+ };
22
+ //#endregion
23
+ //#region src/overflow.d.ts
24
+ /**
25
+ * Base hook for detecting overflow on a DOM element given axis.
26
+ * Observes the element for size changes and recomputes overflow reactively.
27
+ *
28
+ * @param getSizes - A function that extracts scroll and client sizes from the element
29
+ * @param externRef - An optional external ref to attach to the element. If not provided, an internal ref is created.
30
+ * @returns An object containing overflow state and the ref to attach to the element
31
+ *
32
+ * @example
33
+ * // Custom axis (e.g. both dimensions summed)
34
+ * const { isOverflowing, ref } = useDetectOverflow(
35
+ * (el) => ({ scrollSize: el.scrollWidth, clientSize: el.clientWidth }),
36
+ * );
37
+ */
38
+ declare function useDetectOverflow<T extends HTMLElement>(getSizes: GetSizes, externRef?: RefObject<T | null>): DetectOverflow<T>;
10
39
  //#endregion
11
40
  //#region src/index.d.ts
12
41
  /**
@@ -40,4 +69,4 @@ declare function useDetectOverflowX<T extends HTMLElement>(externRef?: RefObject
40
69
  */
41
70
  declare function useDetectOverflowY<T extends HTMLElement>(externRef?: RefObject<T | null>): DetectOverflow<T>;
42
71
  //#endregion
43
- export { useDetectOverflowX, useDetectOverflowY };
72
+ export { useDetectOverflow, useDetectOverflowX, useDetectOverflowY };
package/dist/index.d.mts CHANGED
@@ -7,6 +7,35 @@ type DetectOverflow<T> = {
7
7
  ratio: number;
8
8
  ref: RefObject<T | null>;
9
9
  };
10
+ /**
11
+ * A function that extracts the scroll and client sizes from a DOM element,
12
+ * used to determine the axis of overflow detection.
13
+ *
14
+ * @example
15
+ * // Horizontal axis
16
+ * const getSizes: GetSizes = (el) => ({ scrollSize: el.scrollWidth, clientSize: el.clientWidth });
17
+ */
18
+ type GetSizes = (element: Element) => {
19
+ scrollSize: number;
20
+ clientSize: number;
21
+ };
22
+ //#endregion
23
+ //#region src/overflow.d.ts
24
+ /**
25
+ * Base hook for detecting overflow on a DOM element given axis.
26
+ * Observes the element for size changes and recomputes overflow reactively.
27
+ *
28
+ * @param getSizes - A function that extracts scroll and client sizes from the element
29
+ * @param externRef - An optional external ref to attach to the element. If not provided, an internal ref is created.
30
+ * @returns An object containing overflow state and the ref to attach to the element
31
+ *
32
+ * @example
33
+ * // Custom axis (e.g. both dimensions summed)
34
+ * const { isOverflowing, ref } = useDetectOverflow(
35
+ * (el) => ({ scrollSize: el.scrollWidth, clientSize: el.clientWidth }),
36
+ * );
37
+ */
38
+ declare function useDetectOverflow<T extends HTMLElement>(getSizes: GetSizes, externRef?: RefObject<T | null>): DetectOverflow<T>;
10
39
  //#endregion
11
40
  //#region src/index.d.ts
12
41
  /**
@@ -40,4 +69,4 @@ declare function useDetectOverflowX<T extends HTMLElement>(externRef?: RefObject
40
69
  */
41
70
  declare function useDetectOverflowY<T extends HTMLElement>(externRef?: RefObject<T | null>): DetectOverflow<T>;
42
71
  //#endregion
43
- export { useDetectOverflowX, useDetectOverflowY };
72
+ export { useDetectOverflow, useDetectOverflowX, useDetectOverflowY };
package/dist/index.mjs CHANGED
@@ -1,19 +1,5 @@
1
1
  import { useCallback as e, useLayoutEffect as t, useRef as n, useState as r } from "react";
2
2
  //#region src/overflow.tsx
3
- /**
4
- * Base hook for detecting overflow on a DOM element given axis.
5
- * Observes the element for size changes and recomputes overflow reactively.
6
- *
7
- * @param getSizes - A function that extracts scroll and client sizes from the element
8
- * @param externRef - An optional external ref to attach to the element. If not provided, an internal ref is created.
9
- * @returns An object containing overflow state and the ref to attach to the element
10
- *
11
- * @example
12
- * // Custom axis (e.g. both dimensions summed)
13
- * const { isOverflowing, ref } = useDetectOverflow(
14
- * (el) => ({ scrollSize: el.scrollWidth, clientSize: el.clientWidth }),
15
- * );
16
- */
17
3
  function i(i, a) {
18
4
  let o = n(null), s = n(i), c = a ?? o;
19
5
  t(() => {
@@ -45,40 +31,12 @@ function i(i, a) {
45
31
  }
46
32
  //#endregion
47
33
  //#region src/index.tsx
48
- /**
49
- * Detects horizontal (X-axis) overflow on a DOM element.
50
- * Reactively updates when the element is resized.
51
- *
52
- * @param externRef - An optional external ref. If not provided, an internal ref is created.
53
- * @returns `isOverflowing` — whether the element overflows horizontally
54
- * @returns `amount` — the number of overflowing pixels
55
- * @returns `ratio` — `scrollWidth / clientWidth` (1 means no overflow)
56
- * @returns `ref` — attach this to the element you want to observe
57
- *
58
- * @example
59
- * const { isOverflowing, amount, ratio, ref } = useDetectOverflowX();
60
- * return <div ref={ref}>...</div>;
61
- */
62
34
  function a(e) {
63
35
  return i((e) => ({
64
36
  scrollSize: e.scrollWidth,
65
37
  clientSize: e.clientWidth
66
38
  }), e);
67
39
  }
68
- /**
69
- * Detects vertical (Y-axis) overflow on a DOM element.
70
- * Reactively updates when the element is resized.
71
- *
72
- * @param externRef - An optional external ref. If not provided, an internal ref is created.
73
- * @returns `isOverflowing` — whether the element overflows vertically
74
- * @returns `amount` — the number of overflowing pixels
75
- * @returns `ratio` — `scrollHeight / clientHeight` (1 means no overflow)
76
- * @returns `ref` — attach this to the element you want to observe
77
- *
78
- * @example
79
- * const { isOverflowing, amount, ratio, ref } = useDetectOverflowY();
80
- * return <div ref={ref}>...</div>;
81
- */
82
40
  function o(e) {
83
41
  return i((e) => ({
84
42
  scrollSize: e.scrollHeight,
@@ -86,4 +44,4 @@ function o(e) {
86
44
  }), e);
87
45
  }
88
46
  //#endregion
89
- export { a as useDetectOverflowX, o as useDetectOverflowY };
47
+ export { i as useDetectOverflow, a as useDetectOverflowX, o as useDetectOverflowY };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-detect-overflow",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",