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:
2026-11-20 00:30:24 +02:00
co-authored by Claude Opus 5.5
parent f383060bad
commit 2b44d55f81
14 changed files with 468 additions and 38 deletions
@@ -1,12 +1,14 @@
import { useState, useEffect, useRef } from 'react' import { useState, useEffect, useRef } from 'react'
import { ChevronDown, User, LogOut, Languages, Check } from 'lucide-react' import { ChevronDown, User, LogOut, Languages, Check, Monitor, Moon, Palette, Sun } from 'lucide-react'
import toast from 'react-hot-toast' import toast from 'react-hot-toast'
import { useAccess } from '@xenia/access' import { useAccess } from '@xenia/access'
import { PALETTES, STYLES, THEMES, applyLook, getStoredLook } from '@xenia/ui'
import { LANGUAGE_NAMES, setUserLanguage, useLanguage, useTranslation } from '@xenia/i18n' import { LANGUAGE_NAMES, setUserLanguage, useLanguage, useTranslation } from '@xenia/i18n'
import client from '../api/client' import client from '../api/client'
/** /**
* The profile menu (plan step 2.6a): edit profile, language, sign out. * The profile menu (plan step 2.6a): edit profile, language, the look (6.15: light / dark /
* system, the palette, the style; saved on this device, applied at once), sign out.
* The language changes the screen at once, is saved to the user's profile * The language changes the screen at once, is saved to the user's profile
* (PATCH /api/auth/me) and then the platform bootstrap is reloaded, so it also * (PATCH /api/auth/me) and then the platform bootstrap is reloaded, so it also
* applies on the next login and in the other apps (D-12). * applies on the next login and in the other apps (D-12).
@@ -16,6 +18,8 @@ export default function UserMenuButton({ displayName, onEditProfile, onSignOut }
const { language, languages } = useLanguage() const { language, languages } = useLanguage()
const { refresh } = useAccess() const { refresh } = useAccess()
const [open, setOpen] = useState(false) const [open, setOpen] = useState(false)
const [look, setLook] = useState(getStoredLook)
const pickLook = change => setLook(applyLook({ ...look, ...change }, { save: true }))
const ref = useRef(null) const ref = useRef(null)
useEffect(() => { useEffect(() => {
@@ -60,7 +64,7 @@ export default function UserMenuButton({ displayName, onEditProfile, onSignOut }
</button> </button>
{open && ( {open && (
<div className="absolute right-0 top-full mt-1.5 w-52 rounded-xl border border-line bg-surface shadow-lg py-1 z-50" role="menu"> <div className="absolute right-0 top-full mt-1.5 w-72 rounded-xl border border-line bg-surface shadow-lg py-1 z-50" role="menu">
<button <button
role="menuitem" role="menuitem"
onClick={() => { setOpen(false); onEditProfile() }} onClick={() => { setOpen(false); onEditProfile() }}
@@ -89,6 +93,16 @@ export default function UserMenuButton({ displayName, onEditProfile, onSignOut }
</button> </button>
))} ))}
<div className="my-1 border-t border-line" />
<div className="flex items-center gap-2.5 px-3.5 pt-1.5 pb-1 text-[11px] font-semibold uppercase tracking-wide text-ink-3">
<Palette className="h-3.5 w-3.5" />
{t('profile.look')}
</div>
<LookRow label={t('profile.mode')} options={THEMES} value={look.mode} onPick={mode => pickLook({ mode })}
name={m => t(`profile.modes.${m}`)} icon={m => ({ light: Sun, dark: Moon, system: Monitor })[m]} testId="look-mode" />
<LookRow label={t('profile.palette')} options={PALETTES} value={look.palette} onPick={palette => pickLook({ palette })} name={p => t(`profile.palettes.${p}`)} testId="look-palette" />
<LookRow label={t('profile.style')} options={STYLES} value={look.style} onPick={style => pickLook({ style })} name={x => t(`profile.styles.${x}`)} testId="look-style" />
<div className="my-1 border-t border-line" /> <div className="my-1 border-t border-line" />
<button <button
role="menuitem" role="menuitem"
@@ -103,3 +117,24 @@ export default function UserMenuButton({ displayName, onEditProfile, onSignOut }
</div> </div>
) )
} }
/** One choice of the look: a small segmented row (the menu stays open, the page changes at once). */
function LookRow({ label, options, value, onPick, name, icon, testId }) {
return (
<div className="px-3.5 py-1 grid gap-1" role="group" aria-label={label} data-testid={testId}>
<span className="text-caption text-ink-3">{label}</span>
<span className="flex gap-1">
{options.map(o => {
const Icon = icon?.(o)
const on = o === value
return (
<button key={o} type="button" role="menuitemradio" aria-checked={on} onClick={() => onPick(o)} data-value={o}
className={`flex-1 flex items-center justify-center gap-1 rounded-control border px-1.5 py-1 text-caption font-medium transition-colors ${on ? 'border-accent bg-accent-soft text-accent-ink' : 'border-line text-ink-2 hover:bg-surface-2'}`}>
{Icon && <Icon className="h-3.5 w-3.5" aria-hidden="true" />}{name(o)}
</button>
)
})}
</span>
</div>
)
}
+4 -4
View File
@@ -5,11 +5,11 @@ import { Toaster } from 'react-hot-toast'
import App from './App.jsx' import App from './App.jsx'
import '@xenia/ui/styles.css' // shared tokens + component styles (.x-*), no global rules import '@xenia/ui/styles.css' // shared tokens + component styles (.x-*), no global rules
import './index.css' import './index.css'
import { applyTheme } from '@xenia/ui' import { applyLook, getStoredLook } from '@xenia/ui'
// Light only until phase 6 converts the older pages to the colour tokens (decided // The look saved on this device (6.15): light / dark / system, the palette and the style,
// 2026-11-14); then the profile menu offers light/dark/system: applyTheme(getStoredTheme()). // chosen in the profile menu (every page is on the tokens since 6.14).
applyTheme('light') applyLook(getStoredLook())
const queryClient = new QueryClient({ const queryClient = new QueryClient({
defaultOptions: { defaultOptions: {
+17
View File
@@ -76,6 +76,23 @@
"mismatch": "Οι δύο κωδικοί δεν ταιριάζουν.", "mismatch": "Οι δύο κωδικοί δεν ταιριάζουν.",
"pin": "4 έως 6 ψηφία.", "pin": "4 έως 6 ψηφία.",
"pinMismatch": "Τα δύο PIN δεν ταιριάζουν." "pinMismatch": "Τα δύο PIN δεν ταιριάζουν."
},
"look": "Εμφάνιση",
"mode": "Φωτεινή ή σκοτεινή",
"modes": {
"light": "Φωτεινή",
"dark": "Σκοτεινή",
"system": "Συσκευής"
},
"palette": "Χρώματα",
"palettes": {
"default": "Xenia",
"nord": "Nord"
},
"style": "Σχήματα",
"styles": {
"rounded": "Στρογγυλά",
"sharp": "Γωνιώδη"
} }
}, },
"login": { "login": {
+17
View File
@@ -76,6 +76,23 @@
"mismatch": "The two passwords don't match.", "mismatch": "The two passwords don't match.",
"pin": "4 to 6 digits.", "pin": "4 to 6 digits.",
"pinMismatch": "The two PINs don't match." "pinMismatch": "The two PINs don't match."
},
"look": "Look",
"mode": "Light or dark",
"modes": {
"light": "Light",
"dark": "Dark",
"system": "Device"
},
"palette": "Colours",
"palettes": {
"default": "Xenia",
"nord": "Nord"
},
"style": "Shapes",
"styles": {
"rounded": "Rounded",
"sharp": "Sharp"
} }
}, },
"login": { "login": {
+6 -6
View File
@@ -26,7 +26,7 @@
display: inline-flex; align-items: center; justify-content: center; gap: var(--x-space-2); display: inline-flex; align-items: center; justify-content: center; gap: var(--x-space-2);
box-sizing: border-box; box-sizing: border-box;
min-height: var(--x-control-md); padding: 0 var(--x-space-4); 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); 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; 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), 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 { .x-modal__footer {
display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--x-space-2); display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--x-space-2);
padding: var(--x-space-4) var(--x-space-6); 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; } .x-modal__header + .x-modal__footer { border-top: 0; }
@@ -141,7 +141,7 @@
display: flex; align-items: flex-start; gap: var(--x-space-3); 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); 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); 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); box-shadow: var(--x-shadow-popover);
pointer-events: auto; pointer-events: auto;
animation: x-pop-in var(--x-duration-base) var(--x-ease); animation: x-pop-in var(--x-duration-base) var(--x-ease);
@@ -253,7 +253,7 @@
box-sizing: border-box; width: 100%; box-sizing: border-box; width: 100%;
min-height: var(--x-control-md); padding: 0 var(--x-space-3); min-height: var(--x-control-md); padding: 0 var(--x-space-3);
background: var(--x-surface); color: var(--x-ink); 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 */ 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); 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 { .x-stepper__btn {
display: inline-flex; align-items: center; justify-content: center; display: inline-flex; align-items: center; justify-content: center;
width: var(--x-control-md); height: var(--x-control-md); padding: 0; 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; background: var(--x-surface-2); color: var(--x-ink); cursor: pointer;
transition: background-color var(--x-duration-fast) var(--x-ease); transition: background-color var(--x-duration-fast) var(--x-ease);
-webkit-tap-highlight-color: transparent; -webkit-tap-highlight-color: transparent;
@@ -332,5 +332,5 @@
/* ── QR code (QrCode, @xenia/ui/qr; plan step 6.14c) ─────────────────────── */ /* ── QR code (QrCode, @xenia/ui/qr; plan step 6.14c) ─────────────────────── */
.x-qr { display: grid; justify-items: center; gap: var(--x-space-2); } .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 */ /* 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; } .x-qr__caption { font-size: var(--x-text-label); color: var(--x-ink-2); text-align: center; }
+1 -1
View File
@@ -24,4 +24,4 @@ export { Stepper } from './components/Stepper.jsx'
export { ReasonPicker, reasonText } from './components/ReasonPicker.jsx' export { ReasonPicker, reasonText } from './components/ReasonPicker.jsx'
export { UiLabelsProvider, DEFAULT_LABELS } from './components/labels.js' export { UiLabelsProvider, DEFAULT_LABELS } from './components/labels.js'
export { cx } from './internal/cx.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
View File
@@ -1,34 +1,98 @@
// The colour theme of an app (plan step 2.6f): light | dark | system (follows the OS). // The look of an app (plan steps 2.6f, 6.15): three independent choices, each an attribute on
// tokens.css reads it from data-theme on <html>. The choice is per device (localStorage), // <html> that tokens.css reads. Nothing else changes: every component draws from the tokens.
// like a screen setting, not per user. No React here.
// //
// applyTheme(getStoredTheme()) at startup // mode data-theme light | dark | system (follows the device, live)
// applyTheme('dark', { save: true }) when the user picks one // 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 // "system" is resolved here (matchMedia), so data-theme is always light or dark and a palette
// then it always applies 'light' (decided 2026-11-14), so a saved choice waits unused. // 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 THEMES = ['light', 'dark', 'system']
export const PALETTES = ['default', 'nord']
export const STYLES = ['rounded', 'sharp']
export const THEME_STORAGE_KEY = 'xenia_theme' 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 } } const browserStorage = () => { try { return globalThis.localStorage ?? null } catch { return null } }
const read = (storage, key, list, fallback) => {
/** The saved theme, or 'light'. */
export function getStoredTheme(storage = browserStorage()) {
try { try {
const v = storage?.getItem(THEME_STORAGE_KEY) const v = storage?.getItem(key)
return THEMES.includes(v) ? v : 'light' return list.includes(v) ? v : fallback
} catch { } 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'. */ /** 'light' or 'dark' for a mode ('system' asks the device). */
export function applyTheme(theme, { root = globalThis.document?.documentElement, storage = browserStorage(), save = false } = {}) { export function resolveMode(mode, dark = prefersDark) {
const t = THEMES.includes(theme) ? theme : 'light' return mode === 'dark' || (mode === 'system' && dark()) ? 'dark' : 'light'
root?.setAttribute('data-theme', t) }
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) { 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
View File
@@ -264,8 +264,8 @@
* product's colour whatever the venue's accent, and has a dark-mode version (6.15). */ * product's colour whatever the venue's accent, and has a dark-mode version (6.15). */
:root { :root {
--x-nav-bg-rgb: 17 94 89; /* the rail */ --x-nav-bg-rgb: 17 94 89; /* the rail */
--x-nav-raised-rgb: 15 118 110; /* hover, an open group */ --x-nav-raised-rgb: 21 106 100; /* hover, an open group */
--x-nav-active-rgb: 13 148 136; /* the page you are on */ --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-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-rgb: 255 255 255; /* text on the rail */
--x-nav-ink-2-rgb: 204 251 241; /* items */ --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-ink-3: rgb(var(--x-nav-ink-3-rgb));
--x-nav-dot: rgb(var(--x-nav-dot-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"] { [data-theme="dark"] {
--x-nav-bg-rgb: 4 47 46; --x-nav-bg-rgb: 4 47 46;
--x-nav-raised-rgb: 17 94 89; --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) ─────── /* ── 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, * 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 * 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). */ * resolved where they are declared, then inherited). */
:root, :root,
[data-theme], [data-theme],
[data-venue-theme] { [data-venue-theme],
[data-palette] {
--x-canvas: rgb(var(--x-canvas-rgb)); --x-canvas: rgb(var(--x-canvas-rgb));
--x-surface: rgb(var(--x-surface-rgb)); --x-surface: rgb(var(--x-surface-rgb));
--x-surface-2: rgb(var(--x-surface-2-rgb)); --x-surface-2: rgb(var(--x-surface-2-rgb));
@@ -478,6 +589,7 @@
--x-radius-card: 16px; /* cards, popovers (rounded-2xl) */ --x-radius-card: 16px; /* cards, popovers (rounded-2xl) */
--x-radius-dialog: 20px; /* dialogs, sheets */ --x-radius-dialog: 20px; /* dialogs, sheets */
--x-radius-full: 9999px; --x-radius-full: 9999px;
--x-border-width: 1px; /* every component border and Tailwind's `border` */
/* Control heights: 44 px is the minimum touch target */ /* Control heights: 44 px is the minimum touch target */
--x-control-sm: 36px; --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); --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) { @media (prefers-reduced-motion: reduce) {
:root { :root {
--x-duration-fast: 0ms; --x-duration-fast: 0ms;
+2
View File
@@ -47,6 +47,8 @@ export default {
heading: ['var(--x-text-heading)', { lineHeight: 'var(--x-leading-heading)' }], heading: ['var(--x-text-heading)', { lineHeight: 'var(--x-leading-heading)' }],
display: ['var(--x-text-display)', { lineHeight: 'var(--x-leading-display)' }], display: ['var(--x-text-display)', { lineHeight: 'var(--x-leading-display)' }],
}, },
// `border` follows the look's style (6.15: --x-border-width; 1px by default)
borderWidth: { DEFAULT: 'var(--x-border-width)' },
borderRadius: { borderRadius: {
control: 'var(--x-radius-control)', control: 'var(--x-radius-control)',
card: 'var(--x-radius-card)', card: 'var(--x-radius-card)',
+23
View File
@@ -4,6 +4,7 @@
import assert from 'node:assert/strict' import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs' import { readFileSync } from 'node:fs'
import { test } from 'node:test' import { test } from 'node:test'
import { PALETTES } from '../src/theme.js'
const css = readFileSync(new URL('../src/tokens.css', import.meta.url), 'utf8') const css = readFileSync(new URL('../src/tokens.css', import.meta.url), 'utf8')
@@ -59,6 +60,28 @@ for (const venue of venues) {
} }
} }
// Palettes (6.15): every palette in theme.js, light and dark, the same pairs as the default plus
// the nav rail. A palette block sets every colour itself, so it is checked on its own.
const navPairs = [['nav-ink', 'nav-bg', TEXT], ['nav-ink-2', 'nav-bg', TEXT], ['nav-ink-3', 'nav-bg', TEXT], ['nav-ink', 'nav-active', TEXT], ['nav-ink-2', 'nav-raised', TEXT]]
const check = (t, list) => list.filter(([fg, bg]) => t[fg] && t[bg]).map(([fg, bg, min]) => [fg, bg, min, ratio(t[fg], t[bg])])
.filter(([, , min, r]) => r < min).map(([fg, bg, min, r]) => `${fg} on ${bg}: ${r.toFixed(2)} < ${min}`)
for (const palette of PALETTES.filter(p => p !== 'default')) {
for (const [mode, sel] of [['light', `[data-palette="${palette}"]`], ['dark', `[data-palette="${palette}"][data-theme="dark"]`]]) {
test(`palette ${palette} / ${mode}`, () => {
const t = rule(sel)
const missing = [...pairs, ...navPairs].flatMap(([fg, bg]) => [fg, bg]).filter(k => !t[k])
assert.deepEqual([...new Set(missing)], [], 'a palette sets every colour token')
assert.deepEqual(check(t, [...pairs, ...navPairs]), [])
})
}
}
test('the default nav rail is readable', () => {
const nav = rule(':root') // first :root holds the colours; the nav set is its own :root block
const navRoot = Object.fromEntries([...css.slice(css.indexOf('/* ── Nav')).matchAll(/--x-(nav-[\w-]+)-rgb:\s*([\d\s]+);/g)].slice(0, 8).map(([, k, v]) => [k, v.trim().split(/\s+/).map(Number)]))
assert.ok(nav.canvas && navRoot['nav-bg'])
assert.deepEqual(check(navRoot, navPairs), [])
})
test('system theme mirrors dark', () => { test('system theme mirrors dark', () => {
const sys = css.slice(css.indexOf('@media (prefers-color-scheme: dark)')) const sys = css.slice(css.indexOf('@media (prefers-color-scheme: dark)'))
assert.match(sys, /\[data-theme="system"\]/) assert.match(sys, /\[data-theme="system"\]/)
+22 -2
View File
@@ -1,9 +1,9 @@
import assert from 'node:assert/strict' import assert from 'node:assert/strict'
import { test } from 'node:test' import { test } from 'node:test'
import { applyTheme, getStoredTheme, THEME_STORAGE_KEY } from '../src/theme.js' import { applyLook, applyTheme, getStoredLook, getStoredTheme, resolveMode, THEME_STORAGE_KEY } from '../src/theme.js'
const memory = () => { const m = new Map(); return { getItem: k => m.get(k) ?? null, setItem: (k, v) => m.set(k, v) } } const memory = () => { const m = new Map(); return { getItem: k => m.get(k) ?? null, setItem: (k, v) => m.set(k, v) } }
const element = () => { const a = {}; return { setAttribute: (k, v) => { a[k] = v }, attrs: a } } const element = () => { const a = {}; return { setAttribute: (k, v) => { a[k] = v }, getAttribute: k => a[k] ?? null, attrs: a } }
test('stored theme: light unless a known one is saved', () => { test('stored theme: light unless a known one is saved', () => {
const s = memory() const s = memory()
@@ -25,3 +25,23 @@ test('applyTheme sets data-theme and saves only when asked', () => {
assert.equal(getStoredTheme(s), 'dark') assert.equal(getStoredTheme(s), 'dark')
assert.equal(applyTheme('bogus', { root, storage: s }), 'light') assert.equal(applyTheme('bogus', { root, storage: s }), 'light')
}) })
test('a look: mode, palette and style; "system" resolves to light or dark', () => {
const s = memory()
const root = element()
assert.deepEqual(getStoredLook(s), { mode: 'light', palette: 'default', style: 'rounded' })
const got = applyLook({ mode: 'system', palette: 'nord', style: 'sharp' }, { root, storage: s, save: true, dark: () => true })
assert.deepEqual(got, { mode: 'system', palette: 'nord', style: 'sharp' })
assert.deepEqual([root.attrs['data-theme'], root.attrs['data-theme-choice'], root.attrs['data-palette'], root.attrs['data-style']], ['dark', 'system', 'nord', 'sharp'])
assert.deepEqual(getStoredLook(s), { mode: 'system', palette: 'nord', style: 'sharp' })
assert.deepEqual(applyLook({ palette: 'neon', style: 'wobbly' }, { root, storage: s }), { mode: 'light', palette: 'default', style: 'rounded' })
assert.equal(resolveMode('system', () => false), 'light')
assert.equal(resolveMode('dark'), 'dark')
})
test('applyTheme keeps the palette and the style on the page', () => {
const root = element()
applyLook({ mode: 'light', palette: 'nord', style: 'sharp' }, { root, storage: memory() })
applyTheme('dark', { root, storage: memory() })
assert.deepEqual([root.attrs['data-theme'], root.attrs['data-palette'], root.attrs['data-style']], ['dark', 'nord', 'sharp'])
})
+19
View File
@@ -809,6 +809,25 @@ try {
r.check(`${tl} the profile: a PIN of 2 digits is refused before saving`, (await page.getByTestId('profile-dialog').textContent()).includes('4 to 6 digits')) r.check(`${tl} the profile: a PIN of 2 digits is refused before saving`, (await page.getByTestId('profile-dialog').textContent()).includes('4 to 6 digits'))
await page.keyboard.press('Escape') await page.keyboard.press('Escape')
r.check(`${tl} the side rail is drawn with the nav tokens`, await page.getByTestId('sidebar').evaluate(el => getComputedStyle(el).backgroundColor) === 'rgb(17, 94, 89)') r.check(`${tl} the side rail is drawn with the nav tokens`, await page.getByTestId('sidebar').evaluate(el => getComputedStyle(el).backgroundColor) === 'rgb(17, 94, 89)')
// ── 6.15: the look from the profile menu (mode, palette, style), kept on this device ──
const lk = 'look:'
const attr = n => page.evaluate(k => document.documentElement.getAttribute(k), n)
await page.getByTestId('user-menu').click()
await page.getByTestId('look-mode').locator('[data-value="dark"]').click()
r.check(`${lk} Dark applies at once`, await attr('data-theme') === 'dark' && await page.getByTestId('sidebar').evaluate(el => getComputedStyle(el).backgroundColor) === 'rgb(4, 47, 46)')
await page.getByTestId('look-palette').locator('[data-value="nord"]').click()
await page.getByTestId('look-style').locator('[data-value="sharp"]').click()
await page.reload()
await page.getByTestId('sidebar').waitFor({ timeout: 10_000 })
r.check(`${lk} Nord, sharp and dark are kept after a reload`, await attr('data-theme') === 'dark' && await attr('data-palette') === 'nord' && await attr('data-style') === 'sharp'
&& await page.locator('.x-btn').first().evaluate(el => getComputedStyle(el).borderRadius) === '4px')
await page.getByTestId('user-menu').click()
await page.getByTestId('look-mode').locator('[data-value="system"]').click()
r.check(`${lk} "Device" follows the device (light here)`, await attr('data-theme') === 'light' && await attr('data-theme-choice') === 'system')
await page.getByTestId('look-mode').locator('[data-value="light"]').click()
await page.getByTestId('look-palette').locator('[data-value="default"]').click()
await page.getByTestId('look-style').locator('[data-value="rounded"]').click()
await page.keyboard.press('Escape')
await page.goto(`${APP}/reports/technical`) await page.goto(`${APP}/reports/technical`)
await page.getByText('Log files', { exact: true }).click() await page.getByText('Log files', { exact: true }).click()
+106
View File
@@ -0,0 +1,106 @@
// Every manager page in each look (plan step 6.15: "every manager page reads well in dark, side
// by side screenshots reviewed"). For each page and look: a screenshot, and in dark looks a check
// that nothing large is still painted near-white (a colour that didn't come from the tokens).
// Then contact sheets (light | dark side by side, a few pages each) to review.
//
// node manager_look.mjs → out/manager-look/<page>-<look>.png, sheet-N.png
// node manager_look.mjs nord-sharp → also the Nord palette with the sharp style
//
// Starts its own backend (:8066, demo data) and the manager (:5190).
import { mkdirSync, openSync, writeFileSync } from 'node:fs'
import path from 'node:path'
import { spawn } from 'node:child_process'
import { chromium } from 'playwright'
import { BROWSER_CHANNEL, CS, OUT, reporter, sleep } from './lib/env.mjs'
import { killTree, login, startBackend, waitHttp } from './lib/proc.mjs'
const DIR = path.join(OUT, 'manager-look')
mkdirSync(DIR, { recursive: true })
const extra = process.argv.includes('nord-sharp')
const LOOKS = [
{ id: 'light', mode: 'light', palette: 'default', style: 'rounded' },
{ id: 'dark', mode: 'dark', palette: 'default', style: 'rounded' },
...(extra ? [{ id: 'nord-light', mode: 'light', palette: 'nord', style: 'sharp' }, { id: 'nord-dark', mode: 'dark', palette: 'nord', style: 'sharp' }] : []),
]
const PAGES = [
'dashboard', 'tables', 'online-orders', 'online/fees', 'online/qr', 'crm/contacts', 'crm/customers', 'financials/expenses', 'financials/tabs',
'management/products', 'management/media', 'management/signage', 'management/tables', 'management/staff', 'management/sessions',
'management/approvals', 'management/schedule', 'management/prep-zones', 'management/pricing', 'inventory/throwaways', 'inventory/stock', 'notes',
'reports/today', 'reports/store', 'reports/staff', 'reports/products', 'reports/prep-zones', 'reports/expenses', 'reports/technical', 'reports/misc',
'apps', 'integrations', 'devices', 'license', 'settings?tab=app-info', 'settings?tab=venue', 'settings?tab=security', 'settings?tab=operation',
'settings?tab=colours', 'settings?tab=print-fonts', 'settings?tab=customer-display', 'settings?tab=menu-tablets', 'settings?tab=fiscal', 'apps/phone',
]
const MODULES = ['connect_orders', 'connect_menu', 'crm', 'tabs', 'expenses', 'inventory', 'notes', 'chat', 'customer_display', 'menu_tablet', 'signage',
'fiscal', 'staff_planning', 'reservations', 'pricing', 'caller_id', 'waiter_app']
const backend = await startBackend({ port: 8066, siteId: 'test-site-1', env: { LICENSE_MODE: 'off' } })
const APP = 'http://localhost:5190'
const log = openSync(path.join(OUT, 'vite-5190.log'), 'w')
const vite = spawn('npx', ['vite', '--port', '5190', '--strictPort'], {
cwd: path.join(CS, 'manager_dashboard'), shell: process.platform === 'win32', detached: process.platform !== 'win32',
stdio: ['ignore', log, log], env: { ...process.env, XENIA_BACKEND: backend.url },
})
const browser = await chromium.launch(BROWSER_CHANNEL ? { channel: BROWSER_CHANNEL } : {})
const r = reporter(`manager look (6.15): every page in ${LOOKS.map(l => l.id).join(', ')}`)
const name = p => p.replace(/[/?=]/g, '-')
try {
await waitHttp(APP)
const boss = await login(backend.url)
const put = (url, body) => fetch(`${backend.url}${url}`, { method: 'PUT', headers: { 'content-type': 'application/json', authorization: `Bearer ${boss}` }, body: JSON.stringify(body) })
for (const m of MODULES) await put(`/api/platform/modules/${m}`, { enabled: true }).catch(() => {})
await fetch(`${backend.url}/api/business-day/open`, { method: 'POST', headers: { 'content-type': 'application/json', authorization: `Bearer ${boss}` }, body: '{}' }).catch(() => {})
const ctx = await browser.newContext({ viewport: { width: 1280, height: 800 } })
const page = await ctx.newPage()
const errors = []
page.on('pageerror', e => errors.push(String(e)))
await page.goto(`${APP}/login`)
await page.getByTestId('login-form').waitFor({ timeout: 60_000 })
if (!(await page.getByTestId('login-account').count())) await page.getByLabel('Username').fill('manager')
await page.getByLabel('Password').fill('password')
await page.getByRole('button', { name: 'Sign in', exact: true }).click()
await page.waitForURL(u => u.pathname === '/dashboard', { timeout: 20_000 })
const bright = {}
for (const look of LOOKS) {
await page.evaluate(l => { localStorage.setItem('xenia_theme', l.mode); localStorage.setItem('xenia_palette', l.palette); localStorage.setItem('xenia_style', l.style) }, look)
for (const p of PAGES) {
await page.goto(`${APP}/${p}`)
await page.waitForLoadState('networkidle').catch(() => {})
await sleep(600)
await page.screenshot({ path: path.join(DIR, `${name(p)}-${look.id}.png`) })
if (look.mode === 'dark') {
// large elements still near-white in a dark look: colours that didn't come from the tokens
const hits = await page.evaluate(() => {
const lum = c => { const m = c.match(/rgba?\(([\d.]+),\s*([\d.]+),\s*([\d.]+)(?:,\s*([\d.]+))?/); if (!m || (m[4] !== undefined && Number(m[4]) < 0.5)) return 0; const f = x => { x /= 255; return x <= 0.03928 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4 }; return 0.2126 * f(+m[1]) + 0.7152 * f(+m[2]) + 0.0722 * f(+m[3]) }
const out = []
for (const el of document.querySelectorAll('body *')) {
if (el.closest('.x-qr__tile, svg, img, video, canvas, [data-venue-colour], [data-testid^="signage-"], [data-testid="colours-free"], [data-testid^="colours-"]')) continue
const r = el.getBoundingClientRect()
if (r.width * r.height < 2000 || r.bottom < 0 || r.top > innerHeight) continue
if (lum(getComputedStyle(el).backgroundColor) > 0.8) out.push(`${el.tagName.toLowerCase()}.${String(el.className).split(' ').slice(0, 4).join('.')}`)
}
return out.slice(0, 5)
})
if (hits.length) bright[`${p} (${look.id})`] = hits
}
}
}
r.check('dark looks: no large near-white areas left', Object.keys(bright).length === 0, JSON.stringify(bright, null, 1).slice(0, 2000))
// contact sheets: for each page, every look side by side
const per = 5
for (let i = 0; i < PAGES.length; i += per) {
const rows = PAGES.slice(i, i + per).map(p => `<tr><th colspan="${LOOKS.length}">${p}</th></tr><tr>${LOOKS.map(l => `<td><img src="${name(p)}-${l.id}.png"></td>`).join('')}</tr>`).join('')
const file = path.join(DIR, `sheet-${i / per + 1}.html`)
writeFileSync(file, `<!doctype html><meta charset="utf-8"><style>body{margin:0;font:12px sans-serif;background:#888}th{text-align:left;padding:4px}td{padding:2px}img{width:${LOOKS.length > 2 ? 400 : 640}px;display:block}</style><table>${rows}</table>`)
const sheet = await ctx.newPage()
await sheet.goto(`file://${file.replace(/\\/g, '/')}`)
await sheet.screenshot({ path: path.join(DIR, `sheet-${i / per + 1}.png`), fullPage: true })
await sheet.close()
}
r.check('no page errors', errors.length === 0, errors.slice(0, 3).join(' | '))
console.log(` screenshots and sheets: ${DIR}`)
} finally {
await browser.close()
killTree(vite)
await backend.stop()
}
process.exit(r.done() ? 1 : 0)
+1
View File
@@ -30,6 +30,7 @@ const suites = [
['waiter (sign-in, keys, prices, languages, history, look, bookings)', 'node', ['waiter.mjs'], E2E], ['waiter (sign-in, keys, prices, languages, history, look, bookings)', 'node', ['waiter.mjs'], E2E],
['manager (login, bootstrap, approvals)', 'node', ['manager.mjs'], E2E], ['manager (login, bootstrap, approvals)', 'node', ['manager.mjs'], E2E],
['setup (a fresh install: the wizard to the overview)', 'node', ['setup.mjs'], E2E], ['setup (a fresh install: the wizard to the overview)', 'node', ['setup.mjs'], E2E],
['manager look (every page, light and dark)', 'node', ['manager_look.mjs'], E2E],
['media (Media page, product photos, waiter offline photos)', 'node', ['media.mjs'], E2E], ['media (Media page, product photos, waiter offline photos)', 'node', ['media.mjs'], E2E],
['terminal (pairing, sign-in, states)', 'node', ['terminal.mjs'], E2E], ['terminal (pairing, sign-in, states)', 'node', ['terminal.mjs'], E2E],
['signage (the player on a TV, the editor)', 'node', ['signage.mjs'], E2E], ['signage (the player on a TV, the editor)', 'node', ['signage.mjs'], E2E],