@rovula/ui 0.0.49 → 0.0.51
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 +3 -0
- package/dist/cjs/bundle.js +3 -3
- package/dist/cjs/bundle.js.map +1 -1
- package/dist/cjs/types/components/Tree/Tree.stories.d.ts +1 -0
- package/dist/cjs/types/components/Tree/type.d.ts +19 -12
- package/dist/components/Tree/Tree.js +8 -6
- package/dist/components/Tree/Tree.stories.js +2094 -1
- package/dist/components/Tree/TreeItem.js +16 -15
- package/dist/esm/bundle.css +3 -0
- package/dist/esm/bundle.js +1 -1
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/types/components/Tree/Tree.stories.d.ts +1 -0
- package/dist/esm/types/components/Tree/type.d.ts +19 -12
- package/dist/index.d.ts +19 -12
- package/dist/src/theme/global.css +4 -0
- package/package.json +1 -1
- package/src/components/Tree/Tree.stories.tsx +2168 -1
- package/src/components/Tree/Tree.tsx +17 -6
- package/src/components/Tree/TreeItem.tsx +163 -106
- package/src/components/Tree/type.ts +22 -11
|
@@ -3,6 +3,7 @@ import Tree from "./Tree";
|
|
|
3
3
|
declare const meta: Meta<typeof Tree>;
|
|
4
4
|
export default meta;
|
|
5
5
|
export declare const Default: StoryObj<typeof Tree>;
|
|
6
|
+
export declare const Controller: StoryObj<typeof Tree>;
|
|
6
7
|
export declare const onClick: StoryObj<typeof Tree>;
|
|
7
8
|
export declare const CustomIcon: StoryObj<typeof Tree>;
|
|
8
9
|
export declare const renderRightSection: StoryObj<typeof Tree>;
|
|
@@ -19,6 +19,10 @@ export interface TreeItemProps extends TreeData {
|
|
|
19
19
|
showIcon?: boolean;
|
|
20
20
|
showExpandButton?: boolean;
|
|
21
21
|
enableSeparatorLine?: boolean;
|
|
22
|
+
lineSize?: number;
|
|
23
|
+
horizontalLineWidth?: number;
|
|
24
|
+
expandButtonSize?: number;
|
|
25
|
+
spacing?: number;
|
|
22
26
|
checkIsExpanded: (id: string) => boolean;
|
|
23
27
|
checkIsChecked: (id: string) => boolean;
|
|
24
28
|
checkIsLoading?: (id: string) => void;
|
|
@@ -49,20 +53,23 @@ export interface TreeItemProps extends TreeData {
|
|
|
49
53
|
selected: boolean;
|
|
50
54
|
}) => ReactNode;
|
|
51
55
|
classes?: Partial<{
|
|
52
|
-
elementWrapper
|
|
53
|
-
branch
|
|
54
|
-
itemWrapper
|
|
55
|
-
itemContainer
|
|
56
|
-
horizontalLine
|
|
57
|
-
expandButton
|
|
58
|
-
separatorLine
|
|
59
|
-
checkbox
|
|
60
|
-
item
|
|
61
|
-
title
|
|
62
|
-
|
|
56
|
+
elementWrapper?: string;
|
|
57
|
+
branch?: string;
|
|
58
|
+
itemWrapper?: string;
|
|
59
|
+
itemContainer?: string;
|
|
60
|
+
horizontalLine?: string;
|
|
61
|
+
expandButton?: string;
|
|
62
|
+
separatorLine?: string;
|
|
63
|
+
checkbox?: string;
|
|
64
|
+
item?: string;
|
|
65
|
+
title?: string;
|
|
66
|
+
expandedChildrenWrapper?: string;
|
|
67
|
+
expandedChildrenWrapperInner?: string;
|
|
68
|
+
rowWrapperClasses?: string;
|
|
69
|
+
columnWrapperClasses?: string;
|
|
63
70
|
}>;
|
|
64
71
|
}
|
|
65
|
-
export interface TreeProps extends Pick<TreeItemProps, "renderIcon" | "renderRightSection" | "renderElement" | "renderTitle" | "showIcon" | "disabled" | "enableSeparatorLine" | "classes"> {
|
|
72
|
+
export interface TreeProps extends Pick<TreeItemProps, "renderIcon" | "renderRightSection" | "renderElement" | "renderTitle" | "showIcon" | "disabled" | "enableSeparatorLine" | "classes" | "lineSize" | "horizontalLineWidth" | "expandButtonSize" | "spacing"> {
|
|
66
73
|
data: TreeData[];
|
|
67
74
|
defaultExpandedId?: string[];
|
|
68
75
|
defaultCheckedId?: string[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useEffect, useState } from "react";
|
|
3
3
|
import TreeItem from "./TreeItem";
|
|
4
|
-
const Tree = ({ classes, data, defaultExpandedId
|
|
4
|
+
const Tree = ({ classes, data, defaultExpandedId, defaultCheckedId, checkedId, loadingId, lineSize, horizontalLineWidth, expandButtonSize, spacing, renderIcon, renderRightSection, renderElement, renderTitle, onExpandChange, onCheckedChange, defaultExpandAll = false, defaultCheckAll = false, hierarchicalCheck = false, showIcon = true, disabled, enableSeparatorLine = true, }) => {
|
|
5
5
|
const [checkedState, setCheckedState] = useState({});
|
|
6
6
|
const [expandedState, setExpandedState] = useState({});
|
|
7
7
|
const traverseTree = (nodes, callback) => {
|
|
@@ -13,7 +13,7 @@ const Tree = ({ classes, data, defaultExpandedId = [], defaultCheckedId = [], ch
|
|
|
13
13
|
});
|
|
14
14
|
};
|
|
15
15
|
useEffect(() => {
|
|
16
|
-
if (defaultExpandAll) {
|
|
16
|
+
if (data.length && defaultExpandAll) {
|
|
17
17
|
const allExpanded = {};
|
|
18
18
|
traverseTree(data, (node) => {
|
|
19
19
|
allExpanded[node.id] = true;
|
|
@@ -29,21 +29,23 @@ const Tree = ({ classes, data, defaultExpandedId = [], defaultCheckedId = [], ch
|
|
|
29
29
|
}
|
|
30
30
|
}, [data, defaultExpandedId, defaultExpandAll]);
|
|
31
31
|
useEffect(() => {
|
|
32
|
-
|
|
32
|
+
var _a;
|
|
33
|
+
if (data.length && defaultCheckAll) {
|
|
33
34
|
const allChecked = {};
|
|
34
35
|
traverseTree(data, (node) => {
|
|
35
36
|
allChecked[node.id] = true;
|
|
36
37
|
});
|
|
37
38
|
setCheckedState(allChecked);
|
|
38
39
|
}
|
|
39
|
-
else if (
|
|
40
|
+
else if (((_a = Object.keys(checkedState)) === null || _a === void 0 ? void 0 : _a.length) === 0 &&
|
|
41
|
+
(defaultCheckedId === null || defaultCheckedId === void 0 ? void 0 : defaultCheckedId.length)) {
|
|
40
42
|
const initialCheckedState = defaultCheckedId.reduce((acc, id) => {
|
|
41
43
|
acc[id] = true;
|
|
42
44
|
return acc;
|
|
43
45
|
}, {});
|
|
44
46
|
setCheckedState(initialCheckedState);
|
|
45
47
|
}
|
|
46
|
-
}, [data, defaultCheckedId,
|
|
48
|
+
}, [data, defaultCheckedId, defaultCheckAll]);
|
|
47
49
|
const handleExpandChange = useCallback((id, expanded) => {
|
|
48
50
|
onExpandChange === null || onExpandChange === void 0 ? void 0 : onExpandChange(id, expanded);
|
|
49
51
|
setExpandedState((prev) => (Object.assign(Object.assign({}, prev), { [id]: expanded })));
|
|
@@ -99,6 +101,6 @@ const Tree = ({ classes, data, defaultExpandedId = [], defaultCheckedId = [], ch
|
|
|
99
101
|
return loadingId.includes(id);
|
|
100
102
|
}
|
|
101
103
|
}, [loadingId]);
|
|
102
|
-
return (_jsx("div", { className: "w-full", children: data.map((item, idx) => (_jsx(TreeItem, Object.assign({ classes: classes, isFirstLevel: true, isLastItem: idx === data.length - 1, checkIsExpanded: checkIsExpanded, checkIsChecked: checkIsChecked, onExpandChange: handleExpandChange, onCheckedChange: handleCheckedChange, checkIsLoading: checkIsLoading, renderIcon: renderIcon, renderElement: renderElement, renderTitle: renderTitle, renderRightSection: renderRightSection, enableSeparatorLine: enableSeparatorLine, disabled: disabled, showIcon: showIcon }, item), item.id))) }));
|
|
104
|
+
return (_jsx("div", { className: "w-full", children: data.map((item, idx) => (_jsx(TreeItem, Object.assign({ classes: classes, isFirstLevel: true, isLastItem: idx === data.length - 1, checkIsExpanded: checkIsExpanded, checkIsChecked: checkIsChecked, onExpandChange: handleExpandChange, onCheckedChange: handleCheckedChange, checkIsLoading: checkIsLoading, renderIcon: renderIcon, renderElement: renderElement, renderTitle: renderTitle, renderRightSection: renderRightSection, enableSeparatorLine: enableSeparatorLine, disabled: disabled, showIcon: showIcon, lineSize: lineSize, horizontalLineWidth: horizontalLineWidth, expandButtonSize: expandButtonSize, spacing: spacing }, item), item.id))) }));
|
|
103
105
|
};
|
|
104
106
|
export default Tree;
|