Skip to content

Commit c6bdb03

Browse files
authored
Header row marker options (#913)
1 parent 73e63f5 commit c6bdb03

File tree

5 files changed

+44
-5
lines changed

5 files changed

+44
-5
lines changed

packages/core/src/data-editor/data-editor.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ export interface RowMarkerOptions {
9999
startIndex?: number;
100100
width?: number;
101101
theme?: Partial<Theme>;
102+
headerTheme?: Partial<Theme>;
103+
headerAlwaysVisible?: boolean;
102104
}
103105

104106
interface MouseState {
@@ -861,6 +863,8 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
861863
const rowMarkerWidthRaw = rowMarkersObj?.width ?? p.rowMarkerWidth;
862864
const rowMarkerStartIndex = rowMarkersObj?.startIndex ?? p.rowMarkerStartIndex ?? 1;
863865
const rowMarkerTheme = rowMarkersObj?.theme ?? p.rowMarkerTheme;
866+
const headerRowMarkerTheme = rowMarkersObj?.headerTheme;
867+
const headerRowMarkerAlwaysVisible = rowMarkersObj?.headerAlwaysVisible;
864868
const rowMarkerCheckboxStyle = rowMarkersObj?.checkboxStyle ?? "square";
865869

866870
const minColumnWidth = Math.max(minColumnWidthIn, 20);
@@ -1093,10 +1097,21 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
10931097
themeOverride: rowMarkerTheme,
10941098
rowMarker: rowMarkerCheckboxStyle,
10951099
rowMarkerChecked,
1100+
headerRowMarkerTheme,
1101+
headerRowMarkerAlwaysVisible,
10961102
},
10971103
...columns,
10981104
];
1099-
}, [rowMarkers, columns, rowMarkerWidth, rowMarkerTheme, rowMarkerCheckboxStyle, rowMarkerChecked]);
1105+
}, [
1106+
rowMarkers,
1107+
columns,
1108+
rowMarkerWidth,
1109+
rowMarkerTheme,
1110+
rowMarkerCheckboxStyle,
1111+
rowMarkerChecked,
1112+
headerRowMarkerTheme,
1113+
headerRowMarkerAlwaysVisible,
1114+
]);
11001115

11011116
const visibleRegionRef = React.useRef<VisibleRegion>({
11021117
height: 1,

packages/core/src/docs/examples/row-markers.stories.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ export const RowMarkers: React.VFC<RowMarkersProps> = p => {
4646
verticalBorder={false}
4747
rowMarkers={{
4848
kind: p.markers,
49-
checkboxStyle: "circle",
49+
checkboxStyle: "square",
50+
headerAlwaysVisible: true,
51+
headerTheme: {
52+
textMedium: "rgba(51, 51, 51, 0.50)",
53+
},
5054
}}
5155
columns={cols}
5256
rows={400}

packages/core/src/internal/data-grid/data-grid-types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ export type InnerColumnExtension = {
195195
growOffset?: number;
196196
rowMarker?: "square" | "circle";
197197
rowMarkerChecked?: BooleanIndeterminate | boolean;
198+
headerRowMarkerTheme?: Partial<Theme>;
199+
headerRowMarkerAlwaysVisible?: boolean;
198200
};
199201

200202
/** @category Columns */

packages/core/src/internal/data-grid/render/data-grid-lib.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export function useMappedColumns(
4545
growOffset: c.growOffset,
4646
rowMarker: c.rowMarker,
4747
rowMarkerChecked: c.rowMarkerChecked,
48+
headerRowMarkerTheme: c.headerRowMarkerTheme,
49+
headerRowMarkerAlwaysVisible: c.headerRowMarkerAlwaysVisible,
4850
})
4951
),
5052
[columns, freezeColumns]

packages/core/src/internal/data-grid/render/data-grid-render.header.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,27 @@ function drawHeaderInner(
430430
) {
431431
if (c.rowMarker !== undefined) {
432432
const checked = c.rowMarkerChecked;
433-
if (checked !== true) {
433+
if (checked !== true && c.headerRowMarkerAlwaysVisible !== true) {
434434
ctx.globalAlpha = hoverAmount;
435435
}
436-
drawCheckbox(ctx, theme, checked, x, y, width, height, false, undefined, undefined, 18, "center", c.rowMarker);
437-
if (checked !== true) {
436+
const markerTheme =
437+
c.headerRowMarkerTheme !== undefined ? mergeAndRealizeTheme(theme, c.headerRowMarkerTheme) : theme;
438+
drawCheckbox(
439+
ctx,
440+
markerTheme,
441+
checked,
442+
x,
443+
y,
444+
width,
445+
height,
446+
false,
447+
undefined,
448+
undefined,
449+
18,
450+
"center",
451+
c.rowMarker
452+
);
453+
if (checked !== true && c.headerRowMarkerAlwaysVisible !== true) {
438454
ctx.globalAlpha = 1;
439455
}
440456
return;

0 commit comments

Comments
 (0)