# motherduck-dive-components
> Build Dive UIs from a reusable React component kit (stat cards, gauges, area, heatmap, Sankey, treemap, timeline, date picker), brand themes, and custom components.
Build Dive UIs from a reusable React component kit (stat cards, gauges, area, heatmap, Sankey, treemap, timeline, date picker), brand themes, and custom components.

[Workflow skill](/sql-reference/agent-skills/#workflow-skills) · [View source on GitHub](https://github.com/motherduckdb/agent-skills/tree/v3.3.0/skills/motherduck-dive-components)

:::info

This page shows the skill's `SKILL.md`: the instructions a coding agent loads when a task matches the description above. To install every MotherDuck skill in Claude Code, Codex, Cursor, or Gemini CLI, see [Install MotherDuck Skills](/key-tasks/ai-and-motherduck/agent-skills/). To install only this skill with the [Skills CLI](https://github.com/vercel-labs/skills), run:

```bash
npx -y skills add motherduckdb/agent-skills --skill motherduck-dive-components --yes --global
```

This skill relies on [`motherduck-cli`](/sql-reference/agent-skills/motherduck-cli/) and [`motherduck-query`](/sql-reference/agent-skills/motherduck-query/). Install those too, or install the full catalog.

:::

A component kit for Dives, copied into the Dive as source the way shadcn/ui works: a Dive is one `.tsx` file that may import only the runtime libraries `get_dive_guide` lists, so nothing is installed. Use it when a Dive needs more than the basic charts, a consistent look across several Dives, a brand theme, or a component the kit lacks. [`motherduck-create-dive`](/sql-reference/agent-skills/motherduck-create-dive/) owns the Dive mechanics (runtime contract, saving, sharing, embedding, write-back); this skill owns the visual building blocks.

When MotherDuck MCP is available, call `get_dive_guide` before writing Dive code and before every `save_dive`, `update_dive`, or `edit_dive_content`.

## Start here

1. Open [`artifacts/gallery/index.html`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/gallery/index.html) in a browser to see every component on sample data, with each block's data behind its `</>` button. It needs no MotherDuck account.
2. Read [`artifacts/components.json`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/components.json): for each component, the data shape it renders, when to use it, and the other renderers it can switch to.
3. Pick components for the question, write the Dive's queries, and build blocks from the rows.

## Kit

| Path | What it holds |
| --- | --- |
| [`artifacts/kit/core.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/kit/core.tsx) | Themes, `makeTheme`, `ThemeCtx`, formatting (`N`, `fmt`, `niceTicks`), primitives (`Card`, `Badge`, `Button`, `Segmented`, `Skeleton`, `Delta`, `Sparkline`), `registerComponent`, `BlockView` |
| [`artifacts/kit/blocks.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/kit/blocks.tsx) | KPI row, line, bar, table, callouts, text |
| [`artifacts/kit/stats.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/kit/stats.tsx) | Metric cards, compact stats, radial gauges |
| [`artifacts/kit/area.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/kit/area.tsx) | Area chart with headline value, legend toggles, crosshair |
| [`artifacts/kit/heatmap.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/kit/heatmap.tsx) | Calendar (daily activity) and matrix heatmaps |
| [`artifacts/kit/sankey.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/kit/sankey.tsx) | Flows from one set of categories to another |
| [`artifacts/kit/treemap.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/kit/treemap.tsx) | Part-to-whole, grouped, click to zoom |
| [`artifacts/kit/timeline.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/kit/timeline.tsx) | Events in order |
| [`artifacts/kit/datepicker.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/kit/datepicker.tsx) | Single date and range picker with presets (an input, not a block) |
| [`artifacts/examples/funnel.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/examples/funnel.tsx) | A custom component to copy |
| [`artifacts/assemble.py`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/assemble.py) | Concatenates the kit, custom files, and your Dive into one `index.tsx` |

## Blocks

Every component renders a block: a plain object with `id`, `type`, `title`, and data in the shape `components.json` gives. Components never run SQL. Query with `useSQLQuery`, convert values with `N()`, build the block, and render it with `BlockView`:

```tsx
// @imports
import { useSQLQuery } from '@motherduck/react-sql-query';
// @imports-end

export const REQUIRED_DATABASES = [{ type: 'database', path: 'md:analytics', alias: 'analytics' }];

export default function DailyVisits() {
	const q = useSQLQuery(`SELECT strftime(day, '%Y-%m-%d') AS x, count(*) AS visits
	                       FROM "analytics"."main"."events" GROUP BY 1 ORDER BY 1`);
	const rows = Array.isArray(q.data) ? q.data : [];
	const block = {
		id: 'daily', type: 'heatmap', mode: 'calendar', title: 'Daily visits',
		x: { kind: 'time', grain: 'day' },
		series: [{ key: 'visits', label: 'Visits', format: 'count' }],
		data: rows.map((r: any) => ({ x: String(r.x), visits: N(r.visits) })),
	};
	return (
		<ThemeCtx.Provider value={makeTheme('motherduck')}>
			<Card title={block.title} icon={componentIcon(block.type)}>
				{q.isLoading ? <Skeleton h={140} /> : <BlockView block={block} />}
			</Card>
		</ThemeCtx.Provider>
	);
}
```

Any block can also carry narrative and context:
- `insight`: a "so what" line, rendered by `<BlockInsight>`.
- `about`: `{ definitions: [{ term, text }], why }`, which `<SourceFooter>` shows with the source.
- `probe` and `hypothesis`: mark a follow-up query.

Callout items can carry `continuity` (`new`, `ongoing`, `worsening`, `improving`, `resolved`) with `first_seen` and `times_seen`. Pass a `nav` with `rate` and `rating` to add thumbs up and down.

For any input, use the form fields in `kit/field.tsx`, modelled on shadcn/ui Field:
- **Layout:** `FieldSet` and `FieldLegend` group fields; `FieldGroup` stacks them.
- **One field:** `Field` (orientation `vertical`, `horizontal` or `responsive`, plus `invalid`) wraps a `FieldLabel`, the control, a `FieldDescription` and a `FieldError`.
- **Controls:** `Input`, `Textarea`, `Select` and `ChoiceGroup` (radio or checkbox choice cards, or chips).
- **From a spec:** a `form` block renders a whole form and sends the answers to `nav.submit(blockId, values)`. Use native controls: they work in every Dive.

A `questions` block asks viewers about a date or a segment the data can't explain. Each answer is a note: `{ kind: 'date' | 'topic', x, grain?, dimension?, value?, category, note }`. Pass a `nav` with `annotate` and `noteFor` to take answers. `withNotes(block, notes)` pins notes to every block that shows that date or value, as markers on line and area charts. `<NotesLine>` lists them under a block, and `<NoteForm>`, built on the form fields, adds one from any chart.

Formats are `count`, `currency`, `pct` (a fraction), `number`, `delta_pct`, `text`, and `row` (read `_format` per row). Set `good: 'down'` on measures where lower is better, so deltas colour by meaning rather than direction.

Assemble and preview with the MotherDuck CLI:

```bash
python3 artifacts/assemble.py app.tsx -o my-dive/index.tsx --components kpi,line,heatmap
motherduck dive watch my-dive
```

Omit `--components` to include the whole kit. Before `save_dive` or `update_dive`, follow the review step that `get_dive_guide` sets for your client: when it asks you to show the final source or preview and get the user's go-ahead, do that once, unless the user already said to save without review.

## Variants

A block can render with any registered component whose `accepts(block)` takes its data: a KPI row as stats, metric cards, compact stats, or gauges; a line as area, bar, heatmap, or table; a bar as treemap or table. `variantsFor(block)` lists them. Offer the switch with `Segmented`, and keep the viewer's choice in `useDiveState`.

## Themes and brands

`motherduck` is the default theme and follows the visual rules in `get_dive_guide`: flat, no card chrome, the MotherDuck palette. Use it unless the user asks for another look or the Dive already has one. The kit also ships `swiss` (greyscale, one red accent), `paper` (cards), `duck` (brutalist brand), and `night` (dark).

For a brand, ask for the accent colour, flat or card look, and a font, then derive a theme:

```tsx
const theme = makeTheme({ base: 'paper', name: 'Acme', accent: '#0f766e', font: 'Georgia, serif', radius: 6 });
```

Dives cannot load web fonts, so offer system font stacks. Read [`references/THEMING.md`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/references/THEMING.md) for the token list and the contrast and colour checks.

## Custom components

When no kit component shows the data well, copy [`artifacts/examples/funnel.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/examples/funnel.tsx), render only from the block with `useTheme()` tokens, and register it with `registerComponent(type, { label, icon, render, variants, accepts })`. Pass the file to `assemble.py --extra`. Read [`references/CUSTOM_COMPONENTS.md`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/references/CUSTOM_COMPONENTS.md) for the contract, the catalog entry, and how a Flight can plan the new component.

## Rules

- Keep SQL out of components; a block is data only.
- Run every value through `N()` before maths or charts; format dates in SQL.
- Use inline styles for colours and sizes; arbitrary Tailwind values do not resolve.
- Each kit file declares its imports between `// @imports` and `// @imports-end`; `assemble.py` merges them. Do not name a component after an icon or chart it imports (`Gauge`, `Treemap`, `Sankey`).
- After adding or changing a component, add a sample block to [`artifacts/gallery/app.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/gallery/app.tsx), rebuild the page with `python3 artifacts/gallery/build_page.py` (needs Node.js), and check it in the default theme and one other at desktop and phone width.

## References

- [`references/THEMING.md`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/references/THEMING.md) -- built-in themes, `makeTheme` tokens, asking for a brand, contrast checks
- [`references/CUSTOM_COMPONENTS.md`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/references/CUSTOM_COMPONENTS.md) -- writing, registering, and cataloguing a new component

## Related skills

Load related skills only for missing capabilities; reuse established context.

- [`motherduck-create-dive`](/sql-reference/agent-skills/motherduck-create-dive/) for the Dive runtime contract, saving, sharing, embedding, and write-back
- [`motherduck-cli`](/sql-reference/agent-skills/motherduck-cli/) for `dive watch`, `dive push`, and keeping Dive source in files
- [`motherduck-query`](/sql-reference/agent-skills/motherduck-query/) for validating the SQL each block renders

## Files in this skill

The agent reads these files when the instructions above point to them.

- [`artifacts/assemble.py`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/assemble.py)
- [`artifacts/components.json`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/components.json)
- [`artifacts/examples/funnel.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/examples/funnel.tsx)
- [`artifacts/gallery/app.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/gallery/app.tsx)
- [`artifacts/gallery/build_page.py`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/gallery/build_page.py)
- [`artifacts/gallery/index.html`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/gallery/index.html)
- [`artifacts/kit/area.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/kit/area.tsx)
- [`artifacts/kit/blocks.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/kit/blocks.tsx)
- [`artifacts/kit/core.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/kit/core.tsx)
- [`artifacts/kit/datepicker.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/kit/datepicker.tsx)
- [`artifacts/kit/field.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/kit/field.tsx)
- [`artifacts/kit/heatmap.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/kit/heatmap.tsx)
- [`artifacts/kit/notes.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/kit/notes.tsx)
- [`artifacts/kit/sankey.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/kit/sankey.tsx)
- [`artifacts/kit/stats.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/kit/stats.tsx)
- [`artifacts/kit/timeline.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/kit/timeline.tsx)
- [`artifacts/kit/treemap.tsx`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/artifacts/kit/treemap.tsx)
- [`references/CUSTOM_COMPONENTS.md`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/references/CUSTOM_COMPONENTS.md)
- [`references/THEMING.md`](https://github.com/motherduckdb/agent-skills/blob/v3.3.0/skills/motherduck-dive-components/references/THEMING.md)

## Docs this skill draws on

- [Creating Visualizations with Dives](https://motherduck.com/docs/key-tasks/dives/)
- [Theming and styling your Dives](https://motherduck.com/docs/key-tasks/dives/theming-and-styling-dives/)
- [Manage Dives as code](https://motherduck.com/docs/key-tasks/dives/managing-dives-as-code/)
- [motherduck.com/dive-gallery](https://motherduck.com/dive-gallery/)


---

## Docs feedback

MotherDuck accepts optional user-submitted feedback about this page at `GET https://motherduck.com/docs/api/feedback/agent`.
For agents and automated tools, feedback submission should be user-confirmed before sending.

URL-encode query parameter values and send a GET request:

```text
GET https://motherduck.com/docs/api/feedback/agent?page_path=%2Fsql-reference%2Fagent-skills%2Fmotherduck-dive-components%2F&page_title=motherduck-dive-components&text=<url-encoded user feedback, max 2000 characters>
```

Optionally append `&source=<url-encoded interface identifier>` such as `claude.ai` or `chatgpt`.

`page_path` and `text` are required; `page_title` and `source` are optional. Responses: `200 {"feedback_id": "<uuid>"}`, `400` for malformed query parameters, and `429` when rate-limited.
