Files
xenia-pos-local/terminal/src/apps/kds/components/Rails.jsx
T
bonaminandClaude Opus 5.5 77e0adbe9c 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>
2026-11-14 20:02:35 +02:00

132 lines
8.6 KiB
React

// The board's side rail (status filters with counts, undo/redo, call, sound, settings) and
// top bar (here / takeaway / delivery tabs, item totals button, venue clock, zoom).
// Plan step 3.2b, from KdsPage.jsx.
import { BellRing, CheckCheck, Clock, CookingPot, Flame, Redo2, Settings, Timer, Undo2, Volume2, VolumeX, ZoomIn, ZoomOut } from 'lucide-react'
import { useFormat, useTranslation } from '@xenia/i18n'
import { KDS, alpha } from '../theme'
const STATUSES = [
{ key: 'future', Icon: Clock, colour: KDS.fresh },
{ key: 'pending', Icon: Timer, colour: KDS.warning },
{ key: 'preparing', Icon: Flame, colour: KDS.progress },
{ key: 'done', Icon: CheckCheck, colour: KDS.ink },
]
function RailButton({ active, colour = KDS.ink, onClick, disabled, fs, children, testId }) {
return (
<button type="button" data-testid={testId} data-active={active ? 'true' : 'false'} onClick={onClick} disabled={disabled} style={{
position: 'relative', width: '100%', display: 'flex', flexDirection: 'column', alignItems: 'center',
gap: Math.round(4 * fs), padding: `${Math.round(9 * fs)}px ${Math.round(4 * fs)}px`, borderRadius: Math.round(10 * fs),
color: active ? colour : KDS.ink3, background: active ? alpha('ink', 0.06) : 'none',
border: active ? `1px solid ${alpha('ink', 0.08)}` : '1px solid transparent',
cursor: disabled ? 'default' : 'pointer', fontFamily: 'inherit', opacity: disabled ? 0.32 : 1, transition: 'background .12s, color .12s, opacity .15s',
}}>
{children}
</button>
)
}
export function SideRail({ filters, counts, onToggleFilter, soundOn, onToggleSound, canUndo, canRedo, onUndo, onRedo, onSettings, onCall, fontScale = 1 }) {
const { t } = useTranslation('terminal')
const fs = fontScale
const lg = { width: Math.round(24 * fs), height: Math.round(24 * fs) }
const sm = { width: Math.round(20 * fs), height: Math.round(20 * fs) }
const label = text => <span style={{ fontSize: Math.round(10 * fs), fontWeight: 600, letterSpacing: '.06em', textTransform: 'uppercase' }}>{text}</span>
const badgeH = Math.round(22 * fs)
const group = { display: 'flex', flexDirection: 'column', gap: 2, padding: `2px ${Math.round(8 * fs)}px` }
return (
<nav data-testid="kds-rail" style={{ width: Math.round(KDS.railW * fs), flexShrink: 0, background: KDS.rail, borderRight: `1px solid ${KDS.line}`,
display: 'flex', flexDirection: 'column', alignItems: 'stretch', padding: `${Math.round(10 * fs)}px 0`, gap: 2, overflowY: 'auto' }}>
<div style={group}>
{STATUSES.map(({ key, Icon, colour }) => {
const active = filters.has(key)
return (
<RailButton key={key} testId={`filter-${key}`} active={active} colour={colour} onClick={() => onToggleFilter(key)} fs={fs}>
<Icon style={lg} />
{label(t(`kds.rail.${key}`))}
<span data-testid={`count-${key}`} style={{ minWidth: badgeH, height: badgeH, padding: `0 ${Math.round(6 * fs)}px`, display: 'inline-flex',
alignItems: 'center', justifyContent: 'center', borderRadius: Math.round(11 * fs), fontSize: Math.round(12 * fs), fontWeight: 700,
background: active ? colour : KDS.line, color: active ? KDS.deep : KDS.ink2 }}>
{counts[key] || 0}
</span>
</RailButton>
)
})}
<div style={{ height: 1, background: KDS.line, margin: `${Math.round(6 * fs)}px` }} />
<RailButton testId="kds-undo" active={false} onClick={onUndo} disabled={!canUndo} fs={fs}><Undo2 style={sm} />{label(t('kds.rail.undo'))}</RailButton>
<RailButton testId="kds-redo" active={false} onClick={onRedo} disabled={!canRedo} fs={fs}><Redo2 style={sm} />{label(t('kds.rail.redo'))}</RailButton>
</div>
<div style={{ flex: '1 1 auto' }} />
<div style={group}>
<RailButton testId="kds-call" active={false} onClick={onCall} fs={fs}><BellRing style={sm} />{label(t('kds.rail.call'))}</RailButton>
<RailButton testId="kds-sound" active={false} onClick={onToggleSound} fs={fs}>
{soundOn ? <Volume2 style={sm} /> : <VolumeX style={sm} />}{label(soundOn ? t('kds.rail.sound') : t('kds.rail.muted'))}
</RailButton>
<RailButton testId="kds-settings" active={false} onClick={onSettings} fs={fs}><Settings style={sm} />{label(t('kds.rail.settings'))}</RailButton>
</div>
</nav>
)
}
const TABS = ['all', 'here', 'takeaway', 'delivery']
export function TopBar({ tab, counts, onTab, now, fontScale = 1, zoomPercent, onZoom, showSummaryButton, summaryOpen, onToggleSummary }) {
const { t } = useTranslation('terminal')
const { formatDate, formatTime } = useFormat()
const fs = fontScale
const tabH = Math.round(36 * fs)
const tabR = Math.round(9 * fs)
const clockFont = { fontSize: Math.round(14 * fs), fontFamily: KDS.fontNumber }
const zoomButton = { width: tabH, height: tabH, display: 'flex', alignItems: 'center', justifyContent: 'center', background: 'none', border: 'none',
cursor: 'pointer', color: KDS.ink2, borderRadius: Math.round(7 * fs) }
const zi = { width: Math.round(15 * fs), height: Math.round(15 * fs) }
return (
<div data-testid="kds-topbar" style={{ height: Math.round(KDS.topbarH * fs), flexShrink: 0, background: KDS.topbar, borderBottom: `1px solid ${KDS.line}`,
display: 'flex', alignItems: 'center', gap: 8, padding: '0 12px' }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 6, flexShrink: 0, overflowX: 'auto' }}>
{TABS.map(key => {
const active = tab === key
return (
<button key={key} type="button" data-testid={`tab-${key}`} onClick={() => onTab(key)} style={{
flexShrink: 0, display: 'flex', alignItems: 'center', gap: Math.round(7 * fs), height: tabH, padding: `0 ${Math.round(14 * fs)}px`,
borderRadius: tabR, background: active ? KDS.tabActive : KDS.line, color: active ? KDS.bg : KDS.ink2,
fontSize: Math.round(13 * fs), fontWeight: 600, whiteSpace: 'nowrap', border: 'none', cursor: 'pointer', fontFamily: 'inherit',
}}>
{key === 'all' ? t('kds.tabs.all') : t(`kds.channel.${key}`)}
<span style={{ minWidth: Math.round(20 * fs), height: Math.round(20 * fs), padding: `0 ${Math.round(5 * fs)}px`, display: 'inline-flex',
alignItems: 'center', justifyContent: 'center', borderRadius: Math.round(6 * fs), fontSize: Math.round(11 * fs), fontWeight: 700,
background: active ? alpha('deep', 0.10) : alpha('ink', 0.08), color: active ? KDS.cardInk2 : KDS.ink2 }}>
{counts[key] ?? 0}
</span>
</button>
)
})}
</div>
<div style={{ flex: '1 1 0' }} />
{showSummaryButton && (
<button type="button" data-testid="summary-button" onClick={onToggleSummary} style={{
flexShrink: 0, display: 'flex', alignItems: 'center', gap: Math.round(6 * fs), height: tabH, padding: `0 ${Math.round(14 * fs)}px`,
borderRadius: tabR, background: summaryOpen ? KDS.tabActive : KDS.line, color: summaryOpen ? KDS.bg : KDS.ink2,
fontSize: Math.round(13 * fs), fontWeight: 600, border: 'none', cursor: 'pointer', fontFamily: 'inherit',
}}>
<CookingPot style={zi} />
{t('kds.summary.button')}
</button>
)}
<div style={{ flex: '1 1 0' }} />
<div data-testid="kds-clock" style={{ display: 'flex', alignItems: 'center', gap: Math.round(6 * fs), flexShrink: 0, whiteSpace: 'nowrap' }}>
<span style={{ ...clockFont, fontWeight: 600, color: KDS.ink2 }}>{formatDate(now, 'dateLong')}</span>
<span style={{ ...clockFont, fontWeight: 700, color: KDS.ink }}>{formatTime(now)}</span>
</div>
<div style={{ width: 1, height: Math.round(24 * fs), background: KDS.line, flexShrink: 0 }} />
<div style={{ display: 'flex', alignItems: 'center', gap: 2, background: KDS.line, borderRadius: tabR, padding: `0 ${Math.round(4 * fs)}px`, flexShrink: 0, height: tabH }}>
<button type="button" data-testid="zoom-out" aria-label={t('kds.zoom.smaller')} title={t('kds.zoom.smaller')} onClick={() => onZoom(-1)} style={zoomButton}><ZoomOut style={zi} /></button>
<span data-testid="zoom-level" style={{ fontSize: Math.round(11 * fs), fontWeight: 700, color: KDS.ink2, minWidth: Math.round(34 * fs), textAlign: 'center', fontFamily: KDS.fontMono }}>
{zoomPercent}%
</span>
<button type="button" data-testid="zoom-in" aria-label={t('kds.zoom.larger')} title={t('kds.zoom.larger')} onClick={() => onZoom(1)} style={zoomButton}><ZoomIn style={zi} /></button>
</div>
</div>
)
}