Skip to content

Commit 540e0a0

Browse files
author
FalkWolsky
committed
Adding Layout Component and global style selector
1 parent 06c0f5b commit 540e0a0

File tree

12 files changed

+611
-230
lines changed

12 files changed

+611
-230
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import { CompParams } from "lowcoder-core";
2+
import { ToDataType } from "comps/generators/multi";
3+
import { NameConfigHidden, withExposingConfigs } from "comps/generators/withExposing";
4+
import { NameGenerator } from "comps/utils/nameGenerator";
5+
import { Section, sectionNames } from "lowcoder-design";
6+
import { oldContainerParamsToNew } from "../containerBase";
7+
import { toSimpleContainerData } from "../containerBase/simpleContainerComp";
8+
import { disabledPropertyView, hiddenPropertyView } from "comps/utils/propertyUtils";
9+
import { trans } from "i18n";
10+
import { BoolCodeControl } from "comps/controls/codeControl";
11+
import { DisabledContext } from "comps/generators/uiCompBuilder";
12+
import React, { useContext } from "react";
13+
import { EditorContext } from "comps/editorState";
14+
15+
import {
16+
ContainerChildren,
17+
ContainerCompBuilder,
18+
} from "../pageLayoutComp/pageLayoutCompBuilder";
19+
import { PageLayout } from "../pageLayoutComp/pageLayout";
20+
21+
export const ContainerBaseComp = (function () {
22+
const childrenMap = {
23+
disabled: BoolCodeControl,
24+
};
25+
return new ContainerCompBuilder(childrenMap, (props, dispatch) => {
26+
return (
27+
<DisabledContext.Provider value={props.disabled}>
28+
<PageLayout {...props} />
29+
</DisabledContext.Provider>
30+
);
31+
})
32+
.setPropertyViewFn((children) => {
33+
return (
34+
<>
35+
{(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && (
36+
<Section name={sectionNames.interaction}>
37+
{disabledPropertyView(children)}
38+
{hiddenPropertyView(children)}
39+
{ children.container.appSelectorPropertyView()}
40+
</Section>
41+
)}
42+
43+
{(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && (
44+
<><Section name={sectionNames.layout}>
45+
{children.container.getPropertyView()}
46+
</Section>
47+
<Section name={sectionNames.style}>
48+
{ children.container.stylePropertyView() }
49+
</Section>
50+
{children.container.children.showHeader.getView() && (
51+
<Section name={"Header Style"}>
52+
{ children.container.headerStylePropertyView() }
53+
</Section>
54+
)}
55+
{children.container.children.showSider.getView() && (
56+
<Section name={"Sider Style"}>
57+
{ children.container.siderStylePropertyView() }
58+
</Section>
59+
)}
60+
<Section name={"Body Style"}>
61+
{ children.container.bodyStylePropertyView() }
62+
</Section>
63+
{children.container.children.showFooter.getView() && (
64+
<Section name={"Footer Style"}>
65+
{ children.container.footerStylePropertyView() }
66+
</Section>
67+
)}
68+
</>
69+
)}
70+
</>
71+
);
72+
})
73+
.build();
74+
})();
75+
76+
// Compatible with old data
77+
function convertOldContainerParams(params: CompParams<any>) {
78+
// convert older params to old params
79+
let tempParams = oldContainerParamsToNew(params);
80+
81+
if (tempParams.value) {
82+
const container = tempParams.value.container;
83+
// old params
84+
if (container && (container.hasOwnProperty("layout") || container.hasOwnProperty("items"))) {
85+
const autoHeight = tempParams.value.autoHeight;
86+
const scrollbars = tempParams.value.scrollbars;
87+
return {
88+
...tempParams,
89+
value: {
90+
container: {
91+
showHeader: true,
92+
body: { 0: { view: container } },
93+
showFooter: false,
94+
showSider: true,
95+
autoHeight: autoHeight,
96+
contentScrollbars: scrollbars,
97+
},
98+
},
99+
};
100+
}
101+
}
102+
return tempParams;
103+
}
104+
105+
class ContainerTmpComp extends ContainerBaseComp {
106+
constructor(params: CompParams<any>) {
107+
super(convertOldContainerParams(params));
108+
}
109+
}
110+
111+
export const PageLayoutComp = withExposingConfigs(ContainerTmpComp, [NameConfigHidden]);
112+
113+
type ContainerDataType = ToDataType<ContainerChildren<{}>>;
114+
115+
export function defaultPageLayoutData(
116+
compName: string,
117+
nameGenerator: NameGenerator
118+
): ContainerDataType {
119+
return {
120+
container: {
121+
header: toSimpleContainerData([
122+
{
123+
item: {
124+
compType: "text",
125+
name: nameGenerator.genItemName("containerTitle"),
126+
comp: {
127+
text: "## " + trans("container.title"),
128+
},
129+
},
130+
layoutItem: {
131+
i: "",
132+
h: 6,
133+
w: 24,
134+
x: 0,
135+
y: 0,
136+
},
137+
},
138+
]),
139+
},
140+
};
141+
}

client/packages/lowcoder/src/comps/comps/layout/mobileTabLayout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ MobileTabLayoutTmp = withViewFn(MobileTabLayoutTmp, (comp) => {
191191
/>
192192
);
193193

194+
//console.log("appView", appView);
195+
194196
if (readOnly) {
195197
return (
196198
<TabLayoutViewContainer>

client/packages/lowcoder/src/comps/comps/layoutComp/layout.tsx

Lines changed: 0 additions & 201 deletions
This file was deleted.

0 commit comments

Comments
 (0)