Skip to content

Commit b4e12f2

Browse files
authored
Merge pull request #533 from raheeliftikhar5/foldable-comps-sections
Right Panel: Foldable comps sections
2 parents 5e065a7 + 5fc8cdd commit b4e12f2

File tree

1 file changed

+75
-34
lines changed

1 file changed

+75
-34
lines changed

client/packages/lowcoder/src/pages/editor/right/uiCompPanel.tsx

Lines changed: 75 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ import { draggingUtils } from "layout";
88
import { isEmpty } from "lodash";
99
import { language } from "i18n";
1010
import {
11-
ComListTitle,
1211
CompIconDiv,
1312
EmptyCompContent,
1413
RightPanelContentWrapper,
1514
} from "pages/editor/right/styledComponent";
1615
import { tableDragClassName } from "pages/tutorials/tutorialsConstant";
17-
import React, { useContext, useMemo } from "react";
16+
import React, { useContext, useMemo, useState } from "react";
1817
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";
2025
import { TransparentImg } from "../../../util/commonUtils";
2126
import { RightContext } from "./rightContext";
2227

23-
const GrayLabel = (props: { label: string }) => {
24-
const { label } = props;
25-
return <ComListTitle>{label}</ComListTitle>;
26-
};
27-
2828
const CompDiv = styled.div`
2929
display: flex;
3030
flex-direction: column;
@@ -80,16 +80,25 @@ const InsertContain = styled.div`
8080
gap: 8px;
8181
`;
8282

83-
const CategoryLabel = styled(GrayLabel)`
84-
margin: 0;
85-
`;
86-
8783
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+
}
8990
`;
9091

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+
9199
export const UICompPanel = () => {
92100
const { onDrag, searchValue } = useContext(RightContext);
101+
const [propertySectionState, setPropertySectionState] = useState<PropertySectionState>(initialState);
93102

94103
const categories = useMemo(() => {
95104
const cats: Record<string, [string, UICompManifest][]> = Object.fromEntries(
@@ -103,6 +112,22 @@ export const UICompPanel = () => {
103112
return cats;
104113
}, []);
105114

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+
106131
const compList = useMemo(
107132
() =>
108133
Object.entries(categories)
@@ -122,36 +147,52 @@ export const UICompPanel = () => {
122147

123148
return (
124149
<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>
145175
</SectionWrapper>
146176
);
147177
})
148178
.filter((t) => t != null),
149179
[categories, searchValue, onDrag]
150180
);
151181

182+
if(!compList.length) return (
183+
<RightPanelContentWrapper>
184+
<EmptyCompContent />
185+
</RightPanelContentWrapper>
186+
)
187+
152188
return (
153189
<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>
155196
</RightPanelContentWrapper>
156197
);
157198
};

0 commit comments

Comments
 (0)