@@ -13,10 +13,13 @@ import {
13
13
RightPanelContentWrapper ,
14
14
} from "pages/editor/right/styledComponent" ;
15
15
import { tableDragClassName } from "pages/tutorials/tutorialsConstant" ;
16
- import React , { useContext , useMemo } from "react" ;
16
+ import React , { useContext , useMemo , useState } from "react" ;
17
17
import styled from "styled-components" ;
18
18
import {
19
19
BaseSection ,
20
+ PropertySectionContext ,
21
+ PropertySectionContextType ,
22
+ PropertySectionState ,
20
23
labelCss ,
21
24
} from "lowcoder-design" ;
22
25
import { TransparentImg } from "../../../util/commonUtils" ;
@@ -83,8 +86,16 @@ const SectionWrapper = styled.div`
83
86
}
84
87
` ;
85
88
89
+ const stateCompName = 'UICompSections' ;
90
+ const initialState : PropertySectionState = { [ stateCompName ] : { } } ;
91
+ Object . keys ( uiCompCategoryNames ) . forEach ( ( cat ) => {
92
+ const key = uiCompCategoryNames [ cat as UICompCategory ] ;
93
+ initialState [ stateCompName ] [ key ] = key === uiCompCategoryNames . common
94
+ } )
95
+
86
96
export const UICompPanel = ( ) => {
87
97
const { onDrag, searchValue } = useContext ( RightContext ) ;
98
+ const [ propertySectionState , setPropertySectionState ] = useState < PropertySectionState > ( initialState ) ;
88
99
89
100
const categories = useMemo ( ( ) => {
90
101
const cats : Record < string , [ string , UICompManifest ] [ ] > = Object . fromEntries (
@@ -98,6 +109,22 @@ export const UICompPanel = () => {
98
109
return cats ;
99
110
} , [ ] ) ;
100
111
112
+ const propertySectionContextValue = useMemo < PropertySectionContextType > ( ( ) => {
113
+ return {
114
+ compName : stateCompName ,
115
+ state : propertySectionState ,
116
+ toggle : ( compName : string , sectionName : string ) => {
117
+ setPropertySectionState ( ( oldState ) => {
118
+ const nextSectionState : PropertySectionState = { ...oldState } ;
119
+ const compState = nextSectionState [ compName ] || { } ;
120
+ compState [ sectionName ] = compState [ sectionName ] === false ;
121
+ nextSectionState [ compName ] = compState ;
122
+ return nextSectionState ;
123
+ } ) ;
124
+ } ,
125
+ } ;
126
+ } , [ propertySectionState ] ) ;
127
+
101
128
const compList = useMemo (
102
129
( ) =>
103
130
Object . entries ( categories )
@@ -149,9 +176,20 @@ export const UICompPanel = () => {
149
176
[ categories , searchValue , onDrag ]
150
177
) ;
151
178
179
+ if ( ! compList . length ) return (
180
+ < RightPanelContentWrapper >
181
+ < EmptyCompContent />
182
+ </ RightPanelContentWrapper >
183
+ )
184
+
152
185
return (
153
186
< RightPanelContentWrapper >
154
- { compList . length > 0 ? compList : < EmptyCompContent /> }
187
+ { /* {compList.length > 0 ? compList : <EmptyCompContent />} */ }
188
+ < PropertySectionContext . Provider
189
+ value = { propertySectionContextValue }
190
+ >
191
+ { compList }
192
+ </ PropertySectionContext . Provider >
155
193
</ RightPanelContentWrapper >
156
194
) ;
157
195
} ;
0 commit comments