Rework the dashboard into two looks over one behaviour

A dashboard is a wall panel somebody hangs in their own hallway, so it
now wears what they choose: a look, and a palette of their own colours.

Two complete component sets live under `Dashboard/ui/` — `glass`
(translucent panes over a slowly moving ground) and `material` (Material
3 tonal cards) — behind one prop contract. Every control's state,
keyboard and `aria-` live in `ui/core` and are shared, so the two sets
are the same dashboard drawn twice rather than two products: a set only
decides what a control looks like while doing it.

Four settings join the channel, each drivable by a flow like any other:
`look`, `palette`, `background` and `touch`. A palette is an ordered list
of hex colours — background, surface, primary, accent, text, then more
chart colours — pasted from a coolors.co link or typed, written onto the
canvas as the token variables everything already reads. Trailing roles
are derived, so three colours are a whole dashboard, and derived text is
held to AA rather than trusted (`theme.check.ts` measures it). A palette
also decides light or dark, since its first colour is the ground.

Widgets are measured against their own tile with container queries rather
than against the viewport, animate through `motion`, and can be drawn
without their title. The three reworks:

- a bar draws a row per reading, up to eight, each in the dashboard's own
  data colours and each able to carry its own scale — replacing readings
  nested in one fill, which could only ever share one colour and stop at
  three. Documents written the old way are read as rows.
- a chart's range picker moved to a column down its right-hand edge, which
  gives the plot back a whole row of a short tile.
- the colour wheel became a disc: hue is the angle and saturation the
  distance from the middle, so a colour is one gesture rather than three,
  with brightness on a slider beside it.

