@vnejs/uis.react.text-controls 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/package.json +12 -18
- package/src/TextControls.stories.tsx +79 -0
- package/src/TextControls.tsx +76 -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.text-controls",
|
|
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": "^6.0.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,79 @@
|
|
|
1
|
+
import { useMemo, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { renderWithVneWrap, VneWrap } from "@vnejs/uis.react";
|
|
4
|
+
|
|
5
|
+
import { Flex } from "@vnejs/uis.react";
|
|
6
|
+
|
|
7
|
+
import { TextControls } from "./TextControls";
|
|
8
|
+
|
|
9
|
+
export const Common = {
|
|
10
|
+
args: {
|
|
11
|
+
...VneWrap.DEFAULT_ARGS,
|
|
12
|
+
|
|
13
|
+
textsCount: 8,
|
|
14
|
+
|
|
15
|
+
gap: 96,
|
|
16
|
+
textSize: 48,
|
|
17
|
+
|
|
18
|
+
width: 600,
|
|
19
|
+
height: 600,
|
|
20
|
+
|
|
21
|
+
direction: Flex.DIRECTION.ROW,
|
|
22
|
+
align: Flex.ALIGN.START,
|
|
23
|
+
justify: Flex.JUSTIFY.CENTER,
|
|
24
|
+
|
|
25
|
+
withWrap: false,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const BUTTONS = ["STORY", "AUTO", "SKIP", "HIDE", "SAVE", "LOAD", "SETTINGS", "MENU"];
|
|
30
|
+
|
|
31
|
+
export default {
|
|
32
|
+
title: "Base/TextControls",
|
|
33
|
+
render: renderWithVneWrap(
|
|
34
|
+
({ textsCount, textSize, gap, withWrap, direction, align, justify, width, height }) => {
|
|
35
|
+
const textProps = useMemo(() => ({ size: textSize }), [textSize]);
|
|
36
|
+
const flexProps = useMemo(() => ({ direction, align, justify, width, height, gap, withWrap }), [direction, align, justify, width, height, gap, withWrap]);
|
|
37
|
+
|
|
38
|
+
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
39
|
+
|
|
40
|
+
const texts = useMemo(
|
|
41
|
+
() => BUTTONS.map((text, i) => ({ text, onClick: () => setSelectedIndex(i) })).slice(0, textsCount),
|
|
42
|
+
[textsCount, setSelectedIndex],
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<Flex
|
|
47
|
+
align={Flex.ALIGN.CENTER}
|
|
48
|
+
justify={Flex.JUSTIFY.CENTER}
|
|
49
|
+
height={2160}
|
|
50
|
+
>
|
|
51
|
+
<TextControls
|
|
52
|
+
texts={texts}
|
|
53
|
+
textProps={textProps}
|
|
54
|
+
flexProps={flexProps}
|
|
55
|
+
selectedIndex={selectedIndex}
|
|
56
|
+
/>
|
|
57
|
+
</Flex>
|
|
58
|
+
);
|
|
59
|
+
},
|
|
60
|
+
{ flexCentered: true },
|
|
61
|
+
),
|
|
62
|
+
argTypes: {
|
|
63
|
+
// engine
|
|
64
|
+
...VneWrap.ARGS,
|
|
65
|
+
|
|
66
|
+
textsCount: { control: { type: "number", min: 1, max: 8, step: 1 } },
|
|
67
|
+
|
|
68
|
+
// Flex
|
|
69
|
+
gap: { control: { type: "number", min: 0, max: 144, step: 12 } },
|
|
70
|
+
direction: { control: { type: "select" }, options: Object.values(Flex.DIRECTION) },
|
|
71
|
+
align: { control: { type: "select" }, options: Object.values(Flex.ALIGN) },
|
|
72
|
+
justify: { control: { type: "select" }, options: Object.values(Flex.JUSTIFY) },
|
|
73
|
+
width: { control: { type: "number", min: 0, max: 1800, step: 60 } },
|
|
74
|
+
height: { control: { type: "number", min: 0, max: 1800, step: 60 } },
|
|
75
|
+
|
|
76
|
+
// Text
|
|
77
|
+
textSize: { control: { type: "number", min: 24, max: 180, step: 12 } },
|
|
78
|
+
},
|
|
79
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
|
|
3
|
+
import { Text, Flex, Scrollbar } from "@vnejs/uis.react";
|
|
4
|
+
|
|
5
|
+
export const TextControls = ({
|
|
6
|
+
texts = [],
|
|
7
|
+
selectedIndex = -1,
|
|
8
|
+
textProps = {},
|
|
9
|
+
flexProps = {},
|
|
10
|
+
textSize = 60,
|
|
11
|
+
textWidth = null,
|
|
12
|
+
textAlign = null,
|
|
13
|
+
textMarginTop = null,
|
|
14
|
+
flexGap = 60,
|
|
15
|
+
flexGapVertical = 0,
|
|
16
|
+
flexGapHorizontal = 0,
|
|
17
|
+
flexDirection = Flex.DIRECTION.ROW,
|
|
18
|
+
flexAlign = null,
|
|
19
|
+
flexJustify = null,
|
|
20
|
+
flexWithWrap = null,
|
|
21
|
+
wrapWidth = null,
|
|
22
|
+
wrapHeight = null,
|
|
23
|
+
wrapClassName,
|
|
24
|
+
withScrollbar = false,
|
|
25
|
+
scrollbarWrapRef = null,
|
|
26
|
+
onClick,
|
|
27
|
+
value,
|
|
28
|
+
}) => {
|
|
29
|
+
const renderTexts = useCallback(
|
|
30
|
+
() =>
|
|
31
|
+
texts.map((textInfo, i) => (
|
|
32
|
+
<Text
|
|
33
|
+
key={i}
|
|
34
|
+
size={textSize}
|
|
35
|
+
width={textWidth}
|
|
36
|
+
align={textAlign}
|
|
37
|
+
onClick={onClick}
|
|
38
|
+
isSelected={selectedIndex === i}
|
|
39
|
+
isCurrent={value !== undefined && value === textInfo?.value}
|
|
40
|
+
isHoverable={true}
|
|
41
|
+
marginTop={i === 0 ? null : textMarginTop}
|
|
42
|
+
{...textProps}
|
|
43
|
+
{...textInfo}
|
|
44
|
+
/>
|
|
45
|
+
)),
|
|
46
|
+
[texts, textProps, selectedIndex, onClick, value],
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
return withScrollbar ? (
|
|
50
|
+
<Scrollbar
|
|
51
|
+
className={wrapClassName}
|
|
52
|
+
width={wrapWidth}
|
|
53
|
+
height={wrapHeight}
|
|
54
|
+
scrollTo={selectedIndex}
|
|
55
|
+
wrapRef={scrollbarWrapRef}
|
|
56
|
+
>
|
|
57
|
+
{renderTexts()}
|
|
58
|
+
</Scrollbar>
|
|
59
|
+
) : (
|
|
60
|
+
<Flex
|
|
61
|
+
className={wrapClassName}
|
|
62
|
+
gap={flexGap}
|
|
63
|
+
gapHorizontal={flexGapHorizontal}
|
|
64
|
+
gapVertical={flexGapVertical}
|
|
65
|
+
align={flexAlign}
|
|
66
|
+
justify={flexJustify}
|
|
67
|
+
direction={flexDirection}
|
|
68
|
+
withWrap={flexWithWrap}
|
|
69
|
+
width={wrapWidth}
|
|
70
|
+
height={wrapHeight}
|
|
71
|
+
{...flexProps}
|
|
72
|
+
>
|
|
73
|
+
{renderTexts()}
|
|
74
|
+
</Flex>
|
|
75
|
+
);
|
|
76
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./TextControls";
|
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
|
+
}
|