@@ -8,23 +8,23 @@ import { draggingUtils } from "layout";
8
8
import { isEmpty } from "lodash" ;
9
9
import { language } from "i18n" ;
10
10
import {
11
- ComListTitle ,
12
11
CompIconDiv ,
13
12
EmptyCompContent ,
14
13
RightPanelContentWrapper ,
15
14
} from "pages/editor/right/styledComponent" ;
16
15
import { tableDragClassName } from "pages/tutorials/tutorialsConstant" ;
17
- import React , { useContext , useMemo } from "react" ;
16
+ import React , { useContext , useMemo , useState } from "react" ;
18
17
import styled from "styled-components" ;
19
- import { labelCss } from "lowcoder-design" ;
18
+ import {
19
+ BaseSection ,
20
+ PropertySectionContext ,
21
+ PropertySectionContextType ,
22
+ PropertySectionState ,
23
+ labelCss ,
24
+ } from "lowcoder-design" ;
20
25
import { TransparentImg } from "../../../util/commonUtils" ;
21
26
import { RightContext } from "./rightContext" ;
22
27
23
- const GrayLabel = ( props : { label : string } ) => {
24
- const { label } = props ;
25
- return < ComListTitle > { label } </ ComListTitle > ;
26
- } ;
27
-
28
28
const CompDiv = styled . div `
29
29
display: flex;
30
30
flex-direction: column;
@@ -80,16 +80,25 @@ const InsertContain = styled.div`
80
80
gap: 8px;
81
81
` ;
82
82
83
- const CategoryLabel = styled ( GrayLabel ) `
84
- margin: 0;
85
- ` ;
86
-
87
83
const SectionWrapper = styled . div `
88
- margin-bottom: 16px;
84
+ .section-header {
85
+ margin-left: 0;
86
+ }
87
+ &:not(:last-child){
88
+ border-bottom: 1px solid #e1e3eb;
89
+ }
89
90
` ;
90
91
92
+ const stateCompName = 'UICompSections' ;
93
+ const initialState : PropertySectionState = { [ stateCompName ] : { } } ;
94
+ Object . keys ( uiCompCategoryNames ) . forEach ( ( cat ) => {
95
+ const key = uiCompCategoryNames [ cat as UICompCategory ] ;
96
+ initialState [ stateCompName ] [ key ] = key === uiCompCategoryNames . common
97
+ } )
98
+
91
99
export const UICompPanel = ( ) => {
92
100
const { onDrag, searchValue } = useContext ( RightContext ) ;
101
+ const [ propertySectionState , setPropertySectionState ] = useState < PropertySectionState > ( initialState ) ;
93
102
94
103
const categories = useMemo ( ( ) => {
95
104
const cats : Record < string , [ string , UICompManifest ] [ ] > = Object . fromEntries (
@@ -103,6 +112,22 @@ export const UICompPanel = () => {
103
112
return cats ;
104
113
} , [ ] ) ;
105
114
115
+ const propertySectionContextValue = useMemo < PropertySectionContextType > ( ( ) => {
116
+ return {
117
+ compName : stateCompName ,
118
+ state : propertySectionState ,
119
+ toggle : ( compName : string , sectionName : string ) => {
120
+ setPropertySectionState ( ( oldState ) => {
121
+ const nextSectionState : PropertySectionState = { ...oldState } ;
122
+ const compState = nextSectionState [ compName ] || { } ;
123
+ compState [ sectionName ] = compState [ sectionName ] === false ;
124
+ nextSectionState [ compName ] = compState ;
125
+ return nextSectionState ;
126
+ } ) ;
127
+ } ,
128
+ } ;
129
+ } , [ propertySectionState ] ) ;
130
+
106
131
const compList = useMemo (
107
132
( ) =>
108
133
Object . entries ( categories )
@@ -122,36 +147,52 @@ export const UICompPanel = () => {
122
147
123
148
return (
124
149
< SectionWrapper key = { index } >
125
- < CategoryLabel label = { uiCompCategoryNames [ key as UICompCategory ] } />
126
- < InsertContain >
127
- { infos . map ( ( info ) => (
128
- < CompDiv key = { info [ 0 ] } className = { info [ 0 ] === "table" ? tableDragClassName : "" } >
129
- < HovDiv
130
- draggable
131
- onDragStart = { ( e ) => {
132
- e . dataTransfer . setData ( "compType" , info [ 0 ] ) ;
133
- e . dataTransfer . setDragImage ( TransparentImg , 0 , 0 ) ;
134
- draggingUtils . setData ( "compType" , info [ 0 ] ) ;
135
- onDrag ( info [ 0 ] ) ;
136
- } }
137
- >
138
- < IconContain Icon = { info [ 1 ] . icon } > </ IconContain >
139
- </ HovDiv >
140
- < CompNameLabel > { info [ 1 ] . name } </ CompNameLabel >
141
- { language !== "en" && < CompEnNameLabel > { info [ 1 ] . enName } </ CompEnNameLabel > }
142
- </ CompDiv >
143
- ) ) }
144
- </ InsertContain >
150
+ < BaseSection
151
+ noMargin
152
+ width = { 288 }
153
+ name = { uiCompCategoryNames [ key as UICompCategory ] }
154
+ >
155
+ < InsertContain >
156
+ { infos . map ( ( info ) => (
157
+ < CompDiv key = { info [ 0 ] } className = { info [ 0 ] === "table" ? tableDragClassName : "" } >
158
+ < HovDiv
159
+ draggable
160
+ onDragStart = { ( e ) => {
161
+ e . dataTransfer . setData ( "compType" , info [ 0 ] ) ;
162
+ e . dataTransfer . setDragImage ( TransparentImg , 0 , 0 ) ;
163
+ draggingUtils . setData ( "compType" , info [ 0 ] ) ;
164
+ onDrag ( info [ 0 ] ) ;
165
+ } }
166
+ >
167
+ < IconContain Icon = { info [ 1 ] . icon } > </ IconContain >
168
+ </ HovDiv >
169
+ < CompNameLabel > { info [ 1 ] . name } </ CompNameLabel >
170
+ { language !== "en" && < CompEnNameLabel > { info [ 1 ] . enName } </ CompEnNameLabel > }
171
+ </ CompDiv >
172
+ ) ) }
173
+ </ InsertContain >
174
+ </ BaseSection >
145
175
</ SectionWrapper >
146
176
) ;
147
177
} )
148
178
. filter ( ( t ) => t != null ) ,
149
179
[ categories , searchValue , onDrag ]
150
180
) ;
151
181
182
+ if ( ! compList . length ) return (
183
+ < RightPanelContentWrapper >
184
+ < EmptyCompContent />
185
+ </ RightPanelContentWrapper >
186
+ )
187
+
152
188
return (
153
189
< RightPanelContentWrapper >
154
- { compList . length > 0 ? compList : < EmptyCompContent /> }
190
+ { /* {compList.length > 0 ? compList : <EmptyCompContent />} */ }
191
+ < PropertySectionContext . Provider
192
+ value = { propertySectionContextValue }
193
+ >
194
+ { compList }
195
+ </ PropertySectionContext . Provider >
155
196
</ RightPanelContentWrapper >
156
197
) ;
157
198
} ;
0 commit comments