Conditional formatting
Draw data bars / color scales / status chips with one column option, conditionalFormat
A lightweight helper corresponding to Excel's "Conditional Formatting". With one column option, conditionalFormat, data bars (amounts), color scales (amounts, or direction from a baseline) and status chips (states) are layered on the default cell rendering. min / max are computed automatically from the visible rows (fixed values work too).
const columns: GridColumn<Row>[] = [
{ key: 'qty', title: 'Stock', width: 100, align: 'right', conditionalFormat: { dataBar: {} } },
{ key: 'delta', title: 'MoM %', width: 100, conditionalFormat: { colorScale: { type: 'diverging', min: -30, mid: 0, max: 30 } } },
{ key: 'price', title: 'Unit price', width: 100, conditionalFormat: { colorScale: {} } },
{ key: 'status', title: 'Status', width: 110, conditionalFormat: { chips: { Active: 'good', Stopped: 'warning', Discontinued: 'critical' } } },
];Demo
Data bars (dataBar)
Shows the size of a value with a band in the background. Without min / max, the minimum / maximum of the numbers in the view rows (after filtering and sorting; the loaded range with SSRM) are used, and they're recomputed when editing or filtering changes them. Columns with negative values extend left from a 0 axis, and columns with only negative values use the right edge as the axis (the same as Excel).
color/negativeColor: band colors (by default the tokens--ssg-cf-bar/--ssg-cf-bar-negative).showValue: false: show only the band without text.
Color scales (colorScale)
Colors the cell background by value. The text color doesn't change, and it's limited to light steps to keep contrast.
type: 'sequential'(default): light → dark of one hue.type: 'diverging':mid(when omitted, 0 ifmin < 0 < max, otherwise the middle) is the neutral color, and the negative and positive sides darken in different hues.colors: replace the color steps with an array of CSS colors ([light, dark]/[negative, neutral, positive]). Interpolation uses CSScolor-mix(), so tokens (var(--ssg-accent)) can be mixed in as is.
Status chips (chips)
A map from value (String(value)) to tone, or a function returning a chip from the cell context (the same as the function form of cellClassName). Tones are 'neutral' | 'info' | 'good' | 'warning' | 'critical', and chips are pills with an icon + label (meaning isn't carried by color alone). In columns narrower than 80px, the padding shrinks and the icon is dropped to give the text priority (since 1.0.2).
chips: {
Active: 'good',
Stopped: { tone: 'warning', label: 'Paused' },
Discontinued: { tone: 'critical', icon: false },
Internal: { color: '#7c3aed' }, // any color
}
// function form
chips: ({ row }) => (row.stock === 0 ? 'critical' : null)Without label, the cell's display text is used (after valueFormatter; find in cells highlighting stays too). With label, find in cells searches the label shown on screen too. Values not in the map stay plain text.
Look and scope
- One column can have both
dataBarandcolorScale(the band goes over the background color). Explicit styles fromcellClassName/getRowClassNamewin over conditional formatting. - It's a display-only feature and doesn't affect CSV / TSV / the clipboard /
getExportData/ sorting / filtering. - In
renderCellcolumns, data bars and color scales are drawn in the cell background, andrenderCelldraws the contents (chipsandshowValue: falseofdataBardon't apply). - With
motionat'on', band lengths and background colors change smoothly as values change. - Colors can be changed with tokens:
--ssg-cf-bar/--ssg-cf-seq-min/--ssg-cf-seq-max/--ssg-cf-div-negative/--ssg-cf-div-mid/--ssg-cf-div-positive/--ssg-cf-<tone>/--ssg-cf-<tone>-bg. The dark theme has separate values with re-chosen steps (Theming). - State classes:
.ssg-body-cell--cf-bar/.ssg-cf-bar(--negative)/.ssg-body-cell--cf-scale/.ssg-chip(--<tone>).
Custom rendering
Draw cells, headers, top / bottom bars, editors and the context menu freely with React / Solid components
Range decorations
Draw a box and a name tag on a range decided by row and column keys with rangeDecorations. Marks for ranges in review, places someone else is editing, or what AI changed