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:
@@ -1,8 +1,9 @@
|
||||
import { createContext, useContext } from "react"
|
||||
|
||||
import type { DashboardDef_Output, SettingDef } from "@/client"
|
||||
import { NO_PALETTE, paletteOf } from "@/components/Common/UplotChart"
|
||||
import { NO_PALETTE } from "@/components/Common/UplotChart"
|
||||
import { useLiveValue } from "@/components/Flow/liveStore"
|
||||
import { isLight, parsePalette, rolesOf } from "./ui/core/theme"
|
||||
|
||||
/**
|
||||
* The dashboard's own settings channel.
|
||||
@@ -30,13 +31,21 @@ import { useLiveValue } from "@/components/Flow/liveStore"
|
||||
* on the server (`app/flow/dashboards.py`); a name missing from it is a
|
||||
* setting this build does not act on rather than an error.
|
||||
*/
|
||||
export const SETTING_DTYPES: Record<string, string> = {
|
||||
export const SETTING_DTYPES = {
|
||||
theme: "str",
|
||||
locked: "bool",
|
||||
}
|
||||
/** `glass` or `material`; anything else is material. */
|
||||
look: "str",
|
||||
/** Hex colours, roles by position — see `ui/core/theme.ts`. */
|
||||
palette: "list",
|
||||
/** The URL of an image drawn under the widgets. */
|
||||
background: "str",
|
||||
/** Bigger controls, for a panel that is touched rather than pointed at. */
|
||||
touch: "bool",
|
||||
} as const satisfies Record<string, string>
|
||||
|
||||
/** The settings this build actually wires up. */
|
||||
export type SettingName = "theme" | "locked" | "palette"
|
||||
export type SettingName = keyof typeof SETTING_DTYPES
|
||||
|
||||
/** What `theme` may be set to. `system` follows whatever the device says. */
|
||||
export const THEME_CHOICES = [
|
||||
@@ -61,14 +70,14 @@ export function settingOf(
|
||||
* editor cannot author a document the server would refuse.
|
||||
*/
|
||||
export function settingIssue(name: string, setting: SettingDef): string | null {
|
||||
const want = SETTING_DTYPES[name]
|
||||
const want = SETTING_DTYPES[name as SettingName] as string | undefined
|
||||
if (!want || !setting.message || !setting.dtype) return null
|
||||
if (setting.dtype === want) return null
|
||||
return `${setting.message} is a ${setting.dtype}; ${name} is driven by a ${want}.`
|
||||
}
|
||||
|
||||
/** What the setting is worth now: live if it is bound, stored otherwise. */
|
||||
function useSetting(
|
||||
export function useSetting(
|
||||
dashboard: DashboardDef_Output | undefined,
|
||||
name: SettingName,
|
||||
): unknown {
|
||||
@@ -79,17 +88,59 @@ function useSetting(
|
||||
return live?.value ?? setting.value
|
||||
}
|
||||
|
||||
/** What a dashboard is drawn as. Anything unrecorded is material. */
|
||||
export type Look = "glass" | "material"
|
||||
|
||||
/** The looks, as the editor offers them. */
|
||||
export const LOOK_CHOICES = [
|
||||
["material", "Material"],
|
||||
["glass", "Glass"],
|
||||
] as const
|
||||
|
||||
export const lookOf = (value: unknown): Look =>
|
||||
value === "glass" ? "glass" : "material"
|
||||
|
||||
/** Which of the two component sets draws this dashboard. */
|
||||
export const useDashboardLook = (
|
||||
dashboard: DashboardDef_Output | undefined,
|
||||
): Look => lookOf(useSetting(dashboard, "look"))
|
||||
|
||||
/** The dashboard's own colours, as the hexes a palette named. */
|
||||
export const useDashboardPalette = (
|
||||
dashboard: DashboardDef_Output | undefined,
|
||||
): string[] => parsePalette(useSetting(dashboard, "palette"))
|
||||
|
||||
/** An image drawn under the widgets, or `""` for the look's own ground. */
|
||||
export function useDashboardBackground(
|
||||
dashboard: DashboardDef_Output | undefined,
|
||||
): string {
|
||||
const value = useSetting(dashboard, "background")
|
||||
return typeof value === "string" ? value.trim() : ""
|
||||
}
|
||||
|
||||
/** Whether this dashboard is drawn for a finger rather than a pointer. */
|
||||
export const useDashboardTouch = (
|
||||
dashboard: DashboardDef_Output | undefined,
|
||||
): boolean => useSetting(dashboard, "touch") === true
|
||||
|
||||
/**
|
||||
* The class that themes a dashboard's own surface, or `""` to follow the app.
|
||||
*
|
||||
* A class rather than the root, because inside the app shell this must not
|
||||
* flip the chrome around it. `.light` and `.dark` both redefine the tokens on
|
||||
* whatever carries them (`index.css`), so either direction works on a subtree.
|
||||
*
|
||||
* A palette decides this for itself: its first colour *is* the ground, so
|
||||
* whether the surface is light or dark is a fact about the palette rather than
|
||||
* a second setting that could disagree with it. The class still goes on,
|
||||
* because a chart canvas and the shadcn pieces inside the tile read it.
|
||||
*/
|
||||
export function useDashboardTheme(
|
||||
dashboard: DashboardDef_Output | undefined,
|
||||
): "" | "light" | "dark" {
|
||||
const value = useSetting(dashboard, "theme")
|
||||
const roles = rolesOf(useDashboardPalette(dashboard))
|
||||
if (roles) return isLight(roles.background) ? "light" : "dark"
|
||||
return value === "dark" || value === "light" ? value : ""
|
||||
}
|
||||
|
||||
@@ -105,9 +156,11 @@ const PaletteContext = createContext(NO_PALETTE)
|
||||
/**
|
||||
* The data colours everything drawn under it uses.
|
||||
*
|
||||
* Empty when the dashboard names none, which is not the same as "the ramp":
|
||||
* a chart with no palette spreads itself across the ramp by how many lines it
|
||||
* draws (`slotsFor`), and only a named palette overrides that.
|
||||
* The colours a palette named, in draw order — the primary first, then the
|
||||
* accent, then whatever it listed after the roles. Empty when the dashboard
|
||||
* names no palette, which is not the same as "the ramp": a chart with no
|
||||
* palette spreads itself across the ramp by how many lines it draws
|
||||
* (`slotsFor`), and only a named palette overrides that.
|
||||
*
|
||||
* Mounted by the view *and* the editor: an editor drawing the automatic
|
||||
* spread while the panel beside it showed the dashboard's own palette would
|
||||
@@ -126,7 +179,7 @@ export function PaletteProvider({
|
||||
dashboard: DashboardDef_Output | undefined
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
const palette = paletteOf(useSetting(dashboard, "palette"))
|
||||
const palette = rolesOf(useDashboardPalette(dashboard))?.series ?? NO_PALETTE
|
||||
return (
|
||||
<PaletteContext.Provider value={palette}>
|
||||
{children}
|
||||
|
||||
Reference in New Issue
Block a user