Skip to content

Commit 0d15cc7

Browse files
committed
TreeComponent: Added autoHeight component and a vertical scrollbar
1 parent 5bd097c commit 0d15cc7

File tree

1 file changed

+53
-64
lines changed
  • client/packages/lowcoder/src/comps/comps/treeComp

1 file changed

+53
-64
lines changed

client/packages/lowcoder/src/comps/comps/treeComp/treeComp.tsx

Lines changed: 53 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import { RecordConstructorToView } from "lowcoder-core";
22
import { UICompBuilder } from "comps/generators/uiCompBuilder";
33
import { withExposingConfigs } from "comps/generators/withExposing";
4-
import { Section, sectionNames } from "lowcoder-design";
4+
import { ScrollBar, Section, sectionNames } from "lowcoder-design";
55
import { default as Tree } from "antd/es/tree";
66
import { useEffect, useState } from "react";
77
import styled from "styled-components";
8-
import ReactResizeDetector from "react-resize-detector";
98
import { StyleConfigType, styleControl } from "comps/controls/styleControl";
109
import { InputFieldStyle, LabelStyle, TreeStyle } from "comps/controls/styleControlConstants";
1110
import { LabelControl } from "comps/controls/labelControl";
1211
import { withDefault } from "comps/generators";
1312
import { dropdownControl } from "comps/controls/dropdownControl";
1413
import { BoolControl } from "comps/controls/boolControl";
1514
import {
16-
advancedSection,
17-
expandSection,
1815
formSection,
1916
// intersectSection,
2017
treeCommonChildren,
@@ -24,19 +21,18 @@ import {
2421
valuePropertyView,
2522
} from "./treeUtils";
2623
import {
27-
SelectInputInvalidConfig,
28-
SelectInputValidationChildren,
2924
SelectInputValidationSection,
3025
} from "../selectInputComp/selectInputConstants";
3126
import { selectInputValidate } from "../selectInputComp/selectInputConstants";
3227
import { SelectEventHandlerControl } from "comps/controls/eventHandlerControl";
3328
import { trans } from "i18n";
3429
import { useContext } from "react";
3530
import { EditorContext } from "comps/editorState";
31+
import { AutoHeightControl } from "@lowcoder-ee/index.sdk";
3632

3733
type TreeStyleType = StyleConfigType<typeof TreeStyle>;
3834

39-
const Container = styled.div<TreeStyleType>`
35+
const Container = styled.div<TreeStyleType & { verticalScrollbar: boolean }>`
4036
height: 100%;
4137
padding: 4px;
4238
background: ${(props) => props.background};
@@ -45,18 +41,8 @@ const Container = styled.div<TreeStyleType>`
4541
.ant-tree-show-line .ant-tree-switcher {
4642
background: ${(props) => props.background};
4743
}
48-
.ant-tree:hover .ant-tree-list-scrollbar-show {
49-
display: block !important;
50-
}
51-
.ant-tree-list-scrollbar {
52-
width: 6px !important;
53-
}
54-
.ant-tree-list-scrollbar-thumb {
55-
border-radius: 9999px !important;
56-
background: rgba(139, 143, 163, 0.2) !important;
57-
}
58-
.ant-tree-list-scrollbar-thumb:hover {
59-
background: rgba(139, 143, 163, 0.5) !important;
44+
.simplebar-vertical {
45+
display: ${(props) => props.verticalScrollbar ? 'block' : 'none'};
6046
}
6147
`;
6248

@@ -74,6 +60,8 @@ const childrenMap = {
7460
checkStrictly: BoolControl,
7561
autoExpandParent: BoolControl,
7662
label: withDefault(LabelControl, { position: "column" }),
63+
autoHeight: AutoHeightControl,
64+
verticalScrollbar: withDefault(BoolControl, false),
7765
// TODO: more event
7866
onEvent: SelectEventHandlerControl,
7967
style: styleControl(InputFieldStyle , 'style'),
@@ -101,50 +89,46 @@ const TreeCompView = (props: RecordConstructorToView<typeof childrenMap>) => {
10189
labelStyle,
10290
inputFieldStyle:props.inputFieldStyle,
10391
children: (
104-
<ReactResizeDetector
105-
onResize={(w, h) => setHeight(h)}
106-
render={() => (
107-
<Container {...props.inputFieldStyle}>
108-
<Tree
109-
key={selectType}
110-
disabled={props.disabled}
111-
height={height}
112-
rootStyle={{ background: "transparent", color: props.inputFieldStyle.text }}
113-
fieldNames={{ title: "label", key: "value" }}
114-
treeData={treeData}
115-
selectable={selectable}
116-
multiple={selectType === "multi"}
117-
selectedKeys={selectable ? value.value : []}
118-
checkable={checkable}
119-
checkedKeys={
120-
checkable
121-
? checkStrictly
122-
? { checked: value.value, halfChecked: [] }
123-
: value.value
124-
: undefined
125-
}
126-
checkStrictly={checkStrictly}
127-
showLine={props.showLine ? { showLeafIcon: props.showLeafIcon } : false}
128-
expandedKeys={expanded.value}
129-
autoExpandParent={props.autoExpandParent}
130-
onSelect={(keys) => {
131-
value.onChange(keys as (string | number)[]);
132-
props.onEvent("change");
133-
}}
134-
onCheck={(keys) => {
135-
value.onChange(Array.isArray(keys) ? keys as (string | number)[] : keys.checked as (string | number)[]);
136-
props.onEvent("change");
137-
}}
138-
onExpand={(keys) => {
139-
expanded.onChange(keys as (string | number)[]);
140-
}}
141-
onFocus={() => props.onEvent("focus")}
142-
onBlur={() => props.onEvent("blur")}
143-
/>
144-
</Container>
145-
)}
146-
>
147-
</ReactResizeDetector>
92+
<Container {...props.inputFieldStyle} verticalScrollbar={props.verticalScrollbar}>
93+
<ScrollBar style={{ margin: 0, padding: 0 }}>
94+
<Tree
95+
key={selectType}
96+
disabled={props.disabled}
97+
height={height}
98+
rootStyle={{ background: "transparent", color: props.inputFieldStyle.text }}
99+
fieldNames={{ title: "label", key: "value" }}
100+
treeData={treeData}
101+
selectable={selectable}
102+
multiple={selectType === "multi"}
103+
selectedKeys={selectable ? value.value : []}
104+
checkable={checkable}
105+
checkedKeys={
106+
checkable
107+
? checkStrictly
108+
? { checked: value.value, halfChecked: [] }
109+
: value.value
110+
: undefined
111+
}
112+
checkStrictly={checkStrictly}
113+
showLine={props.showLine ? { showLeafIcon: props.showLeafIcon } : false}
114+
expandedKeys={expanded.value}
115+
autoExpandParent={props.autoExpandParent}
116+
onSelect={(keys) => {
117+
value.onChange(keys as (string | number)[]);
118+
props.onEvent("change");
119+
}}
120+
onCheck={(keys) => {
121+
value.onChange(Array.isArray(keys) ? keys as (string | number)[] : keys.checked as (string | number)[]);
122+
props.onEvent("change");
123+
}}
124+
onExpand={(keys) => {
125+
expanded.onChange(keys as (string | number)[]);
126+
}}
127+
onFocus={() => props.onEvent("focus")}
128+
onBlur={() => props.onEvent("blur")}
129+
/>
130+
</ScrollBar>
131+
</Container>
148132
),
149133
});
150134
};
@@ -179,6 +163,11 @@ let TreeBasicComp = (function () {
179163

180164
{["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && (
181165
<Section name={sectionNames.layout}>
166+
{children.autoHeight.getPropertyView()}
167+
{!children.autoHeight.getView() &&
168+
children.verticalScrollbar.propertyView({
169+
label: trans("prop.showVerticalScrollbar")
170+
})}
182171
{children.expanded.propertyView({ label: trans("tree.expanded") })}
183172
{children.defaultExpandAll.propertyView({ label: trans("tree.defaultExpandAll") })}
184173
{children.showLine.propertyView({ label: trans("tree.showLine") })}
@@ -202,7 +191,7 @@ let TreeBasicComp = (function () {
202191

203192
TreeBasicComp = class extends TreeBasicComp {
204193
override autoHeight(): boolean {
205-
return false;
194+
return this.children.autoHeight.getView();
206195
}
207196
};
208197

0 commit comments

Comments
 (0)