# Theming and appearance

> Theming with five color seeds, light and dark schemes, compact density, the font family, a tinted neutral ramp and region surfaces, plus grid lines, alternate rows, hover, row and header height, text wrap, custom icons and stable CSS hooks.

Canonical: https://salmonui.dev/docs/data-grid/appearance

The theme is a small set of inputs on `ThemeProvider`: five semantic color
seeds and a color scheme, plus four optional settings: `density`,
`fontFamily`, a `neutral` tint and region `surfaces`. Every other value is
derived from them and written as `--salmon-*` custom properties, and every
derived color keeps the contrast guarantees. There is no radius, spacing,
type scale or token-table input: each setting is one value, not a table.

```ts
interface SalmonThemeInput {
  colors?: { primary?; success?; warning?; danger?; info? }; // hex seeds
  colorScheme?: 'light' | 'dark' | 'auto';
  density?: 'default' | 'compact';
  fontFamily?: string;
  neutral?: { hue?: number; chroma?: number };
  surfaces?: { sidebar?; appBar?; tableHeader? }; // hex or 'primary'
}
```

## Color seeds

`ThemeProvider` takes `primary`, `success`, `warning`, `danger` and `info`
as opaque hex colors. Each seed becomes a tonal scale; neutrals,
surfaces, borders, hover, selection and the focus ring are derived from
it, so a seed cannot break the contrast guarantees: at least 7:1 for body
text, 4.5:1 for secondary text and 3:1 for borders, focus ring and selection
in both schemes. Invalid seeds (named colors, alpha, `oklch()`, CSS
variables) fall back to the default with a development warning.

```tsx
import { ThemeProvider } from '@salmonui/core/theme';
import { ThemeStyle } from '@salmonui/core/server';

const theme = { colors: { primary: '#0f766e', danger: '#be123c' }, colorScheme: 'auto' } as const;

<ThemeStyle theme={theme} />
<ThemeProvider theme={theme}>
  <DataGrid aria-label="Orders" data={orders} columns={columns} />
</ThemeProvider>
```

The scheme is `light`, `dark` or `auto` (follows `prefers-color-scheme`).
`ThemeStyle` emits the scope's variables server-side as a hoisted,
deduplicated `<style>`, so server-rendered pages paint in the right colors
before hydration; the default theme ships precompiled in
`@salmonui/core/styles.css`. Application CSS may read the
`--salmon-*` variables but not set them.

### Live demo: Theme colors and contrast

Live demo: https://salmonui.dev/demos/data-grid/theme-colors

The five semantic color seeds and the color scheme are the whole theme input; the derived palette keeps text, border, focus and selection contrast for any seed, checked live below the grid.

`Demo.tsx`:

