Skip to content

Commit a198f6e

Browse files
feat: added column styles
1 parent 75fe04e commit a198f6e

File tree

4 files changed

+49
-11
lines changed

4 files changed

+49
-11
lines changed

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

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
defaultTheme,
1818
handleToHoverRow,
1919
handleToSelectedRow,
20+
TableColumnStyleType,
2021
TableStyleType,
2122
} from "comps/controls/styleControlConstants";
2223
import { CompNameContext, EditorContext } from "comps/editorState";
@@ -292,19 +293,29 @@ const TableTh = styled.th<{ width?: number }>`
292293
${(props) => props.width && `width: ${props.width}px`};
293294
`;
294295

295-
const TableTd = styled.td<{ background: string; $isEditing: boolean }>`
296+
const TableTd = styled.td<{
297+
background: string;
298+
columnStyle: TableColumnStyleType;
299+
$isEditing: boolean;
300+
}>`
296301
.ant-table-row-expand-icon,
297302
.ant-table-row-indent {
298303
display: ${(props) => (props.$isEditing ? "none" : "initial")};
299304
}
300-
301-
${(props) =>
302-
props.background &&
303-
`
304-
background: ${props.background} !important;
305-
`};
305+
> div > div {
306+
background: ${(props) => props.background};
307+
color: ${(props) => props.columnStyle.cellText} !important;
308+
border-radius: ${(props) => props.columnStyle.radius};
309+
border-color: ${(props) => props.columnStyle.border};
310+
}
306311
`;
307312

313+
// ${(props) =>
314+
// props.background &&
315+
// `
316+
// background: ${props.background} !important;
317+
// `};
318+
308319
const ResizeableTitle = (props: any) => {
309320
const { onResize, onResizeStop, width, viewModeResizable, ...restProps } = props;
310321
const [widthChild, setWidthChild] = useState(0);
@@ -365,6 +376,7 @@ type CustomTableProps<RecordType> = Omit<TableProps<RecordType>, "components" |
365376
columns: CustomColumnType<RecordType>[];
366377
viewModeResizable: boolean;
367378
rowColor: RowColorViewType;
379+
columnStyle: TableColumnStyleType;
368380
};
369381

370382
function TableCellView(props: {
@@ -373,8 +385,10 @@ function TableCellView(props: {
373385
rowColor: RowColorViewType;
374386
rowIndex: number;
375387
children: any;
388+
columnStyle: TableColumnStyleType;
376389
}) {
377-
const { record, title, rowIndex, rowColor, children, ...restProps } = props;
390+
const { record, title, rowIndex, rowColor, children, columnStyle, ...restProps } = props;
391+
console.log(columnStyle)
378392
const [editing, setEditing] = useState(false);
379393
const rowContext = useContext(TableRowContext);
380394
let tdView;
@@ -387,7 +401,7 @@ function TableCellView(props: {
387401
currentOriginalIndex: record[OB_ROW_ORI_INDEX],
388402
columnTitle: title,
389403
});
390-
let background = "";
404+
let { background } = columnStyle;
391405
if (color) {
392406
background = genLinerGradient(color);
393407
}
@@ -398,7 +412,12 @@ function TableCellView(props: {
398412
background = genLinerGradient(handleToHoverRow(color)) + "," + background;
399413
}
400414
tdView = (
401-
<TableTd {...restProps} background={background} $isEditing={editing}>
415+
<TableTd
416+
{...restProps}
417+
background={background}
418+
columnStyle={columnStyle}
419+
$isEditing={editing}
420+
>
402421
{children}
403422
</TableTd>
404423
);
@@ -466,6 +485,7 @@ function ResizeableTable<RecordType extends object>(props: CustomTableProps<Reco
466485
title: col.titleText,
467486
rowColor: props.rowColor,
468487
rowIndex: rowIndex,
488+
columnStyle: props.columnStyle,
469489
}),
470490
onHeaderCell: () => ({
471491
width: resizeWidth,
@@ -533,6 +553,7 @@ export function TableCompView(props: {
533553
const changeSet = useMemo(() => compChildren.columns.getChangeSet(), [compChildren.columns]);
534554
const hasChange = useMemo(() => !_.isEmpty(changeSet), [changeSet]);
535555
const columns = useMemo(() => compChildren.columns.getView(), [compChildren.columns]);
556+
const columnStyle = useMemo(() => compChildren.columnStyle.getView(), [compChildren.columnStyle]);
536557
const columnViews = useMemo(() => columns.map((c) => c.getView()), [columns]);
537558
const data = comp.filterData;
538559
const sort = useMemo(() => compChildren.sort.getView(), [compChildren.sort]);
@@ -657,6 +678,7 @@ export function TableCompView(props: {
657678
}}
658679
showHeader={!compChildren.hideHeader.getView()}
659680
columns={antdColumns}
681+
columnStyle={columnStyle}
660682
viewModeResizable={compChildren.viewModeResizable.getView()}
661683
dataSource={pageDataInfo.data}
662684
size={compChildren.size.getView()}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,9 @@ export function compTablePropertyView<T extends MultiBaseComp<TableChildrenType>
463463
label: trans("table.hideBordered"),
464464
})}
465465
</Section>
466+
<Section name={'Column Styles'}>
467+
{comp.children.columnStyle.getPropertyView()}
468+
</Section>
466469
</>
467470
);
468471
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import { dropdownControl } from "comps/controls/dropdownControl";
1111
import { eventHandlerControl } from "comps/controls/eventHandlerControl";
1212
import { styleControl } from "comps/controls/styleControl";
13-
import { TableStyle } from "comps/controls/styleControlConstants";
13+
import { TableColumnStyle, TableStyle } from "comps/controls/styleControlConstants";
1414
import {
1515
MultiCompBuilder,
1616
stateComp,
@@ -143,6 +143,7 @@ const tableChildrenMap = {
143143
sort: valueComp<Array<SortValue>>([]),
144144
toolbar: TableToolbarComp,
145145
style: styleControl(TableStyle),
146+
columnStyle: styleControl(TableColumnStyle),
146147
viewModeResizable: BoolControl,
147148
// sample data for regenerating columns
148149
dataRowExample: stateComp<JSONObject | null>(null),

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,17 @@ export const TableStyle = [
694694
},
695695
] as const;
696696

697+
export const TableColumnStyle = [
698+
...BG_STATIC_BORDER_RADIUS,
699+
{
700+
name: "cellText",
701+
label: trans("style.tableCellText"),
702+
depName: "background",
703+
depType: DEP_TYPE.CONTRAST_TEXT,
704+
transformer: contrastText,
705+
}
706+
] as const;
707+
697708
export const FileStyle = [...getStaticBgBorderRadiusByBg(SURFACE_COLOR), TEXT, ACCENT, MARGIN, PADDING] as const;
698709

699710
export const FileViewerStyle = [
@@ -1001,6 +1012,7 @@ export type CheckboxStyleType = StyleConfigType<typeof CheckboxStyle>;
10011012
export type RadioStyleType = StyleConfigType<typeof RadioStyle>;
10021013
export type SegmentStyleType = StyleConfigType<typeof SegmentStyle>;
10031014
export type TableStyleType = StyleConfigType<typeof TableStyle>;
1015+
export type TableColumnStyleType = StyleConfigType<typeof TableColumnStyle>;
10041016
export type FileStyleType = StyleConfigType<typeof FileStyle>;
10051017
export type FileViewerStyleType = StyleConfigType<typeof FileViewerStyle>;
10061018
export type IframeStyleType = StyleConfigType<typeof IframeStyle>;

0 commit comments

Comments
 (0)