wrolpi/app/src/themes/tokens.css
Roland fb4c03d7a0
ui: token-driven component library on Mantine
Adds src/components/ui: buttons, messages, labels, progress, status, tables,
form controls, panels, cards, statistics, modals, tooltips, tabs, and icons.
Everything resolves its colors through theme tokens, so no component branches
on the current theme, and Semantic UI keeps rendering the app meanwhile.

Mantine is bridged rather than restyled: its own CSS variables are pointed at
our tokens. Four details were not obvious, and each caused a visible defect
in night mode before being fixed:

  - Structural colors must go in the resolver's light/dark blocks. Mantine
    emits its values under [data-mantine-color-scheme], which outranks the
    :root block that `variables` becomes, so its grays were winning.
  - The dark and gray palettes are mapped shade by shade to tokens. Mantine
    reads them directly for table borders, zebra stripes and input chrome;
    they can be neither flattened nor left alone.
  - Mantine writes --button-* as inline styles, which no stylesheet can
    outrank, so the dashed danger treatment sets real properties instead.
  - Switch colors are written onto inner elements, so they need scoped CSS
    rather than a variable on the root. Adds a --knob token for control
    handles, because Mantine's default thumb follows theme.white, which is
    near-black in the dark-based themes.

An audit of every painted pixel in the /theme-sample gallery now finds no
non-red channel in night mode.

Icons come from @tabler/icons-react with the 102 Semantic names the app uses
mapped to components; they stroke with currentColor, so they follow the theme
without any rule of their own. Toasts keep the react-semantic-toasts-2
signature so those call sites migrate by changing an import.

TypeScript 5 is required: Mantine's declarations use `const` type parameters,
which 4.9 cannot parse (Mantine 7 is the same, so downgrading is no escape).
That needs two npm overrides to keep clean installs working, both verified
against a Docker build: react-scripts declares peerOptional typescript ^3||^4,
and fork-ts-checker 6.5.2 assigns typescript.performance.mark, which TS 5
made getter-only - crashing the dev server's type checker on every rebuild.

semantic-baseline.test.js ratchets the removal: it fails if a file not already
listed imports Semantic UI. An ESLint rule would have printed 75 warnings per
rebuild, and CI unsets CI= for its build step, so it would guard nothing there.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-05 18:34:44 -06:00

184 lines
4.9 KiB
CSS

/*
* WROLPi theme tokens.
*
* Every color in the interface resolves through these custom properties, so a
* theme is a table of values and components never branch on the current mode.
* See ui-design.md for the design rules and ui-migration-plan.md for the
* migration this is part of.
*
* Four built-in themes:
* light - default
* dark - default when the OS prefers dark
* night - night-vision preserving; red hues ONLY. Status is encoded by
* brightness, danger by dashed borders. Explicit choice only.
* amber - monochrome amber terminal palette. Explicit choice only.
*
* `data-theme` is stamped on <html> by an inline script in index.html before
* first paint, then maintained by ThemeProvider.
*/
/* Light is also the fallback when `data-theme` is missing or unrecognized. */
:root,
html[data-theme="light"] {
--bg: #f3f4f3;
--panel: #ffffff;
--head: #e4e6e5;
--border: #8f9698;
--text: #22282a;
--muted: #5f686a;
--red: #b23a3a;
--amber: #95661a;
--orange: #b05a24;
--yellow: #96821c;
--olive: #6f7a24;
--green: #3f7a2e;
--teal: #2a7d78;
--blue: #20629c;
--violet: #5c4fa8;
--purple: #7b3f9c;
--pink: #b03a72;
--brown: #7a5233;
--grey: #6a7072;
--black: #22282a;
--white: #ffffff;
/* Text drawn on top of a filled color button. */
--btn-text: #ffffff;
/* Switch thumbs and slider handles. */
--knob: #ffffff;
}
/*
* Role aliases. Declared once: `var()` resolves on <html>, where each theme
* has already redefined the color it points at.
*/
:root {
--primary: var(--blue);
--success: var(--green);
--warning: var(--amber);
--danger: var(--red);
}
html[data-theme="dark"] {
--bg: #1c1f21;
--panel: #26292b;
--head: #141617;
--border: #4a5052;
--text: #e6e8e6;
--muted: #93999b;
--red: #e06c6c;
--amber: #d6a656;
--orange: #dd8a55;
--yellow: #d6c156;
--olive: #b5bd63;
--green: #7fb069;
--teal: #63bdb6;
--blue: #5c9dd6;
--violet: #9a8fe0;
--purple: #b884d6;
--pink: #dd7fae;
--brown: #b08a68;
--grey: #93999b;
--black: #0d0f10;
--white: #e6e8e6;
--btn-text: #1c1f21;
--knob: var(--text);
}
/*
* Night: red hues only. A single non-red pixel defeats the purpose of the
* mode, so the whole palette collapses onto one red ramp ordered by
* brightness — dim for structural roles, brightest reserved for danger.
*/
html[data-theme="night"] {
--bg: #0a0000;
--panel: #160404;
--head: #000000;
--border: #5c1010;
--text: #e04a4a;
--muted: #7a2525;
--red: #ff3b3b;
--amber: #d94040;
--orange: #e04a4a;
--yellow: #d94040;
--olive: #5c1a1a;
--green: #b03030;
--teal: #963030;
--blue: #8a2828;
--violet: #7a2929;
--purple: #6e2020;
--pink: #c04848;
--brown: #451212;
--grey: #7a2525;
--black: #2a0808;
--white: #ff8a8a;
--btn-text: #0a0000;
--knob: var(--text);
}
/* Amber: a monochrome amber terminal palette, same flat style as the rest. */
html[data-theme="amber"] {
--bg: #0d0600;
--panel: #1a0f00;
--head: #000000;
--border: #5c3a08;
--text: #ff9500;
--muted: #8a5810;
--red: #ffc040;
--amber: #e08a20;
--orange: #f09428;
--yellow: #e08a20;
--olive: #6e4610;
--green: #c97a10;
--teal: #8a581c;
--blue: #a86618;
--violet: #7a4c14;
--purple: #6e4410;
--pink: #d08430;
--brown: #452708;
--grey: #8a5810;
--black: #241504;
--white: #ffc875;
--btn-text: #0d0600;
--knob: var(--text);
/* Amber assigns the mono face to the body role; that is its character. */
--font-body: var(--font-system-mono);
}
/* ------------------------------------------------------------------------- */
/* Shell */
/* ------------------------------------------------------------------------- */
body {
background: var(--bg);
color: var(--text);
font-family: var(--font-body);
}
/* ------------------------------------------------------------------------- */
/* Media filtering */
/* ------------------------------------------------------------------------- */
/*
* Videos, images, PDFs, embedded pages, and the map canvas cannot consume
* tokens, so night mode passes them through an SVG color matrix that maps
* luminance onto the red channel and drives green and blue to zero. Nothing
* a user opens can break their dark adaptation.
*
* Tag the media element (or its immediate wrapper) with `.media`. Never
* filter an app-level ancestor: a CSS filter creates a containing block, which
* breaks `position: fixed` descendants like modals and the nav bar.
*
* Filter definitions live in <MediaFilterDefs/> (mounted once by App).
*/
html[data-theme="night"] .media {
filter: url(#wrolpi-night-red);
}