From 3580f2815c6061cbf7777cc98501e32578f4d19b Mon Sep 17 00:00:00 2001 From: bonamin Date: Fri, 13 Nov 2026 19:33:58 +0200 Subject: [PATCH] feat(ui): @xenia/ui design tokens, Tailwind preset and base components MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Platform-v2 step 2.3 (APPS_PLATFORM D-15 §9): - tokens.css: --x- prefixed colours (light/dark/system + 5 venue accent themes), spacing, radius, type scale, shadows, motion, z-index; variables only - components.css: .x-* classes only, no element selectors (new rule CS-16) - Button, IconButton, Dialog, Sheet, Toast, PinPad, InfoTip, EmptyState, Spinner, Field/Input/Textarea/Select, Switch (accessible: focus trap and restore, ARIA wiring, 44px targets) - tailwind-preset.js (adds names only); manager uses it + styles.css, the waiter imports tokens.css; existing screens unchanged - dev-only /ui-gallery in the manager; e2e suite tests/e2e/ui.mjs; unit tests for PIN rules and WCAG AA contrast of every token pair, both in run-all Co-Authored-By: Claude Opus 5.5 --- docs/README.md | 6 +- manager_dashboard/package.json | 1 + manager_dashboard/src/App.jsx | 6 +- manager_dashboard/src/main.jsx | 1 + manager_dashboard/tailwind.config.js | 4 + package-lock.json | 8 +- packages/ui/gallery/Gallery.jsx | 167 +++++++++ packages/ui/package.json | 16 +- packages/ui/src/components.css | 297 ++++++++++++++++ packages/ui/src/components/Button.jsx | 46 +++ packages/ui/src/components/Dialog.jsx | 20 ++ packages/ui/src/components/EmptyState.jsx | 18 + packages/ui/src/components/Field.jsx | 79 +++++ packages/ui/src/components/InfoTip.jsx | 90 +++++ packages/ui/src/components/PinPad.jsx | 118 +++++++ packages/ui/src/components/Sheet.jsx | 19 ++ packages/ui/src/components/Spinner.jsx | 23 ++ packages/ui/src/components/Switch.jsx | 41 +++ packages/ui/src/components/Toast.jsx | 88 +++++ packages/ui/src/components/pin.js | 22 ++ packages/ui/src/components/toastContext.js | 10 + packages/ui/src/index.js | 26 +- packages/ui/src/internal/ModalFrame.jsx | 61 ++++ packages/ui/src/internal/Portal.jsx | 7 + packages/ui/src/internal/cx.js | 4 + packages/ui/src/internal/useModal.js | 82 +++++ packages/ui/src/styles.css | 3 + packages/ui/src/tokens.css | 374 +++++++++++++++++++++ packages/ui/tailwind-preset.js | 62 ++++ packages/ui/tests/contrast.test.mjs | 67 ++++ packages/ui/tests/pin.test.mjs | 23 ++ tests/e2e/README.md | 4 + tests/e2e/run-all.mjs | 4 +- tests/e2e/ui.mjs | 129 +++++++ waiter_pwa/package.json | 1 + waiter_pwa/src/main.jsx | 1 + 36 files changed, 1920 insertions(+), 8 deletions(-) create mode 100644 packages/ui/gallery/Gallery.jsx create mode 100644 packages/ui/src/components.css create mode 100644 packages/ui/src/components/Button.jsx create mode 100644 packages/ui/src/components/Dialog.jsx create mode 100644 packages/ui/src/components/EmptyState.jsx create mode 100644 packages/ui/src/components/Field.jsx create mode 100644 packages/ui/src/components/InfoTip.jsx create mode 100644 packages/ui/src/components/PinPad.jsx create mode 100644 packages/ui/src/components/Sheet.jsx create mode 100644 packages/ui/src/components/Spinner.jsx create mode 100644 packages/ui/src/components/Switch.jsx create mode 100644 packages/ui/src/components/Toast.jsx create mode 100644 packages/ui/src/components/pin.js create mode 100644 packages/ui/src/components/toastContext.js create mode 100644 packages/ui/src/internal/ModalFrame.jsx create mode 100644 packages/ui/src/internal/Portal.jsx create mode 100644 packages/ui/src/internal/cx.js create mode 100644 packages/ui/src/internal/useModal.js create mode 100644 packages/ui/src/styles.css create mode 100644 packages/ui/src/tokens.css create mode 100644 packages/ui/tailwind-preset.js create mode 100644 packages/ui/tests/contrast.test.mjs create mode 100644 packages/ui/tests/pin.test.mjs create mode 100644 tests/e2e/ui.mjs diff --git a/docs/README.md b/docs/README.md index a4834fa..ac425f5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -49,6 +49,7 @@ The manager calls the API **same-origin, with relative paths**. The waiter app r | `install.sh` | Site installer. **Writes its own copy of the proxy config.** | | `docker-compose.yml` / `docker-compose.dev.yml` | Prod (pull images) / dev override (build + expose ports) | | `package.json`, `package-lock.json`, `packages/` | **npm workspace** for the frontends (D-15): `waiter_pwa`, `manager_dashboard` and the shared `packages/{ui,i18n,api,access}` (imported from source, no build step). One lockfile at this root; the apps have none of their own. | +| `packages/ui/` | Shared design tokens, Tailwind preset and base components (CS-16). Visual check: `npm run dev:manager` → `/ui-gallery` | | `.dockerignore` | The frontend images build with **`client-services/` as context** (`-f waiter_pwa/Dockerfile .`), so this file decides what Docker sees. The backend still builds from `local_backend/`. | --- @@ -144,7 +145,7 @@ The native plugins (`@capacitor/*`, `@capgo/*`) are pinned to **exact** versions ## Testing Automated tests cover the native-app/LAN work and licensing. See **[tests/e2e/README.md](../tests/e2e/README.md)**. -- **Unit (seconds):** `python -m pytest tests -q` in `local_backend/`, and `npm test` in `waiter_pwa/`. +- **Unit (seconds):** `python -m pytest tests -q` in `local_backend/`, `npm test` in `waiter_pwa/`, and `npm test -w @xenia/ui` at the workspace root. - **End-to-end:** `node run-all.mjs` in `tests/e2e/`. That covers install.sh, licensing with a real cloud, browser modes, and the Android emulator suites. `--no-android` skips the emulator. **CS-11. Tests follow the code.** When you change something a test covers (licensing, LAN IP, TLS, pairing, rediscovery, bundles, install.sh, the proxy config), run its suite and update the test in the same commit. Run `node run-all.mjs` before every release. @@ -160,6 +161,9 @@ Use `core.access.deps.require("..")` (or `require_any`, `p Paired devices (D-8, `routers/devices.py`, `core/access/context.py`) send `X-Xenia-Device: `; a device may only use keys matching its app's `DeviceApp.scope` (plus `.*`) and only reach routes of those modules. A new device app with user logins must declare `.access`. Device-only endpoints use `require_device("")`; users log in on a device with `POST /api/auth/login {client: "terminal"}`, and that session only works together with the device's header. 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`. + **CS-15. Support access is a challenge code, never a password** (branch `platform-v2`, D-16). There is no master account. A site's `SUPPORT_SECRET` (env only) comes from `tools/support_code.py --site-secret `, derived from the builder's master key in `%USERPROFILE%\.xenia\support_master_key.txt` (outside the repo, back it up). The derivation lives in `local_backend/core/support_codes.py` (stdlib only, the tool loads it by path) and is re-implemented for the e2e suites in `tests/e2e/lib/support.mjs`; `tests/test_support.py` pins a vector both must match. The e2e backends log in through support access (`login()` in `lib/proc.mjs`). diff --git a/manager_dashboard/package.json b/manager_dashboard/package.json index 7790b2b..71279e4 100644 --- a/manager_dashboard/package.json +++ b/manager_dashboard/package.json @@ -10,6 +10,7 @@ }, "dependencies": { "@tanstack/react-query": "^5.62.0", + "@xenia/ui": "^0.0.0", "axios": "^1.7.9", "lucide-react": "^1.14.0", "qrcode.react": "^4.2.0", diff --git a/manager_dashboard/src/App.jsx b/manager_dashboard/src/App.jsx index 5451d60..43d721f 100644 --- a/manager_dashboard/src/App.jsx +++ b/manager_dashboard/src/App.jsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from 'react' +import { lazy, Suspense, useEffect, useState } from 'react' import { BrowserRouter, Routes, Route, Navigate, useNavigate } from 'react-router-dom' import useAuthStore from './store/authStore' import AppLayout from './layouts/AppLayout' @@ -54,6 +54,9 @@ import SettingsPage from './pages/Settings/SettingsPage' import NotesPage from './pages/NotesPage' import PermissionGuard from './components/PermissionGuard' +// @xenia/ui visual check page, dev builds only (left out of production bundles) +const UiGallery = import.meta.env.DEV ? lazy(() => import('@xenia/ui/gallery')) : null + function Spinner() { return (
@@ -109,6 +112,7 @@ export default function App() { } /> + {UiGallery && } />} } /> } /> diff --git a/manager_dashboard/src/main.jsx b/manager_dashboard/src/main.jsx index 4d57aa5..d913bb7 100644 --- a/manager_dashboard/src/main.jsx +++ b/manager_dashboard/src/main.jsx @@ -3,6 +3,7 @@ import ReactDOM from 'react-dom/client' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { Toaster } from 'react-hot-toast' import App from './App.jsx' +import '@xenia/ui/styles.css' // shared tokens + component styles (.x-*), no global rules import './index.css' const queryClient = new QueryClient({ diff --git a/manager_dashboard/tailwind.config.js b/manager_dashboard/tailwind.config.js index 732c650..923dce7 100644 --- a/manager_dashboard/tailwind.config.js +++ b/manager_dashboard/tailwind.config.js @@ -1,5 +1,9 @@ +import xenia from '@xenia/ui/tailwind-preset' + /** @type {import('tailwindcss').Config} */ export default { + // Shared design tokens (bg-surface, text-ink-2, rounded-control…); adds names only + presets: [xenia], content: ['./index.html', './src/**/*.{js,jsx}'], theme: { extend: { diff --git a/package-lock.json b/package-lock.json index b08190f..88a7893 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "version": "0.0.0", "dependencies": { "@tanstack/react-query": "^5.62.0", + "@xenia/ui": "^0.0.0", "axios": "^1.7.9", "lucide-react": "^1.14.0", "qrcode.react": "^4.2.0", @@ -2880,7 +2881,11 @@ }, "packages/ui": { "name": "@xenia/ui", - "version": "0.0.0" + "version": "0.0.0", + "peerDependencies": { + "react": "^19.0.0", + "react-dom": "^19.0.0" + } }, "waiter_pwa": { "version": "0.0.0", @@ -2890,6 +2895,7 @@ "@capacitor/core": "8.5.2", "@capgo/capacitor-updater": "8.51.25", "@tanstack/react-query": "^5.100.11", + "@xenia/ui": "^0.0.0", "axios": "^1.15.1", "dexie": "^4.4.2", "qr-scanner": "^1.4.2", diff --git a/packages/ui/gallery/Gallery.jsx b/packages/ui/gallery/Gallery.jsx new file mode 100644 index 0000000..8c411a2 --- /dev/null +++ b/packages/ui/gallery/Gallery.jsx @@ -0,0 +1,167 @@ +// Visual check page for @xenia/ui (plan step 2.3). Dev builds only: the manager mounts +// it at /ui-gallery under `import.meta.env.DEV` (moves to the terminal dev build in 3.1). +// Sets data-theme / data-venue-theme on while open and restores them on leave. +import { useEffect, useState } from 'react' +import { + Button, Dialog, EmptyState, Field, IconButton, InfoTip, Input, PinPad, Select, Sheet, + Spinner, Switch, Textarea, ToastProvider, useToast, +} from '../src/index.js' +import '../src/styles.css' + +const THEMES = ['light', 'dark', 'system'] +const VENUES = ['teal', 'amber', 'blue', 'violet', 'rose'] + +const Plus = () => ( + +) +const Trash = () => ( + +) +const Inbox = () => ( + +) + +const page = { + minHeight: '100vh', background: 'var(--x-canvas)', color: 'var(--x-ink)', + fontFamily: 'var(--x-font-sans)', fontSize: 'var(--x-text-body)', padding: 'var(--x-space-6)', +} +const card = { + background: 'var(--x-surface)', border: '1px solid var(--x-line)', borderRadius: 'var(--x-radius-card)', + boxShadow: 'var(--x-shadow-raised)', padding: 'var(--x-space-6)', marginBottom: 'var(--x-space-6)', +} +const row = { display: 'flex', flexWrap: 'wrap', gap: 'var(--x-space-3)', alignItems: 'center' } +const h2 = { margin: '0 0 var(--x-space-4)', fontSize: 'var(--x-text-title)', fontWeight: 600 } + +function Section({ title, children }) { + return