```tsx
'use client';

import { useEffect, useRef, useState } from 'react';
import { Button } from '@salmonui/buttons/button';
import { ColorField } from '@salmonui/inputs/color-picker';
import { DataGrid, type DataGridColumn } from '@salmonui/data-grid';
import { Select } from '@salmonui/dropdowns/select';
import { ThemeStyle } from '@salmonui/core/server';
import { defaultSalmonTheme, ThemeProvider, type SalmonColorScheme, type SalmonHexColor } from '@salmonui/core/theme';
import { createOrders, type Order } from '../../lib/fixtures';

const orders = createOrders(120, 21);

const columns: DataGridColumn<Order>[] = [
  { type: 'selection' },
  { field: 'id', header: 'Order', primaryKey: true, width: 110 },
  { field: 'customer', header: 'Customer', width: 150 },
  { field: 'priority', header: 'Priority', width: 100, cellClassName: (ctx) => (ctx.value === 'High' ? 'demo-cell--negative' : undefined) },
  { field: 'amount', header: 'Amount', type: 'number', format: 'C2', align: 'end', width: 120 },
  { field: 'shipped', header: 'Shipped', type: 'boolean', displayAsCheckbox: true, align: 'center', width: 100 },
];

const SCHEMES = [
  { value: 'light', label: 'light' },
  { value: 'dark', label: 'dark' },
  { value: 'auto', label: 'auto' },
];

type SeedName = keyof typeof defaultSalmonTheme.colors;
const seedNames: readonly SeedName[] = ['primary', 'success', 'warning', 'danger', 'info'];

/** Pairs the theme guarantees: foreground, background, minimum ratio. */
const checks: readonly (readonly [string, string, number])[] = [
  ['--salmon-text-primary', '--salmon-surface-raised', 7],
  ['--salmon-text-secondary', '--salmon-surface-raised', 4.5],
  ['--salmon-text-primary', '--salmon-surface-selected', 7],
  ['--salmon-border-selected', '--salmon-surface-raised', 3],
  ['--salmon-state-focus-ring', '--salmon-surface-raised', 3],
  ['--salmon-color-primary-on', '--salmon-color-primary', 4.5],
  ['--salmon-color-danger-text', '--salmon-surface-base', 4.5],
];

function luminance(hex: string): number {
  const value = hex.replace('#', '');
  const full = value.length === 3 ? [...value].map((c) => c + c).join('') : value;
  const channel = (i: number) => {
    const c = parseInt(full.slice(i, i + 2), 16) / 255;
    return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
  };
  return 0.2126 * channel(0) + 0.7152 * channel(2) + 0.0722 * channel(4);
}

function contrast(a: string, b: string): number {
  const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x) as [number, number];
  return (hi + 0.05) / (lo + 0.05);
}

interface Reading {
  readonly pair: string;
  readonly ratio: number;
  readonly min: number;
}

export default function ThemeColorsDemo() {
  const [seeds, setSeeds] = useState<Record<SeedName, SalmonHexColor>>({ ...defaultSalmonTheme.colors });
  const [scheme, setScheme] = useState<SalmonColorScheme>('light');
  const [readings, setReadings] = useState<readonly Reading[]>([]);
  const scope = useRef<HTMLDivElement | null>(null);
  const theme = { colors: seeds, colorScheme: scheme };

  // Reads the derived variables after commit (never during render) and checks the contrast guarantees.
  useEffect(() => {
    const root = scope.current?.querySelector('.salmon-theme-scope');
    if (!root) return;
    const style = getComputedStyle(root);
    const read = (name: string) => style.getPropertyValue(name).trim();
    setReadings(checks.map(([fg, bg, min]) => ({ pair: `${fg} on ${bg}`, ratio: contrast(read(fg), read(bg)), min })));
  }, [seeds, scheme]);

  return (
    <>
      <div className="demo-toolbar">
        {seedNames.map((name) => (
          <label key={name}>
            {name}
            <ColorField
              aria-label={name}
              valueFormat="hex"
              value={seeds[name]}
              onValueChange={(value) => value != null && setSeeds({ ...seeds, [name]: value as SalmonHexColor })}
              style={{ inlineSize: 128 }}
            />
          </label>
        ))}
        <label>
          Scheme
          <Select aria-label="Scheme" data={SCHEMES} value={scheme} onValueChange={(value) => value != null && setScheme(value as SalmonColorScheme)} />
        </label>
        <Button variant="outline" onClick={() => setSeeds({ ...defaultSalmonTheme.colors })}>
          Reset seeds
        </Button>
      </div>
      {/* The five seeds and the scheme are the whole theme input; ThemeStyle emits the scope's variables. */}
      <ThemeStyle theme={theme} />
      <div ref={scope}>
        <ThemeProvider theme={theme}>
          <DataGrid<Order>
            aria-label="Orders in the chosen theme colors"
            data={orders}
            columns={columns}
            height={300}
            locale="en-US"
            currency="USD"
            timeZone="UTC"
            selection={{ multiple: true, rowIds: ['ORD-10001', 'ORD-10002'] }}
          />
          <table className="demo-contrast" aria-label="Contrast of the derived colors">
            <thead>
              <tr>
                <th scope="col">Pair</th>
                <th scope="col">Ratio</th>
                <th scope="col">Minimum</th>
                <th scope="col">Result</th>
              </tr>
            </thead>
            <tbody>
              {readings.map((r) => (
                <tr key={r.pair}>
                  <td>
                    <code>{r.pair}</code>
                  </td>
                  <td>{r.ratio.toFixed(2)}:1</td>
                  <td>{r.min}:1</td>
                  <td data-result={r.ratio >= r.min ? 'pass' : 'fail'}>{r.ratio >= r.min ? 'Pass' : 'Fail'}</td>
                </tr>
              ))}
            </tbody>
          </table>
        </ThemeProvider>
      </div>
    </>
  );
}
```

## Density

`density: 'compact'` tightens every control and Data Grid row; `'default'`
is the regular size. Density does not replace the component `size` prop:
each `size` has a default and a compact metric set, so `size` picks the
step and density picks the set.

| `size` | `default`: height, inline padding | `compact`: height, inline padding |
| --- | --- | --- |
| `sm` | 24px, 8px | 20px, 6px |
| `md` | 32px, 12px | 28px, 10px |
| `lg` | 40px, 16px | 36px, 14px |

- Buttons, text fields, selects, comboboxes, date and time pickers, tags
  and every other single-line control follow the matrix. Menu, listbox,
  tree view and navigation items, pager buttons, toolbars and icon buttons
  use the `md` height; tabs are 4px taller than it.
- The Data Grid default `rowHeight` / `headerHeight` are 36 / 40 px at
  `default` and 32 / 36 px at `compact`, and cell and header text is 13px
  instead of 14px (Tree Grid and Pivot Table render through the same
  cells). An explicit `rowHeight` or `headerHeight` prop always wins.
- Spacing, radius, type scale and icon sizes stay the same: compact is
  tighter controls and rows, not a different layout.
- A nested `ThemeProvider` that does not set `density` inherits it, so one
  setting at the root covers the whole application, and a compact panel
  inside a default page is one nested provider.

The metrics are CSS variables (`--salmon-control-height-sm|md|lg`,
`--salmon-control-padding-sm|md|lg`, `--salmon-font-size-cell`) that the
default theme does not emit: components read them with the default value
as a fallback, so an application that never sets `density` pays nothing.
Application CSS reads them the same way, for example
`min-block-size: var(--salmon-control-height-md, 32px)`.

### Live demo: Theme density

Live demo: https://salmonui.dev/demos/data-grid/theme-density

The same buttons, text field, select, date picker, tabs and Data Grid under density default and compact side by side, with the measured control, row and header heights.

