feat(ui,manager): looks: light / dark / device, palettes and styles, chosen in the manager's profile menu (platform-v2 step 6.15)
- @xenia/ui theme.js: a look = mode (light | dark | system) + palette (data-palette) + style (data-style); applyLook / getStoredLook (per device), 'system' resolved with matchMedia and followed live, so a palette is just a light and a dark token block; applyTheme kept for older callers (keeps palette and style) - tokens.css: 'Palettes' (first: Nord, light + dark, every colour and the nav rail) and 'Styles' (first: sharp: small corners, 1.5px borders, flat cards); --x-border-width used by every component and Tailwind's 'border' - contrast test: every palette in both modes (+ the nav rail); it caught the default rail's active item at 3.7:1 -> 5.5:1 - manager: the saved look applied at start (was light only); profile menu -> Look: Light / Dark / Device, Colours (Xenia, Nord), Shapes (Rounded, Sharp), applied at once and kept on this device - e2e: manager_look.mjs (every page in light and dark, no large near-white area in dark, contact sheets; 'nord-sharp' adds that look; in run-all), manager.mjs 'look:' (dark at once, kept after a reload, Device follows the device) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
display: inline-flex; align-items: center; justify-content: center; gap: var(--x-space-2);
|
||||
box-sizing: border-box;
|
||||
min-height: var(--x-control-md); padding: 0 var(--x-space-4);
|
||||
border: 1px solid transparent; border-radius: var(--x-radius-control);
|
||||
border: var(--x-border-width) solid transparent; border-radius: var(--x-radius-control);
|
||||
font: inherit; font-size: var(--x-text-body); line-height: var(--x-leading-body); font-weight: var(--x-weight-semibold);
|
||||
white-space: nowrap; cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
|
||||
transition: background-color var(--x-duration-fast) var(--x-ease), border-color var(--x-duration-fast) var(--x-ease),
|
||||
@@ -114,7 +114,7 @@
|
||||
.x-modal__footer {
|
||||
display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--x-space-2);
|
||||
padding: var(--x-space-4) var(--x-space-6);
|
||||
border-top: 1px solid var(--x-line);
|
||||
border-top: var(--x-border-width) solid var(--x-line);
|
||||
}
|
||||
.x-modal__header + .x-modal__footer { border-top: 0; }
|
||||
|
||||
@@ -141,7 +141,7 @@
|
||||
display: flex; align-items: flex-start; gap: var(--x-space-3);
|
||||
padding: var(--x-space-3) var(--x-space-2) var(--x-space-3) var(--x-space-4);
|
||||
background: var(--x-surface); color: var(--x-ink);
|
||||
border: 1px solid var(--x-line); border-radius: var(--x-radius-card);
|
||||
border: var(--x-border-width) solid var(--x-line); border-radius: var(--x-radius-card);
|
||||
box-shadow: var(--x-shadow-popover);
|
||||
pointer-events: auto;
|
||||
animation: x-pop-in var(--x-duration-base) var(--x-ease);
|
||||
@@ -253,7 +253,7 @@
|
||||
box-sizing: border-box; width: 100%;
|
||||
min-height: var(--x-control-md); padding: 0 var(--x-space-3);
|
||||
background: var(--x-surface); color: var(--x-ink);
|
||||
border: 1px solid var(--x-line-strong); border-radius: var(--x-radius-control);
|
||||
border: var(--x-border-width) solid var(--x-line-strong); border-radius: var(--x-radius-control);
|
||||
font: inherit; font-size: var(--x-text-body-lg); /* 16px: phones don't zoom in on focus */
|
||||
transition: border-color var(--x-duration-fast) var(--x-ease), box-shadow var(--x-duration-fast) var(--x-ease);
|
||||
}
|
||||
@@ -276,7 +276,7 @@
|
||||
.x-stepper__btn {
|
||||
display: inline-flex; align-items: center; justify-content: center;
|
||||
width: var(--x-control-md); height: var(--x-control-md); padding: 0;
|
||||
border: 1px solid var(--x-line-strong); border-radius: var(--x-radius-control);
|
||||
border: var(--x-border-width) solid var(--x-line-strong); border-radius: var(--x-radius-control);
|
||||
background: var(--x-surface-2); color: var(--x-ink); cursor: pointer;
|
||||
transition: background-color var(--x-duration-fast) var(--x-ease);
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
@@ -332,5 +332,5 @@
|
||||
/* ── QR code (QrCode, @xenia/ui/qr; plan step 6.14c) ─────────────────────── */
|
||||
.x-qr { display: grid; justify-items: center; gap: var(--x-space-2); }
|
||||
/* always light behind the code, in dark themes too: scanners need the contrast */
|
||||
.x-qr__tile { padding: var(--x-space-3); border-radius: var(--x-radius-card); border: 1px solid var(--x-line); background: var(--x-on-colour); line-height: 0; }
|
||||
.x-qr__tile { padding: var(--x-space-3); border-radius: var(--x-radius-card); border: var(--x-border-width) solid var(--x-line); background: var(--x-on-colour); line-height: 0; }
|
||||
.x-qr__caption { font-size: var(--x-text-label); color: var(--x-ink-2); text-align: center; }
|
||||
|
||||
@@ -24,4 +24,4 @@ export { Stepper } from './components/Stepper.jsx'
|
||||
export { ReasonPicker, reasonText } from './components/ReasonPicker.jsx'
|
||||
export { UiLabelsProvider, DEFAULT_LABELS } from './components/labels.js'
|
||||
export { cx } from './internal/cx.js'
|
||||
export { THEMES, THEME_STORAGE_KEY, applyTheme, getStoredTheme } from './theme.js'
|
||||
export { THEMES, PALETTES, STYLES, THEME_STORAGE_KEY, PALETTE_STORAGE_KEY, STYLE_STORAGE_KEY, applyLook, applyTheme, getStoredLook, getStoredTheme, resolveMode } from './theme.js'
|
||||
|
||||
+83
-19
@@ -1,34 +1,98 @@
|
||||
// The colour theme of an app (plan step 2.6f): light | dark | system (follows the OS).
|
||||
// tokens.css reads it from data-theme on <html>. The choice is per device (localStorage),
|
||||
// like a screen setting, not per user. No React here.
|
||||
// The look of an app (plan steps 2.6f, 6.15): three independent choices, each an attribute on
|
||||
// <html> that tokens.css reads. Nothing else changes: every component draws from the tokens.
|
||||
//
|
||||
// applyTheme(getStoredTheme()) at startup
|
||||
// applyTheme('dark', { save: true }) when the user picks one
|
||||
// mode data-theme light | dark | system (follows the device, live)
|
||||
// palette data-palette the colours: default | nord | … (light and dark versions each)
|
||||
// style data-style the shape of the components: rounded | sharp | … (radius, shadows, borders)
|
||||
//
|
||||
// The manager offers the choice only once its older pages use the tokens (phase 6): until
|
||||
// then it always applies 'light' (decided 2026-11-14), so a saved choice waits unused.
|
||||
// "system" is resolved here (matchMedia), so data-theme is always light or dark and a palette
|
||||
// needs only a light and a dark block. The choice is per device (localStorage), like a screen
|
||||
// setting. No React here.
|
||||
//
|
||||
// applyLook(getStoredLook()) at startup
|
||||
// applyLook({ mode: 'dark', palette: 'nord' }, { save: true }) when the user picks
|
||||
// applyTheme('dark') mode only (older callers)
|
||||
//
|
||||
// Adding a palette or a style: a token block in tokens.css (see "Palettes" / "Styles" there), its
|
||||
// name in PALETTES / STYLES below, and its label in the apps' texts. The contrast test checks
|
||||
// every palette in both modes.
|
||||
|
||||
export const THEMES = ['light', 'dark', 'system']
|
||||
export const PALETTES = ['default', 'nord']
|
||||
export const STYLES = ['rounded', 'sharp']
|
||||
export const THEME_STORAGE_KEY = 'xenia_theme'
|
||||
export const PALETTE_STORAGE_KEY = 'xenia_palette'
|
||||
export const STYLE_STORAGE_KEY = 'xenia_style'
|
||||
|
||||
const browserStorage = () => { try { return globalThis.localStorage ?? null } catch { return null } }
|
||||
|
||||
/** The saved theme, or 'light'. */
|
||||
export function getStoredTheme(storage = browserStorage()) {
|
||||
const read = (storage, key, list, fallback) => {
|
||||
try {
|
||||
const v = storage?.getItem(THEME_STORAGE_KEY)
|
||||
return THEMES.includes(v) ? v : 'light'
|
||||
const v = storage?.getItem(key)
|
||||
return list.includes(v) ? v : fallback
|
||||
} catch {
|
||||
return 'light'
|
||||
return fallback
|
||||
}
|
||||
}
|
||||
const prefersDark = () => { try { return !!globalThis.matchMedia?.('(prefers-color-scheme: dark)').matches } catch { return false } }
|
||||
|
||||
/** The saved mode, or 'light'. */
|
||||
export function getStoredTheme(storage = browserStorage()) {
|
||||
return read(storage, THEME_STORAGE_KEY, THEMES, 'light')
|
||||
}
|
||||
|
||||
/** The saved look: { mode, palette, style } (unknown or missing values: the defaults). */
|
||||
export function getStoredLook(storage = browserStorage()) {
|
||||
return {
|
||||
mode: getStoredTheme(storage),
|
||||
palette: read(storage, PALETTE_STORAGE_KEY, PALETTES, 'default'),
|
||||
style: read(storage, STYLE_STORAGE_KEY, STYLES, 'rounded'),
|
||||
}
|
||||
}
|
||||
|
||||
/** Set data-theme on the root element (and save it when asked). Unknown values become 'light'. */
|
||||
export function applyTheme(theme, { root = globalThis.document?.documentElement, storage = browserStorage(), save = false } = {}) {
|
||||
const t = THEMES.includes(theme) ? theme : 'light'
|
||||
root?.setAttribute('data-theme', t)
|
||||
/** 'light' or 'dark' for a mode ('system' asks the device). */
|
||||
export function resolveMode(mode, dark = prefersDark) {
|
||||
return mode === 'dark' || (mode === 'system' && dark()) ? 'dark' : 'light'
|
||||
}
|
||||
|
||||
let unwatch = null
|
||||
|
||||
/** Set the look on the root element (and save it when asked). Returns what was applied. */
|
||||
export function applyLook(look = {}, { root = globalThis.document?.documentElement, storage = browserStorage(), save = false, dark = prefersDark } = {}) {
|
||||
const mode = THEMES.includes(look.mode) ? look.mode : 'light'
|
||||
const palette = PALETTES.includes(look.palette) ? look.palette : 'default'
|
||||
const style = STYLES.includes(look.style) ? look.style : 'rounded'
|
||||
const set = () => root?.setAttribute('data-theme', resolveMode(mode, dark))
|
||||
set()
|
||||
root?.setAttribute('data-theme-choice', mode)
|
||||
root?.setAttribute('data-palette', palette)
|
||||
root?.setAttribute('data-style', style)
|
||||
// "system": follow the device when it switches
|
||||
unwatch?.()
|
||||
unwatch = null
|
||||
if (mode === 'system' && root) {
|
||||
try {
|
||||
const mq = globalThis.matchMedia?.('(prefers-color-scheme: dark)')
|
||||
if (mq?.addEventListener) {
|
||||
mq.addEventListener('change', set)
|
||||
unwatch = () => mq.removeEventListener('change', set)
|
||||
}
|
||||
} catch { /* no matchMedia: stays as resolved */ }
|
||||
}
|
||||
if (save) {
|
||||
try {
|
||||
storage?.setItem(THEME_STORAGE_KEY, mode)
|
||||
storage?.setItem(PALETTE_STORAGE_KEY, palette)
|
||||
storage?.setItem(STYLE_STORAGE_KEY, style)
|
||||
} catch { /* private mode: not remembered */ }
|
||||
}
|
||||
return { mode, palette, style }
|
||||
}
|
||||
|
||||
/** The mode only; the palette and the style stay as they are on the page (older callers). */
|
||||
export function applyTheme(theme, { root = globalThis.document?.documentElement, storage = browserStorage(), save = false, dark = prefersDark } = {}) {
|
||||
const { mode } = applyLook({ mode: theme, palette: root?.getAttribute?.('data-palette'), style: root?.getAttribute?.('data-style') }, { root, storage, dark })
|
||||
if (save) {
|
||||
try { storage?.setItem(THEME_STORAGE_KEY, t) } catch { /* private mode: not remembered */ }
|
||||
try { storage?.setItem(THEME_STORAGE_KEY, mode) } catch { /* private mode: not remembered */ }
|
||||
}
|
||||
return t
|
||||
return mode
|
||||
}
|
||||
|
||||
+129
-3
@@ -264,8 +264,8 @@
|
||||
* product's colour whatever the venue's accent, and has a dark-mode version (6.15). */
|
||||
:root {
|
||||
--x-nav-bg-rgb: 17 94 89; /* the rail */
|
||||
--x-nav-raised-rgb: 15 118 110; /* hover, an open group */
|
||||
--x-nav-active-rgb: 13 148 136; /* the page you are on */
|
||||
--x-nav-raised-rgb: 21 106 100; /* hover, an open group */
|
||||
--x-nav-active-rgb: 15 118 110; /* the page you are on (white text: 5.5:1) */
|
||||
--x-nav-line-rgb: 13 148 136; /* dividers, a group's left line */
|
||||
--x-nav-ink-rgb: 255 255 255; /* text on the rail */
|
||||
--x-nav-ink-2-rgb: 204 251 241; /* items */
|
||||
@@ -280,6 +280,16 @@
|
||||
--x-nav-ink-3: rgb(var(--x-nav-ink-3-rgb));
|
||||
--x-nav-dot: rgb(var(--x-nav-dot-rgb));
|
||||
}
|
||||
[data-theme], [data-palette] {
|
||||
--x-nav-bg: rgb(var(--x-nav-bg-rgb));
|
||||
--x-nav-raised: rgb(var(--x-nav-raised-rgb));
|
||||
--x-nav-active: rgb(var(--x-nav-active-rgb));
|
||||
--x-nav-line: rgb(var(--x-nav-line-rgb));
|
||||
--x-nav-ink: rgb(var(--x-nav-ink-rgb));
|
||||
--x-nav-ink-2: rgb(var(--x-nav-ink-2-rgb));
|
||||
--x-nav-ink-3: rgb(var(--x-nav-ink-3-rgb));
|
||||
--x-nav-dot: rgb(var(--x-nav-dot-rgb));
|
||||
}
|
||||
[data-theme="dark"] {
|
||||
--x-nav-bg-rgb: 4 47 46;
|
||||
--x-nav-raised-rgb: 17 94 89;
|
||||
@@ -295,6 +305,106 @@
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Palettes (plan step 6.15) ──────────────────────────────────────────────
|
||||
* A palette is the colours of a look: every colour token above (and the nav rail's), once for
|
||||
* light and once for dark. data-theme is always light or dark (theme.js resolves "system"), so
|
||||
* a palette is exactly two blocks. To add one (Tokyo Night, Solarized…): copy the nord blocks,
|
||||
* change the values, add its name to PALETTES in theme.js and its label to the apps' texts; the
|
||||
* contrast test (tests/contrast.test.mjs) checks it in both modes. A palette brings its own
|
||||
* accent, so it wins over the venue's accent (data-venue-theme) while it is on.
|
||||
* Nord: nordtheme.com (Polar Night, Snow Storm, Frost, Aurora), darkened / lightened where text
|
||||
* needed the contrast. */
|
||||
[data-palette="nord"] {
|
||||
--x-canvas-rgb: 236 239 244;
|
||||
--x-surface-rgb: 250 251 252;
|
||||
--x-surface-2-rgb: 229 233 240;
|
||||
--x-surface-3-rgb: 216 222 233;
|
||||
--x-line-rgb: 216 222 233;
|
||||
--x-line-strong-rgb: 174 184 202;
|
||||
--x-ink-rgb: 46 52 64;
|
||||
--x-ink-2-rgb: 59 66 82;
|
||||
--x-ink-3-rgb: 76 86 106;
|
||||
--x-success-rgb: 79 115 59;
|
||||
--x-success-fg-rgb: 255 255 255;
|
||||
--x-success-soft-rgb: 226 236 218;
|
||||
--x-success-ink-rgb: 66 98 49;
|
||||
--x-warning-rgb: 142 98 22;
|
||||
--x-warning-fg-rgb: 255 255 255;
|
||||
--x-warning-soft-rgb: 248 238 214;
|
||||
--x-warning-ink-rgb: 122 83 16;
|
||||
--x-danger-rgb: 166 72 82;
|
||||
--x-danger-fg-rgb: 255 255 255;
|
||||
--x-danger-soft-rgb: 246 224 226;
|
||||
--x-danger-ink-rgb: 148 60 70;
|
||||
--x-info-rgb: 76 106 146;
|
||||
--x-info-fg-rgb: 255 255 255;
|
||||
--x-info-soft-rgb: 222 231 242;
|
||||
--x-info-ink-rgb: 59 85 120;
|
||||
--x-special-rgb: 133 94 128;
|
||||
--x-special-fg-rgb: 255 255 255;
|
||||
--x-special-soft-rgb: 240 228 238;
|
||||
--x-special-ink-rgb: 112 76 107;
|
||||
--x-scrim-rgb: 46 52 64;
|
||||
--x-accent-rgb: 76 106 146;
|
||||
--x-accent-strong-rgb: 59 85 120;
|
||||
--x-accent-fg-rgb: 255 255 255;
|
||||
--x-accent-soft-rgb: 222 231 242;
|
||||
--x-accent-ink-rgb: 59 85 120;
|
||||
--x-nav-bg-rgb: 59 66 82;
|
||||
--x-nav-raised-rgb: 67 76 94;
|
||||
--x-nav-active-rgb: 76 106 146;
|
||||
--x-nav-line-rgb: 76 86 106;
|
||||
--x-nav-ink-rgb: 255 255 255;
|
||||
--x-nav-ink-2-rgb: 229 233 240;
|
||||
--x-nav-ink-3-rgb: 136 192 208;
|
||||
--x-nav-dot-rgb: 136 192 208;
|
||||
}
|
||||
[data-palette="nord"][data-theme="dark"] {
|
||||
--x-canvas-rgb: 46 52 64;
|
||||
--x-surface-rgb: 59 66 82;
|
||||
--x-surface-2-rgb: 67 76 94;
|
||||
--x-surface-3-rgb: 76 86 106;
|
||||
--x-line-rgb: 76 86 106;
|
||||
--x-line-strong-rgb: 97 108 130;
|
||||
--x-ink-rgb: 236 239 244;
|
||||
--x-ink-2-rgb: 216 222 233;
|
||||
--x-ink-3-rgb: 184 193 208;
|
||||
--x-success-rgb: 163 190 140;
|
||||
--x-success-fg-rgb: 46 52 64;
|
||||
--x-success-soft-rgb: 64 82 66;
|
||||
--x-success-ink-rgb: 193 214 176;
|
||||
--x-warning-rgb: 235 203 139;
|
||||
--x-warning-fg-rgb: 46 52 64;
|
||||
--x-warning-soft-rgb: 88 79 61;
|
||||
--x-warning-ink-rgb: 242 220 176;
|
||||
--x-danger-rgb: 220 140 148;
|
||||
--x-danger-fg-rgb: 46 52 64;
|
||||
--x-danger-soft-rgb: 94 62 72;
|
||||
--x-danger-ink-rgb: 236 184 189;
|
||||
--x-info-rgb: 129 161 193;
|
||||
--x-info-fg-rgb: 46 52 64;
|
||||
--x-info-soft-rgb: 63 82 106;
|
||||
--x-info-ink-rgb: 190 210 230;
|
||||
--x-special-rgb: 190 155 184;
|
||||
--x-special-fg-rgb: 46 52 64;
|
||||
--x-special-soft-rgb: 85 68 90;
|
||||
--x-special-ink-rgb: 222 200 218;
|
||||
--x-scrim-rgb: 0 0 0;
|
||||
--x-accent-rgb: 136 192 208;
|
||||
--x-accent-strong-rgb: 143 188 187;
|
||||
--x-accent-fg-rgb: 46 52 64;
|
||||
--x-accent-soft-rgb: 55 79 94;
|
||||
--x-accent-ink-rgb: 163 210 224;
|
||||
--x-nav-bg-rgb: 46 52 64;
|
||||
--x-nav-raised-rgb: 59 66 82;
|
||||
--x-nav-active-rgb: 76 106 146;
|
||||
--x-nav-line-rgb: 67 76 94;
|
||||
--x-nav-ink-rgb: 255 255 255;
|
||||
--x-nav-ink-2-rgb: 229 233 240;
|
||||
--x-nav-ink-3-rgb: 136 192 208;
|
||||
--x-nav-dot-rgb: 136 192 208;
|
||||
}
|
||||
|
||||
/* ── Board (the kitchen display's design language, plan step 3.2b-2) ───────
|
||||
* A dark board with light cards, for screens read from a distance (kitchen, bar,
|
||||
* and any later "board" screen). Always dark: it doesn't follow data-theme; the
|
||||
@@ -389,7 +499,8 @@
|
||||
* resolved where they are declared, then inherited). */
|
||||
:root,
|
||||
[data-theme],
|
||||
[data-venue-theme] {
|
||||
[data-venue-theme],
|
||||
[data-palette] {
|
||||
--x-canvas: rgb(var(--x-canvas-rgb));
|
||||
--x-surface: rgb(var(--x-surface-rgb));
|
||||
--x-surface-2: rgb(var(--x-surface-2-rgb));
|
||||
@@ -478,6 +589,7 @@
|
||||
--x-radius-card: 16px; /* cards, popovers (rounded-2xl) */
|
||||
--x-radius-dialog: 20px; /* dialogs, sheets */
|
||||
--x-radius-full: 9999px;
|
||||
--x-border-width: 1px; /* every component border and Tailwind's `border` */
|
||||
|
||||
/* Control heights: 44 px is the minimum touch target */
|
||||
--x-control-sm: 36px;
|
||||
@@ -511,6 +623,20 @@
|
||||
--x-shadow-overlay: 0 24px 48px rgb(0 0 0 / 0.55), 0 8px 16px rgb(0 0 0 / 0.35);
|
||||
}
|
||||
}
|
||||
/* ── Styles (plan step 6.15) ────────────────────────────────────────────────
|
||||
* A style is the shape of the components, not their colours: corners, borders, depth (and
|
||||
* could be the type or the density). Every component reads these tokens, so a style changes
|
||||
* buttons, fields, cards, dialogs and pills everywhere at once. "rounded" is the default (the
|
||||
* values above). To add one: a block like this, its name in STYLES (theme.js), its label. */
|
||||
[data-style="sharp"] {
|
||||
--x-radius-sm: 2px;
|
||||
--x-radius-control: 4px;
|
||||
--x-radius-card: 6px;
|
||||
--x-radius-dialog: 8px;
|
||||
--x-border-width: 1.5px;
|
||||
--x-shadow-raised: none; /* flat cards: the border draws them */
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
:root {
|
||||
--x-duration-fast: 0ms;
|
||||
|
||||
Reference in New Issue
Block a user