@vx-oss/heroui-v2-use-data-scroll-overflow 2.2.14-alpha.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/LICENSE ADDED
@@ -0,0 +1,32 @@
1
+ SPDX-License-Identifier: MIT
2
+
3
+ The MIT License (MIT)
4
+
5
+ Parameters
6
+
7
+ Creator / Maintainer : Vezham Technologies Private Limited
8
+ Original Author : NextUI Inc
9
+ Licensor : Vezham Technologies Private Limited
10
+
11
+ Copyright © 2025, Vezham Technologies Private Limited. All rights reserved.
12
+ Copyright (c) 2020, NextUI Inc.
13
+
14
+ ---
15
+
16
+ Permission is hereby granted, free of charge, to any person obtaining a copy
17
+ of this software and associated documentation files (the "Software"), to deal
18
+ in the Software without restriction, including without limitation the rights
19
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
+ copies of the Software, and to permit persons to whom the Software is
21
+ furnished to do so, subject to the following conditions:
22
+
23
+ The above copyright notice and this permission notice shall be included in all
24
+ copies or substantial portions of the Software.
25
+
26
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # @vx-oss/heroui-v2-use-data-scroll-overflow
2
+
3
+ A Quick description of the component
4
+
5
+ > This is an internal utility, not intended for public usage.
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ yarn add @vx-oss/heroui-v2-use-data-scroll-overflow
11
+ # or
12
+ npm i @vx-oss/heroui-v2-use-data-scroll-overflow
13
+ ```
14
+
15
+ ## Contribution
16
+
17
+ Yes please! See the
18
+ [contributing guidelines](https://github.com/heroui-inc/heroui/blob/master/CONTRIBUTING.md)
19
+ for details.
20
+
21
+ ## License
22
+
23
+ This project is licensed under the terms of the
24
+ [MIT license](https://github.com/heroui-inc/heroui/blob/master/LICENSE).
@@ -0,0 +1,50 @@
1
+ type ScrollOverflowVisibility = "auto" | "top" | "bottom" | "left" | "right" | "both" | "none";
2
+ type ScrollOverflowEdgeCheck = "all" | "top" | "bottom" | "left" | "right";
3
+ type ScrollOverflowOrientation = "horizontal" | "vertical";
4
+ type ScrollOverflowCheck = ScrollOverflowOrientation | "both";
5
+ interface UseDataScrollOverflowProps {
6
+ /**
7
+ * The reference to the DOM element on which we're checking overflow.
8
+ */
9
+ domRef?: React.RefObject<HTMLElement>;
10
+ /**
11
+ * Determines the direction of overflow to check.
12
+ * - "horizontal" will check for overflow on the x-axis.
13
+ * - "vertical" will check for overflow on the y-axis.
14
+ * - "both" (default) will check for overflow on both axes.
15
+ *
16
+ * @default "both"
17
+ */
18
+ overflowCheck?: ScrollOverflowCheck;
19
+ /**
20
+ * Controlled visible state. Passing "auto" will make the shadow visible only when the scroll reaches the edge.
21
+ * use "left" / "right" for horizontal scroll and "top" / "bottom" for vertical scroll.
22
+ * @default "auto"
23
+ */
24
+ visibility?: ScrollOverflowVisibility;
25
+ /**
26
+ * Enables or disables the overflow checking mechanism.
27
+ * @default true
28
+ */
29
+ isEnabled?: boolean;
30
+ /**
31
+ * Defines a buffer or margin within which we won't treat the scroll as reaching the edge.
32
+ *
33
+ * @default 0 - meaning the check will behave exactly at the edge.
34
+ */
35
+ offset?: number;
36
+ /**
37
+ * List of dependencies to update the overflow check.
38
+ */
39
+ updateDeps?: any[];
40
+ /**
41
+ * Callback to be called when the overflow state changes.
42
+ *
43
+ * @param visibility ScrollOverflowVisibility
44
+ */
45
+ onVisibilityChange?: (overflow: ScrollOverflowVisibility) => void;
46
+ }
47
+ declare function useDataScrollOverflow(props?: UseDataScrollOverflowProps): void;
48
+ type UseDataScrollOverflowReturn = ReturnType<typeof useDataScrollOverflow>;
49
+
50
+ export { type ScrollOverflowCheck, type ScrollOverflowEdgeCheck, type ScrollOverflowOrientation, type ScrollOverflowVisibility, type UseDataScrollOverflowProps, type UseDataScrollOverflowReturn, useDataScrollOverflow };
@@ -0,0 +1,50 @@
1
+ type ScrollOverflowVisibility = "auto" | "top" | "bottom" | "left" | "right" | "both" | "none";
2
+ type ScrollOverflowEdgeCheck = "all" | "top" | "bottom" | "left" | "right";
3
+ type ScrollOverflowOrientation = "horizontal" | "vertical";
4
+ type ScrollOverflowCheck = ScrollOverflowOrientation | "both";
5
+ interface UseDataScrollOverflowProps {
6
+ /**
7
+ * The reference to the DOM element on which we're checking overflow.
8
+ */
9
+ domRef?: React.RefObject<HTMLElement>;
10
+ /**
11
+ * Determines the direction of overflow to check.
12
+ * - "horizontal" will check for overflow on the x-axis.
13
+ * - "vertical" will check for overflow on the y-axis.
14
+ * - "both" (default) will check for overflow on both axes.
15
+ *
16
+ * @default "both"
17
+ */
18
+ overflowCheck?: ScrollOverflowCheck;
19
+ /**
20
+ * Controlled visible state. Passing "auto" will make the shadow visible only when the scroll reaches the edge.
21
+ * use "left" / "right" for horizontal scroll and "top" / "bottom" for vertical scroll.
22
+ * @default "auto"
23
+ */
24
+ visibility?: ScrollOverflowVisibility;
25
+ /**
26
+ * Enables or disables the overflow checking mechanism.
27
+ * @default true
28
+ */
29
+ isEnabled?: boolean;
30
+ /**
31
+ * Defines a buffer or margin within which we won't treat the scroll as reaching the edge.
32
+ *
33
+ * @default 0 - meaning the check will behave exactly at the edge.
34
+ */
35
+ offset?: number;
36
+ /**
37
+ * List of dependencies to update the overflow check.
38
+ */
39
+ updateDeps?: any[];
40
+ /**
41
+ * Callback to be called when the overflow state changes.
42
+ *
43
+ * @param visibility ScrollOverflowVisibility
44
+ */
45
+ onVisibilityChange?: (overflow: ScrollOverflowVisibility) => void;
46
+ }
47
+ declare function useDataScrollOverflow(props?: UseDataScrollOverflowProps): void;
48
+ type UseDataScrollOverflowReturn = ReturnType<typeof useDataScrollOverflow>;
49
+
50
+ export { type ScrollOverflowCheck, type ScrollOverflowEdgeCheck, type ScrollOverflowOrientation, type ScrollOverflowVisibility, type UseDataScrollOverflowProps, type UseDataScrollOverflowReturn, useDataScrollOverflow };
package/dist/index.js ADDED
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ useDataScrollOverflow: () => useDataScrollOverflow
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var import_heroui_v2_shared_utils = require("@vx-oss/heroui-v2-shared-utils");
27
+ var import_react = require("react");
28
+ function useDataScrollOverflow(props = {}) {
29
+ const {
30
+ domRef,
31
+ isEnabled = true,
32
+ overflowCheck = "vertical",
33
+ visibility = "auto",
34
+ offset = 0,
35
+ onVisibilityChange,
36
+ updateDeps = []
37
+ } = props;
38
+ const visibleRef = (0, import_react.useRef)(visibility);
39
+ (0, import_react.useEffect)(() => {
40
+ const el = domRef == null ? void 0 : domRef.current;
41
+ if (!el || !isEnabled) return;
42
+ const setAttributes = (direction, hasBefore, hasAfter, prefix, suffix) => {
43
+ if (visibility === "auto") {
44
+ const both = `${prefix}${(0, import_heroui_v2_shared_utils.capitalize)(suffix)}Scroll`;
45
+ if (hasBefore && hasAfter) {
46
+ el.dataset[both] = "true";
47
+ el.removeAttribute(`data-${prefix}-scroll`);
48
+ el.removeAttribute(`data-${suffix}-scroll`);
49
+ } else {
50
+ el.dataset[`${prefix}Scroll`] = hasBefore.toString();
51
+ el.dataset[`${suffix}Scroll`] = hasAfter.toString();
52
+ el.removeAttribute(`data-${prefix}-${suffix}-scroll`);
53
+ }
54
+ } else {
55
+ const next = hasBefore && hasAfter ? "both" : hasBefore ? prefix : hasAfter ? suffix : "none";
56
+ if (next !== visibleRef.current) {
57
+ onVisibilityChange == null ? void 0 : onVisibilityChange(next);
58
+ visibleRef.current = next;
59
+ }
60
+ }
61
+ };
62
+ const checkOverflow = () => {
63
+ var _a, _b;
64
+ const directions = [
65
+ { type: "vertical", prefix: "top", suffix: "bottom" },
66
+ { type: "horizontal", prefix: "left", suffix: "right" }
67
+ ];
68
+ const listbox = el.querySelector('ul[data-slot="list"]');
69
+ const scrollHeight = +((_a = listbox == null ? void 0 : listbox.getAttribute("data-virtual-scroll-height")) != null ? _a : el.scrollHeight);
70
+ const scrollTop = +((_b = listbox == null ? void 0 : listbox.getAttribute("data-virtual-scroll-top")) != null ? _b : el.scrollTop);
71
+ for (const { type, prefix, suffix } of directions) {
72
+ if (overflowCheck === type || overflowCheck === "both") {
73
+ const hasBefore = type === "vertical" ? scrollTop > offset : el.scrollLeft > offset;
74
+ const hasAfter = type === "vertical" ? scrollTop + el.clientHeight + offset < scrollHeight : el.scrollLeft + el.clientWidth + offset < el.scrollWidth;
75
+ setAttributes(type, hasBefore, hasAfter, prefix, suffix);
76
+ }
77
+ }
78
+ };
79
+ const clearOverflow = () => {
80
+ ["top", "bottom", "top-bottom", "left", "right", "left-right"].forEach((attr) => {
81
+ el.removeAttribute(`data-${attr}-scroll`);
82
+ });
83
+ };
84
+ checkOverflow();
85
+ el.addEventListener("scroll", checkOverflow, true);
86
+ if (visibility !== "auto") {
87
+ clearOverflow();
88
+ if (visibility === "both") {
89
+ el.dataset.topBottomScroll = String(overflowCheck === "vertical");
90
+ el.dataset.leftRightScroll = String(overflowCheck === "horizontal");
91
+ } else {
92
+ el.dataset.topBottomScroll = "false";
93
+ el.dataset.leftRightScroll = "false";
94
+ ["top", "bottom", "left", "right"].forEach((attr) => {
95
+ el.dataset[`${attr}Scroll`] = String(visibility === attr);
96
+ });
97
+ }
98
+ }
99
+ return () => {
100
+ el.removeEventListener("scroll", checkOverflow, true);
101
+ clearOverflow();
102
+ };
103
+ }, [...updateDeps, isEnabled, visibility, overflowCheck, onVisibilityChange, domRef]);
104
+ }
105
+ // Annotate the CommonJS export names for ESM import in node:
106
+ 0 && (module.exports = {
107
+ useDataScrollOverflow
108
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,83 @@
1
+ // src/index.ts
2
+ import { capitalize } from "@vx-oss/heroui-v2-shared-utils";
3
+ import { useEffect, useRef } from "react";
4
+ function useDataScrollOverflow(props = {}) {
5
+ const {
6
+ domRef,
7
+ isEnabled = true,
8
+ overflowCheck = "vertical",
9
+ visibility = "auto",
10
+ offset = 0,
11
+ onVisibilityChange,
12
+ updateDeps = []
13
+ } = props;
14
+ const visibleRef = useRef(visibility);
15
+ useEffect(() => {
16
+ const el = domRef == null ? void 0 : domRef.current;
17
+ if (!el || !isEnabled) return;
18
+ const setAttributes = (direction, hasBefore, hasAfter, prefix, suffix) => {
19
+ if (visibility === "auto") {
20
+ const both = `${prefix}${capitalize(suffix)}Scroll`;
21
+ if (hasBefore && hasAfter) {
22
+ el.dataset[both] = "true";
23
+ el.removeAttribute(`data-${prefix}-scroll`);
24
+ el.removeAttribute(`data-${suffix}-scroll`);
25
+ } else {
26
+ el.dataset[`${prefix}Scroll`] = hasBefore.toString();
27
+ el.dataset[`${suffix}Scroll`] = hasAfter.toString();
28
+ el.removeAttribute(`data-${prefix}-${suffix}-scroll`);
29
+ }
30
+ } else {
31
+ const next = hasBefore && hasAfter ? "both" : hasBefore ? prefix : hasAfter ? suffix : "none";
32
+ if (next !== visibleRef.current) {
33
+ onVisibilityChange == null ? void 0 : onVisibilityChange(next);
34
+ visibleRef.current = next;
35
+ }
36
+ }
37
+ };
38
+ const checkOverflow = () => {
39
+ var _a, _b;
40
+ const directions = [
41
+ { type: "vertical", prefix: "top", suffix: "bottom" },
42
+ { type: "horizontal", prefix: "left", suffix: "right" }
43
+ ];
44
+ const listbox = el.querySelector('ul[data-slot="list"]');
45
+ const scrollHeight = +((_a = listbox == null ? void 0 : listbox.getAttribute("data-virtual-scroll-height")) != null ? _a : el.scrollHeight);
46
+ const scrollTop = +((_b = listbox == null ? void 0 : listbox.getAttribute("data-virtual-scroll-top")) != null ? _b : el.scrollTop);
47
+ for (const { type, prefix, suffix } of directions) {
48
+ if (overflowCheck === type || overflowCheck === "both") {
49
+ const hasBefore = type === "vertical" ? scrollTop > offset : el.scrollLeft > offset;
50
+ const hasAfter = type === "vertical" ? scrollTop + el.clientHeight + offset < scrollHeight : el.scrollLeft + el.clientWidth + offset < el.scrollWidth;
51
+ setAttributes(type, hasBefore, hasAfter, prefix, suffix);
52
+ }
53
+ }
54
+ };
55
+ const clearOverflow = () => {
56
+ ["top", "bottom", "top-bottom", "left", "right", "left-right"].forEach((attr) => {
57
+ el.removeAttribute(`data-${attr}-scroll`);
58
+ });
59
+ };
60
+ checkOverflow();
61
+ el.addEventListener("scroll", checkOverflow, true);
62
+ if (visibility !== "auto") {
63
+ clearOverflow();
64
+ if (visibility === "both") {
65
+ el.dataset.topBottomScroll = String(overflowCheck === "vertical");
66
+ el.dataset.leftRightScroll = String(overflowCheck === "horizontal");
67
+ } else {
68
+ el.dataset.topBottomScroll = "false";
69
+ el.dataset.leftRightScroll = "false";
70
+ ["top", "bottom", "left", "right"].forEach((attr) => {
71
+ el.dataset[`${attr}Scroll`] = String(visibility === attr);
72
+ });
73
+ }
74
+ }
75
+ return () => {
76
+ el.removeEventListener("scroll", checkOverflow, true);
77
+ clearOverflow();
78
+ };
79
+ }, [...updateDeps, isEnabled, visibility, overflowCheck, onVisibilityChange, domRef]);
80
+ }
81
+ export {
82
+ useDataScrollOverflow
83
+ };
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@vx-oss/heroui-v2-use-data-scroll-overflow",
3
+ "version": "2.2.14-alpha.0",
4
+ "description": "A hook to add data attributes when the element has top or bottom scroll.",
5
+ "keywords": [
6
+ "use-data-scroll-overflow"
7
+ ],
8
+ "author": "Vx OSS Devs <oss-developers@vezham.com>",
9
+ "homepage": "https://vezham.com",
10
+ "license": "MIT",
11
+ "main": "dist/index.js",
12
+ "sideEffects": false,
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/vezham/heroui-v2.git",
22
+ "directory": "packages/hooks/use-data-scroll-overflow"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/vezham/heroui-v2/issues"
26
+ },
27
+ "dependencies": {
28
+ "@vx-oss/heroui-v2-shared-utils": "2.1.13-alpha.0"
29
+ },
30
+ "peerDependencies": {
31
+ "react": ">=18 || >=19.0.0-rc.0"
32
+ },
33
+ "clean-package": "../../../clean-package.config.json",
34
+ "tsup": {
35
+ "clean": true,
36
+ "target": "es2019",
37
+ "format": [
38
+ "cjs",
39
+ "esm"
40
+ ]
41
+ },
42
+ "module": "dist/index.mjs",
43
+ "types": "dist/index.d.ts",
44
+ "exports": {
45
+ ".": {
46
+ "types": "./dist/index.d.ts",
47
+ "import": "./dist/index.mjs",
48
+ "require": "./dist/index.js"
49
+ },
50
+ "./package.json": "./package.json"
51
+ },
52
+ "scripts": {
53
+ "build": "tsup src --dts",
54
+ "build:fast": "tsup src",
55
+ "dev": "pnpm build:fast --watch",
56
+ "clean": "rimraf dist .turbo",
57
+ "typecheck": "tsc --noEmit"
58
+ }
59
+ }