`Demo.tsx`:

```tsx
'use client';

import { useEffect, useRef, useState } from 'react';
import { Button } from '@salmonui/buttons/button';
import { DataGrid, type DataGridColumn } from '@salmonui/data-grid';
import { DatePicker } from '@salmonui/calendars/date-picker';
import { Select } from '@salmonui/dropdowns/select';
import { Tab, TabList, TabPanel, Tabs } from '@salmonui/navigation/tabs';
import { TextField } from '@salmonui/inputs/text-field';
import { ThemeStyle } from '@salmonui/core/server';
import { ThemeProvider, type SalmonDensity } from '@salmonui/core/theme';
import { createOrders, type Order } from '../../lib/fixtures';

const orders = createOrders(6, 7);

const columns: DataGridColumn<Order>[] = [
  { field: 'id', header: 'Order', primaryKey: true, width: 110 },
  { field: 'customer', header: 'Customer', width: 130 },
  { field: 'amount', header: 'Amount', type: 'number', format: 'C2', align: 'end', width: 110 },
];

const STATUSES = [
  { value: 'paid', label: 'Paid' },
  { value: 'pending', label: 'Pending' },
  { value: 'refunded', label: 'Refunded' },
];

const DENSITIES: readonly SalmonDensity[] = ['default', 'compact'];

interface Metrics {
  readonly button: number;
  readonly field: number;
  readonly row: number;
  readonly header: number;
}

/** One column of controls under its own density scope. */
function Column({ density }: { density: SalmonDensity }) {
  const ref = useRef<HTMLDivElement | null>(null);
  const [metrics, setMetrics] = useState<Metrics | null>(null);
  const theme = { density };

  // Measures the rendered heights after commit (never during render).
  useEffect(() => {
    const root = ref.current;
    if (!root) return;
    const height = (selector: string) => Math.round(root.querySelector(selector)?.getBoundingClientRect().height ?? 0);
    const frame = requestAnimationFrame(() =>
      setMetrics({
        button: height('.salmon-button[data-size="md"]'),
        field: height('.salmon-text-field .salmon-input-group'),
        row: height('.salmon-data-grid-row'),
        header: height('.salmon-data-grid-header-row'),
      }),
    );
    return () => cancelAnimationFrame(frame);
  }, []);

  return (
    <section ref={ref} aria-labelledby={`density-${density}`} data-density={density} style={{ display: 'grid', gap: 12, alignContent: 'start', minInlineSize: 0 }}>
      <h3 id={`density-${density}`} style={{ margin: 0, fontSize: 'var(--salmon-font-size-md)' }}>
        <code>density: &apos;{density}&apos;</code>
      </h3>
      <ThemeStyle theme={theme} />
      <ThemeProvider theme={theme}>
        <div style={{ display: 'grid', gap: 12 }}>
          <div style={{ display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: 8 }}>
            <Button size="sm">Small</Button>
            <Button size="md" tone="primary">
              Medium
            </Button>
            <Button size="lg" variant="outline">
              Large
            </Button>
          </div>
          <TextField label="Keyword" placeholder="Order, customer or email" />
          <div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
            <Select aria-label={`Status (${density})`} data={STATUSES} placeholder="All statuses" style={{ inlineSize: 150 }} />
            <DatePicker aria-label={`Updated (${density})`} defaultValue="2026-11-24" />
          </div>
          <Tabs defaultValue="orders">
            <TabList aria-label={`Sections (${density})`}>
              <Tab value="orders">Orders</Tab>
              <Tab value="returns">Returns</Tab>
              <Tab value="history">History</Tab>
            </TabList>
            <TabPanel value="orders">Recent orders.</TabPanel>
            <TabPanel value="returns">Open returns.</TabPanel>
            <TabPanel value="history">Order history.</TabPanel>
          </Tabs>
          <DataGrid<Order> aria-label={`Orders (${density} density)`} data={orders} columns={columns} height={260} locale="en-US" currency="USD" timeZone="UTC" />
        </div>
      </ThemeProvider>
      <p className="demo-status" data-metrics={metrics ? `${metrics.button},${metrics.field},${metrics.row},${metrics.header}` : undefined}>
        {metrics
          ? `Button ${metrics.button}px, field ${metrics.field}px, grid row ${metrics.row}px, grid header ${metrics.header}px`
          : 'Measuring…'}
      </p>
    </section>
  );
}

export default function ThemeDensityDemo() {
  return (
    <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(min(100%, 340px), 1fr))', gap: 24 }}>
      {DENSITIES.map((density) => (
        <Column key={density} density={density} />
      ))}
    </div>
  );
}
```

## Font family

`fontFamily` sets `--salmon-font-sans`, the family every component uses.
The value is a CSS `font-family` list. The application loads the font
itself (with `@font-face`, a font service or `next/font`), because Salmon
UI ships no font files; end the list with a system fallback so text
renders before the font arrives.

```ts
const theme = { fontFamily: 'Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif' };
```

Only letters, digits, spaces, commas, quotes, dots, hyphens and
underscores are accepted. Anything else (a semicolon, braces, `url()`) is
rejected with a development warning and the system stack is used. Unset,
a nested scope inherits the enclosing scope's font and the root uses the
system stack. The type scale (sizes, weights, line heights)
does not change.

