@rovula/ui 0.0.52 → 0.0.53
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/cjs/bundle.css +50 -10
- package/dist/cjs/bundle.js +2 -2
- package/dist/cjs/bundle.js.map +1 -1
- package/dist/cjs/types/components/Tabs/Tabs.d.ts +14 -1
- package/dist/cjs/types/components/Tabs/Tabs.stories.d.ts +81 -2
- package/dist/cjs/types/components/Tree/Tree.stories.d.ts +3 -0
- package/dist/cjs/types/components/Tree/example-data.d.ts +5 -0
- package/dist/cjs/types/components/Tree/type.d.ts +13 -4
- package/dist/components/Tabs/Tabs.js +35 -18
- package/dist/components/Tabs/Tabs.stories.js +70 -3
- package/dist/components/Tree/Tree.js +6 -4
- package/dist/components/Tree/Tree.stories.js +34 -2090
- package/dist/components/Tree/TreeItem.js +16 -8
- package/dist/components/Tree/example-data.js +2125 -0
- package/dist/esm/bundle.css +50 -10
- package/dist/esm/bundle.js +2 -2
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/types/components/Tabs/Tabs.d.ts +14 -1
- package/dist/esm/types/components/Tabs/Tabs.stories.d.ts +81 -2
- package/dist/esm/types/components/Tree/Tree.stories.d.ts +3 -0
- package/dist/esm/types/components/Tree/example-data.d.ts +5 -0
- package/dist/esm/types/components/Tree/type.d.ts +13 -4
- package/dist/index.d.ts +26 -5
- package/dist/src/theme/global.css +36 -13
- package/package.json +6 -1
- package/src/components/Tabs/Tabs.css +21 -0
- package/src/components/Tabs/Tabs.stories.tsx +140 -4
- package/src/components/Tabs/Tabs.tsx +134 -50
- package/src/components/Tree/Tree.stories.tsx +58 -2125
- package/src/components/Tree/Tree.tsx +15 -2
- package/src/components/Tree/TreeItem.tsx +47 -17
- package/src/components/Tree/example-data.ts +2162 -0
- package/src/components/Tree/type.ts +17 -4
|
@@ -20,12 +20,16 @@ const Tree: FC<TreeProps> = ({
|
|
|
20
20
|
renderTitle,
|
|
21
21
|
onExpandChange,
|
|
22
22
|
onCheckedChange,
|
|
23
|
+
onClickItem,
|
|
24
|
+
onCheckedItem,
|
|
23
25
|
defaultExpandAll = false,
|
|
24
26
|
defaultCheckAll = false,
|
|
25
27
|
hierarchicalCheck = false,
|
|
26
28
|
showIcon = true,
|
|
27
29
|
disabled,
|
|
28
30
|
enableSeparatorLine = true,
|
|
31
|
+
checkable = true,
|
|
32
|
+
maxLevel,
|
|
29
33
|
}) => {
|
|
30
34
|
const [checkedState, setCheckedState] = useState<Record<string, boolean>>({});
|
|
31
35
|
const [expandedState, setExpandedState] = useState<Record<string, boolean>>(
|
|
@@ -89,6 +93,7 @@ const Tree: FC<TreeProps> = ({
|
|
|
89
93
|
|
|
90
94
|
const handleCheckedChange = useCallback(
|
|
91
95
|
(id: string, checked: boolean) => {
|
|
96
|
+
onCheckedItem?.(id, checked);
|
|
92
97
|
let newState = { ...checkedState, [id]: checked };
|
|
93
98
|
|
|
94
99
|
if (hierarchicalCheck) {
|
|
@@ -140,10 +145,14 @@ const Tree: FC<TreeProps> = ({
|
|
|
140
145
|
|
|
141
146
|
if (onCheckedChange) {
|
|
142
147
|
const checkedIds = Object.keys(newState).filter((key) => newState[key]);
|
|
143
|
-
|
|
148
|
+
const uncheckedIds = Object.keys(newState).filter(
|
|
149
|
+
(key) => !newState[key]
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
onCheckedChange?.(checkedIds, uncheckedIds, newState);
|
|
144
153
|
}
|
|
145
154
|
},
|
|
146
|
-
[checkedState, data, onCheckedChange, hierarchicalCheck]
|
|
155
|
+
[checkedState, data, onCheckedChange, hierarchicalCheck, onCheckedItem]
|
|
147
156
|
);
|
|
148
157
|
|
|
149
158
|
const checkIsExpanded = useCallback(
|
|
@@ -194,6 +203,10 @@ const Tree: FC<TreeProps> = ({
|
|
|
194
203
|
horizontalLineWidth={horizontalLineWidth}
|
|
195
204
|
expandButtonSize={expandButtonSize}
|
|
196
205
|
spacing={spacing}
|
|
206
|
+
notifyClickItem={onClickItem}
|
|
207
|
+
maxLevel={maxLevel}
|
|
208
|
+
currentLevel={1}
|
|
209
|
+
checkable={checkable}
|
|
197
210
|
{...item}
|
|
198
211
|
/>
|
|
199
212
|
))}
|
|
@@ -10,12 +10,14 @@ const TreeItem: FC<TreeItemProps> = ({
|
|
|
10
10
|
classes,
|
|
11
11
|
children,
|
|
12
12
|
isFirstLevel = false,
|
|
13
|
+
isLeaf = false,
|
|
13
14
|
disabled,
|
|
14
15
|
icon,
|
|
15
16
|
showIcon,
|
|
16
17
|
showExpandButton,
|
|
17
18
|
enableSeparatorLine = true,
|
|
18
19
|
isLastItem,
|
|
20
|
+
checkable,
|
|
19
21
|
checkIsExpanded,
|
|
20
22
|
checkIsChecked,
|
|
21
23
|
checkIsLoading,
|
|
@@ -30,19 +32,26 @@ const TreeItem: FC<TreeItemProps> = ({
|
|
|
30
32
|
horizontalLineWidth = 4,
|
|
31
33
|
expandButtonSize = 30,
|
|
32
34
|
spacing = 2,
|
|
35
|
+
currentLevel = 1,
|
|
36
|
+
maxLevel = 10,
|
|
37
|
+
notifyClickItem,
|
|
33
38
|
}) => {
|
|
34
39
|
const isLoading = useMemo(() => checkIsLoading?.(id), [checkIsLoading, id]);
|
|
35
40
|
const isChecked = useMemo(() => checkIsChecked(id), [checkIsChecked, id]);
|
|
36
41
|
const isExpanded = useMemo(() => checkIsExpanded(id), [checkIsExpanded, id]);
|
|
37
42
|
const hasChildren = useMemo(() => !!children?.length, [children]);
|
|
38
43
|
const shouldExpandButton = useMemo(
|
|
39
|
-
() =>
|
|
40
|
-
|
|
44
|
+
() =>
|
|
45
|
+
(showExpandButton !== undefined ? showExpandButton : hasChildren) &&
|
|
46
|
+
currentLevel < (maxLevel || Infinity),
|
|
47
|
+
[hasChildren, showExpandButton, maxLevel, currentLevel]
|
|
48
|
+
);
|
|
49
|
+
const shouldShowCheckbox = useMemo(
|
|
50
|
+
() => (!checkable ? false : !isLeaf),
|
|
51
|
+
[checkable, isLeaf]
|
|
41
52
|
);
|
|
42
53
|
|
|
43
|
-
const
|
|
44
|
-
onExpandChange?.(id, !isExpanded);
|
|
45
|
-
}, [id, isExpanded, onExpandChange]);
|
|
54
|
+
const checkboxSpace = isLeaf ? 21.328 : 0;
|
|
46
55
|
|
|
47
56
|
const styles = useMemo(
|
|
48
57
|
() => ({
|
|
@@ -55,7 +64,8 @@ const TreeItem: FC<TreeItemProps> = ({
|
|
|
55
64
|
width:
|
|
56
65
|
lineSize +
|
|
57
66
|
horizontalLineWidth +
|
|
58
|
-
(shouldExpandButton ? 0 : expandButtonSize + spacing)
|
|
67
|
+
(shouldExpandButton ? 0 : expandButtonSize + spacing) +
|
|
68
|
+
checkboxSpace,
|
|
59
69
|
marginLeft: -lineSize,
|
|
60
70
|
borderBottomLeftRadius: lineSize / 2,
|
|
61
71
|
},
|
|
@@ -77,9 +87,14 @@ const TreeItem: FC<TreeItemProps> = ({
|
|
|
77
87
|
isFirstLevel,
|
|
78
88
|
isLastItem,
|
|
79
89
|
shouldExpandButton,
|
|
90
|
+
checkboxSpace,
|
|
80
91
|
]
|
|
81
92
|
);
|
|
82
93
|
|
|
94
|
+
const handleExpandToggle = useCallback(() => {
|
|
95
|
+
onExpandChange?.(id, !isExpanded);
|
|
96
|
+
}, [id, isExpanded, onExpandChange]);
|
|
97
|
+
|
|
83
98
|
useEffect(() => {
|
|
84
99
|
if (isExpanded && !isLoading && !hasChildren) {
|
|
85
100
|
handleExpandToggle();
|
|
@@ -88,7 +103,8 @@ const TreeItem: FC<TreeItemProps> = ({
|
|
|
88
103
|
|
|
89
104
|
const handleOnClickItem = useCallback(() => {
|
|
90
105
|
onClickItem?.(id);
|
|
91
|
-
|
|
106
|
+
notifyClickItem?.(id);
|
|
107
|
+
}, [onClickItem, notifyClickItem, id]);
|
|
92
108
|
|
|
93
109
|
const defaultIcon = (
|
|
94
110
|
<Icon
|
|
@@ -194,15 +210,25 @@ const TreeItem: FC<TreeItemProps> = ({
|
|
|
194
210
|
</ActionButton>
|
|
195
211
|
</div>
|
|
196
212
|
)}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
onCheckedChange
|
|
204
|
-
|
|
205
|
-
|
|
213
|
+
{shouldShowCheckbox ? (
|
|
214
|
+
<Checkbox
|
|
215
|
+
id={id}
|
|
216
|
+
className={cn("size-[16pt]", classes?.checkbox)}
|
|
217
|
+
checked={isChecked}
|
|
218
|
+
disabled={disabled}
|
|
219
|
+
onCheckedChange={(newChecked) =>
|
|
220
|
+
onCheckedChange?.(id, newChecked as boolean)
|
|
221
|
+
}
|
|
222
|
+
/>
|
|
223
|
+
) : (
|
|
224
|
+
<div
|
|
225
|
+
className={
|
|
226
|
+
isFirstLevel && checkable
|
|
227
|
+
? cn("size-[16pt]", classes?.checkbox)
|
|
228
|
+
: ""
|
|
229
|
+
}
|
|
230
|
+
/>
|
|
231
|
+
)}
|
|
206
232
|
<div
|
|
207
233
|
className={cn(
|
|
208
234
|
"ml-2 gap-1 flex flex-1 items-center text-foreground",
|
|
@@ -224,7 +250,7 @@ const TreeItem: FC<TreeItemProps> = ({
|
|
|
224
250
|
</div>
|
|
225
251
|
</div>
|
|
226
252
|
|
|
227
|
-
{isExpanded && hasChildren && (
|
|
253
|
+
{isExpanded && hasChildren && currentLevel < (maxLevel || Infinity) && (
|
|
228
254
|
<div
|
|
229
255
|
className={cn(
|
|
230
256
|
"flex flex-row overflow-hidden max-h-screen",
|
|
@@ -266,6 +292,10 @@ const TreeItem: FC<TreeItemProps> = ({
|
|
|
266
292
|
horizontalLineWidth={horizontalLineWidth}
|
|
267
293
|
expandButtonSize={expandButtonSize}
|
|
268
294
|
spacing={spacing}
|
|
295
|
+
notifyClickItem={notifyClickItem}
|
|
296
|
+
maxLevel={maxLevel}
|
|
297
|
+
currentLevel={currentLevel + 1}
|
|
298
|
+
checkable={checkable}
|
|
269
299
|
{...child}
|
|
270
300
|
/>
|
|
271
301
|
))}
|