@gridui/follow-scroll 1.0.4 → 1.0.7
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/index.js +5 -2
- package/dist/index.js.map +2 -2
- package/dist/styles.css +1 -1
- package/docs/catalog.json +43 -0
- package/package.json +7 -8
package/dist/index.js
CHANGED
|
@@ -71,24 +71,27 @@ var useFollowScroll = ({ threshold = 48, onFollowingChange } = {}) => {
|
|
|
71
71
|
|
|
72
72
|
// src/follow-scroll/follow-scroll.tsx
|
|
73
73
|
import { Button } from "@gridui/button";
|
|
74
|
+
import { useScrollbars } from "@gridui/overlay";
|
|
74
75
|
import { cn } from "@gridui/style-utils";
|
|
75
76
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
76
77
|
var FollowScroll = (props) => {
|
|
77
|
-
const { label, jumpLabel, threshold, onFollowingChange, children, className, ...restProps } = props;
|
|
78
|
+
const { ref: forwardedRef, label, jumpLabel, threshold, onFollowingChange, children, className, ...restProps } = props;
|
|
78
79
|
const { viewportRef, contentRef, following, scrollToEnd } = useFollowScroll({
|
|
79
80
|
...threshold === void 0 ? {} : { threshold },
|
|
80
81
|
...onFollowingChange === void 0 ? {} : { onFollowingChange }
|
|
81
82
|
});
|
|
83
|
+
const scrollRef = useScrollbars({ ref: viewportRef });
|
|
82
84
|
return /* @__PURE__ */ jsxs(
|
|
83
85
|
"div",
|
|
84
86
|
{
|
|
85
87
|
...restProps,
|
|
88
|
+
ref: forwardedRef,
|
|
86
89
|
className: cn("gridui-follow-scroll", className),
|
|
87
90
|
children: [
|
|
88
91
|
/* @__PURE__ */ jsx(
|
|
89
92
|
"div",
|
|
90
93
|
{
|
|
91
|
-
ref:
|
|
94
|
+
ref: scrollRef,
|
|
92
95
|
className: "gridui-follow-scroll-viewport",
|
|
93
96
|
role: "region",
|
|
94
97
|
"aria-label": label,
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/follow-scroll/use-follow-scroll.ts", "../src/follow-scroll/follow-scroll.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * @author WMXPY\n * @package Follow Scroll\n * @namespace FollowScroll\n * @description Use Follow Scroll\n */\n\nimport { useCallback, useEffect, useRef, useState } from \"react\";\n\nexport type FollowScrollOptions = {\n readonly threshold?: number;\n readonly onFollowingChange?: (following: boolean) => void;\n};\n\nexport const useFollowScroll = ({ threshold = 48, onFollowingChange }: FollowScrollOptions = {}) => {\n if (!Number.isFinite(threshold) || threshold < 0) {\n throw new Error(\"FollowScroll threshold must be finite and nonnegative.\");\n }\n const viewportRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n const followingRef = useRef(true);\n const [\n following,\n setFollowing,\n ] = useState(true);\n const changeFollowing = useCallback((next: boolean) => {\n if (followingRef.current === next) {\n return;\n }\n followingRef.current = next;\n setFollowing(next);\n onFollowingChange?.(next);\n }, [onFollowingChange]);\n const scrollToEnd = useCallback(() => {\n const viewport = viewportRef.current;\n if (viewport) {\n changeFollowing(true);\n viewport.scrollTop = viewport.scrollHeight;\n }\n }, [changeFollowing]);\n useEffect(() => {\n const viewport = viewportRef.current;\n const content = contentRef.current;\n if (!viewport || !content) {\n return;\n }\n let frame = 0;\n const followGrowth = () => {\n cancelAnimationFrame(frame);\n frame = requestAnimationFrame(() => {\n const distance = viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop;\n if (followingRef.current || distance <= threshold) {\n changeFollowing(true);\n viewport.scrollTop = viewport.scrollHeight;\n }\n });\n };\n const onScroll = () => {\n const distance = viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop;\n changeFollowing(distance <= threshold);\n };\n const observer = typeof ResizeObserver === \"undefined\" ? undefined : new ResizeObserver(followGrowth);\n observer?.observe(content);\n observer?.observe(viewport);\n viewport.addEventListener(\"scroll\", onScroll);\n followGrowth();\n return () => {\n cancelAnimationFrame(frame);\n observer?.disconnect();\n viewport.removeEventListener(\"scroll\", onScroll);\n };\n }, [\n threshold,\n changeFollowing,\n ]);\n return {\n viewportRef,\n contentRef,\n following,\n scrollToEnd,\n };\n};\n", "/**\n * @author WMXPY\n * @package Follow Scroll\n * @namespace FollowScroll\n * @description Follow Scroll\n */\n\nimport { type FollowScrollOptions, useFollowScroll } from \"./use-follow-scroll\";\nimport { Button } from \"@gridui/button\";\nimport { cn } from \"@gridui/style-utils\";\nimport type { ComponentPropsWithRef, FC } from \"react\";\n\nexport type FollowScrollProps = Omit<ComponentPropsWithRef<\"div\">, \"onScroll\"> & FollowScrollOptions & {\n readonly label: string;\n readonly jumpLabel: string;\n};\n\nexport const FollowScroll: FC<FollowScrollProps> = (props: FollowScrollProps) => {\n const { label, jumpLabel, threshold, onFollowingChange, children, className, ...restProps } = props;\n const { viewportRef, contentRef, following, scrollToEnd } = useFollowScroll({\n ...(threshold === undefined ? {} : { threshold }),\n ...(onFollowingChange === undefined ? {} : { onFollowingChange }),\n });\n return (<div\n {...restProps}\n className={cn(\"gridui-follow-scroll\", className)}\n >\n <div\n ref={
|
|
5
|
-
"mappings": ";AAOA,SAAS,aAAa,WAAW,QAAQ,gBAAgB;AAOlD,IAAM,kBAAkB,CAAC,EAAE,YAAY,IAAI,kBAAkB,IAAyB,CAAC,MAAM;AAChG,MAAI,CAAC,OAAO,SAAS,SAAS,KAAK,YAAY,GAAG;AAC9C,UAAM,IAAI,MAAM,wDAAwD;AAAA,EAC5E;AACA,QAAM,cAAc,OAAuB,IAAI;AAC/C,QAAM,aAAa,OAAuB,IAAI;AAC9C,QAAM,eAAe,OAAO,IAAI;AAChC,QAAM;AAAA,IACF;AAAA,IACA;AAAA,EACJ,IAAI,SAAS,IAAI;AACjB,QAAM,kBAAkB,YAAY,CAAC,SAAkB;AACnD,QAAI,aAAa,YAAY,MAAM;AAC/B;AAAA,IACJ;AACA,iBAAa,UAAU;AACvB,iBAAa,IAAI;AACjB,wBAAoB,IAAI;AA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{ useCallback, useEffect, useRef, useState } from \"react\";\n\nexport type FollowScrollOptions = {\n readonly threshold?: number;\n readonly onFollowingChange?: (following: boolean) => void;\n};\n\nexport const useFollowScroll = ({ threshold = 48, onFollowingChange }: FollowScrollOptions = {}) => {\n if (!Number.isFinite(threshold) || threshold < 0) {\n throw new Error(\"FollowScroll threshold must be finite and nonnegative.\");\n }\n const viewportRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n const followingRef = useRef(true);\n const [\n following,\n setFollowing,\n ] = useState(true);\n const changeFollowing = useCallback((next: boolean) => {\n if (followingRef.current === next) {\n return;\n }\n followingRef.current = next;\n setFollowing(next);\n onFollowingChange?.(next);\n }, [onFollowingChange]);\n const scrollToEnd = useCallback(() => {\n const viewport = viewportRef.current;\n if (viewport) {\n changeFollowing(true);\n viewport.scrollTop = viewport.scrollHeight;\n }\n }, [changeFollowing]);\n useEffect(() => {\n const viewport = viewportRef.current;\n const content = contentRef.current;\n if (!viewport || !content) {\n return;\n }\n let frame = 0;\n const followGrowth = () => {\n cancelAnimationFrame(frame);\n frame = requestAnimationFrame(() => {\n const distance = viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop;\n if (followingRef.current || distance <= threshold) {\n changeFollowing(true);\n viewport.scrollTop = viewport.scrollHeight;\n }\n });\n };\n const onScroll = () => {\n const distance = viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop;\n changeFollowing(distance <= threshold);\n };\n const observer = typeof ResizeObserver === \"undefined\" ? undefined : new ResizeObserver(followGrowth);\n observer?.observe(content);\n observer?.observe(viewport);\n viewport.addEventListener(\"scroll\", onScroll);\n followGrowth();\n return () => {\n cancelAnimationFrame(frame);\n observer?.disconnect();\n viewport.removeEventListener(\"scroll\", onScroll);\n };\n }, [\n threshold,\n changeFollowing,\n ]);\n return {\n viewportRef,\n contentRef,\n following,\n scrollToEnd,\n };\n};\n", "/**\n * @author WMXPY\n * @package Follow Scroll\n * @namespace FollowScroll\n * @description Follow Scroll\n */\n\nimport { type FollowScrollOptions, useFollowScroll } from \"./use-follow-scroll\";\nimport { Button } from \"@gridui/button\";\nimport { useScrollbars } from \"@gridui/overlay\";\nimport { cn } from \"@gridui/style-utils\";\nimport type { ComponentPropsWithRef, FC } from \"react\";\n\nexport type FollowScrollProps = Omit<ComponentPropsWithRef<\"div\">, \"onScroll\"> & FollowScrollOptions & {\n readonly label: string;\n readonly jumpLabel: string;\n};\n\nexport const FollowScroll: FC<FollowScrollProps> = (props: FollowScrollProps) => {\n const { ref: forwardedRef, label, jumpLabel, threshold, onFollowingChange, children, className, ...restProps } = props;\n const { viewportRef, contentRef, following, scrollToEnd } = useFollowScroll({\n ...(threshold === undefined ? {} : { threshold }),\n ...(onFollowingChange === undefined ? {} : { onFollowingChange }),\n });\n const scrollRef = useScrollbars({ ref: viewportRef });\n return (<div\n {...restProps}\n ref={forwardedRef}\n className={cn(\"gridui-follow-scroll\", className)}\n >\n <div\n ref={scrollRef}\n className=\"gridui-follow-scroll-viewport\"\n role=\"region\"\n aria-label={label}\n tabIndex={0}\n >\n <div\n ref={contentRef}\n className=\"gridui-follow-scroll-content\"\n >\n {children}\n </div>\n </div>\n {!following && (<Button\n className=\"gridui-follow-scroll-jump\"\n size=\"small\"\n onClick={() => {\n scrollToEnd();\n viewportRef.current?.focus({ preventScroll: true });\n }}\n >\n {jumpLabel}\n </Button>)}\n </div>);\n};\n"],
|
|
5
|
+
"mappings": ";AAOA,SAAS,aAAa,WAAW,QAAQ,gBAAgB;AAOlD,IAAM,kBAAkB,CAAC,EAAE,YAAY,IAAI,kBAAkB,IAAyB,CAAC,MAAM;AAChG,MAAI,CAAC,OAAO,SAAS,SAAS,KAAK,YAAY,GAAG;AAC9C,UAAM,IAAI,MAAM,wDAAwD;AAAA,EAC5E;AACA,QAAM,cAAc,OAAuB,IAAI;AAC/C,QAAM,aAAa,OAAuB,IAAI;AAC9C,QAAM,eAAe,OAAO,IAAI;AAChC,QAAM;AAAA,IACF;AAAA,IACA;A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
|
+
"category": "core",
|
|
6
|
+
"description": "GridUI React follow scroll",
|
|
7
|
+
"usage": "GridUI React follow scroll",
|
|
8
|
+
"documentation": [
|
|
9
|
+
"README.md",
|
|
10
|
+
"docs/follow-scroll.md"
|
|
11
|
+
],
|
|
12
|
+
"exports": [
|
|
13
|
+
{
|
|
14
|
+
"name": "FollowScroll",
|
|
15
|
+
"kind": "component",
|
|
16
|
+
"importPath": "@gridui/follow-scroll"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "FollowScrollOptions",
|
|
20
|
+
"kind": "type",
|
|
21
|
+
"importPath": "@gridui/follow-scroll"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"name": "FollowScrollProps",
|
|
25
|
+
"kind": "type",
|
|
26
|
+
"importPath": "@gridui/follow-scroll"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"name": "useFollowScroll",
|
|
30
|
+
"kind": "function",
|
|
31
|
+
"importPath": "@gridui/follow-scroll"
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"styles": [
|
|
35
|
+
"@gridui/theme/styles.css",
|
|
36
|
+
"@gridui/button/styles.css",
|
|
37
|
+
"@gridui/overlay/styles.css",
|
|
38
|
+
"@gridui/follow-scroll/styles.css"
|
|
39
|
+
],
|
|
40
|
+
"examples": [
|
|
41
|
+
"https://github.com/sudo-ui/GridUI-React-Monorepo/blob/main/packages-core/follow-scroll/stories/follow-scroll.stories.tsx"
|
|
42
|
+
]
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gridui/follow-scroll",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "GridUI React follow scroll",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -27,14 +27,15 @@
|
|
|
27
27
|
"react-dom": "^19.2.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@gridui/button": "^3.
|
|
31
|
-
"@gridui/
|
|
32
|
-
"@gridui/
|
|
30
|
+
"@gridui/button": "^3.1.2",
|
|
31
|
+
"@gridui/overlay": "^1.2.2",
|
|
32
|
+
"@gridui/style-utils": "^2.2.2",
|
|
33
|
+
"@gridui/theme": "^2.5.3"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@gridui-internal/configuration": "0.0.0-internal",
|
|
36
37
|
"@jest/globals": "30.5.2",
|
|
37
|
-
"@storybook/react-vite": "10.6.
|
|
38
|
+
"@storybook/react-vite": "10.6.6",
|
|
38
39
|
"@types/jest": "30.0.0",
|
|
39
40
|
"@types/node": "26.6.6",
|
|
40
41
|
"@types/react": "19.3.0",
|
|
@@ -46,8 +47,6 @@
|
|
|
46
47
|
},
|
|
47
48
|
"scripts": {
|
|
48
49
|
"build": "node ../../scripts/compilation/package.ts",
|
|
49
|
-
"compile": "tsc --project tsconfig.json"
|
|
50
|
-
"test": "jest --passWithNoTests",
|
|
51
|
-
"coverage": "jest --coverage --passWithNoTests"
|
|
50
|
+
"compile": "tsc --project tsconfig.json"
|
|
52
51
|
}
|
|
53
52
|
}
|