## Neutral tint

Neutrals (surfaces, borders, text, hover) are near-achromatic by default,
leaning slightly toward the primary hue. `neutral` tints the whole ramp:

- `hue` in degrees (any number, taken modulo 360). Unset, the primary hue.
- `chroma` in OKLCH, clamped to `[0, 0.04]` so neutrals stay neutral.

`neutral: { chroma: 0.032 }` with a teal primary such as `#0e4d5c` gives
blue-green grays for text, borders and the page background. The tinted
ramp goes through the same contrast pickers as the default one, so body
text, secondary text, borders, the focus ring and selection keep 7:1,
4.5:1 and 3:1 in both schemes whatever the tint.

## Surfaces

`surfaces` gives three application regions their own background with a
derived foreground:

| Surface | Region | The attribute comes from |
| --- | --- | --- |
| `sidebar` | The `SidebarLayout` panel and the navigation inside it | `SidebarPanel` |
| `appBar` | The application's top bar | Your `<header>` |
| `tableHeader` | The Data Grid header (also Tree Grid and Pivot Table) | The grid header |

Each value is a hex color, or `'primary'` for the resolved primary seed.
The seed is used as is in both color schemes; the theme derives the rest
of the region's colors from it:

| Role | Derived as |
| --- | --- |
| Foreground | Near-white on a dark seed, near-black on a light one: at least 7:1 against the background and 4.5:1 against hover and selected |
| Muted text | The step closest to the background that keeps 4.5:1 (group headings, secondary text, placeholders) |
| Hover, selected | The seed moved in lightness, with the foreground still readable on them |
| Border | A divider step toward the foreground |
| Focus ring, accents | The theme focus ring and primary accents when they keep 3:1 on the seed, else the foreground |

So a sort arrow in a primary-colored header, or a checked checkbox or a
selected item in a near-black sidebar, stays visible without any override.

The surface applies to the element carrying
`data-salmon-surface="sidebar"`, `"app-bar"` or `"table-header"`: the theme
emits one rule per set surface that paints the element and remaps the
color variables for its subtree, so every component inside follows it.
`SidebarPanel` and the Data Grid header carry the attribute already; put
`data-salmon-surface="app-bar"` on your own top bar:

```tsx
<header className="salmon-app-bar" data-salmon-surface="app-bar">…</header>
```

Without the surface in the theme the attribute matches nothing and costs
nothing. Overlays opened from inside a surface (menus, popovers, date
pickers) are portaled out of it and keep the regular overlay colors.

For custom navigation markup, each set surface also exposes its derived
colors on the theme scope:

| Variable | Meaning |
| --- | --- |
| `--salmon-surface-<name>-bg`, `-fg`, `-muted` | Background, text, secondary text |
| `--salmon-surface-<name>-hover` | Item hover background |
| `--salmon-surface-<name>-selected-bg`, `-selected-fg` | Selected item background and text |
| `--salmon-surface-<name>-border` | Dividers |

with `<name>` one of `sidebar`, `app-bar` and `table-header`:

```css
.app-nav a { color: var(--salmon-surface-sidebar-fg); }
.app-nav a:hover { background: var(--salmon-surface-sidebar-hover); }
.app-nav a[aria-current='page'] {
  background: var(--salmon-surface-sidebar-selected-bg);
  color: var(--salmon-surface-sidebar-selected-fg);
}
.app-nav h2 { color: var(--salmon-surface-sidebar-muted); }
```

Reading these variables is supported; setting them is not. A nested
`ThemeProvider` that does not set `surfaces` inherits the enclosing
scope's surfaces. For a region that should be fully in the dark scheme
(every role, not only its background), wrap it in a nested
`ThemeProvider` with `colorScheme: 'dark'` instead.

### Live demo: Theme surfaces

Live demo: https://salmonui.dev/demos/data-grid/theme-surfaces

A SidebarLayout with a near-black sidebar surface, a white app bar surface and a primary-colored Data Grid header, on a teal-tinted neutral ramp, all from one theme object.

`Demo.tsx`:

