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:
@@ -4,7 +4,7 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import {
|
||||
Button, Dialog, EmptyState, Field, IconButton, InfoTip, Input, PinPad, Select, Sheet,
|
||||
Spinner, Switch, Textarea, ToastProvider, useToast,
|
||||
Spinner, Stepper, Switch, Textarea, ToastProvider, useToast,
|
||||
} from '../src/index.js'
|
||||
import '../src/styles.css'
|
||||
|
||||
@@ -44,6 +44,7 @@ function Demo() {
|
||||
const [locked, setLocked] = useState(false)
|
||||
const [sheet, setSheet] = useState(null)
|
||||
const [on, setOn] = useState(true)
|
||||
const [step, setStep] = useState(30)
|
||||
const [off, setOff] = useState(false)
|
||||
const [name, setName] = useState('')
|
||||
const [lang, setLang] = useState('el')
|
||||
@@ -143,6 +144,7 @@ function Demo() {
|
||||
<Switch checked={on} onChange={setOn} label="Print kitchen tickets" description="Send new items to the kitchen printer." />
|
||||
<Switch checked={off} onChange={setOff} label="Alert after print failures" />
|
||||
<Switch checked disabled label="Disabled (on)" />
|
||||
<div style={row}><Stepper value={step} steps={[10, 15, 20, 30, 45, 60]} format={v => `${v}s`} onChange={setStep} label="Check every" /> <Stepper value={3} min={1} max={5} disabled label="Disabled" /></div>
|
||||
<div style={row}>Alert after <InfoTip side="bottom">How many failed print attempts before managers are notified. 0 turns the alert off.</InfoTip></div>
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
@@ -271,6 +271,24 @@
|
||||
.x-select__control { appearance: none; -webkit-appearance: none; padding-right: var(--x-space-10); cursor: pointer; }
|
||||
.x-select__chevron { position: absolute; right: var(--x-space-3); top: 50%; transform: translateY(-50%); color: var(--x-ink-3); pointer-events: none; }
|
||||
|
||||
/* ── Stepper ─────────────────────────────────────────────────────────────── */
|
||||
.x-stepper { display: inline-flex; align-items: center; gap: var(--x-space-1-5); flex-shrink: 0; }
|
||||
.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);
|
||||
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;
|
||||
}
|
||||
.x-stepper__btn:hover:not(:disabled) { background: var(--x-surface-3); }
|
||||
.x-stepper__btn:focus-visible { outline: none; box-shadow: var(--x-focus-ring); }
|
||||
.x-stepper__btn:disabled { color: var(--x-ink-3); opacity: 0.5; cursor: default; }
|
||||
.x-stepper__value {
|
||||
min-width: 64px; text-align: center; font-family: var(--x-font-mono);
|
||||
font-size: var(--x-text-body-lg); font-weight: var(--x-weight-bold); color: var(--x-ink);
|
||||
}
|
||||
|
||||
/* ── Switch ──────────────────────────────────────────────────────────────── */
|
||||
.x-switch {
|
||||
position: relative; flex-shrink: 0;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { cx } from '../internal/cx.js'
|
||||
import { useLabels } from './labels.js'
|
||||
|
||||
const Icon = ({ d }) => (
|
||||
<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" strokeWidth="2.25" strokeLinecap="round" aria-hidden="true"><path d={d} /></svg>
|
||||
)
|
||||
|
||||
/**
|
||||
* − value + for numbers picked in steps on a touch screen (plan step 3.2b-2).
|
||||
* <Stepper value={30} steps={[10, 15, 20, 30, 45, 60]} format={v => `${v}s`} onChange={setSeconds} />
|
||||
* <Stepper value={5} min={1} max={12} onChange={setMinutes} /> (step 1)
|
||||
* With `steps`, the value snaps to the nearest step; min/max limit the steps too.
|
||||
* aria: the value is announced (aria-live); label names the group.
|
||||
*/
|
||||
export function Stepper({ value, onChange, steps, min = -Infinity, max = Infinity, step = 1, format = String, label, disabled = false, className, ...rest }) {
|
||||
const labels = useLabels()
|
||||
const options = steps ? steps.filter(s => s >= min && s <= max) : null
|
||||
const cur = options?.length ? options.reduce((a, b) => (Math.abs(b - value) < Math.abs(a - value) ? b : a)) : value
|
||||
const i = options ? options.indexOf(cur) : -1
|
||||
const canDec = !disabled && (options ? i > 0 : cur - step >= min)
|
||||
const canInc = !disabled && (options ? i < options.length - 1 : cur + step <= max)
|
||||
const dec = () => canDec && onChange?.(options ? options[i - 1] : cur - step)
|
||||
const inc = () => canInc && onChange?.(options ? options[i + 1] : cur + step)
|
||||
return (
|
||||
<div role="group" aria-label={label} className={cx('x-stepper', disabled && 'x-stepper--disabled', className)} {...rest}>
|
||||
<button type="button" className="x-stepper__btn" onClick={dec} disabled={!canDec} aria-label={labels.decrease}><Icon d="M5 12h14" /></button>
|
||||
<span className="x-stepper__value" aria-live="polite">{format(cur)}</span>
|
||||
<button type="button" className="x-stepper__btn" onClick={inc} disabled={!canInc} aria-label={labels.increase}><Icon d="M12 5v14M5 12h14" /></button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -12,6 +12,8 @@ export const DEFAULT_LABELS = {
|
||||
moreInfo: 'More info',
|
||||
notifications: 'Notifications',
|
||||
backspace: 'Delete',
|
||||
decrease: 'Less',
|
||||
increase: 'More',
|
||||
submit: 'OK',
|
||||
pinProgress: (n, total) => `${n} of ${total} digits entered`,
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ export { EmptyState } from './components/EmptyState.jsx'
|
||||
export { Spinner } from './components/Spinner.jsx'
|
||||
export { Field, Input, Textarea, Select } from './components/Field.jsx'
|
||||
export { Switch } from './components/Switch.jsx'
|
||||
export { Stepper } from './components/Stepper.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'
|
||||
|
||||
@@ -246,6 +246,94 @@
|
||||
}
|
||||
}
|
||||
|
||||
/* ── 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
|
||||
* dialogs on a board use the normal components in data-theme="dark".
|
||||
* The age colours here are only defaults: each KDS screen stores its own. */
|
||||
:root {
|
||||
--x-board-bg-rgb: 29 35 43; /* the board behind the cards */
|
||||
--x-board-rail-rgb: 22 27 33; /* side rail, side panels */
|
||||
--x-board-topbar-rgb: 32 39 47; /* top bar */
|
||||
--x-board-line-rgb: 43 51 61; /* dividers, tabs, badges */
|
||||
--x-board-deep-rgb: 10 14 19; /* action bars, text on light badges, scrims */
|
||||
--x-board-ink-rgb: 231 236 242; /* text on the board */
|
||||
--x-board-ink-2-rgb: 170 180 192; /* secondary text, tabs */
|
||||
--x-board-ink-3-rgb: 123 134 148; /* muted text, idle rail buttons */
|
||||
--x-board-ink-4-rgb: 94 103 114; /* empty states */
|
||||
--x-board-tab-active-rgb: 243 246 249; /* the selected tab */
|
||||
--x-board-on-status-rgb: 255 255 255; /* text on coloured headers */
|
||||
--x-board-card-rgb: 255 255 255; /* card body */
|
||||
--x-board-card-ink-rgb: 31 36 43; /* item names */
|
||||
--x-board-card-ink-2-rgb: 65 71 79; /* card footer text */
|
||||
--x-board-card-muted-rgb: 174 180 188; /* done items, labels on the card */
|
||||
--x-board-card-soft-rgb: 240 242 245; /* quantity badges, footer, scheduled orders */
|
||||
--x-board-card-line-rgb: 232 235 239; /* lines inside a card */
|
||||
--x-board-card-progress-rgb: 243 248 255; /* body of an order in progress */
|
||||
--x-board-card-done-rgb: 244 247 244; /* body of a done order */
|
||||
--x-board-note-rgb: 255 251 235; /* order note background */
|
||||
--x-board-note-ink-rgb: 180 83 9; /* order note text */
|
||||
--x-board-fresh-rgb: 52 181 106; /* new order (default age colour) */
|
||||
--x-board-fresh-deep-rgb: 30 128 72; /* its subheader; extras on items */
|
||||
--x-board-warning-rgb: 240 165 42; /* waiting a while */
|
||||
--x-board-warning-deep-rgb: 184 115 16; /* its subheader; choices on items; call waiter */
|
||||
--x-board-late-rgb: 232 81 63; /* late */
|
||||
--x-board-late-deep-rgb: 160 45 30; /* its subheader; removed on items; decline */
|
||||
--x-board-done-rgb: 61 71 87; /* done order header */
|
||||
--x-board-done-deep-rgb: 42 49 64; /* its subheader */
|
||||
--x-board-future-rgb: 74 85 104; /* scheduled order header */
|
||||
--x-board-future-deep-rgb: 55 65 81; /* its subheader */
|
||||
--x-board-future-glow-rgb: 109 208 138; /* scheduled: rail badge, card glow */
|
||||
--x-board-progress-rgb: 47 127 240; /* in progress, selection, item notes */
|
||||
--x-board-fresh-soft-rgb: 134 239 172; /* extras in the totals panel */
|
||||
--x-board-warning-soft-rgb: 252 211 77; /* choices in the totals panel */
|
||||
--x-board-late-soft-rgb: 252 165 165; /* removed in the totals panel */
|
||||
--x-board-progress-soft-rgb: 147 197 253; /* notes in the totals panel */
|
||||
|
||||
--x-board-bg: rgb(var(--x-board-bg-rgb));
|
||||
--x-board-rail: rgb(var(--x-board-rail-rgb));
|
||||
--x-board-topbar: rgb(var(--x-board-topbar-rgb));
|
||||
--x-board-line: rgb(var(--x-board-line-rgb));
|
||||
--x-board-deep: rgb(var(--x-board-deep-rgb));
|
||||
--x-board-ink: rgb(var(--x-board-ink-rgb));
|
||||
--x-board-ink-2: rgb(var(--x-board-ink-2-rgb));
|
||||
--x-board-ink-3: rgb(var(--x-board-ink-3-rgb));
|
||||
--x-board-ink-4: rgb(var(--x-board-ink-4-rgb));
|
||||
--x-board-tab-active: rgb(var(--x-board-tab-active-rgb));
|
||||
--x-board-on-status: rgb(var(--x-board-on-status-rgb));
|
||||
--x-board-card: rgb(var(--x-board-card-rgb));
|
||||
--x-board-card-ink: rgb(var(--x-board-card-ink-rgb));
|
||||
--x-board-card-ink-2: rgb(var(--x-board-card-ink-2-rgb));
|
||||
--x-board-card-muted: rgb(var(--x-board-card-muted-rgb));
|
||||
--x-board-card-soft: rgb(var(--x-board-card-soft-rgb));
|
||||
--x-board-card-line: rgb(var(--x-board-card-line-rgb));
|
||||
--x-board-card-progress: rgb(var(--x-board-card-progress-rgb));
|
||||
--x-board-card-done: rgb(var(--x-board-card-done-rgb));
|
||||
--x-board-note: rgb(var(--x-board-note-rgb));
|
||||
--x-board-note-ink: rgb(var(--x-board-note-ink-rgb));
|
||||
--x-board-fresh: rgb(var(--x-board-fresh-rgb));
|
||||
--x-board-fresh-deep: rgb(var(--x-board-fresh-deep-rgb));
|
||||
--x-board-warning: rgb(var(--x-board-warning-rgb));
|
||||
--x-board-warning-deep: rgb(var(--x-board-warning-deep-rgb));
|
||||
--x-board-late: rgb(var(--x-board-late-rgb));
|
||||
--x-board-late-deep: rgb(var(--x-board-late-deep-rgb));
|
||||
--x-board-done: rgb(var(--x-board-done-rgb));
|
||||
--x-board-done-deep: rgb(var(--x-board-done-deep-rgb));
|
||||
--x-board-future: rgb(var(--x-board-future-rgb));
|
||||
--x-board-future-deep: rgb(var(--x-board-future-deep-rgb));
|
||||
--x-board-future-glow: rgb(var(--x-board-future-glow-rgb));
|
||||
--x-board-progress: rgb(var(--x-board-progress-rgb));
|
||||
--x-board-fresh-soft: rgb(var(--x-board-fresh-soft-rgb));
|
||||
--x-board-warning-soft: rgb(var(--x-board-warning-soft-rgb));
|
||||
--x-board-late-soft: rgb(var(--x-board-late-soft-rgb));
|
||||
--x-board-progress-soft: rgb(var(--x-board-progress-soft-rgb));
|
||||
|
||||
--x-board-radius-card: 10px;
|
||||
--x-board-shadow-card: 0 1px 2px rgb(0 0 0 / 0.25), 0 6px 16px rgb(0 0 0 / 0.22);
|
||||
--x-board-shadow-focus: 0 10px 24px rgb(0 0 0 / 0.40), 0 0 0 4px rgb(var(--x-board-progress-rgb) / 0.25);
|
||||
--x-board-font-number: "Inter", "SF Pro Display", var(--x-font-sans);
|
||||
}
|
||||
|
||||
/* ── Ready-to-use colours ────────────────────────────────────────────────────
|
||||
* Redeclared wherever the channels can change, so a nested data-theme /
|
||||
* data-venue-theme container gets its own values (custom properties are
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
// The app must also load the tokens: import '@xenia/ui/tokens.css' (or styles.css).
|
||||
|
||||
const c = name => `rgb(var(--x-${name}-rgb) / <alpha-value>)`
|
||||
const BOARD = ['bg', 'rail', 'topbar', 'line', 'deep', 'ink', 'ink-2', 'ink-3', 'ink-4', 'tab-active', 'on-status', 'card', 'card-ink', 'card-ink-2', 'card-muted', 'card-soft', 'card-line', 'card-progress', 'card-done', 'note', 'note-ink', 'fresh', 'fresh-deep', 'warning', 'warning-deep', 'late', 'late-deep', 'done', 'done-deep', 'future', 'future-deep', 'future-glow', 'progress', 'fresh-soft', 'warning-soft', 'late-soft', 'progress-soft']
|
||||
const tone = name => ({ DEFAULT: c(name), fg: c(`${name}-fg`), soft: c(`${name}-soft`), ink: c(`${name}-ink`) })
|
||||
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
@@ -31,6 +32,8 @@ export default {
|
||||
warning: tone('warning'),
|
||||
danger: tone('danger'),
|
||||
info: tone('info'),
|
||||
// the board design language (kitchen display): bg-board-bg, text-board-ink-2, bg-board-late…
|
||||
board: Object.fromEntries(BOARD.map(n => [n, c(`board-${n}`)])),
|
||||
},
|
||||
fontSize: {
|
||||
caption: ['var(--x-text-caption)', { lineHeight: 'var(--x-leading-caption)' }],
|
||||
@@ -45,6 +48,7 @@ export default {
|
||||
control: 'var(--x-radius-control)',
|
||||
card: 'var(--x-radius-card)',
|
||||
dialog: 'var(--x-radius-dialog)',
|
||||
'board-card': 'var(--x-board-radius-card)',
|
||||
},
|
||||
boxShadow: {
|
||||
raised: 'var(--x-shadow-raised)',
|
||||
|
||||
@@ -65,3 +65,20 @@ test('system theme mirrors dark', () => {
|
||||
const darkCanvas = dark.canvas.join(' ')
|
||||
assert.ok(sys.includes(`--x-canvas-rgb: ${darkCanvas};`), 'system dark uses the dark canvas')
|
||||
})
|
||||
|
||||
// The board (kitchen display, 3.2b-2): always dark, so one set. Done items (card-muted) and
|
||||
// empty states (ink-4) are meant to recede and aren't checked.
|
||||
test('board token pairs are readable', () => {
|
||||
const b = Object.fromEntries([...css.matchAll(/--x-board-([\w-]+)-rgb:\s*([\d\s]+);/g)].map(([, k, v]) => [k, v.trim().split(/\s+/).map(Number)]))
|
||||
const boardPairs = [
|
||||
['ink', 'bg', TEXT], ['ink-2', 'bg', TEXT], ['ink-2', 'line', TEXT], ['ink-3', 'rail', TEXT], ['bg', 'tab-active', TEXT],
|
||||
['card-ink', 'card', TEXT], ['card-ink-2', 'card-soft', TEXT], ['note-ink', 'note', TEXT],
|
||||
['late-deep', 'card', TEXT], ['fresh-deep', 'card', TEXT], ['on-status', 'fresh-deep', TEXT], ['on-status', 'late-deep', TEXT],
|
||||
['warning-deep', 'card', UI], ['progress', 'card', UI], ['on-status', 'warning-deep', UI],
|
||||
]
|
||||
for (const [fg, bg, min] of boardPairs) {
|
||||
assert.ok(b[fg] && b[bg], `board tokens ${fg} / ${bg} exist`)
|
||||
const r = ratio(b[fg], b[bg])
|
||||
assert.ok(r >= min, `board ${fg} on ${bg}: ${r.toFixed(2)} < ${min}`)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user