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 { 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 }
</button>
{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
role="menuitem"
onClick={() => { setOpen(false); onEditProfile() }}
@@ -89,6 +93,16 @@ export default function UserMenuButton({ displayName, onEditProfile, onSignOut }
</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" />
<button
role="menuitem"
@@ -103,3 +117,24 @@ export default function UserMenuButton({ displayName, onEditProfile, onSignOut }
</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>
)
}