Themes

How the grid theming system works. Themes are plain objects that map to CSS custom properties on the grid container. Two built-in themes (light and dark) are provided; register custom themes for full control.

A theme is a flat object of CSS values. The grid converts each key to a CSS custom property and applies it to the grid container. The grid's stylesheet references these variables for colors, spacing, borders, and typography.

Using a theme

Pass the theme name via GridConfig.theme:

const grid = new Grid({ theme: "dark" }, mountEl);

The grid ships with two built-in themes: "light" (default) and "dark".

Theme interface

A Theme is a plain Record<string, string | number>. Each key is converted to a CSS variable by:

  1. Inserting a - before each uppercase letter and lowercasing
  2. Prepending --

For example, columnFacetBackgroundColor becomes --column-facet-background-color.

Built-in themes

Light theme

const lightTheme: Theme = {
  cellPaddingY: 6,
  cellPaddingX: 10,
  verticalBorderWidth: 1,
  verticalBorderColor: "#ccd0da",
  horizontalBorderWidth: 1,
  horizontalBorderColor: "#ccd0da",
  fontSize: 12,
  fontWeight: "normal",
  columnFacetBackgroundColor: "#e6e9ef",
  columnFacetFontWeight: 500,
  columnFacetTextColor: "#5c5f77",
  rowFacetBackgroundColor: "#eff1f5",
  valueTextColor: "#4c4f69",
  valueBackgroundColor: "#FAFAFA",
  facetHeaderBackgroundColor: "#e6e9ef",
  facetHeaderFontColor: "#5c5f77",
  facetHeaderFontSize: 12,
  facetHeaderFontWeight: "normal",
  dataLeftBorderWidth: 1,
  dataLeftBorderColor: "#ccd0da",
  dataTopBorderWidth: 1,
  dataTopBorderColor: "#ccd0da",
  errOverlayBackgroundColor: "rgba(255, 255, 255, 0.9)",
  errOverlayTextColor: "#d81b60",
};

Dark theme

const darkTheme: Theme = {
  cellPaddingY: 6,
  cellPaddingX: 10,
  verticalBorderWidth: 1,
  verticalBorderColor: "#414559",
  horizontalBorderWidth: 1,
  horizontalBorderColor: "#414559",
  fontSize: 12,
  fontWeight: "normal",
  columnFacetBackgroundColor: "#292c3c",
  columnFacetFontWeight: 500,
  columnFacetTextColor: "#cdd6f4",
  rowFacetBackgroundColor: "#303446",
  valueTextColor: "#c6d0f5",
  valueBackgroundColor: "#303446",
  facetHeaderBackgroundColor: "#292c3c",
  facetHeaderFontColor: "#cdd6f4",
  facetHeaderFontSize: 12,
  facetHeaderFontWeight: "normal",
  dataLeftBorderWidth: 1,
  dataLeftBorderColor: "#414559",
  dataTopBorderWidth: 1,
  dataTopBorderColor: "#414559",
  errOverlayBackgroundColor: "rgba(48, 52, 70, 0.9)",
  errOverlayTextColor: "#ff7043",
};

Theme properties reference

PropertyCSS variableApplies to
cellPaddingY--cell-padding-yVertical padding on all cells
cellPaddingX--cell-padding-xHorizontal padding on all cells
verticalBorderWidth--vertical-border-widthRight border on facet and data cells
verticalBorderColor--vertical-border-colorRight border color; also used for resize handles
horizontalBorderWidth--horizontal-border-widthBottom border on column facets, row facets, data cells, and headers
horizontalBorderColor--horizontal-border-colorBottom border color
fontSize--font-sizeBase font size for all cells
fontWeight--font-weightBase font weight for all cells
columnFacetBackgroundColor--column-facet-background-colorBackground of column facet (header) cells
columnFacetFontWeight--column-facet-font-weightFont weight of column facet cells
columnFacetTextColor--column-facet-text-colorText color of column facet cells and row facet cells
rowFacetBackgroundColor--row-facet-background-colorBackground of row facet cells
valueTextColor--value-text-colorText color of data cells
valueBackgroundColor--value-background-colorBackground of data cells
facetHeaderBackgroundColor--facet-header-background-colorBackground of corner/header cells
facetHeaderFontColor--facet-header-font-colorText color of corner/header cells
facetHeaderFontSize--facet-header-font-sizeFont size of corner/header cells
facetHeaderFontWeight--facet-header-font-weightFont weight of corner/header cells
dataLeftBorderWidth--data-left-border-widthLeft border on the first data column (separator between row facets and data)
dataLeftBorderColor--data-left-border-colorLeft border color of the first data column
dataTopBorderWidth--data-top-border-widthTop border on the first data row (separator between column facets and data)
dataTopBorderColor--data-top-border-colorTop border color of the first data row
errOverlayBackgroundColor--err-overlay-background-colorBackground of error overlay
errOverlayTextColor--err-overlay-text-colorText color of error overlay

Registering a custom theme

Use registerTheme(name, theme) to add a new theme. Then pass its name to GridConfig.theme.

import { registerTheme } from "grid";

registerTheme("corporate", {
  cellPaddingY: 8,
  cellPaddingX: 12,
  verticalBorderWidth: 1,
  verticalBorderColor: "#e0e0e0",
  horizontalBorderWidth: 1,
  horizontalBorderColor: "#e0e0e0",
  fontSize: 13,
  fontWeight: "normal",
  columnFacetBackgroundColor: "#f5f5f5",
  columnFacetFontWeight: 600,
  columnFacetTextColor: "#333",
  rowFacetBackgroundColor: "#fafafa",
  valueTextColor: "#222",
  valueBackgroundColor: "#fff",
  facetHeaderBackgroundColor: "#f5f5f5",
  facetHeaderFontColor: "#333",
  facetHeaderFontSize: 13,
  facetHeaderFontWeight: 600,
  dataLeftBorderWidth: 2,
  dataLeftBorderColor: "#bbb",
  dataTopBorderWidth: 2,
  dataTopBorderColor: "#bbb",
  errOverlayBackgroundColor: "rgba(255, 255, 255, 0.95)",
  errOverlayTextColor: "#c62828",
});

const grid = new Grid({ theme: "corporate" }, mountEl);

You can also add custom properties that don't exist in the built-in themes. Any key on the object becomes a CSS variable on the grid container, which you can reference in custom cell renderers or via selection rule style functions:

registerTheme("custom", {
  ...lightTheme,
  highlightColor: "#ffeb3b",
});

// Use in a selection rule style function:
grid.selectAll((dim, val) => val === "Total")
  .style((el) => {
    el.style.backgroundColor = "var(--highlight-color)";
  });

Theme storage

Themes are stored in a global registry on window.__dataflow_grid__.themes. This means themes registered in one module are available to all grid instances on the page. The registry persists for the page lifetime.

On this page