{title}

{children}
+} + +function Demo() { + const toast = useToast() + const [theme, setTheme] = useState('light') + const [venue, setVenue] = useState('teal') + const [dialog, setDialog] = useState(false) + const [locked, setLocked] = useState(false) + const [sheet, setSheet] = useState(null) + const [on, setOn] = useState(true) + const [off, setOff] = useState(false) + const [name, setName] = useState('') + const [lang, setLang] = useState('el') + const [pinError, setPinError] = useState('') + const [unlocked, setUnlocked] = useState('') + + useEffect(() => { + const html = document.documentElement + const before = [html.getAttribute('data-theme'), html.getAttribute('data-venue-theme')] + html.setAttribute('data-theme', theme) + html.setAttribute('data-venue-theme', venue) + return () => { + before[0] == null ? html.removeAttribute('data-theme') : html.setAttribute('data-theme', before[0]) + before[1] == null ? html.removeAttribute('data-venue-theme') : html.setAttribute('data-venue-theme', before[1]) + } + }, [theme, venue]) + + const checkPin = pin => new Promise((resolve, reject) => setTimeout(() => { + if (pin === '1234') { setPinError(''); setUnlocked(`Unlocked at ${new Date().toLocaleTimeString()}`); resolve() } + else { setPinError('Wrong PIN'); reject(new Error('wrong')) } + }, 500)) + + return ( +
+
+

@xenia/ui gallery

+
+ setVenue(e.target.value)} options={VENUES.map(v => ({ value: v, label: `Venue: ${v}` }))} /> +
+
+ +
+
+ + + + + + + + + + +
+
+ +
+
+ + + + + + + +
+ setDialog(false)} title="Delete product?" + description="Freddo espresso will be removed from every category." + footer={<>} + > + + + setLocked(false)}>Done} + > + Escape and the backdrop don't close this one. + + setSheet(null)} title="Move order" + footer={} + > + setName(e.target.value)} placeholder="e.g. Freddo espresso" /> + + + + + The language staff screens start in. Each person can change their own.}> +