feat(ui): board design language as global tokens; KDS on tokens and shared components (platform-v2 3.2b-2)

- @xenia/ui: --x-board-* tokens (the kitchen display's look: dark board, light cards,
  status colours, card radius/shadows, number font), Tailwind board.* colours, contrast
  test for the board pairs; near-identical shades merged.
- New shared Stepper component (gallery + ui.mjs), labels ui.decrease / ui.increase.
- KDS: theme.js maps to the board tokens, no colour literals left (only stored setting
  values); decline / call waiter / settings use Dialog, Button, Switch, Select, Stepper;
  toasts are @xenia/ui toasts (ToastProvider at the terminal root).
- Terminal: apps can set their theme (APP_THEMES, KDS dark) while they run.
- CS-16: board screens and "no hard-coded colours in app code".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 20:02:35 +02:00
co-authored by Claude Opus 5.5
parent 5f6d4ab428
commit 77e0adbe9c
26 changed files with 485 additions and 383 deletions
+18 -20
View File
@@ -7,17 +7,20 @@
// (this session only; the saved size is the font_scale setting);
// - the board: cards packed in columns without vertical scrolling (logic/layout.js), tap a
// card to select it, tap its items to move them on, long press to decline;
// - item totals panel, decline / call-waiter dialogs, toasts.
// - item totals panel, decline / call-waiter dialogs, toasts (@xenia/ui).
// Look: the board design language of @xenia/ui (--x-board-* tokens, ./theme.js); the app runs
// in the dark theme (apps/registry.js), so the shared dialogs and toasts match the board.
// Settings are the device's (3.2a): GET /api/devices/me → me.config, live on device.updated.
// Orders come from the backend for this screen's zone and stay fresh through the live
// connection (useKdsData). Sound needs one tap after the screen starts (browser rule).
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { CookingPot } from 'lucide-react'
import { useLanguage, useTranslation } from '@xenia/i18n'
import { useToast } from '@xenia/ui'
import client from '../../api/client'
import { useDevice } from '../../device/context'
import { chime, soundUnlocked, unlockSound } from './chime'
import { CallWaiterDialog, DeclineDialog, Toasts } from './components/Dialogs'
import { CallWaiterDialog, DeclineDialog } from './components/Dialogs'
import MeasureLayer from './components/MeasureLayer'
import OrderCard from './components/OrderCard'
import { SideRail, TopBar } from './components/Rails'
@@ -29,7 +32,7 @@ import {
} from './logic/board'
import { layoutBoard } from './logic/layout'
import { boardSettings, senderName, zoomStep } from './logic/settings'
import { KDS, KEYFRAMES } from './theme'
import { KDS, KEYFRAMES, alpha } from './theme'
import useKdsData from './useKdsData'
const HISTORY = 10
@@ -52,7 +55,6 @@ export default function KdsApp() {
const [showSummary, setShowSummary] = useState(false)
const [soundOn, setSoundOn] = useState(true)
const [started, setStarted] = useState(() => soundUnlocked())
const [toasts, setToasts] = useState([])
const [boardH, setBoardH] = useState(0)
const [measured, setMeasured] = useState({})
const undoStack = useRef([])
@@ -60,11 +62,8 @@ export default function KdsApp() {
const [hist, setHist] = useState({ undo: 0, redo: 0 }) // stack sizes, for the rail buttons
const known = useRef(null) // order ids seen so far (new-order chime)
const toast = useCallback(msg => {
const id = Math.random().toString(36).slice(2)
setToasts(ts => [...ts, { id, msg }])
setTimeout(() => setToasts(ts => ts.filter(x => x.id !== id)), TOAST_MS)
}, [])
const ui = useToast()
const toast = useCallback((msg, tone = 'neutral') => ui.show({ title: msg, tone, duration: TOAST_MS }), [ui])
// a fresh answer replaces the board; new orders chime (not the first load)
const soundRef = useRef(false)
@@ -134,7 +133,7 @@ export default function KdsApp() {
const callWaiter = useCallback(orderId => {
client.post(`/api/kds/orders/${orderId}/call-waiter`, {})
.then(() => toast(t('kds.toast.waiterCalled'))).catch(() => toast(t('kds.toast.sendFailed')))
.then(() => toast(t('kds.toast.waiterCalled'))).catch(() => toast(t('kds.toast.sendFailed'), 'danger'))
}, [t, toast])
const setOrderStatus = useCallback((orderId, status) => {
@@ -180,14 +179,14 @@ export default function KdsApp() {
toast(t('kds.toast.orderDeclined'))
}
reload()
} catch { toast(t('kds.toast.declineFailed')) }
} catch { toast(t('kds.toast.declineFailed'), 'danger') }
}, [reload, t, toast])
const print = useCallback(async orderId => {
try {
await client.post(`/api/kds/orders/${orderId}/retry-print`)
toast(t('kds.toast.printSent'))
} catch { toast(t('kds.toast.printFailed')) }
} catch { toast(t('kds.toast.printFailed'), 'danger') }
}, [t, toast])
const replay = useCallback((entry, which) => {
@@ -267,7 +266,7 @@ export default function KdsApp() {
return (
<div data-testid="app-kds" style={{
display: 'flex', position: 'absolute', inset: 0, overflow: 'hidden',
background: KDS.bg, color: '#e7ecf2', WebkitFontSmoothing: 'antialiased', userSelect: 'none', WebkitUserSelect: 'none',
background: KDS.bg, color: KDS.ink, WebkitFontSmoothing: 'antialiased', userSelect: 'none', WebkitUserSelect: 'none',
}}>
<style>{KEYFRAMES}</style>
<SideRail filters={filters} counts={counts} fontScale={fs} onToggleFilter={toggleFilter}
@@ -292,15 +291,15 @@ export default function KdsApp() {
<div style={{ position: 'relative', height: '100%', width: Math.max(layout.totalW, 1), minWidth: '100%',
paddingRight: summary === 'floating' ? `calc(${sideWidth} + 32px)` : 0 }}>
{loaded === null && (
<div style={{ position: 'absolute', inset: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#5e6772', fontSize: 14 }}>
<div style={{ position: 'absolute', inset: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', color: KDS.ink4, fontSize: 14 }}>
{t('kds.loading')}
</div>
)}
{loaded !== null && visible.length === 0 && (
<div data-testid="kds-empty" onClick={e => e.stopPropagation()} style={{ position: 'absolute', inset: 0, display: 'flex', flexDirection: 'column',
alignItems: 'center', justifyContent: 'center', gap: 14, color: '#5e6772' }}>
alignItems: 'center', justifyContent: 'center', gap: 14, color: KDS.ink4 }}>
<CookingPot style={{ width: 54, height: 54, opacity: 0.5 }} />
<div style={{ fontSize: 17, fontWeight: 600, color: '#7b8694' }}>{t('kds.empty')}</div>
<div style={{ fontSize: 17, fontWeight: 600, color: KDS.ink3 }}>{t('kds.empty')}</div>
</div>
)}
{visible.map(order => {
@@ -346,7 +345,7 @@ export default function KdsApp() {
{dialog === 'call' && (
<CallWaiterDialog zoneName={sender} onClose={() => setDialog(null)}
onSend={ids => client.post('/api/kds/call-waiter-general', { waiter_ids: ids })
.then(() => toast(t('kds.toast.called'))).catch(() => toast(t('kds.toast.sendFailed')))} />
.then(() => toast(t('kds.toast.called'))).catch(() => toast(t('kds.toast.sendFailed'), 'danger'))} />
)}
{dialog?.decline && (
<DeclineDialog itemId={dialog.decline.itemId} itemName={dialog.decline.itemName}
@@ -355,15 +354,14 @@ export default function KdsApp() {
{!started && settings.sound && (
<button type="button" data-testid="kds-start" onClick={() => { unlockSound(); setStarted(true) }} style={{
position: 'absolute', inset: 0, zIndex: 400, background: 'rgba(10,13,17,.72)', border: 'none', cursor: 'pointer', color: '#e7ecf2',
position: 'absolute', inset: 0, zIndex: 400, background: alpha('deep', 0.72), border: 'none', cursor: 'pointer', color: KDS.ink,
display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: 10, fontFamily: 'inherit',
}}>
<span style={{ fontSize: 28, fontWeight: 800 }}>{t('kds.start.title')}</span>
<span style={{ fontSize: 15, color: '#aab4c0', maxWidth: 420, textAlign: 'center' }}>{t('kds.start.body')}</span>
<span style={{ fontSize: 15, color: KDS.ink2, maxWidth: 420, textAlign: 'center' }}>{t('kds.start.body')}</span>
</button>
)}
<Toasts toasts={toasts} />
</div>
)
}