From 2b44d55f81d7cbf77e0c21ec0039a851abcec02c Mon Sep 17 00:00:00 2001 From: bonamin Date: Fri, 20 Nov 2026 00:30:24 +0200 Subject: [PATCH] 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 --- .../src/components/UserMenuButton.jsx | 41 +++++- manager_dashboard/src/main.jsx | 8 +- packages/i18n/locales/el/manager.json | 17 +++ packages/i18n/locales/en/manager.json | 17 +++ packages/ui/src/components.css | 12 +- packages/ui/src/index.js | 2 +- packages/ui/src/theme.js | 102 +++++++++++--- packages/ui/src/tokens.css | 132 +++++++++++++++++- packages/ui/tailwind-preset.js | 2 + packages/ui/tests/contrast.test.mjs | 23 +++ packages/ui/tests/theme.test.mjs | 24 +++- tests/e2e/manager.mjs | 19 +++ tests/e2e/manager_look.mjs | 106 ++++++++++++++ tests/e2e/run-all.mjs | 1 + 14 files changed, 468 insertions(+), 38 deletions(-) create mode 100644 tests/e2e/manager_look.mjs diff --git a/manager_dashboard/src/components/UserMenuButton.jsx b/manager_dashboard/src/components/UserMenuButton.jsx index 22f6125..393ff6a 100644 --- a/manager_dashboard/src/components/UserMenuButton.jsx +++ b/manager_dashboard/src/components/UserMenuButton.jsx @@ -1,12 +1,14 @@ 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 { useAccess } from '@xenia/access' +import { PALETTES, STYLES, THEMES, applyLook, getStoredLook } from '@xenia/ui' import { LANGUAGE_NAMES, setUserLanguage, useLanguage, useTranslation } from '@xenia/i18n' 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 * (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). @@ -16,6 +18,8 @@ export default function UserMenuButton({ displayName, onEditProfile, onSignOut } const { language, languages } = useLanguage() const { refresh } = useAccess() const [open, setOpen] = useState(false) + const [look, setLook] = useState(getStoredLook) + const pickLook = change => setLook(applyLook({ ...look, ...change }, { save: true })) const ref = useRef(null) useEffect(() => { @@ -60,7 +64,7 @@ export default function UserMenuButton({ displayName, onEditProfile, onSignOut } {open && ( -
+
))} +
+
+ + {t('profile.look')} +
+ pickLook({ mode })} + name={m => t(`profile.modes.${m}`)} icon={m => ({ light: Sun, dark: Moon, system: Monitor })[m]} testId="look-mode" /> + pickLook({ palette })} name={p => t(`profile.palettes.${p}`)} testId="look-palette" /> + pickLook({ style })} name={x => t(`profile.styles.${x}`)} testId="look-style" /> +
+ ) + })} + +
+ ) +} diff --git a/manager_dashboard/src/main.jsx b/manager_dashboard/src/main.jsx index a44b176..8fd73fe 100644 --- a/manager_dashboard/src/main.jsx +++ b/manager_dashboard/src/main.jsx @@ -5,11 +5,11 @@ import { Toaster } from 'react-hot-toast' import App from './App.jsx' import '@xenia/ui/styles.css' // shared tokens + component styles (.x-*), no global rules 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 -// 2026-11-14); then the profile menu offers light/dark/system: applyTheme(getStoredTheme()). -applyTheme('light') +// The look saved on this device (6.15): light / dark / system, the palette and the style, +// chosen in the profile menu (every page is on the tokens since 6.14). +applyLook(getStoredLook()) const queryClient = new QueryClient({ defaultOptions: { diff --git a/packages/i18n/locales/el/manager.json b/packages/i18n/locales/el/manager.json index 8dc7ae1..c890d4e 100644 --- a/packages/i18n/locales/el/manager.json +++ b/packages/i18n/locales/el/manager.json @@ -76,6 +76,23 @@ "mismatch": "Οι δύο κωδικοί δεν ταιριάζουν.", "pin": "4 έως 6 ψηφία.", "pinMismatch": "Τα δύο PIN δεν ταιριάζουν." + }, + "look": "Εμφάνιση", + "mode": "Φωτεινή ή σκοτεινή", + "modes": { + "light": "Φωτεινή", + "dark": "Σκοτεινή", + "system": "Συσκευής" + }, + "palette": "Χρώματα", + "palettes": { + "default": "Xenia", + "nord": "Nord" + }, + "style": "Σχήματα", + "styles": { + "rounded": "Στρογγυλά", + "sharp": "Γωνιώδη" } }, "login": { diff --git a/packages/i18n/locales/en/manager.json b/packages/i18n/locales/en/manager.json index 75444b9..8e6e82d 100644 --- a/packages/i18n/locales/en/manager.json +++ b/packages/i18n/locales/en/manager.json @@ -76,6 +76,23 @@ "mismatch": "The two passwords don't match.", "pin": "4 to 6 digits.", "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": { diff --git a/packages/ui/src/components.css b/packages/ui/src/components.css index b712df6..755c374 100644 --- a/packages/ui/src/components.css +++ b/packages/ui/src/components.css @@ -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; } diff --git a/packages/ui/src/index.js b/packages/ui/src/index.js index fb97005..dda900a 100644 --- a/packages/ui/src/index.js +++ b/packages/ui/src/index.js @@ -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' diff --git a/packages/ui/src/theme.js b/packages/ui/src/theme.js index 074f28c..d1bbc5f 100644 --- a/packages/ui/src/theme.js +++ b/packages/ui/src/theme.js @@ -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 . 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 +// 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 } diff --git a/packages/ui/src/tokens.css b/packages/ui/src/tokens.css index 47a6340..a1076e4 100644 --- a/packages/ui/src/tokens.css +++ b/packages/ui/src/tokens.css @@ -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; diff --git a/packages/ui/tailwind-preset.js b/packages/ui/tailwind-preset.js index 28dc1e1..4a6a12e 100644 --- a/packages/ui/tailwind-preset.js +++ b/packages/ui/tailwind-preset.js @@ -47,6 +47,8 @@ export default { heading: ['var(--x-text-heading)', { lineHeight: 'var(--x-leading-heading)' }], 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: { control: 'var(--x-radius-control)', card: 'var(--x-radius-card)', diff --git a/packages/ui/tests/contrast.test.mjs b/packages/ui/tests/contrast.test.mjs index 1045c80..f6d5c8f 100644 --- a/packages/ui/tests/contrast.test.mjs +++ b/packages/ui/tests/contrast.test.mjs @@ -4,6 +4,7 @@ import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' import { test } from 'node:test' +import { PALETTES } from '../src/theme.js' 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', () => { const sys = css.slice(css.indexOf('@media (prefers-color-scheme: dark)')) assert.match(sys, /\[data-theme="system"\]/) diff --git a/packages/ui/tests/theme.test.mjs b/packages/ui/tests/theme.test.mjs index c4979cd..026b775 100644 --- a/packages/ui/tests/theme.test.mjs +++ b/packages/ui/tests/theme.test.mjs @@ -1,9 +1,9 @@ import assert from 'node:assert/strict' 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 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', () => { const s = memory() @@ -25,3 +25,23 @@ test('applyTheme sets data-theme and saves only when asked', () => { assert.equal(getStoredTheme(s), 'dark') 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']) +}) diff --git a/tests/e2e/manager.mjs b/tests/e2e/manager.mjs index 3feef37..ca3342f 100644 --- a/tests/e2e/manager.mjs +++ b/tests/e2e/manager.mjs @@ -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')) 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)') + // ── 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.getByText('Log files', { exact: true }).click() diff --git a/tests/e2e/manager_look.mjs b/tests/e2e/manager_look.mjs new file mode 100644 index 0000000..8204190 --- /dev/null +++ b/tests/e2e/manager_look.mjs @@ -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/-.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 => `${p}${LOOKS.map(l => ``).join('')}`).join('') + const file = path.join(DIR, `sheet-${i / per + 1}.html`) + writeFileSync(file, `${rows}
`) + 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) diff --git a/tests/e2e/run-all.mjs b/tests/e2e/run-all.mjs index fbb6706..560b209 100644 --- a/tests/e2e/run-all.mjs +++ b/tests/e2e/run-all.mjs @@ -30,6 +30,7 @@ const suites = [ ['waiter (sign-in, keys, prices, languages, history, look, bookings)', 'node', ['waiter.mjs'], E2E], ['manager (login, bootstrap, approvals)', 'node', ['manager.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], ['terminal (pairing, sign-in, states)', 'node', ['terminal.mjs'], E2E], ['signage (the player on a TV, the editor)', 'node', ['signage.mjs'], E2E],