Skip to content

Commit 630e92a

Browse files
authored
Add theming property to define max checkbox size (#1061)
* Add theming property to define max checkbox size * Remove * Set checkbox max size propt to 18
1 parent a3f9b16 commit 630e92a

File tree

9 files changed

+24
-18
lines changed

9 files changed

+24
-18
lines changed

packages/core/API.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,8 @@ The data grid uses the `Theme` provided to the DataEditer in the `theme` prop. T
391391
| bubbleHeight | number | --gdg-bubble-height | The height (in pixels) of a bubble. |
392392
| bubblePadding | number | --gdg-bubble-padding | The left & right padding (in pixels) of a bubble. |
393393
| bubbleMargin | number | --gdg-bubble-margin | The margin (in pixels) between bubbles. |
394+
| checkboxMaxSize | number | --gdg-checkbox-max-size | The maximum size of checkboxes (in pixels), e.g. for boolean cell and row markers. |
395+
| roundingRadius | number \| undefined | --gdg-rounding-radius | The radius of rounded corners used by various grid elements (in pixels). |
394396

395397
---
396398

@@ -1317,4 +1319,4 @@ If `isDraggable` is set, the whole Grid is draggable, and `onDragStart` will be
13171319

13181320
Behavior not defined or officially supported. Feel free to check out what this does in github but anything in here is up for grabs to be changed at any time.
13191321

1320-
---
1322+
---

packages/core/src/cells/boolean-cell.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import {
1212
import { drawCheckbox } from "../internal/data-grid/render/draw-checkbox.js";
1313
import type { BaseDrawArgs, InternalCellRenderer } from "./cell-types.js";
1414

15-
const defaultCellMaxSize = 20;
16-
1715
function isOverEditableRegion(e: {
1816
readonly cell: BooleanCell;
1917
readonly posX: number;
@@ -23,7 +21,7 @@ function isOverEditableRegion(e: {
2321
}): boolean {
2422
const { cell, posX: pointerX, posY: pointerY, bounds, theme } = e;
2523
const { width, height, x: cellX, y: cellY } = bounds;
26-
const maxWidth = cell.maxSize ?? defaultCellMaxSize;
24+
const maxWidth = cell.maxSize ?? theme.checkboxMaxSize;
2725
const cellCenterY = Math.floor(bounds.y + height / 2);
2826
const checkBoxWidth = getSquareWidth(maxWidth, height, theme.cellVerticalPadding);
2927
const posX = getSquareXPosFromAlign(
@@ -51,7 +49,7 @@ export const booleanCellRenderer: InternalCellRenderer<BooleanCell> = {
5149
a,
5250
a.cell.data,
5351
booleanCellIsEditable(a.cell),
54-
a.cell.maxSize ?? defaultCellMaxSize,
52+
a.cell.maxSize ?? a.theme.checkboxMaxSize,
5553
a.cell.hoverEffectIntensity ?? 0.35
5654
),
5755
onDelete: c => ({

packages/core/src/cells/marker-cell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function drawMarkerRowCell(
7373
true,
7474
undefined,
7575
undefined,
76-
18,
76+
theme.checkboxMaxSize,
7777
"center",
7878
style
7979
);

packages/core/src/common/styles.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export function makeCSSStyle(theme: Theme): Record<string, string> {
4242
"--gdg-marker-font-style": theme.markerFontStyle,
4343
"--gdg-font-family": theme.fontFamily,
4444
"--gdg-editor-font-size": theme.editorFontSize,
45+
"--gdg-checkbox-max-size": `${theme.checkboxMaxSize}px`,
4546
...(theme.resizeIndicatorColor === undefined
4647
? {}
4748
: { "--gdg-resize-indicator-color": theme.resizeIndicatorColor }),
@@ -91,6 +92,7 @@ export interface Theme {
9192
fontFamily: string;
9293
editorFontSize: string;
9394
lineHeight: number;
95+
checkboxMaxSize: number;
9496

9597
resizeIndicatorColor?: string;
9698
horizontalBorderColor?: string;
@@ -145,6 +147,7 @@ const dataEditorBaseTheme: Theme = {
145147
"Inter, Roboto, -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Ubuntu, noto, arial, sans-serif",
146148
editorFontSize: "13px",
147149
lineHeight: 1.4, //unitless scaler depends on your font
150+
checkboxMaxSize: 18,
148151
};
149152

150153
export interface FullTheme extends Theme {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ export function lossyCopyData<T extends EditableGridCell>(source: EditableGridCe
105105
}
106106
// No default
107107
}
108-
assertNever(target);
109108
}
110109

111110
export type GridColumnWithMockingInfo = GridColumn & {
@@ -814,7 +813,7 @@ export function useAllMockedKinds() {
814813
const copied = lossyCopyData(val, current);
815814
cache.current.set(col, row, {
816815
...copied,
817-
displayData: noDisplay === true ? undefined : copied.data?.toString() ?? "",
816+
displayData: noDisplay === true ? undefined : (copied.data?.toString() ?? ""),
818817
} as any);
819818

820819
if (forceUpdate === true) {

packages/core/src/docs/08-theming.stories.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ The global theme is provided by the DataEditor by default and can be overriden b
277277
| fontFamily | --gdg-font-family | string | The font family used by the data grid. |
278278
| editorFontSize | --gdg-editor-font-size | string | The font size used by overlay editors. |
279279
| lineHeight | None | number | A unitless scaler which defines the height of a line of text relative to the ink size. |
280+
| checkboxMaxSize | --gdg-checkbox-max-size | number | The maximum size of checkboxes (in pixels), e.g. for boolean cell and row markers. |
281+
| roundingRadius | --gdg-rounding-radius | number | The radius of rounded corners used by various grid elements (in pixels). |
280282
281283
If an option is missing from any theme it will be filled in with the default theme.
282284
`}

packages/core/src/docs/examples/theme-support.stories.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const darkTheme = {
5757
baseFontStyle: "13px",
5858
fontFamily:
5959
"Inter, Roboto, -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Ubuntu, noto, arial, sans-serif",
60+
checkboxMaxSize: 18,
6061
};
6162

6263
const hotdogStand = {
@@ -94,6 +95,7 @@ const hotdogStand = {
9495
fontFamily:
9596
"Inter, Roboto, -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Ubuntu, noto, arial, sans-serif",
9697
roundingRadius: 6,
98+
checkboxMaxSize: 40,
9799
};
98100

99101
export const ThemeSupport: React.VFC = () => {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export function drawGridHeaders(
8181
const hoveredBoolean = !noHover && hRow === -1 && hCol === c.sourceIndex;
8282
const hover = noHover
8383
? 0
84-
: hoverValues.find(s => s.item[0] === c.sourceIndex && s.item[1] === -1)?.hoverAmount ?? 0;
84+
: (hoverValues.find(s => s.item[0] === c.sourceIndex && s.item[1] === -1)?.hoverAmount ?? 0);
8585

8686
const hasSelectedCell = selection?.current !== undefined && selection.current.cell[0] === c.sourceIndex;
8787

@@ -186,8 +186,8 @@ export function drawGroups(
186186
group?.overrideTheme === undefined ? theme : mergeAndRealizeTheme(theme, group.overrideTheme);
187187
const isHovered = hRow === -2 && hCol !== undefined && hCol >= span[0] && hCol <= span[1];
188188
const fillColor = isHovered
189-
? groupTheme.bgGroupHeaderHovered ?? groupTheme.bgHeaderHovered
190-
: groupTheme.bgGroupHeader ?? groupTheme.bgHeader;
189+
? (groupTheme.bgGroupHeaderHovered ?? groupTheme.bgHeaderHovered)
190+
: (groupTheme.bgGroupHeader ?? groupTheme.bgHeader);
191191

192192
if (fillColor !== theme.bgHeader) {
193193
ctx.fillStyle = fillColor;
@@ -389,7 +389,7 @@ export function computeHeaderLayout(
389389
if (c.indicatorIcon !== undefined) {
390390
const textWidth =
391391
ctx === undefined
392-
? getMeasuredTextCache(c.title, theme.headerFontFull)?.width ?? 0
392+
? (getMeasuredTextCache(c.title, theme.headerFontFull)?.width ?? 0)
393393
: measureTextCached(c.title, ctx, theme.headerFontFull).width;
394394
textBounds.width = textWidth;
395395
drawX += textWidth + xPad;
@@ -448,7 +448,7 @@ function drawHeaderInner(
448448
false,
449449
undefined,
450450
undefined,
451-
18,
451+
theme.checkboxMaxSize,
452452
"center",
453453
c.rowMarker
454454
);

packages/core/src/internal/data-grid/render/draw-checkbox.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { assertNever } from "../../../common/support.js";
2-
import { getSquareWidth, getSquareXPosFromAlign, getSquareBB, pointIsWithinBB } from "../../../common/utils.js";
2+
import { getSquareBB, getSquareWidth, getSquareXPosFromAlign, pointIsWithinBB } from "../../../common/utils.js";
33
import type { Theme } from "../../../index.js";
4-
import { roundedRect } from "./data-grid-lib.js";
54
import { BooleanEmpty, BooleanIndeterminate, type BaseGridCell } from "../data-grid-types.js";
5+
import { roundedRect } from "./data-grid-lib.js";
66

77
export function drawCheckbox(
88
ctx: CanvasRenderingContext2D,
@@ -15,13 +15,13 @@ export function drawCheckbox(
1515
highlighted: boolean,
1616
hoverX: number = -20,
1717
hoverY: number = -20,
18-
maxSize: number = 32,
18+
maxSize: number | undefined = undefined,
1919
alignment: BaseGridCell["contentAlign"] = "center",
2020
style: "circle" | "square" = "square"
2121
) {
2222
const centerY = Math.floor(y + height / 2);
23-
const rectBordRadius = style === "circle" ? 10_000 : theme.roundingRadius ?? 4;
24-
let checkBoxWidth = getSquareWidth(maxSize, height, theme.cellVerticalPadding);
23+
const rectBordRadius = style === "circle" ? 10_000 : (theme.roundingRadius ?? 4);
24+
let checkBoxWidth = getSquareWidth(maxSize ?? theme.checkboxMaxSize, height, theme.cellVerticalPadding);
2525
let checkBoxHalfWidth = checkBoxWidth / 2;
2626
const posX = getSquareXPosFromAlign(alignment, x, width, theme.cellHorizontalPadding, checkBoxWidth);
2727
const bb = getSquareBB(posX, centerY, checkBoxWidth);

0 commit comments

Comments
 (0)