Skip to content

Commit 66046ec

Browse files
Theme: apply theme styles in triContainerComp
1 parent 26cb4a3 commit 66046ec

File tree

2 files changed

+57
-7
lines changed

2 files changed

+57
-7
lines changed

client/packages/lowcoder/src/comps/comps/triContainerComp/triContainer.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,43 @@ const Wrapper = styled.div<{$style: ContainerStyleType; $animationStyle?:Animati
3535
`;
3636

3737
const HeaderInnerGrid = styled(InnerGrid)<{
38-
$backgroundColor: string
38+
$backgroundColor: string,
39+
$headerBackgroundImage: string;
40+
$headerBackgroundImageRepeat: string;
41+
$headerBackgroundImageSize: string;
42+
$headerBackgroundImagePosition: string;
43+
$headerBackgroundImageOrigin: string;
3944
}>`
4045
overflow: visible;
4146
${(props) => props.$backgroundColor && `background-color: ${props.$backgroundColor};`}
4247
border-radius: 0;
48+
${(props) => props.$headerBackgroundImage && `background-image: url(${props.$headerBackgroundImage});`}
49+
${(props) => props.$headerBackgroundImageRepeat && `background-repeat: ${props.$headerBackgroundImageRepeat};`}
50+
${(props) => props.$headerBackgroundImageSize && `background-size: ${props.$headerBackgroundImageSize};`}
51+
${(props) => props.$headerBackgroundImagePosition && `background-position: ${props.$headerBackgroundImagePosition};`}
52+
${(props) => props.$headerBackgroundImageOrigin && `background-origin: ${props.$headerBackgroundImageOrigin};`}
4353
`;
4454

4555
const BodyInnerGrid = styled(InnerGrid)<{
4656
$showBorder: boolean;
4757
$backgroundColor: string;
4858
$borderColor: string;
4959
$borderWidth: string;
60+
$backgroundImage: string;
61+
$backgroundImageRepeat: string;
62+
$backgroundImageSize: string;
63+
$backgroundImagePosition: string;
64+
$backgroundImageOrigin: string;
5065
}>`
5166
border-top: ${(props) => `${props.$showBorder ? props.$borderWidth : 0} solid ${props.$borderColor}`};
5267
flex: 1;
5368
${(props) => props.$backgroundColor && `background-color: ${props.$backgroundColor};`}
5469
border-radius: 0;
70+
${(props) => props.$backgroundImage && `background-image: url(${props.$backgroundImage});`}
71+
${(props) => props.$backgroundImageRepeat && `background-repeat: ${props.$backgroundImageRepeat};`}
72+
${(props) => props.$backgroundImageSize && `background-size: ${props.$backgroundImageSize};`}
73+
${(props) => props.$backgroundImagePosition && `background-position: ${props.$backgroundImagePosition};`}
74+
${(props) => props.$backgroundImageOrigin && `background-origin: ${props.$backgroundImageOrigin};`}
5575
`;
5676

5777
const FooterInnerGrid = styled(InnerGrid)<{
@@ -117,6 +137,11 @@ export function TriContainer(props: TriContainerProps) {
117137
containerPadding={[paddingWidth, 3]}
118138
showName={{ bottom: showBody || showFooter ? 20 : 0 }}
119139
$backgroundColor={headerStyle?.headerBackground || 'transparent'}
140+
$headerBackgroundImage={headerStyle?.headerBackgroundImage}
141+
$headerBackgroundImageRepeat={headerStyle?.headerBackgroundImageRepeat}
142+
$headerBackgroundImageSize={headerStyle?.headerBackgroundImageSize}
143+
$headerBackgroundImagePosition={headerStyle?.headerBackgroundImagePosition}
144+
$headerBackgroundImageOrigin={headerStyle?.headerBackgroundImageOrigin}
120145
style={{padding: headerStyle.containerHeaderPadding}}
121146

122147
/>
@@ -139,6 +164,11 @@ export function TriContainer(props: TriContainerProps) {
139164
$backgroundColor={bodyStyle?.background || 'transparent'}
140165
$borderColor={style?.border}
141166
$borderWidth={style?.borderWidth}
167+
$backgroundImage={bodyStyle?.backgroundImage}
168+
$backgroundImageRepeat={bodyStyle?.backgroundImageRepeat}
169+
$backgroundImageSize={bodyStyle?.backgroundImageSize}
170+
$backgroundImagePosition={bodyStyle?.backgroundImagePosition}
171+
$backgroundImageOrigin={bodyStyle?.backgroundImageOrigin}
142172
style={{padding: bodyStyle.containerBodyPadding}}
143173
/>
144174
</ScrollBar>

client/packages/lowcoder/src/comps/comps/triContainerComp/triContainerComp.tsx

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import {
1111
import { MultiCompBuilder, sameTypeMap, withDefault } from "comps/generators";
1212
import { migrateOldData } from "comps/generators/simpleGenerators";
1313
import { NameGenerator } from "comps/utils";
14-
import { fromRecord, Node } from "lowcoder-core";
14+
import { changeValueAction, fromRecord, multiChangeAction, Node } from "lowcoder-core";
1515
import { nodeIsRecord } from "lowcoder-core";
1616
import _ from "lodash";
17-
import { ReactNode } from "react";
17+
import { ReactNode, useContext, useEffect } from "react";
1818
import { lastValueIfEqual } from "util/objectUtils";
1919
import {
2020
CompTree,
@@ -27,6 +27,9 @@ import { SimpleContainerComp } from "../containerBase/simpleContainerComp";
2727
import { ContainerBodyChildComp } from "./containerBodyChildComp";
2828
import { trans } from "i18n";
2929
import { ControlNode } from "lowcoder-design";
30+
import { ThemeContext } from "@lowcoder-ee/comps/utils/themeContext";
31+
import { CompTypeContext } from "@lowcoder-ee/comps/utils/compTypeContext";
32+
import { setInitialCompStyles } from "@lowcoder-ee/comps/utils/themeUtil";
3033

3134
const childrenMap = {
3235
header: SimpleContainerComp,
@@ -40,15 +43,32 @@ const childrenMap = {
4043
showFooter: BoolControl,
4144
autoHeight: AutoHeightControl,
4245
scrollbars: withDefault(BoolControl, false),
43-
style: withDefault(styleControl(ContainerStyle),{borderWidth:'1px'}),
44-
headerStyle: styleControl(ContainerHeaderStyle),
45-
bodyStyle: styleControl(ContainerBodyStyle),
46-
footerStyle: styleControl(ContainerFooterStyle),
46+
style: withDefault(styleControl(ContainerStyle, 'style'),{borderWidth:'1px'}),
47+
headerStyle: styleControl(ContainerHeaderStyle, 'headerStyle'),
48+
bodyStyle: styleControl(ContainerBodyStyle, 'bodyStyle'),
49+
footerStyle: styleControl(ContainerFooterStyle, 'footerStyle'),
4750
};
4851

4952
// Compatible with old style data 2022-8-15
5053
const TriContainerBaseComp = migrateOldData(
5154
new MultiCompBuilder(childrenMap, (props, dispatch) => {
55+
const theme = useContext(ThemeContext);
56+
const compType = useContext(CompTypeContext);
57+
const compTheme = theme?.theme?.components?.[compType];
58+
// Filter style props from children props
59+
const styleProps: Record<string, any> = {};
60+
['style', 'headerStyle', 'bodyStyle', 'footerStyle'].forEach((key: string) => {
61+
styleProps[key] = (props as any)[key];
62+
});
63+
// Update comp styles with combination of default style and comp theme style
64+
useEffect(() => {
65+
setInitialCompStyles({
66+
dispatch,
67+
compTheme,
68+
styleProps,
69+
});
70+
}, []);
71+
5272
return { ...props, dispatch };
5373
}).build(),
5474
fixOldStyleData

0 commit comments

Comments
 (0)