Skip to content

Commit 8942536

Browse files
Theme: apply theme styles on table comp
1 parent fafe071 commit 8942536

File tree

6 files changed

+53
-10
lines changed

6 files changed

+53
-10
lines changed

client/packages/lowcoder/src/comps/comps/tableComp/tableCompView.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ import { messageInstance } from "lowcoder-design/src/components/GlobalInstances"
4141
import { ReactRef, ResizeHandleAxis } from "layout/gridLayoutPropTypes";
4242
import { CellColorViewType } from "./column/tableColumnComp";
4343
import { defaultTheme } from "@lowcoder-ee/constants/themeConstants";
44+
import { ThemeContext } from "@lowcoder-ee/comps/utils/themeContext";
45+
import { CompTypeContext } from "@lowcoder-ee/comps/utils/compTypeContext";
46+
import { setInitialCompStyles } from "@lowcoder-ee/comps/utils/themeUtil";
47+
import { childrenToProps } from "@lowcoder-ee/comps/generators/multi";
4448

4549

4650
function genLinerGradient(color: string) {
@@ -345,7 +349,6 @@ const TableTd = styled.td<{
345349
background: ${(props) => props.$background} !important;
346350
border-color: ${(props) => props.$style.border} !important;
347351
border-radius: ${(props) => props.$style.radius};
348-
349352
padding: 0 !important;
350353
351354
> div {
@@ -775,6 +778,24 @@ export function TableCompView(props: {
775778
};
776779
}, [pagination, data]);
777780

781+
const childrenProps = childrenToProps(comp.children);
782+
const theme = useContext(ThemeContext);
783+
const compType = useContext(CompTypeContext);
784+
const compTheme = theme?.theme?.components?.[compType];
785+
786+
const styleProps: Record<string, any> = {};
787+
['style', 'rowStyle', 'toolbarStyle', 'headerStyle', 'columnsStyle'].forEach((key: string) => {
788+
styleProps[key] = (childrenProps as any)[key];
789+
});
790+
791+
useEffect(() => {
792+
setInitialCompStyles({
793+
dispatch: comp.dispatch,
794+
compTheme,
795+
styleProps,
796+
});
797+
}, []);
798+
778799
const handleChangeEvent = useCallback(
779800
(eventName: TableEventOptionValues) => {
780801
if (eventName === "saveChanges" && !compChildren.onEvent.isBind(eventName)) {

client/packages/lowcoder/src/comps/comps/tableComp/tableTypes.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ const tableChildrenMap = {
205205
pagination: PaginationControl,
206206
sort: valueComp<Array<SortValue>>([]),
207207
toolbar: TableToolbarComp,
208-
style: withDefault(styleControl(TableStyle), {borderWidth: '1px'}),
209-
rowStyle: withDefault(styleControl(TableRowStyle),{ borderWidth: '1px'}),
210-
toolbarStyle: styleControl(TableToolbarStyle),
211-
headerStyle:withDefault(styleControl(TableHeaderStyle), {borderWidth: '1px'}),
208+
style: styleControl(TableStyle, 'style'),
209+
rowStyle: styleControl(TableRowStyle, 'rowStyle'),
210+
toolbarStyle: styleControl(TableToolbarStyle, 'toolbarStyle'),
211+
headerStyle: styleControl(TableHeaderStyle, 'headerStyle'),
212212
searchText: StringControl,
213-
columnsStyle: withDefault(styleControl(TableColumnStyle), {radius:'0px'}),
213+
columnsStyle: styleControl(TableColumnStyle, 'columnsStyle'),
214214
viewModeResizable: BoolControl,
215215
visibleResizables: BoolControl,
216216
// sample data for regenerating columns

client/packages/lowcoder/src/comps/controls/styleControl.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,12 @@ function calcColors<ColorMap extends Record<string, string>>(
355355
bgColor?: string,
356356
compTheme?: Record<string, string>,
357357
) {
358-
let themeWithDefault = (theme || defaultTheme) as unknown as Record<string, string>;
359-
themeWithDefault = {...themeWithDefault, ...(compTheme || {})};
358+
// let themeWithDefault = (theme || defaultTheme) as unknown as Record<string, string>;
359+
let themeWithDefault = {
360+
...defaultTheme,
361+
...(theme || {}),
362+
...(compTheme || {}),
363+
} as unknown as Record<string, string>;
360364

361365
// Cover what is not there for the first pass
362366
let res: Record<string, string> = {};

client/packages/lowcoder/src/comps/controls/styleControlConstants.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export function contrastText(
241241
textDark: string,
242242
textLight: string
243243
) {
244-
return isDarkColor(color) && color !== "#00000000" ? textLight : textDark;
244+
return color && isDarkColor(color) && color !== "#00000000" ? textLight : textDark;
245245
}
246246

247247
// return similar background color

client/packages/lowcoder/src/constants/themeConstants.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ const input = {
2020
}
2121
};
2222

23+
const table = {
24+
style: {
25+
borderWidth: '1px'
26+
},
27+
rowStyle: {
28+
borderWidth: '1px'
29+
},
30+
headerStyle: {
31+
borderWidth: '1px'
32+
},
33+
columnsStyle: {
34+
radius: '0px'
35+
}
36+
}
37+
2338
export const defaultTheme: ThemeDetail = {
2439
primary: "#3377FF",
2540
textDark: "#222222",
@@ -34,6 +49,7 @@ export const defaultTheme: ThemeDetail = {
3449
padding: "3px",
3550
gridColumns: "24",
3651
textSize: "14px",
52+
text: "#222222",
3753
animation: "",
3854
animationDelay: "",
3955
animationDuration: "",
@@ -44,5 +60,6 @@ export const defaultTheme: ThemeDetail = {
4460
components: {
4561
text,
4662
input,
63+
table,
4764
},
4865
};

client/packages/lowcoder/src/pages/setting/theme/ThemeCompPanel.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import ThemeSettingsCompStyles from "components/ThemeSettingsCompStyles";
3030
import { JSONObject } from "util/jsonTypes";
3131
import PreviewApp from "components/PreviewApp";
3232
import { parseCompType } from "comps/utils/remote";
33+
import { defaultTheme } from "@lowcoder-ee/constants/themeConstants";
3334

3435
const CompDiv = styled.div`
3536
display: flex;
@@ -308,7 +309,7 @@ export const ThemeCompPanel = (props: any) => {
308309
minWidth: "auto",
309310
width: "100%",
310311
}}
311-
theme={theme}
312+
theme={{...defaultTheme, ...theme}}
312313
dsl={appDsl}
313314
/>
314315
);

0 commit comments

Comments
 (0)