@vnejs/uis.react.scroll-content 0.1.3 → 0.1.4
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/ScrollContent.d.ts +0 -1
- package/dist/ScrollContent.d.ts.map +1 -1
- package/dist/ScrollContent.js +1 -3
- package/dist/ScrollContent.js.map +1 -1
- package/dist/ScrollContent.styles.d.ts +2 -0
- package/dist/ScrollContent.styles.d.ts.map +1 -0
- package/dist/ScrollContent.styles.js +13 -0
- package/dist/ScrollContent.styles.js.map +1 -0
- package/package.json +12 -17
- package/src/ScrollContent.stories.tsx +52 -0
- package/src/ScrollContent.styles.ts +15 -0
- package/src/ScrollContent.tsx +64 -0
- package/src/index.ts +1 -0
- package/tsconfig.json +18 -0
- package/dist/ScrollContent.styl +0 -8
package/dist/ScrollContent.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScrollContent.d.ts","sourceRoot":"","sources":["../src/ScrollContent.tsx"],"names":[],"mappings":"AAIA,
|
|
1
|
+
{"version":3,"file":"ScrollContent.d.ts","sourceRoot":"","sources":["../src/ScrollContent.tsx"],"names":[],"mappings":"AAIA,eAAO,MAAM,aAAa,GAAI;;;;;;;;;CAA6G,4CA2D1I,CAAC"}
|
package/dist/ScrollContent.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useEffect, useRef } from "react";
|
|
3
|
-
import {
|
|
4
|
-
import "./ScrollContent.styl";
|
|
5
|
-
const b = cn("ScrollContent");
|
|
3
|
+
import { b } from "./ScrollContent.styles.js";
|
|
6
4
|
export const ScrollContent = ({ className = "", children, shouldScroll, waitCommonDelay, waitStartDelay, waitEndDelay, duration, onFinish }) => {
|
|
7
5
|
const contentRef = useRef(null);
|
|
8
6
|
const closeTimeout = useRef(0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScrollContent.js","sourceRoot":"","sources":["../src/ScrollContent.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEvD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ScrollContent.js","sourceRoot":"","sources":["../src/ScrollContent.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEvD,OAAO,EAAE,CAAC,EAAE,MAAM,2BAA2B,CAAC;AAE9C,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAAE,SAAS,GAAG,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC7I,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAChC,MAAM,YAAY,GAAG,MAAM,CAAM,CAAC,CAAC,CAAC;IACpC,MAAM,aAAa,GAAG,MAAM,CAAM,CAAC,CAAC,CAAC;IAErC,MAAM,eAAe,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,QAAQ,IAAI,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAE9E,MAAM,aAAa,GAAG,WAAW,CAC/B,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QACvB,MAAM,KAAK,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,GAAG,QAAQ,CAAC;QAC1D,UAAU,CAAC,OAAO,CAAC,SAAS,GAAG,IAAI,GAAG,KAAK,CAAC;QAE5C,IAAI,KAAK,IAAI,CAAC;YAAE,OAAO,KAAK,EAAE,CAAC;QAE/B,aAAa,CAAC,OAAO,GAAG,qBAAqB,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,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O,CACL,cACE,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,EAC7B,GAAG,EAAE,UAAU,YAEd,QAAQ,GACL,CACP,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScrollContent.styles.d.ts","sourceRoot":"","sources":["../src/ScrollContent.styles.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,CAAC,4BAAsB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { cn, injectStyles, sel } from "@vnejs/uis.utils";
|
|
2
|
+
export const b = cn("ScrollContent");
|
|
3
|
+
const CSS = `
|
|
4
|
+
${sel(b())} {
|
|
5
|
+
display: block;
|
|
6
|
+
position: relative;
|
|
7
|
+
width: 100%;
|
|
8
|
+
height: 100%;
|
|
9
|
+
overflow: hidden;
|
|
10
|
+
}
|
|
11
|
+
`;
|
|
12
|
+
injectStyles(CSS);
|
|
13
|
+
//# sourceMappingURL=ScrollContent.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScrollContent.styles.js","sourceRoot":"","sources":["../src/ScrollContent.styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAEzD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,eAAe,CAAC,CAAC;AAErC,MAAM,GAAG,GAAG;EACV,GAAG,CAAC,CAAC,EAAE,CAAC;;;;;;;CAOT,CAAC;AAEF,YAAY,CAAC,GAAG,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,31 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/uis.react.scroll-content",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"build": "
|
|
8
|
-
"publish:major:
|
|
9
|
-
"publish:minor:
|
|
10
|
-
"publish:patch:
|
|
11
|
-
"publish:major": "
|
|
12
|
-
"publish:minor": "
|
|
13
|
-
"publish:patch": "
|
|
7
|
+
"build": "npx @vnejs/monorepo package",
|
|
8
|
+
"publish:major:uis:react": "npm run publish:major",
|
|
9
|
+
"publish:minor:uis:react": "npm run publish:minor",
|
|
10
|
+
"publish:patch:uis:react": "npm run publish:patch",
|
|
11
|
+
"publish:major": "npx @vnejs/monorepo publish major --access public",
|
|
12
|
+
"publish:minor": "npx @vnejs/monorepo publish minor --access public",
|
|
13
|
+
"publish:patch": "npx @vnejs/monorepo publish patch --access public"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
|
-
"@
|
|
17
|
-
"@vnejs/uis.utils": "~0.1.0",
|
|
18
|
-
"react": "19.2.4",
|
|
19
|
-
"react-dom": "19.2.4"
|
|
16
|
+
"@vnejs/uis.utils": "~0.1.0"
|
|
20
17
|
},
|
|
21
18
|
"devDependencies": {
|
|
22
|
-
"@vnejs/uis.react": "~0.1.0"
|
|
23
|
-
"typescript": "^6.0.3",
|
|
24
|
-
"@types/react": "^19.0.10",
|
|
25
|
-
"@types/react-dom": "^19.0.4"
|
|
19
|
+
"@vnejs/uis.react": "~0.1.0"
|
|
26
20
|
},
|
|
27
21
|
"files": [
|
|
28
22
|
"dist",
|
|
29
|
-
"
|
|
23
|
+
"src",
|
|
24
|
+
"tsconfig.json"
|
|
30
25
|
]
|
|
31
26
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { renderWithVneWrap, DEFAULT_ARGS, ARGS } from "@vnejs/uis.react";
|
|
2
|
+
|
|
3
|
+
import { Text, ScrollContent, Flex } from "@vnejs/uis.react";
|
|
4
|
+
|
|
5
|
+
export const Common = {
|
|
6
|
+
args: {
|
|
7
|
+
...DEFAULT_ARGS,
|
|
8
|
+
textCount: 18,
|
|
9
|
+
|
|
10
|
+
shouldScroll: true,
|
|
11
|
+
waitCommonDelay: 1000,
|
|
12
|
+
waitStartDelay: 500,
|
|
13
|
+
waitEndDelay: 2000,
|
|
14
|
+
duration: 10000,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default {
|
|
19
|
+
title: "Primitives/ScrollContent",
|
|
20
|
+
render: renderWithVneWrap(({ textCount, ...args }) => (
|
|
21
|
+
<ScrollContent
|
|
22
|
+
{...args}
|
|
23
|
+
onFinish={() => console.log("finished")}
|
|
24
|
+
>
|
|
25
|
+
<Flex
|
|
26
|
+
direction={Flex.DIRECTION.COLUMN}
|
|
27
|
+
gap={96}
|
|
28
|
+
>
|
|
29
|
+
{Array.from({ length: textCount }, (_, index) => index).map((i) => (
|
|
30
|
+
<Text
|
|
31
|
+
key={i}
|
|
32
|
+
size={96}
|
|
33
|
+
align={Text.ALIGNS.CENTER}
|
|
34
|
+
text={`text text ${i} text text`}
|
|
35
|
+
/>
|
|
36
|
+
))}
|
|
37
|
+
</Flex>
|
|
38
|
+
</ScrollContent>
|
|
39
|
+
)),
|
|
40
|
+
argTypes: {
|
|
41
|
+
// engine
|
|
42
|
+
...ARGS,
|
|
43
|
+
|
|
44
|
+
// text
|
|
45
|
+
textCount: { control: { type: "number", min: 12, max: 36, step: 1 } },
|
|
46
|
+
|
|
47
|
+
waitCommonDelay: { control: { type: "number", min: 100, max: 2000, step: 100 } },
|
|
48
|
+
waitStartDelay: { control: { type: "number", min: 100, max: 2000, step: 100 } },
|
|
49
|
+
waitEndDelay: { control: { type: "number", min: 100, max: 2000, step: 100 } },
|
|
50
|
+
duration: { control: { type: "number", min: 100, max: 15000, step: 100 } },
|
|
51
|
+
},
|
|
52
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { cn, injectStyles, sel } from "@vnejs/uis.utils";
|
|
2
|
+
|
|
3
|
+
export const b = cn("ScrollContent");
|
|
4
|
+
|
|
5
|
+
const CSS = `
|
|
6
|
+
${sel(b())} {
|
|
7
|
+
display: block;
|
|
8
|
+
position: relative;
|
|
9
|
+
width: 100%;
|
|
10
|
+
height: 100%;
|
|
11
|
+
overflow: hidden;
|
|
12
|
+
}
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
injectStyles(CSS);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
import { b } from "./ScrollContent.styles.js";
|
|
4
|
+
|
|
5
|
+
export const ScrollContent = ({ className = "", children, shouldScroll, waitCommonDelay, waitStartDelay, waitEndDelay, duration, onFinish }) => {
|
|
6
|
+
const contentRef = useRef(null);
|
|
7
|
+
const closeTimeout = useRef<any>(0);
|
|
8
|
+
const scrollRequest = useRef<any>(0);
|
|
9
|
+
|
|
10
|
+
const onFinishHandler = useCallback(() => onFinish && onFinish(), [onFinish]);
|
|
11
|
+
|
|
12
|
+
const scrollContent = useCallback(
|
|
13
|
+
(tsStart, path, onEnd) => {
|
|
14
|
+
const ratio = (new Date().getTime() - tsStart) / duration;
|
|
15
|
+
contentRef.current.scrollTop = path * ratio;
|
|
16
|
+
|
|
17
|
+
if (ratio >= 1) return onEnd();
|
|
18
|
+
|
|
19
|
+
scrollRequest.current = requestAnimationFrame(() => scrollContent(tsStart, path, onEnd));
|
|
20
|
+
},
|
|
21
|
+
[duration],
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
// показываем
|
|
26
|
+
|
|
27
|
+
if (!shouldScroll) return;
|
|
28
|
+
|
|
29
|
+
contentRef.current.scrollTop = 0;
|
|
30
|
+
|
|
31
|
+
const tm = setTimeout(() => {
|
|
32
|
+
const tsStart = new Date().getTime();
|
|
33
|
+
|
|
34
|
+
scrollRequest.current = requestAnimationFrame(() =>
|
|
35
|
+
scrollContent(tsStart, contentRef.current.scrollHeight - contentRef.current.clientHeight, () => {
|
|
36
|
+
clearTimeout(closeTimeout.current);
|
|
37
|
+
closeTimeout.current = setTimeout(onFinishHandler, waitStartDelay + waitEndDelay);
|
|
38
|
+
}),
|
|
39
|
+
);
|
|
40
|
+
}, waitCommonDelay + waitStartDelay);
|
|
41
|
+
|
|
42
|
+
return () => clearTimeout(tm);
|
|
43
|
+
}, [shouldScroll, waitCommonDelay, waitStartDelay, waitEndDelay, scrollContent]);
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (shouldScroll) return;
|
|
47
|
+
|
|
48
|
+
const tm = setTimeout(() => {
|
|
49
|
+
cancelAnimationFrame(scrollRequest.current);
|
|
50
|
+
clearTimeout(closeTimeout.current);
|
|
51
|
+
}, waitCommonDelay);
|
|
52
|
+
|
|
53
|
+
return () => clearTimeout(tm);
|
|
54
|
+
}, [shouldScroll, waitCommonDelay]);
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<div
|
|
58
|
+
className={b({}, [className])}
|
|
59
|
+
ref={contentRef}
|
|
60
|
+
>
|
|
61
|
+
{children}
|
|
62
|
+
</div>
|
|
63
|
+
);
|
|
64
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./ScrollContent";
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../tsconfig.react.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "dist",
|
|
5
|
+
"rootDir": "src"
|
|
6
|
+
},
|
|
7
|
+
"include": [
|
|
8
|
+
"src/**/*.ts",
|
|
9
|
+
"src/**/*.tsx",
|
|
10
|
+
"../../../globals.d.ts",
|
|
11
|
+
"../../../peer-modules.d.ts"
|
|
12
|
+
],
|
|
13
|
+
"exclude": [
|
|
14
|
+
"dist",
|
|
15
|
+
"node_modules",
|
|
16
|
+
"src/**/*.stories.tsx"
|
|
17
|
+
]
|
|
18
|
+
}
|