```tsx
'use client';

import type { ReactNode } from 'react';
import { Avatar } from '@salmonui/layout/avatar';
import { BreadcrumbItem, Breadcrumbs } from '@salmonui/navigation/breadcrumbs';
import { Button } from '@salmonui/buttons/button';
import { DataGrid, type DataGridColumn } from '@salmonui/data-grid';
import { SidebarLayout, SidebarMain, SidebarPanel } from '@salmonui/navigation/sidebar-layout';
import { SidebarMenu, type SidebarMenuEntry, type SidebarMenuItem } from '@salmonui/navigation/sidebar-menu';
import { ThemeStyle } from '@salmonui/core/server';
import { ThemeProvider, type SalmonThemeInput } from '@salmonui/core/theme';
import { createOrders, type Order } from '../../lib/fixtures';

const theme: SalmonThemeInput = {
  colors: { primary: '#0e4d5c', success: '#0c8f54', warning: '#d4690b', danger: '#d62f23', info: '#0e4d5c' },
  colorScheme: 'light',
  neutral: { chroma: 0.032 },
  surfaces: { sidebar: '#192225', appBar: '#ffffff', tableHeader: 'primary' },
};

const orders = createOrders(40, 11);

const columns: DataGridColumn<Order>[] = [
  { type: 'selection' },
  { field: 'id', header: 'Order', primaryKey: true, width: 110 },
  { field: 'customer', header: 'Customer', width: 140 },
  { field: 'product', header: 'Product', width: 140 },
  { field: 'amount', header: 'Amount', type: 'number', format: 'C2', align: 'end', width: 110 },
];

// Placeholder links target this demo's own title, which exists on both the
// docs page and the demo page, so no link dangles in the static export.
const HREF = '#demo-theme-surfaces-title';

const glyph = (d: string) => (
  <svg viewBox="0 0 16 16" width="16" height="16" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
    <path d={d} />
  </svg>
);

const leaf = (id: string, label: string, icon: ReactNode): SidebarMenuItem => ({ id, label, href: HREF, icon });

const MENU: SidebarMenuEntry[] = [
  {
    type: 'group',
    id: 'workspace',
    label: 'Workspace',
    children: [
      leaf('overview', 'Overview', glyph('M2 2h5v5H2zM9 2h5v5H9zM2 9h5v5H2zM9 9h5v5H9z')),
      leaf('orders', 'Orders', glyph('M2 3h1.5l1.5 7h8l1.5-5H4.5M6 13.5h.01M12 13.5h.01')),
      leaf('customers', 'Customers', glyph('M6 7a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5zM1.5 14c0-2.5 2-4.5 4.5-4.5s4.5 2 4.5 4.5M11 2.5a2.5 2.5 0 0 1 0 4.5M12.5 9.8c1.2.6 2 2 2 4.2')),
    ],
  },
  {
    type: 'group',
    id: 'system',
    label: 'System',
    children: [
      leaf('settings', 'Settings', glyph('M8 10a2 2 0 1 0 0-4 2 2 0 0 0 0 4zM8 1.5v2M8 12.5v2M1.5 8h2M12.5 8h2M3.4 3.4l1.4 1.4M11.2 11.2l1.4 1.4M3.4 12.6l1.4-1.4M11.2 4.8l1.4-1.4')),
      leaf('help', 'Help', glyph('M8 14.5a6.5 6.5 0 1 0 0-13 6.5 6.5 0 0 0 0 13zM6 6a2 2 0 1 1 2.5 2c-.3.1-.5.4-.5.7V10M8 12h.01')),
    ],
  },
];

export default function ThemeSurfacesDemo() {
  return (
    <>
      <ThemeStyle theme={theme} />
      <ThemeProvider theme={theme}>
        <SidebarLayout size="13rem" style={{ blockSize: 420, border: '1px solid var(--salmon-border-default)', borderRadius: 'var(--salmon-radius-lg)', overflow: 'hidden' }}>
          {/* SidebarPanel carries data-salmon-surface="sidebar"; SidebarMenu reads the --salmon-surface-sidebar-* variables. */}
          <SidebarPanel navigation aria-label="Admin navigation">
            <SidebarMenu landmark={false} items={MENU} defaultSelected="orders" />
          </SidebarPanel>
          <SidebarMain style={{ display: 'flex', flexDirection: 'column', minBlockSize: 0, background: 'var(--salmon-surface-base)' }}>
            {/* The application's own top bar opts in to the app bar surface. */}
            <header className="salmon-app-bar" data-salmon-surface="app-bar" style={{ justifyContent: 'space-between' }}>
              <Breadcrumbs>
                <BreadcrumbItem href={HREF}>Workspace</BreadcrumbItem>
                <BreadcrumbItem>Orders</BreadcrumbItem>
              </Breadcrumbs>
              <span style={{ display: 'inline-flex', alignItems: 'center', gap: 8 }}>
                <Avatar name="Olivia Lin" size={22} shape="circle" />
                Olivia
              </span>
            </header>
            <div style={{ display: 'grid', gap: 8, padding: 12, minBlockSize: 0, flex: '1 1 auto', gridTemplateRows: 'auto minmax(0, 1fr)' }}>
              <div style={{ display: 'flex', gap: 8 }}>
                <Button tone="primary">New order</Button>
                <Button variant="outline">Export</Button>
              </div>
              {/* The grid header carries data-salmon-surface="table-header": the primary seed with a derived foreground. */}
              <DataGrid<Order>
                aria-label="Orders"
                data={orders}
                columns={columns}
                height="100%"
                sorting
                selection={{ multiple: true, rowIds: ['ORD-10002'] }}
                locale="en-US"
                currency="USD"
                timeZone="UTC"
              />
            </div>
          </SidebarMain>
        </SidebarLayout>
      </ThemeProvider>
    </>
  );
}
```

## Theme like an admin template

A compact, teal-tinted admin layout with a dark sidebar, a white top bar
and a primary-colored table header is one theme object:

