11import { RecordConstructorToView } from "lowcoder-core" ;
22import { UICompBuilder } from "comps/generators/uiCompBuilder" ;
33import { withExposingConfigs } from "comps/generators/withExposing" ;
4- import { Section , sectionNames } from "lowcoder-design" ;
4+ import { ScrollBar , Section , sectionNames } from "lowcoder-design" ;
55import { default as Tree } from "antd/es/tree" ;
66import { useEffect , useState } from "react" ;
77import styled from "styled-components" ;
8- import ReactResizeDetector from "react-resize-detector" ;
98import { StyleConfigType , styleControl } from "comps/controls/styleControl" ;
109import { InputFieldStyle , LabelStyle , TreeStyle } from "comps/controls/styleControlConstants" ;
1110import { LabelControl } from "comps/controls/labelControl" ;
1211import { withDefault } from "comps/generators" ;
1312import { dropdownControl } from "comps/controls/dropdownControl" ;
1413import { BoolControl } from "comps/controls/boolControl" ;
1514import {
16- advancedSection ,
17- expandSection ,
1815 formSection ,
1916 // intersectSection,
2017 treeCommonChildren ,
@@ -24,19 +21,18 @@ import {
2421 valuePropertyView ,
2522} from "./treeUtils" ;
2623import {
27- SelectInputInvalidConfig ,
28- SelectInputValidationChildren ,
2924 SelectInputValidationSection ,
3025} from "../selectInputComp/selectInputConstants" ;
3126import { selectInputValidate } from "../selectInputComp/selectInputConstants" ;
3227import { SelectEventHandlerControl } from "comps/controls/eventHandlerControl" ;
3328import { trans } from "i18n" ;
3429import { useContext } from "react" ;
3530import { EditorContext } from "comps/editorState" ;
31+ import { AutoHeightControl } from "@lowcoder-ee/index.sdk" ;
3632
3733type 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
203192TreeBasicComp = class extends TreeBasicComp {
204193 override autoHeight ( ) : boolean {
205- return false ;
194+ return this . children . autoHeight . getView ( ) ;
206195 }
207196} ;
208197
0 commit comments