From 77e0adbe9c05b46a0be6452be7a32613377a8991 Mon Sep 17 00:00:00 2001 From: bonamin Date: Sat, 14 Nov 2026 20:02:35 +0200 Subject: [PATCH] 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 --- docs/README.md | 2 +- packages/i18n/locales/el/common.json | 4 +- packages/i18n/locales/en/common.json | 4 +- packages/i18n/src/hooks.js | 2 + packages/ui/gallery/Gallery.jsx | 4 +- packages/ui/src/components.css | 18 ++ packages/ui/src/components/Stepper.jsx | 31 ++++ packages/ui/src/components/labels.js | 2 + packages/ui/src/index.js | 1 + packages/ui/src/tokens.css | 88 ++++++++++ packages/ui/tailwind-preset.js | 4 + packages/ui/tests/contrast.test.mjs | 17 ++ terminal/src/App.jsx | 6 +- terminal/src/apps/kds/KdsApp.jsx | 38 ++-- .../src/apps/kds/components/ActionBars.jsx | 22 +-- terminal/src/apps/kds/components/Dialogs.jsx | 156 +++++------------ .../src/apps/kds/components/ItemBlock.jsx | 26 +-- .../src/apps/kds/components/OrderCard.jsx | 59 ++++--- terminal/src/apps/kds/components/Rails.jsx | 54 +++--- .../src/apps/kds/components/SettingsPanel.jsx | 165 +++++++----------- .../src/apps/kds/components/SummaryPanel.jsx | 31 ++-- terminal/src/apps/kds/theme.js | 94 +++++----- terminal/src/apps/registry.js | 9 + terminal/src/screens/AppScreen.jsx | 15 +- tests/e2e/terminal.mjs | 9 +- tests/e2e/ui.mjs | 7 + 26 files changed, 485 insertions(+), 383 deletions(-) create mode 100644 packages/ui/src/components/Stepper.jsx diff --git a/docs/README.md b/docs/README.md index cd70af9..34a57c0 100644 --- a/docs/README.md +++ b/docs/README.md @@ -171,7 +171,7 @@ Paired devices (D-8, `routers/devices.py`, `core/access/context.py`) send `X-Xen Manager override (D-10, `core/access/override.py`): mark a key `Perm(..., overridable=True)` and a user without it gets `access.override_possible`; the client gets a manager's one-time token from `POST /api/access/override {key, username, pin}` and retries with `X-Xenia-Override`. `require()` routes handle it in `check()`; an endpoint with its own rule calls `require_override(request, db, key, target="order:12")` where the rule says no, **after** its other checks (a used token is spent). **CS-16. Shared UI lives in `packages/ui` and never restyles an app** (branch `platform-v2`, D-15, §9). -Design tokens are CSS variables prefixed `--x-` (`packages/ui/src/tokens.css`), components use `.x-*` classes (`src/components.css`); neither file has element selectors, resets or anything that applies outside `.x-*` (the waiter keeps its own `--bg`/`--text`…; the manager's Tailwind classes keep their meaning). Theme comes from `data-theme` (`light`/`dark`/`system`) and `data-venue-theme` on ``. Tailwind apps use `@xenia/ui/tailwind-preset` (adds `bg-surface`, `text-ink-2`, `rounded-control`… only). A colour change must pass `npm test -w @xenia/ui` (WCAG AA for every pair the components use, every venue theme, light and dark). Components take their visible text as props with English defaults until `@xenia/i18n` (2.4). New components get a section in `packages/ui/gallery/Gallery.jsx` (dev-only `/ui-gallery` in the manager) and checks in `tests/e2e/ui.mjs`. +Design tokens are CSS variables prefixed `--x-` (`packages/ui/src/tokens.css`), components use `.x-*` classes (`src/components.css`); neither file has element selectors, resets or anything that applies outside `.x-*` (the waiter keeps its own `--bg`/`--text`…; the manager's Tailwind classes keep their meaning). Theme comes from `data-theme` (`light`/`dark`/`system`) and `data-venue-theme` on ``. Tailwind apps use `@xenia/ui/tailwind-preset` (adds `bg-surface`, `text-ink-2`, `rounded-control`… only). A colour change must pass `npm test -w @xenia/ui` (WCAG AA for every pair the components use, every venue theme, light and dark). Components take their visible text as props with English defaults until `@xenia/i18n` (2.4). New components get a section in `packages/ui/gallery/Gallery.jsx` (dev-only `/ui-gallery` in the manager) and checks in `tests/e2e/ui.mjs`. **Board screens** (the kitchen display, and any later screen in the same style) use the board design language: `--x-board-*` tokens in the same file (Tailwind `bg-board-bg`, `text-board-ink-2`…; always dark, contrast-tested too) for the board itself, and the normal components in `data-theme="dark"` for their dialogs, toasts and forms (the terminal sets an app's theme from `apps/registry.js` `APP_THEMES`). No hard-coded colours in app code: a colour that isn't a token yet becomes one (values the user stores, like a KDS screen's age colours, are data, not styling). **CS-17. Frontend text is a key; dates are venue time** (branch `platform-v2`, D-11, D-12, §7.2, §8). New UI text goes into `packages/i18n/locales/en/.json` first, then `el` (same keys, same `{{placeholders}}`), and is shown with `t()` from `@xenia/i18n` (`useTranslation`, re-exported). Dates and times are shown only through `useFormat()` (`formatTime`, `formatDateTime`, `formatDate`, `formatRelative`), which use the venue zone from bootstrap; money with `formatMoney`, numbers with `formatNumber`; typed numbers are read with `parseNumber` (comma or dot). Business dates (`YYYY-MM-DD`) go to `formatDate` as they are. `npm test -w @xenia/i18n` runs `scripts/check-i18n.mjs`, which fails on keys missing in English, placeholder mismatches, and `toLocale…String()` / `new Intl.DateTimeFormat(` without `timeZone` in new code (`packages/*`, `terminal/`); it warns for missing Greek. Module names, their limits and **every permission key** have texts in `modules.json` (`modules:.name`, `.limits.`, `.permissions.`); `tests/test_module_texts.py` fails for a new module or key without them in both languages. The v1 apps' Greek strings convert in phases 4 and 6. The `@xenia/ui` components get their texts from `` at the app root. diff --git a/packages/i18n/locales/el/common.json b/packages/i18n/locales/el/common.json index 8b4a29d..639267c 100644 --- a/packages/i18n/locales/el/common.json +++ b/packages/i18n/locales/el/common.json @@ -32,7 +32,9 @@ "notifications": "Ειδοποιήσεις", "backspace": "Διαγραφή", "pinProgress": "{{count}} από {{total}} ψηφία", - "submit": "OK" + "submit": "OK", + "decrease": "Λιγότερο", + "increase": "Περισσότερο" }, "override": { "title": "Έγκριση υπευθύνου", diff --git a/packages/i18n/locales/en/common.json b/packages/i18n/locales/en/common.json index 31bd885..5d0b371 100644 --- a/packages/i18n/locales/en/common.json +++ b/packages/i18n/locales/en/common.json @@ -32,7 +32,9 @@ "notifications": "Notifications", "backspace": "Delete", "pinProgress": "{{count}} of {{total}} digits entered", - "submit": "OK" + "submit": "OK", + "decrease": "Less", + "increase": "More" }, "override": { "title": "Manager approval", diff --git a/packages/i18n/src/hooks.js b/packages/i18n/src/hooks.js index 3321659..e51b8cc 100644 --- a/packages/i18n/src/hooks.js +++ b/packages/i18n/src/hooks.js @@ -34,6 +34,8 @@ export function useUiLabels() { moreInfo: t('ui.moreInfo'), notifications: t('ui.notifications'), backspace: t('ui.backspace'), + decrease: t('ui.decrease'), + increase: t('ui.increase'), submit: t('ui.submit'), pinProgress: (count, total) => t('ui.pinProgress', { count, total }), }), [t, language]) // eslint-disable-line react-hooks/exhaustive-deps diff --git a/packages/ui/gallery/Gallery.jsx b/packages/ui/gallery/Gallery.jsx index d0fea5e..f80e752 100644 --- a/packages/ui/gallery/Gallery.jsx +++ b/packages/ui/gallery/Gallery.jsx @@ -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() { +
`${v}s`} onChange={setStep} label="Check every" />
Alert after How many failed print attempts before managers are notified. 0 turns the alert off.
diff --git a/packages/ui/src/components.css b/packages/ui/src/components.css index d80e49c..b4cd78a 100644 --- a/packages/ui/src/components.css +++ b/packages/ui/src/components.css @@ -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; diff --git a/packages/ui/src/components/Stepper.jsx b/packages/ui/src/components/Stepper.jsx new file mode 100644 index 0000000..67e56fc --- /dev/null +++ b/packages/ui/src/components/Stepper.jsx @@ -0,0 +1,31 @@ +import { cx } from '../internal/cx.js' +import { useLabels } from './labels.js' + +const Icon = ({ d }) => ( + +) + +/** + * − value + for numbers picked in steps on a touch screen (plan step 3.2b-2). + * `${v}s`} onChange={setSeconds} /> + * (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 ( +
+ + {format(cur)} + +
+ ) +} diff --git a/packages/ui/src/components/labels.js b/packages/ui/src/components/labels.js index a38101f..f03300a 100644 --- a/packages/ui/src/components/labels.js +++ b/packages/ui/src/components/labels.js @@ -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`, } diff --git a/packages/ui/src/index.js b/packages/ui/src/index.js index e9dff64..98bbaab 100644 --- a/packages/ui/src/index.js +++ b/packages/ui/src/index.js @@ -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' diff --git a/packages/ui/src/tokens.css b/packages/ui/src/tokens.css index 04ef38b..db5ed98 100644 --- a/packages/ui/src/tokens.css +++ b/packages/ui/src/tokens.css @@ -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 diff --git a/packages/ui/tailwind-preset.js b/packages/ui/tailwind-preset.js index 232ee77..ad3a912 100644 --- a/packages/ui/tailwind-preset.js +++ b/packages/ui/tailwind-preset.js @@ -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) / )` +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)', diff --git a/packages/ui/tests/contrast.test.mjs b/packages/ui/tests/contrast.test.mjs index 9108bf0..7a81319 100644 --- a/packages/ui/tests/contrast.test.mjs +++ b/packages/ui/tests/contrast.test.mjs @@ -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}`) + } +}) diff --git a/terminal/src/App.jsx b/terminal/src/App.jsx index 8b5fe5c..0de813d 100644 --- a/terminal/src/App.jsx +++ b/terminal/src/App.jsx @@ -10,7 +10,7 @@ import { lazy, Suspense } from 'react' import { BrowserRouter, Route, Routes } from 'react-router-dom' import { AccessProvider } from '@xenia/access' import { createI18n } from '@xenia/i18n' -import { Spinner } from '@xenia/ui' +import { Spinner, ToastProvider } from '@xenia/ui' import client from './api/client' import DeviceProvider from './device/DeviceProvider' import { useDevice } from './device/context' @@ -29,7 +29,9 @@ function Root() { const { sessionKey } = useDevice() return ( - + + + ) } diff --git a/terminal/src/apps/kds/KdsApp.jsx b/terminal/src/apps/kds/KdsApp.jsx index 9fbaec3..431b277 100644 --- a/terminal/src/apps/kds/KdsApp.jsx +++ b/terminal/src/apps/kds/KdsApp.jsx @@ -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 (
{loaded === null && ( -
+
{t('kds.loading')}
)} {loaded !== null && visible.length === 0 && (
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 }}> -
{t('kds.empty')}
+
{t('kds.empty')}
)} {visible.map(order => { @@ -346,7 +345,7 @@ export default function KdsApp() { {dialog === 'call' && ( 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 && ( { 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', }}> {t('kds.start.title')} - {t('kds.start.body')} + {t('kds.start.body')} )} -
) } diff --git a/terminal/src/apps/kds/components/ActionBars.jsx b/terminal/src/apps/kds/components/ActionBars.jsx index e555761..35caa9d 100644 --- a/terminal/src/apps/kds/components/ActionBars.jsx +++ b/terminal/src/apps/kds/components/ActionBars.jsx @@ -5,14 +5,14 @@ import { Ban, BellRing, Check, Flame, Printer, Undo2, X } from 'lucide-react' import { useTranslation } from '@xenia/i18n' import { CARD_FOOT_H_BASE, CARD_HEAD_H_BASE, CARD_SUB_H_BASE } from '../logic/layout' -import { KDS } from '../theme' +import { KDS, alpha } from '../theme' function Bar({ fs, z, children }) { const pad = Math.round(6 * fs) return (
e.stopPropagation()} style={{ position: 'absolute', left: 0, right: 0, top: 0, height: Math.round((CARD_HEAD_H_BASE + CARD_SUB_H_BASE) * fs), zIndex: z, - background: '#0a0e13', borderRadius: '10px 10px 0 0', display: 'flex', alignItems: 'stretch', padding: pad, gap: pad, + background: KDS.deep, borderRadius: `${KDS.radiusCard} ${KDS.radiusCard} 0 0`, display: 'flex', alignItems: 'stretch', padding: pad, gap: pad, }}> {children}
@@ -25,7 +25,7 @@ function BarButton({ bg, label, title, onClick, fs, children, testId }) { onClick={e => { e.stopPropagation(); onClick() }} style={{ flex: 1, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: Math.round(3 * fs), - background: bg, color: '#fff', border: 'none', cursor: 'pointer', fontFamily: 'inherit', borderRadius: Math.round(9 * fs), + background: bg, color: KDS.onStatus, border: 'none', cursor: 'pointer', fontFamily: 'inherit', borderRadius: Math.round(9 * fs), fontSize: Math.round(10 * fs), fontWeight: 700, letterSpacing: '.06em', textTransform: 'uppercase', }}> {children} @@ -43,14 +43,14 @@ export function ActionBar({ order, onStatus, onPrint, onCallWaiter, fs = 1, hasW <> onStatus(order.id, isPreparing ? 'pending' : 'preparing')}> + bg={isPreparing ? KDS.done : KDS.progress} onClick={() => onStatus(order.id, isPreparing ? 'pending' : 'preparing')}> {isPreparing ? : } onStatus(order.id, isDone ? 'pending' : 'done')}> + bg={isDone ? KDS.done : KDS.freshDeep} onClick={() => onStatus(order.id, isDone ? 'pending' : 'done')}> {isDone ? : } - onPrint(order.id)}> + onPrint(order.id)}> @@ -58,7 +58,7 @@ export function ActionBar({ order, onStatus, onPrint, onCallWaiter, fs = 1, hasW ) } -const REASONS = ['out_of_stock', 'too_many_orders', 'other'] - export function DeclineDialog({ itemId, itemName, onConfirm, onClose }) { const { t } = useTranslation('terminal') const [reason, setReason] = useState(null) const [note, setNote] = useState('') - const isItem = itemId != null - const title = isItem ? t('kds.decline.item') : t('kds.decline.order') + const title = itemId != null ? t('kds.decline.item') : t('kds.decline.order') const confirm = () => { if (!reason) return // the waiter app shows this text as it is: the reason in the screen's language, or the note @@ -43,43 +33,20 @@ export function DeclineDialog({ itemId, itemName, onConfirm, onClose }) { onClose() } return ( - -
-
{title}
- {isItem && itemName &&
{itemName}
} -
-
- {REASONS.map(r => { - const on = reason === r - return ( - - ) - })} + + + + }> +
+ {REASONS.map(r => ( + setReason(r)} data-reason={r}>{t(`kds.decline.reasons.${r}`)} + ))} {reason === 'other' && ( - setNote(e.target.value)} placeholder={t('kds.decline.notePlaceholder')} autoFocus style={{ - width: '100%', height: 44, borderRadius: 10, padding: '0 12px', background: '#232d38', border: '1px solid #3d4f5e', - color: KDS.panelInk, fontSize: 14, fontFamily: 'inherit', outline: 'none', boxSizing: 'border-box', - }} /> + setNote(e.target.value)} placeholder={t('kds.decline.notePlaceholder')} autoFocus /> )}
-
- - -
- +
) } @@ -108,73 +75,38 @@ export function CallWaiterDialog({ zoneName, onSend, onClose }) { setSending(true) try { await onSend([...selected]); onClose() } finally { setSending(false) } } - const chip = on => ({ - width: '100%', borderRadius: 12, marginBottom: 8, cursor: 'pointer', fontFamily: 'inherit', display: 'flex', alignItems: 'center', - background: on ? 'rgba(47,127,240,.18)' : KDS.field, border: `2px solid ${on ? KDS.accent : KDS.panelLine}`, - }) - const ready = selected.size > 0 && !sending return ( - -
-
-
{t('kds.call.title')}
- {zoneName &&
{t('kds.call.needsHelp', { zone: zoneName })}
} -
- -
-
- {waiters === null &&
{t('kds.loading')}
} - {waiters?.length === 0 &&
{t('kds.call.none')}
} + + + + }> +
+ {waiters === null &&
} + {waiters?.length === 0 &&

{t('kds.call.none')}

} {waiters?.length > 0 && ( <> - + setSelected(all ? new Set() : new Set(waiters.map(w => w.id)))}> + {all && }{t('kds.call.all')} + {waiters.map(w => { const on = selected.has(w.id) const name = w.nickname || w.username return ( - + {name} + ) })} )}
-
- - -
- - ) -} - -export function Toasts({ toasts }) { - return ( -
- {toasts.map(x => ( -
- {x.msg} -
- ))} -
+
) } diff --git a/terminal/src/apps/kds/components/ItemBlock.jsx b/terminal/src/apps/kds/components/ItemBlock.jsx index bd8cede..814db04 100644 --- a/terminal/src/apps/kds/components/ItemBlock.jsx +++ b/terminal/src/apps/kds/components/ItemBlock.jsx @@ -9,7 +9,7 @@ const MOD_ICON_SZ = 13 const HOLD_MS = 500 export function ModRow({ Icon, color, text, done, fs }) { - const col = done ? KDS.doneInk : color + const col = done ? KDS.cardMuted : color const fontSize = Math.round(12 * fs) const lineH = Math.round(fontSize * 1.4) const iconSz = Math.round(MOD_ICON_SZ * fs) @@ -57,13 +57,13 @@ export default function ItemBlock({ item, focused, onBump, onDecline, fontScale flexShrink: 0, minWidth: badgeH, height: badgeH, paddingLeft: hasUnit(item.unit_type) ? Math.round(4 * fs) : 0, paddingRight: hasUnit(item.unit_type) ? Math.round(4 * fs) : 0, display: 'inline-flex', alignItems: 'center', justifyContent: 'center', - background: done ? '#f1f2f4' : KDS.qtyBg, color: done ? KDS.doneInk : KDS.qtyInk, - borderRadius: Math.round(5 * fs), fontFamily: 'ui-monospace, monospace', fontWeight: 700, fontSize: Math.round(12 * fs), lineHeight: 1, + background: KDS.cardSoft, color: done ? KDS.cardMuted : KDS.cardInk, + borderRadius: Math.round(5 * fs), fontFamily: KDS.fontMono, fontWeight: 700, fontSize: Math.round(12 * fs), lineHeight: 1, }}> {formatQty(item.quantity, item.unit_type)} {item.product_name} @@ -71,8 +71,8 @@ export default function ItemBlock({ item, focused, onBump, onDecline, fontScale {focused && ( )}
@@ -80,18 +80,18 @@ export default function ItemBlock({ item, focused, onBump, onDecline, fontScale
{combineModifiers ? ( <> - {removed.length > 0 && } - {extras.length > 0 && } - {prefs.length > 0 && } + {removed.length > 0 && } + {extras.length > 0 && } + {prefs.length > 0 && } ) : ( <> - {removed.map((r, i) => )} - {extras.map((x, i) => )} - {prefs.map((p, i) => )} + {removed.map((r, i) => )} + {extras.map((x, i) => )} + {prefs.map((p, i) => )} )} - {item.notes && } + {item.notes && }
) : null}
diff --git a/terminal/src/apps/kds/components/OrderCard.jsx b/terminal/src/apps/kds/components/OrderCard.jsx index 370d96f..dad7ca7 100644 --- a/terminal/src/apps/kds/components/OrderCard.jsx +++ b/terminal/src/apps/kds/components/OrderCard.jsx @@ -8,7 +8,7 @@ import { Bike, Info, ShoppingBag, User, Utensils } from 'lucide-react' import { useTranslation } from '@xenia/i18n' import { courseGroups, minutesSince } from '../logic/board' import { BLOCK_GAP, BODY_PAD_B, BODY_PAD_H, BODY_PAD_T, CARD_FOOT_H_BASE, CARD_HEAD_H_BASE, CARD_SUB_H_BASE } from '../logic/layout' -import { KDS } from '../theme' +import { KDS, alpha } from '../theme' import { ActionBar, QuickActionBar } from './ActionBars' import ItemBlock from './ItemBlock' @@ -22,7 +22,7 @@ function ChannelBadge({ orderType, tableName, fs }) { const Icon = CHANNEL_ICONS[type] const iconSz = Math.round(17 * fs) return ( - + {type === 'here' && tableName ? tableName : t(`kds.channel.${type}`)} @@ -30,17 +30,18 @@ function ChannelBadge({ orderType, tableName, fs }) { } function headColours(age, colours) { - if (age === 'done') return [colours.done, KDS.doneSub] - if (age === 'future') return [KDS.futureHead, KDS.futureSubBg] - if (age === 'green') return [colours.fresh, KDS.greenD] - if (age === 'amber') return [colours.warning, KDS.amberD] - return [colours.late, KDS.redD] + if (age === 'done') return [colours.done, KDS.doneDeep] + if (age === 'future') return [KDS.future, KDS.futureDeep] + if (age === 'green') return [colours.fresh, KDS.freshDeep] + if (age === 'amber') return [colours.warning, KDS.warningDeep] + return [colours.late, KDS.lateDeep] } +/** The board token a card glows in when several status filters are on. */ function glowFor(order, age) { - if (age === 'done') return KDS.glowDone - if (age === 'future') return KDS.glowFuture - return order.kds_status === 'preparing' ? KDS.glowPreparing : KDS.glowPending + if (age === 'done') return 'ink' + if (age === 'future') return 'future-glow' + return order.kds_status === 'preparing' ? 'progress' : 'warning' } export default function OrderCard({ order, age, ageText, layout, focused, dimmed, settings, multiFilter, courses, now, @@ -94,13 +95,13 @@ export default function OrderCard({ order, age, ageText, layout, focused, dimmed return (
-
+ letterSpacing: '.1em', color: KDS.cardMuted, padding: bi === 0 ? '0 0 2px' : '4px 0 2px' }}> +
{t('kds.card.batch', { n: bi + 1 })} - + {t('kds.age.minutes', { m: Math.max(0, minutesSince(batch.opened_at, now)) })} -
+
{items.map(item)} @@ -113,7 +114,7 @@ export default function OrderCard({ order, age, ageText, layout, focused, dimmed return column(ci, courseGroups(colItems, courses).map((g, gi) => (
+ color: g.course ? g.course.color : KDS.cardMuted, padding: '4px 10px 2px' }}> {g.course ? g.course.name : t('kds.card.noCourse')}
{g.items.map(item)} @@ -131,11 +132,11 @@ export default function OrderCard({ order, age, ageText, layout, focused, dimmed onPointerDown={onPointerDown} onPointerUp={cancelHold} onPointerLeave={cancelHold} onPointerCancel={cancelHold} style={{ position: 'absolute', left: layout.x, top: layout.y, width: layout.w, height: layout.h, - background: headBg, borderRadius: 10, overflow: 'hidden', + background: headBg, borderRadius: KDS.radiusCard, overflow: 'hidden', boxShadow: focused - ? `0 10px 24px rgba(0,0,0,.4), 0 0 0 4px rgba(47,127,240,.25)${glow ? `, 0 0 0 2px ${glow}40` : ''}` - : `0 1px 2px rgba(0,0,0,.25), 0 6px 16px rgba(0,0,0,.22)${glow ? `, 0 0 12px 2px ${glow}55, 0 0 0 2px ${glow}44` : ''}`, - outline: focused ? `2px solid ${KDS.accent}` : '2px solid transparent', outlineOffset: 2, + ? `${KDS.shadowFocus}${glow ? `, 0 0 0 2px ${alpha(glow, 0.25)}` : ''}` + : `${KDS.shadowCard}${glow ? `, 0 0 12px 2px ${alpha(glow, 0.33)}, 0 0 0 2px ${alpha(glow, 0.27)}` : ''}`, + outline: focused ? `2px solid ${KDS.progress}` : '2px solid transparent', outlineOffset: 2, display: 'flex', flexDirection: 'column', transform: focused ? 'scale(1.012)' : 'none', transition: 'box-shadow .15s, transform .15s, outline-color .15s', opacity: dimmed ? 0.42 : 1, filter: dimmed ? 'saturate(.7)' : 'none', zIndex: focused ? 60 : 1, @@ -143,13 +144,13 @@ export default function OrderCard({ order, age, ageText, layout, focused, dimmed }} >
{ageText} @@ -162,7 +163,7 @@ export default function OrderCard({ order, age, ageText, layout, focused, dimmed
#{order.id} @@ -172,7 +173,7 @@ export default function OrderCard({ order, age, ageText, layout, focused, dimmed
@@ -180,13 +181,13 @@ export default function OrderCard({ order, age, ageText, layout, focused, dimmed
{order.notes && ( -
+
- + {order.notes}
@@ -194,8 +195,8 @@ export default function OrderCard({ order, age, ageText, layout, focused, dimmed {waiter && (
{waiter} diff --git a/terminal/src/apps/kds/components/Rails.jsx b/terminal/src/apps/kds/components/Rails.jsx index e8829cf..88e6927 100644 --- a/terminal/src/apps/kds/components/Rails.jsx +++ b/terminal/src/apps/kds/components/Rails.jsx @@ -3,22 +3,22 @@ // 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 } from '../theme' +import { KDS, alpha } from '../theme' const STATUSES = [ - { key: 'future', Icon: Clock, colour: KDS.green }, - { key: 'pending', Icon: Timer, colour: KDS.amber }, - { key: 'preparing', Icon: Flame, colour: KDS.accent }, - { key: 'done', Icon: CheckCheck, colour: '#cdd6e0' }, + { 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, onClick, disabled, fs, children, testId }) { +function RailButton({ active, colour = KDS.ink, onClick, disabled, fs, children, testId }) { return ( @@ -106,7 +106,7 @@ export function TopBar({ tab, counts, onTab, now, fontScale = 1, zoomPercent, on {showSummaryButton && ( - + {zoomPercent}% diff --git a/terminal/src/apps/kds/components/SettingsPanel.jsx b/terminal/src/apps/kds/components/SettingsPanel.jsx index 4d3de8d..35a68bb 100644 --- a/terminal/src/apps/kds/components/SettingsPanel.jsx +++ b/terminal/src/apps/kds/components/SettingsPanel.jsx @@ -1,66 +1,36 @@ -// This screen's settings, changed on the screen itself (plan step 3.2b): the device config of -// 3.2a, saved with PATCH /api/devices/me/config (only someone holding core.devices.manage; -// others see the settings and a note). The texts are the Devices page's -// (modules:kds.config.*), so both places say the same thing. The saved settings come back -// through device.updated → GET /api/devices/me, like an edit on the Devices page. +// This screen's settings, changed on the screen itself (plan steps 3.2b, 3.2b-2): the device +// config of 3.2a, saved with PATCH /api/devices/me/config (only someone holding +// core.devices.manage; others see the settings and a note). Texts are the Devices page's +// (modules:kds.config.*), so both places say the same thing. Shared @xenia/ui components +// (dark theme on the KDS). The saved settings come back through device.updated → GET +// /api/devices/me, like an edit on the Devices page. import { useState } from 'react' import { Check } from 'lucide-react' import { useCan } from '@xenia/access' import { errorMessage } from '@xenia/api' import { useTranslation } from '@xenia/i18n' +import { Button, Dialog, Select, Stepper, Switch } from '@xenia/ui' import client from '../../../api/client' import { DEFAULT_CONFIG, FONT_SCALE_MAX, FONT_SCALE_MIN, FONT_SCALE_STEP } from '../logic/settings' -import { KDS, secondaryButton } from '../theme' -import { CloseButton, KdsModal } from './Dialogs' const CARD_WIDTHS = [200, 220, 240, 260, 272, 280, 300, 320, 340, 360, 380, 400, 420, 440, 460, 480, 500, 540, 580, 620, 660, 700, 750, 800] const WEIGHTS = [300, 400, 500, 600, 700, 800] const REFRESH = [10, 15, 20, 30, 45, 60, 90, 120] const SIGN_OUT = [0, 2, 5, 10, 30, 60] const FONT_SCALES = Array.from({ length: (FONT_SCALE_MAX - FONT_SCALE_MIN) / FONT_SCALE_STEP + 1 }, (_, i) => FONT_SCALE_MIN + i * FONT_SCALE_STEP) -const PRESETS = ['#34b56a', '#7ec828', '#f5c518', '#f07d2a', '#e8513f', '#e84f9a', '#9b5de5', '#2f7ff0', '#1fabbe', '#e7ecf2', '#3d4757'] +// Colours offered for the age states: the board's own (--x-board-*) first, then a few more. +// They are stored as values in the device config, so they are data here, not styling. +const PRESETS = ['#34b56a', '#7ec828', '#f5c518', '#f0a52a', '#f07d2a', '#e8513f', '#e84f9a', '#9b5de5', '#2f7ff0', '#1fabbe', '#e7ecf2', '#3d4757'] const TABS = ['zone', 'behaviour', 'board', 'age', 'notifications'] -const nearest = (steps, v) => steps.reduce((a, b) => (Math.abs(b - v) < Math.abs(a - v) ? b : a)) - -function Stepper({ value, steps, display, onChange, min = -Infinity, max = Infinity, testId }) { - const options = steps.filter(s => s >= min && s <= max) - const cur = nearest(options, value) - const i = options.indexOf(cur) - const btn = on => ({ - width: 44, height: 44, borderRadius: 10, flexShrink: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', - background: on ? '#2e3a47' : '#232d38', color: on ? KDS.panelInk : '#4a5568', border: `1px solid ${on ? '#3d4f5e' : '#2a3542'}`, - cursor: on ? 'pointer' : 'default', fontFamily: 'inherit', fontSize: 22, fontWeight: 300, userSelect: 'none', - }) - return ( -
- - {display(cur)} - -
- ) -} - -function Toggle({ on, onToggle, testId }) { - return ( - - ) -} - function Swatches({ value, onChange, testId }) { return ( -
+
{PRESETS.map(p => ( -
) } @@ -77,39 +47,35 @@ export default function SettingsPanel({ config, context, onClose, onSaved }) { const choice = (key, v) => t(`modules:kds.config.${key}.choices.${v}`, { defaultValue: String(v) }) const row = (key, control) => ( -
-
-
{L(key)}
- {L(key, 'hint') &&
{L(key, 'hint')}
} +
+
+
{L(key)}
+ {L(key, 'hint') &&
{L(key, 'hint')}
}
-
{control}
+
{control}
+
+ ) + const toggle = key => ( +
+ set(key, on)} label={L(key)} description={L(key, 'hint') || undefined} data-testid={`set-${key}`} />
) - const toggle = key => row(key, set(key, !local[key])} />) const select = (key, options) => row(key, ( - - )) - const minutes = (key, min, max) => row(key, ( - i + 1)} min={min} max={max} - display={v => t('kds.age.minutes', { m: v })} onChange={v => set(key, v)} /> +