`index.css` and `lib/motion.ts` are untouched — the dashboard overrides
token *values* on its canvas, never the blocks the two repos share.
This commit is contained in:
2026-08-23 21:52:14 +02:00
parent 7c6e655e17
commit acae48ddb6
52 changed files with 5517 additions and 1568 deletions
@@ -1,5 +1,5 @@
import { motion } from "motion/react"
import { useEffect, useRef, useState } from "react"
import type {
DashboardDef_Output,
PageDef_Output,
@@ -7,10 +7,19 @@ import type {
SectionDef_Output,
WidgetDef,
} from "@/client"
import { cn } from "@/lib/utils"
import "./dashboard.css"
import { LockedProvider, PaletteProvider, useDashboardTheme } from "./settings"
import { WidgetBody, WidgetFrame, widgetIssue } from "./widgets"
import {
LockedProvider,
PaletteProvider,
useDashboardBackground,
} from "./settings"
import { useUi } from "./ui"
import { showTitle } from "./ui/core/config"
import { LookProvider, useCanvasRoot, useLook } from "./ui/core/look"
import { gridStagger, LOOK } from "./ui/core/motion"
import { WidgetBody, widgetIssue } from "./widgets"
export type Dashboard = DashboardDef_Output
@@ -97,10 +106,10 @@ export const rowsOf = (dashboard: Dashboard) =>
* narrower screen, changes only the scale — the arrangement being designed,
* and the dot grid under it, stay the layout the panel will actually show.
*
* This box is also exactly what the dashboard's `theme` setting applies to: it
* is the panel, so a dashboard forced light or dark paints its own ground here
* and leaves the shell around it alone. Which is why it states a background at
* all — without one it would borrow whatever it was dropped into.
* This box is also exactly what a dashboard's own appearance applies to: it is
* the panel, so its palette, its look and its light or dark all land here and
* leave the shell around it alone. Which is why it states a background at all
* — without one it would borrow whatever it was dropped into.
*/
export function CanvasSurface({
dashboard,
@@ -130,42 +139,65 @@ export function CanvasSurface({
const { width, height } = canvasOf(dashboard)
const scale = Math.min(box.width / width, box.height / height)
const theme = useDashboardTheme(dashboard)
const root = useCanvasRoot(dashboard)
return (
<div ref={ref} className="relative size-full overflow-hidden">
{/* Measured first: a guessed scale would place the whole panel once and
then move it. */}
{scale > 0 ? (
<div
className={cn(
"absolute overflow-hidden bg-background text-foreground",
theme,
dots && "dot-canvas",
)}
data-testid="canvas-surface"
style={
{
width,
height,
left: (box.width - width * scale) / 2,
top: (box.height - height * scale) / 2,
transform: `scale(${scale})`,
transformOrigin: "top left",
// One dot per cell corner. The column pitch the grid snaps to is
// (width + gap) / columns; a row is one row plus the gap.
"--dot-x": `${(width + GRID_GAP) / columnsOf(dashboard)}px`,
"--dot-y": `${rowPitchOf(dashboard)}px`,
} as React.CSSProperties
}
>
{children(scale)}
</div>
<LookProvider dashboard={dashboard}>
<div
data-look={root["data-look"]}
data-touch={root["data-touch"]}
data-palette={root["data-palette"]}
className={cn(
"absolute overflow-hidden bg-background text-foreground",
root.className,
)}
data-testid="canvas-surface"
style={
{
...root.style,
width,
height,
left: (box.width - width * scale) / 2,
top: (box.height - height * scale) / 2,
transform: `scale(${scale})`,
transformOrigin: "top left",
// One dot per cell corner. The column pitch the grid snaps to
// is (width + gap) / columns; a row is one row plus the gap.
"--dot-x": `${(width + GRID_GAP) / columnsOf(dashboard)}px`,
"--dot-y": `${rowPitchOf(dashboard)}px`,
} as React.CSSProperties
}
>
<CanvasGround dashboard={dashboard} />
{/* Over the ground rather than under it: the dots are what is
being arranged against, and a wallpaper must not hide them. */}
{dots ? (
<div className="dot-canvas pointer-events-none absolute inset-0" />
) : null}
{children(scale)}
</div>
</LookProvider>
) : null}
</div>
)
}
/**
* What the widgets sit on.
*
* The image a dashboard was given, or whatever ground its look brings — glass
* needs something behind it to refract, and material is happy with the surface
* colour alone.
*/
export function CanvasGround({ dashboard }: { dashboard: Dashboard }) {
const { Backdrop } = useUi()
return <Backdrop image={useDashboardBackground(dashboard)} />
}
export function placement(widget: WidgetDef): Placement {
const layout = (widget.layout ?? {}) as Record<string, Placement>
return layout.lg ?? layout.md ?? layout.sm ?? {}
@@ -303,37 +335,80 @@ export function DashboardView({
const columns = columnsOf(dashboard)
return (
<LockedProvider dashboard={dashboard}>
<PaletteProvider dashboard={dashboard}>
<div
className={cn("widget-grid", stacked && "widget-stacked")}
data-placed={isPlaced(widgets) || undefined}
style={
{
"--widget-cols": columns,
// The row height follows the canvas, so the CSS grid and the
// editor's grid library cannot drift apart.
"--row-height": `${rowHeightOf(dashboard)}px`,
} as React.CSSProperties
}
<LookProvider dashboard={dashboard}>
<LockedProvider dashboard={dashboard}>
<PaletteProvider dashboard={dashboard}>
<WidgetGrid
dashboard={dashboard}
widgets={widgets}
columns={columns}
stacked={stacked}
renderWidget={renderWidget}
/>
</PaletteProvider>
</LockedProvider>
</LookProvider>
)
}
/**
* The arrangement itself.
*
* Its own component because it draws with the look's components, which are
* only knowable below `LookProvider`. Widgets arrive as a page rather than all
* at once — a stagger, at whatever stiffness the look moves with.
*/
function WidgetGrid({
dashboard,
widgets,
columns,
stacked,
renderWidget,
}: {
dashboard: Dashboard
widgets: WidgetDef[]
columns: number
stacked?: boolean
renderWidget?: (widget: WidgetDef) => React.ReactNode
}) {
const { Frame } = useUi()
const { look } = useLook()
return (
<motion.div
className={cn("widget-grid", stacked && "widget-stacked")}
data-placed={isPlaced(widgets) || undefined}
variants={gridStagger}
initial="hidden"
animate="visible"
style={
{
"--widget-cols": columns,
// The row height follows the canvas, so the CSS grid and the
// editor's grid library cannot drift apart.
"--row-height": `${rowHeightOf(dashboard)}px`,
} as React.CSSProperties
}
>
{widgets.map((widget) => (
<motion.div
key={widget.id}
style={widgetStyle(widget, columns)}
className="widget-cell"
variants={LOOK[look].enter}
transition={LOOK[look].spring}
>
{widgets.map((widget) => (
<div
key={widget.id}
style={widgetStyle(widget, columns)}
className="widget-cell"
{renderWidget ? (
renderWidget(widget)
) : (
<Frame
title={showTitle(widget) ? widget.title : undefined}
issue={widgetIssue(widget)}
>
{renderWidget ? (
renderWidget(widget)
) : (
<WidgetFrame title={widget.title} issue={widgetIssue(widget)}>
<WidgetBody widget={widget} dashboard={dashboard.name} />
</WidgetFrame>
)}
</div>
))}
</div>
</PaletteProvider>
</LockedProvider>
<WidgetBody widget={widget} dashboard={dashboard.name} />
</Frame>
)}
</motion.div>
))}
</motion.div>
)
}