```tsx
import type { ReactNode } from 'react';
import { ThemeProvider, type SalmonThemeInput } from '@salmonui/core/theme';
import { ThemeStyle } from '@salmonui/core/server';
import { SidebarLayout, SidebarMain, SidebarPanel } from '@salmonui/navigation/sidebar-layout';

const theme: SalmonThemeInput = {
  colors: { primary: '#0e4d5c', success: '#0c8f54', warning: '#d4690b', danger: '#d62f23', info: '#0e4d5c' },
  density: 'compact',
  fontFamily: 'Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
  neutral: { chroma: 0.032 },
  surfaces: { sidebar: '#192225', appBar: '#ffffff', tableHeader: 'primary' },
};

export function AdminShell({ children }: { children: ReactNode }) {
  return (
    <>
      <ThemeStyle theme={theme} />
      <ThemeProvider theme={theme}>
        <SidebarLayout style={{ blockSize: '100dvh' }}>
          <SidebarPanel navigation aria-label="Main navigation">…</SidebarPanel>
          <SidebarMain render={(props) => <main {...props} />}>
            <header className="salmon-app-bar" data-salmon-surface="app-bar">…</header>
            {children}
          </SidebarMain>
        </SidebarLayout>
      </ThemeProvider>
    </>
  );
}
```

The sidebar, the app bar and every Data Grid header pick up their surfaces
from the attributes; controls and grid rows are compact; text uses Inter
once the application loads it.

## Design notes

### One theme, branded through the seeds

