Skip to content

Commit

Permalink
Header row marker options (#913)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivoelbert authored Mar 7, 2024
1 parent 73e63f5 commit c6bdb03
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
17 changes: 16 additions & 1 deletion packages/core/src/data-editor/data-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ export interface RowMarkerOptions {
startIndex?: number;
width?: number;
theme?: Partial<Theme>;
headerTheme?: Partial<Theme>;
headerAlwaysVisible?: boolean;
}

interface MouseState {
Expand Down Expand Up @@ -861,6 +863,8 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
const rowMarkerWidthRaw = rowMarkersObj?.width ?? p.rowMarkerWidth;
const rowMarkerStartIndex = rowMarkersObj?.startIndex ?? p.rowMarkerStartIndex ?? 1;
const rowMarkerTheme = rowMarkersObj?.theme ?? p.rowMarkerTheme;
const headerRowMarkerTheme = rowMarkersObj?.headerTheme;
const headerRowMarkerAlwaysVisible = rowMarkersObj?.headerAlwaysVisible;
const rowMarkerCheckboxStyle = rowMarkersObj?.checkboxStyle ?? "square";

const minColumnWidth = Math.max(minColumnWidthIn, 20);
Expand Down Expand Up @@ -1093,10 +1097,21 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
themeOverride: rowMarkerTheme,
rowMarker: rowMarkerCheckboxStyle,
rowMarkerChecked,
headerRowMarkerTheme,
headerRowMarkerAlwaysVisible,
},
...columns,
];
}, [rowMarkers, columns, rowMarkerWidth, rowMarkerTheme, rowMarkerCheckboxStyle, rowMarkerChecked]);
}, [
rowMarkers,
columns,
rowMarkerWidth,
rowMarkerTheme,
rowMarkerCheckboxStyle,
rowMarkerChecked,
headerRowMarkerTheme,
headerRowMarkerAlwaysVisible,
]);

const visibleRegionRef = React.useRef<VisibleRegion>({
height: 1,
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/docs/examples/row-markers.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export const RowMarkers: React.VFC<RowMarkersProps> = p => {
verticalBorder={false}
rowMarkers={{
kind: p.markers,
checkboxStyle: "circle",
checkboxStyle: "square",
headerAlwaysVisible: true,
headerTheme: {
textMedium: "rgba(51, 51, 51, 0.50)",
},
}}
columns={cols}
rows={400}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/internal/data-grid/data-grid-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ export type InnerColumnExtension = {
growOffset?: number;
rowMarker?: "square" | "circle";
rowMarkerChecked?: BooleanIndeterminate | boolean;
headerRowMarkerTheme?: Partial<Theme>;
headerRowMarkerAlwaysVisible?: boolean;
};

/** @category Columns */
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/internal/data-grid/render/data-grid-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export function useMappedColumns(
growOffset: c.growOffset,
rowMarker: c.rowMarker,
rowMarkerChecked: c.rowMarkerChecked,
headerRowMarkerTheme: c.headerRowMarkerTheme,
headerRowMarkerAlwaysVisible: c.headerRowMarkerAlwaysVisible,
})
),
[columns, freezeColumns]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,27 @@ function drawHeaderInner(
) {
if (c.rowMarker !== undefined) {
const checked = c.rowMarkerChecked;
if (checked !== true) {
if (checked !== true && c.headerRowMarkerAlwaysVisible !== true) {
ctx.globalAlpha = hoverAmount;
}
drawCheckbox(ctx, theme, checked, x, y, width, height, false, undefined, undefined, 18, "center", c.rowMarker);
if (checked !== true) {
const markerTheme =
c.headerRowMarkerTheme !== undefined ? mergeAndRealizeTheme(theme, c.headerRowMarkerTheme) : theme;
drawCheckbox(
ctx,
markerTheme,
checked,
x,
y,
width,
height,
false,
undefined,
undefined,
18,
"center",
c.rowMarker
);
if (checked !== true && c.headerRowMarkerAlwaysVisible !== true) {
ctx.globalAlpha = 1;
}
return;
Expand Down

0 comments on commit c6bdb03

Please sign in to comment.