1
1
import { RecordConstructorToView } from "lowcoder-core" ;
2
2
import { UICompBuilder } from "comps/generators/uiCompBuilder" ;
3
3
import { withExposingConfigs } from "comps/generators/withExposing" ;
4
- import { Section , sectionNames } from "lowcoder-design" ;
4
+ import { ScrollBar , Section , sectionNames } from "lowcoder-design" ;
5
5
import { default as Tree } from "antd/es/tree" ;
6
6
import { useEffect , useState } from "react" ;
7
7
import styled from "styled-components" ;
8
- import ReactResizeDetector from "react-resize-detector" ;
9
8
import { StyleConfigType , styleControl } from "comps/controls/styleControl" ;
10
9
import { InputFieldStyle , LabelStyle , TreeStyle } from "comps/controls/styleControlConstants" ;
11
10
import { LabelControl } from "comps/controls/labelControl" ;
12
11
import { withDefault } from "comps/generators" ;
13
12
import { dropdownControl } from "comps/controls/dropdownControl" ;
14
13
import { BoolControl } from "comps/controls/boolControl" ;
15
14
import {
16
- advancedSection ,
17
- expandSection ,
18
15
formSection ,
19
16
// intersectSection,
20
17
treeCommonChildren ,
@@ -24,19 +21,18 @@ import {
24
21
valuePropertyView ,
25
22
} from "./treeUtils" ;
26
23
import {
27
- SelectInputInvalidConfig ,
28
- SelectInputValidationChildren ,
29
24
SelectInputValidationSection ,
30
25
} from "../selectInputComp/selectInputConstants" ;
31
26
import { selectInputValidate } from "../selectInputComp/selectInputConstants" ;
32
27
import { SelectEventHandlerControl } from "comps/controls/eventHandlerControl" ;
33
28
import { trans } from "i18n" ;
34
29
import { useContext } from "react" ;
35
30
import { EditorContext } from "comps/editorState" ;
31
+ import { AutoHeightControl } from "@lowcoder-ee/index.sdk" ;
36
32
37
33
type TreeStyleType = StyleConfigType < typeof TreeStyle > ;
38
34
39
- const Container = styled . div < TreeStyleType > `
35
+ const Container = styled . div < TreeStyleType & { verticalScrollbar : boolean } > `
40
36
height: 100%;
41
37
padding: 4px;
42
38
background: ${ ( props ) => props . background } ;
@@ -45,18 +41,8 @@ const Container = styled.div<TreeStyleType>`
45
41
.ant-tree-show-line .ant-tree-switcher {
46
42
background: ${ ( props ) => props . background } ;
47
43
}
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' } ;
60
46
}
61
47
` ;
62
48
@@ -74,6 +60,8 @@ const childrenMap = {
74
60
checkStrictly : BoolControl ,
75
61
autoExpandParent : BoolControl ,
76
62
label : withDefault ( LabelControl , { position : "column" } ) ,
63
+ autoHeight : AutoHeightControl ,
64
+ verticalScrollbar : withDefault ( BoolControl , false ) ,
77
65
// TODO: more event
78
66
onEvent : SelectEventHandlerControl ,
79
67
style : styleControl ( InputFieldStyle , 'style' ) ,
@@ -101,50 +89,46 @@ const TreeCompView = (props: RecordConstructorToView<typeof childrenMap>) => {
101
89
labelStyle,
102
90
inputFieldStyle :props . inputFieldStyle ,
103
91
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 >
148
132
) ,
149
133
} ) ;
150
134
} ;
@@ -179,6 +163,11 @@ let TreeBasicComp = (function () {
179
163
180
164
{ [ "layout" , "both" ] . includes ( useContext ( EditorContext ) . editorModeStatus ) && (
181
165
< Section name = { sectionNames . layout } >
166
+ { children . autoHeight . getPropertyView ( ) }
167
+ { ! children . autoHeight . getView ( ) &&
168
+ children . verticalScrollbar . propertyView ( {
169
+ label : trans ( "prop.showVerticalScrollbar" )
170
+ } ) }
182
171
{ children . expanded . propertyView ( { label : trans ( "tree.expanded" ) } ) }
183
172
{ children . defaultExpandAll . propertyView ( { label : trans ( "tree.defaultExpandAll" ) } ) }
184
173
{ children . showLine . propertyView ( { label : trans ( "tree.showLine" ) } ) }
@@ -202,7 +191,7 @@ let TreeBasicComp = (function () {
202
191
203
192
TreeBasicComp = class extends TreeBasicComp {
204
193
override autoHeight ( ) : boolean {
205
- return false ;
194
+ return this . children . autoHeight . getView ( ) ;
206
195
}
207
196
} ;
208
197
0 commit comments