Salmon UI ships one neutral flat theme with automatic light and dark
schemes, branded through the seeds; each extra theme would be a
surface whose contrast and layout must be guaranteed separately. Pick the
seeds closest to the palette in use. High Contrast users get the operating
system's forced-colors mode, which the grid supports with system colors
(see [Accessibility](https://salmonui.dev/docs/data-grid/accessibility)).

### Customizing the theme

The five seeds and `colorScheme`, plus `density`, `fontFamily`, `neutral`
and `surfaces`, are the whole customization surface, and the demos above
are the preview. Set the seeds to your brand's primary and status colors.

### Size modes

The theme's `density` is the size mode: `'compact'` makes rows 32px and
headers 36px with 13px text (see [Density](https://salmonui.dev/docs/data-grid/appearance#density)). Row and header
heights also stay available as grid layout props for any other size: set
`rowHeight` and `headerHeight` on the `DataGrid` (the "Row size" control
below); an explicit prop wins over the density.

## Data Grid appearance

- `gridLines`: `'default'`, `'both'`, `'horizontal'`, `'vertical'` or
  `'none'`.
- `striped` (alternate row shading) and `highlightOnHover`, both default
  `true`.
- A fixed `rowHeight` (default 36 px, 32 px at compact density), or a
  per-row `getRowHeight` function, and `headerHeight` per header level
  (default 40 px, 36 px at compact density).
- `textWrap`: `'header'`, `'content'` or `'both'` (`true`) wraps text instead
  of truncating it. Content wrap needs measured rows: set
  `estimatedRowHeight` (see [Virtualization](https://salmonui.dev/docs/data-grid/virtualization)).
- `className` and `style` on the grid, and attributes on cells and headers,
  merge after the system classes. `classNames` and `styles` take
  one entry per part: `root`, `toolbar`, `header`, `headerCell`, `body`,
  `row`, `cell`, `footer`, `pager`, `groupDropArea`, `groupCaption`,
  `detailRow`, `columnMenu`, `contextMenu`, `filterMenu`, `editor` (the
  wrapper of each inline or dialog cell editor), `empty` and `loading`.
- The root carries `.salmon-data-grid` and each part a `.salmon-data-grid-<part>`
  class (`.salmon-data-grid-cell`, `.salmon-data-grid-header-cell`,
  `.salmon-data-grid-row`); BEM `__` marks only a sub-element
  (`.salmon-data-grid-toolbar__more`). These classes and the `data-*` state
  attributes are stable within a major version. Style parts
  through `classNames` / `styles`; targeting the classes directly is
  permitted but, like any visual override, unsupported.
- Every Salmon UI rule is in the `salmon` cascade layer, so your own
  unlayered CSS overrides it whatever the specificity or the import order:
  `.orders .salmon-data-grid-cell { padding-inline: 4px }` wins without
  `!important`. If your app uses cascade layers, order `salmon` before
  importing any Salmon UI stylesheet, for example `@layer reset, salmon,
  app;`. The order in which you import the family stylesheets does not
  matter.

### Live demo: Grid lines, striping, row height and theme

Live demo: https://salmonui.dev/demos/data-grid/appearance

Grid line modes, alternate rows, hover highlight, fixed and conditional row heights, row and header size props in place of size modes, text wrap, className/style passthrough, and the colors-only theme with light, dark and auto schemes.

`Demo.tsx`:

```tsx
'use client';

import { useState } from 'react';
import { Checkbox } from '@salmonui/inputs/checkbox';
import { DataGrid, type DataGridColumn, type DataGridLines, type DataGridTextWrap } from '@salmonui/data-grid';
import { Select } from '@salmonui/dropdowns/select';
import { ThemeStyle } from '@salmonui/core/server';
import { ThemeProvider, type SalmonColorScheme, type SalmonHexColor } from '@salmonui/core/theme';
import { createOrders, type Order } from '../../lib/fixtures';

const orders = createOrders(200, 3);

const columns: DataGridColumn<Order>[] = [
  { field: 'id', header: 'Order', primaryKey: true, width: 110 },
  { field: 'customer', header: 'Customer', width: 160 },
  { field: 'priority', header: 'Delivery priority', width: 100 },
  { field: 'note', header: 'Note', width: 180 },
  { field: 'amount', header: 'Amount', type: 'number', format: 'C2', align: 'end', width: 120 },
  { field: 'shipped', header: 'Shipped', type: 'boolean', displayAsCheckbox: true, align: 'center', width: 100 },
];

const lines: readonly DataGridLines[] = ['default', 'both', 'horizontal', 'vertical', 'none'];
const seeds: readonly SalmonHexColor[] = ['#c2410c', '#0f766e', '#4338ca', '#be185d'];
const wraps: readonly Exclude<DataGridTextWrap, true>[] = [false, 'header', 'content', 'both'];
// no size modes; row and header heights are plain layout props.
const sizes = { small: { rowHeight: 28, headerHeight: 32 }, default: { rowHeight: 36, headerHeight: 40 }, large: { rowHeight: 48, headerHeight: 52 } } as const;
type Size = keyof typeof sizes;
const lineItems = lines.map((value) => ({ value, label: value }));
const sizeItems = Object.keys(sizes).map((value) => ({ value, label: value }));
const wrapItems = wraps.map((value) => ({ value: String(value), label: value === false ? 'off' : value }));
const schemeItems = (['auto', 'light', 'dark'] as const).map((value) => ({ value, label: value }));
const seedItems = seeds.map((value) => ({ value, label: value }));

export default function AppearanceDemo() {
  const [gridLines, setGridLines] = useState<DataGridLines>('default');
  const [striped, setStriped] = useState(true);
  const [hover, setHover] = useState(true);
  const [compact, setCompact] = useState(false);
  const [size, setSize] = useState<Size>('default');
  const [wrap, setWrap] = useState<Exclude<DataGridTextWrap, true>>(false);
  const measured = wrap === 'content' || wrap === 'both';
  const [scheme, setScheme] = useState<SalmonColorScheme>('auto');
  const [primary, setPrimary] = useState<SalmonHexColor>('#c2410c');
  return (
    <>
      <div className="demo-toolbar">
        <label>
          Grid lines
          <Select aria-label="Grid lines" data={lineItems} value={gridLines} onValueChange={(value) => value != null && setGridLines(value as DataGridLines)} />
        </label>
        <Checkbox checked={striped} onCheckedChange={(checked) => setStriped(checked)}>
          Alternate rows
        </Checkbox>
        <Checkbox checked={hover} onCheckedChange={(checked) => setHover(checked)}>
          Hover highlight
        </Checkbox>
        <Checkbox checked={compact} onCheckedChange={(checked) => setCompact(checked)}>
          Conditional row height
        </Checkbox>
        <label>
          Row size
          <Select aria-label="Row size" data={sizeItems} value={size} onValueChange={(value) => value != null && setSize(value as Size)} />
        </label>
        <label>
          Text wrap
          <Select aria-label="Text wrap" data={wrapItems} value={String(wrap)} onValueChange={(value) => setWrap(wraps.find((w) => String(w) === value) ?? false)} />
        </label>
        <label>
          Scheme
          <Select aria-label="Scheme" data={schemeItems} value={scheme} onValueChange={(value) => value != null && setScheme(value as SalmonColorScheme)} />
        </label>
        <label>
          Primary seed
          <Select aria-label="Primary seed" data={seedItems} value={primary} onValueChange={(value) => value != null && setPrimary(value as SalmonHexColor)} />
        </label>
      </div>
      {/* Colors-only theme: seeds plus colorScheme. ThemeStyle emits the scope's --salmon-* variables (hoisted, deduplicated). */}
      <ThemeStyle theme={{ colors: { primary } }} />
      <ThemeProvider theme={{ colors: { primary }, colorScheme: scheme }}>
        <DataGrid<Order>
          // Switching between fixed, per-row and measured heights remounts the grid.
          key={measured ? 'measured' : compact ? 'compact' : 'fixed'}
          aria-label="Orders with configurable grid lines, striping and theme"
          data={orders}
          columns={columns}
          height={340}
          locale="en-US"
          currency="USD"
          timeZone="UTC"
          gridLines={gridLines}
          striped={striped}
          highlightOnHover={hover}
          className="demo-appearance"
          headerHeight={sizes[size].headerHeight}
          textWrap={wrap}
          {...(measured
            ? { estimatedRowHeight: sizes[size].rowHeight }
            : compact
              ? { getRowHeight: (row: Order) => (row.priority === 'High' ? 48 : 30) }
              : { rowHeight: sizes[size].rowHeight })}
        />
      </ThemeProvider>
    </>
  );
}
```

## Icons

The grid's icons are built-in SVG images drawn by the grid stylesheet: they
paint with the current text color, so they follow the theme, hover and
active states, dark mode and forced-colors mode, mirror in right-to-left
layouts, and add no markup to the page. There is no icon font; replace an
icon with the `icons` prop. It is a component
prop, not part of the theme:

```tsx
import { ArrowUp, ArrowDown, Menu } from './my-icons';

<DataGrid
  aria-label="Orders"
  data={orders}
  columns={columns}
  sorting
  columnMenu
  icons={{
    sortAscending: <ArrowUp aria-hidden />,
    sortDescending: <ArrowDown aria-hidden />,
    columnMenu: <Menu aria-hidden />,
    filtered: null, // hide the filtered-column dot
  }}
/>
```

| Name | Where |
| --- | --- |
| `sortAscending`, `sortDescending` | Sorted header and group chip |
| `filter`, `filtered` | Header filter button; marker of a filtered column without one |
| `columnMenu` | Header column menu button |
| `groupByColumn`, `ungroup` | Header group toggle; group chip remove button |
| `expanded`, `collapsed` | Group caption and detail row toggles |
| `pagerFirst`, `pagerPrevious`, `pagerNext`, `pagerLast` | Pager buttons |
| `submenu`, `check` | Menu items with a submenu; checked menu items |
| `close`, `overflow`, `dragHandle` | Dialog and sheet close; toolbar overflow; row drag handle |

- A node replaces the built-in inside its button, which keeps its
  accessible name, so mark the icon `aria-hidden`. `null` hides an icon; a
  name left out keeps the built-in.
- `DataGridIconsProvider` gives every grid below it the same icons (for example
  an application icon set); a grid's own `icons` merge over it, and child
  grids inherit them.
- The icons are ordinary React nodes, so they render on the server and
  hydrate without a mismatch. Custom icons are not mirrored in right-to-left
  layouts; pass direction-aware icons if that matters.
- Menu and toolbar items keep their own `icon` field.

### Live demo: Custom icons

Live demo: https://salmonui.dev/demos/data-grid/icons

The grid draws built-in SVG icons with CSS; the icons prop replaces sort, filter, column menu, group, pager and menu icons with your own nodes, rendered on the server and hydrated without a mismatch.

`Demo.tsx`:

```tsx
'use client';

import { useState, type ReactNode } from 'react';
import { Checkbox } from '@salmonui/inputs/checkbox';
import { DataGrid, type DataGridColumn, type DataGridIcons } from '@salmonui/data-grid';
import { createOrders, type Order } from '../../lib/fixtures';

const orders = createOrders(200, 11);

const columns: DataGridColumn<Order>[] = [
  { field: 'id', header: 'Order', primaryKey: true, width: 120 },
  { field: 'customer', header: 'Customer', width: 170 },
  { field: 'country', header: 'Country', width: 140 },
  { field: 'amount', header: 'Amount', type: 'number', format: 'C2', align: 'end', width: 150 },
];

/** A decorative 14px stroke icon: the control around it keeps its accessible name. */
function Icon({ d }: { d: string }): ReactNode {
  return (
    <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.25" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" focusable="false">
      <path d={d} />
    </svg>
  );
}

// A different icon family (rounded arrows and chevrons) for the grid's own controls.
const customIcons: DataGridIcons = {
  sortAscending: <Icon d="M12 19V5M5 12l7-7 7 7" />,
  sortDescending: <Icon d="M12 5v14M19 12l-7 7-7-7" />,
  filter: <Icon d="M4 6h16M7 12h10M10 18h4" />,
  columnMenu: <Icon d="M4 6h16M4 12h16M4 18h16" />,
  expanded: <Icon d="M6 9l6 6 6-6" />,
  collapsed: <Icon d="M9 6l6 6-6 6" />,
  ungroup: <Icon d="M18 6L6 18M6 6l12 12" />,
  pagerFirst: <Icon d="M17 18l-6-6 6-6M7 6v12" />,
  pagerPrevious: <Icon d="M15 18l-6-6 6-6" />,
  pagerNext: <Icon d="M9 18l6-6-6-6" />,
  pagerLast: <Icon d="M7 18l6-6-6-6M17 6v12" />,
  submenu: <Icon d="M9 18l6-6-6-6" />,
  check: <Icon d="M5 12l5 5L20 7" />,
};

export default function IconsDemo() {
  const [custom, setCustom] = useState(true);
  return (
    <>
      <div className="demo-toolbar">
        <Checkbox checked={custom} onCheckedChange={(checked) => setCustom(checked)}>
          Custom icons
        </Checkbox>
      </div>
      <DataGrid<Order>
        aria-label="Orders with custom icons"
        data={orders}
        columns={columns}
        icons={custom ? customIcons : undefined}
        sorting={{ sortBy: [{ field: 'amount', direction: 'desc' }] }}
        filtering={{ ui: 'menu' }}
        columnMenu
        grouping={{ groupBy: ['country'] }}
        paging={{ pageSize: 8 }}
        height={360}
        locale="en-US"
        currency="USD"
      />
    </>
  );
}
```

## API reference

[`DataGridProps`](https://salmonui.dev/docs/reference/data-grid/DataGridProps) lists the
appearance props, [`DataGridPart`](https://salmonui.dev/docs/reference/data-grid/DataGridPart)
the `classNames` / `styles` keys and
[`DataGridIcons`](https://salmonui.dev/docs/reference/data-grid/DataGridIcons) the icon
names; [`ThemeProvider`](https://salmonui.dev/docs/reference/core/theme/ThemeProvider) and
[`ThemeStyle`](https://salmonui.dev/docs/reference/core/server/ThemeStyle) take the theme and
[`SalmonThemeInput`](https://salmonui.dev/docs/reference/core/theme/SalmonThemeInput) lists
its settings.
