@vnejs/uis.react.page-selector 0.1.2 → 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/package.json +12 -18
- package/src/PageSelector.stories.tsx +43 -0
- package/src/PageSelector.tsx +68 -0
- package/src/index.ts +1 -0
- package/tsconfig.json +18 -0
package/package.json
CHANGED
|
@@ -1,32 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/uis.react.page-selector",
|
|
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",
|
|
20
|
-
"@vnejs/uis.react": "~0.1.0"
|
|
16
|
+
"@vnejs/uis.utils": "~0.1.0"
|
|
21
17
|
},
|
|
22
18
|
"devDependencies": {
|
|
23
|
-
"@vnejs/uis.react": "~0.1.0"
|
|
24
|
-
"typescript": "^5.7.3",
|
|
25
|
-
"@types/react": "^19.0.10",
|
|
26
|
-
"@types/react-dom": "^19.0.4"
|
|
19
|
+
"@vnejs/uis.react": "~0.1.0"
|
|
27
20
|
},
|
|
28
21
|
"files": [
|
|
29
22
|
"dist",
|
|
30
|
-
"
|
|
23
|
+
"src",
|
|
24
|
+
"tsconfig.json"
|
|
31
25
|
]
|
|
32
26
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { renderWithVneWrap, VneWrap } from "@vnejs/uis.react";
|
|
4
|
+
|
|
5
|
+
import { PageSelector } from "@vnejs/uis.react";
|
|
6
|
+
|
|
7
|
+
export const Common = {
|
|
8
|
+
args: {
|
|
9
|
+
...VneWrap.DEFAULT_ARGS,
|
|
10
|
+
|
|
11
|
+
gap: 120,
|
|
12
|
+
size: 60,
|
|
13
|
+
pagesCount: 20,
|
|
14
|
+
itemWidth: 480,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default {
|
|
19
|
+
title: "Base/PageSelector",
|
|
20
|
+
render: renderWithVneWrap(({ valuePostfix, ...args }) => {
|
|
21
|
+
const [page, setPage] = useState(0);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<PageSelector
|
|
25
|
+
{...args}
|
|
26
|
+
page={page}
|
|
27
|
+
onNextPage={() => setPage(page + 1)}
|
|
28
|
+
onPrevPage={() => setPage(page - 1)}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
}),
|
|
32
|
+
argTypes: {
|
|
33
|
+
// engine
|
|
34
|
+
...VneWrap.ARGS,
|
|
35
|
+
|
|
36
|
+
gap: { control: { type: "number", min: 12, max: 240, step: 12 } },
|
|
37
|
+
|
|
38
|
+
size: { control: { type: "number", min: 12, max: 156, step: 12 } },
|
|
39
|
+
|
|
40
|
+
pagesCount: { control: { type: "number", min: 10, max: 300, step: 5 } },
|
|
41
|
+
itemWidth: { control: { type: "number", min: 120, max: 780, step: 12 } },
|
|
42
|
+
},
|
|
43
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { useCallback, useMemo } from "react";
|
|
2
|
+
|
|
3
|
+
import { getVneLength } from "@vnejs/uis.utils";
|
|
4
|
+
|
|
5
|
+
import { Text, Flex } from "@vnejs/uis.react";
|
|
6
|
+
|
|
7
|
+
const LINE_ARGS = { x1: "3", y1: "24", x2: "60", y2: "60" };
|
|
8
|
+
const LINE_ARGS_1 = { ...LINE_ARGS, y1: "24" };
|
|
9
|
+
const LINE_ARGS_2 = { ...LINE_ARGS, y1: "96" };
|
|
10
|
+
|
|
11
|
+
const renderArrow = (style, angle, shift, onClick) => (
|
|
12
|
+
<svg
|
|
13
|
+
width="60"
|
|
14
|
+
height="60"
|
|
15
|
+
viewBox="0 0 60 120"
|
|
16
|
+
xmlns="http://www.w3.org/2000/Text"
|
|
17
|
+
fill="none"
|
|
18
|
+
stroke="white"
|
|
19
|
+
strokeWidth="6"
|
|
20
|
+
strokeLinecap="round"
|
|
21
|
+
style={style}
|
|
22
|
+
onClick={onClick}
|
|
23
|
+
>
|
|
24
|
+
<g transform={`rotate(${angle} ${shift} 60)`}>
|
|
25
|
+
<line {...LINE_ARGS_1} />
|
|
26
|
+
<line {...LINE_ARGS_2} />
|
|
27
|
+
</g>
|
|
28
|
+
</svg>
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
export const PageSelector = ({ page, pagesCount, pagesMinCount, gap = 120, size = 60, transition = 300, itemWidth = 720, onNextPage, onPrevPage }) => {
|
|
32
|
+
const styleArrow = useMemo(() => {
|
|
33
|
+
const result: Record<string, any> = {};
|
|
34
|
+
|
|
35
|
+
if (size) result.height = getVneLength(size);
|
|
36
|
+
if (itemWidth) result.width = getVneLength(itemWidth);
|
|
37
|
+
if (transition) result.transition = `${transition}ms`;
|
|
38
|
+
|
|
39
|
+
return result;
|
|
40
|
+
}, [size, itemWidth, transition]);
|
|
41
|
+
|
|
42
|
+
const showArrowLeft = page > pagesMinCount;
|
|
43
|
+
const showArrowRight = page < pagesCount;
|
|
44
|
+
|
|
45
|
+
const styleArrowLeft = useMemo(() => ({ ...styleArrow, opacity: showArrowLeft ? 1 : 0 }), [styleArrow, showArrowLeft]);
|
|
46
|
+
const styleArrowRight = useMemo(() => ({ ...styleArrow, opacity: showArrowRight ? 1 : 0 }), [styleArrow, showArrowRight]);
|
|
47
|
+
|
|
48
|
+
const onPrevPageHandler = useCallback(() => showArrowLeft && onPrevPage && onPrevPage(), [onPrevPage, showArrowLeft]);
|
|
49
|
+
const onNextPageHandler = useCallback(() => showArrowRight && onNextPage && onNextPage(), [onNextPage, showArrowRight]);
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<Flex
|
|
53
|
+
align={Flex.ALIGN.CENTER}
|
|
54
|
+
justify={Flex.JUSTIFY.CENTER}
|
|
55
|
+
direction={Flex.DIRECTION.ROW}
|
|
56
|
+
gap={gap}
|
|
57
|
+
>
|
|
58
|
+
{renderArrow(styleArrowLeft, 180, 30, onPrevPageHandler)}
|
|
59
|
+
<Text
|
|
60
|
+
width={itemWidth}
|
|
61
|
+
size={size}
|
|
62
|
+
text={`${page} / ${pagesCount}`}
|
|
63
|
+
align={Text.ALIGNS.CENTER}
|
|
64
|
+
/>
|
|
65
|
+
{renderArrow(styleArrowRight, 0, 60, onNextPageHandler)}
|
|
66
|
+
</Flex>
|
|
67
|
+
);
|
|
68
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./PageSelector";
|
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
|
+
}
|