feat(ui): the QR card shared in @xenia/ui/qr (platform-v2 step 6.14c)

- QrCode (a QR on a light tile, optional caption; framed or not) in packages/ui, on its own subpath so only
  the apps that show one need qrcode.react (an optional peer); x-qr styles keep the code dark on light in dark themes
- used by the terminal's customer display, the manager's online-ordering link, table QR codes and Settings' pairing QR
  (four copies of the same markup gone)
- the money pad and the order line row stay where they are: the manager's payment is the phones' cash / card choice
  (no cash given, change or split) and its order lines are not the counter's cart lines, so neither has a second user;
  the signage slides keep their own QR (inline styles scaled to the TV)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 20:11:34 +02:00
co-authored by Claude Opus 5.5
parent 294b769850
commit f383060bad
7 changed files with 47 additions and 13 deletions
@@ -6,12 +6,12 @@
import { useState } from 'react'
import { useMutation, useQueryClient } from '@tanstack/react-query'
import toast from 'react-hot-toast'
import { QRCodeSVG } from 'qrcode.react'
import { Lock, LockOpen, QrCode, RefreshCw } from 'lucide-react'
import { Lock, LockOpen, QrCode as QrIcon, RefreshCw } from 'lucide-react'
import { useAccess } from '@xenia/access'
import { errorMessage } from '@xenia/api'
import { useFormat, useTranslation } from '@xenia/i18n'
import { Button, Dialog, Input, Spinner } from '@xenia/ui'
import { QrCode } from '@xenia/ui/qr'
import client from '../../../api/client'
import { useLiveQuery } from '../../../live/useLiveQuery'
import { Pill } from '../../overview/parts'
@@ -67,7 +67,7 @@ export default function SystemSettings() {
{status?.waiter_domain && (
<SettingRow label={t('settings.system.oldDomain')} hint={t('settings.system.oldDomainHint')}>
<span className="flex items-center gap-2 text-label font-mono break-all">{status.waiter_domain}
<Button size="sm" variant="secondary" icon={<QrCode size={14} />} onClick={() => setQr({ url: status.waiter_domain })}>{t('settings.system.qr')}</Button>
<Button size="sm" variant="secondary" icon={<QrIcon size={14} />} onClick={() => setQr({ url: status.waiter_domain })}>{t('settings.system.qr')}</Button>
</span>
</SettingRow>
)}
@@ -101,7 +101,7 @@ export default function SystemSettings() {
<Dialog open size="sm" onClose={() => setQr(null)} title={t('settings.system.qrTitle')} description={qr.caption}
footer={<Button variant="secondary" onClick={() => setQr(null)}>{t('settings.back')}</Button>}>
<div className="grid justify-items-center gap-3" data-testid="system-qr">
<div className="p-3 rounded-card bg-surface border border-line"><QRCodeSVG value={qr.url} size={220} /></div>
<QrCode value={qr.url} size={220} />
<p className="text-caption font-mono text-ink-2 break-all text-center">{qr.url}</p>
</div>
</Dialog>
@@ -155,7 +155,7 @@ function LanAccess({ status, onQr }) {
<SettingRow label={t('settings.lan.waiters')} hint={t('settings.lan.waitersHint')}>
<span className="flex flex-wrap items-center gap-2">
<span className="font-mono text-label text-ink break-all">http://{ip}</span>
<Button size="sm" variant="secondary" icon={<QrCode size={14} />} data-testid="lan-qr"
<Button size="sm" variant="secondary" icon={<QrIcon size={14} />} data-testid="lan-qr"
onClick={() => onQr({ url: waiterPairUrl(ip, status?.site_id, status?.tls?.spki_sha256), caption: t('settings.lan.qrCaption') })}>{t('settings.system.qr')}</Button>
</span>
</SettingRow>
@@ -3,10 +3,10 @@
// as a QR code for flyers and the shop window. GET /api/connect/fees → links.order (the cloud
// tells the venue where the customer apps live: PUBLIC_APPS_URL, sent with the heartbeat).
import toast from 'react-hot-toast'
import { QRCodeSVG } from 'qrcode.react'
import { Copy, ExternalLink, Printer } from 'lucide-react'
import { useTranslation } from '@xenia/i18n'
import { Button } from '@xenia/ui'
import { QrCode } from '@xenia/ui/qr'
export default function OrderingLink({ url }) {
const { t } = useTranslation('manager')
@@ -15,7 +15,7 @@ export default function OrderingLink({ url }) {
}
return (
<section className="p-4 rounded-card border border-line bg-surface flex flex-wrap items-center gap-4 print:border-0" aria-labelledby="ordering-link-h" data-testid="ordering-link">
<div className="bg-surface p-2 rounded-control border border-line"><QRCodeSVG value={url} size={112} includeMargin={false} /></div>
<QrCode value={url} size={112} />
<div className="grid gap-2 flex-1 min-w-[16rem]">
<h2 id="ordering-link-h" className="text-title font-semibold text-ink">{t('orderingLink.title')}</h2>
<p className="text-label text-ink-2">{t('orderingLink.intro')}</p>
@@ -6,11 +6,11 @@
// Backend: /api/connect/qr (connect_menu.manage), services/table_qr.py.
import { useCallback, useEffect, useState } from 'react'
import toast from 'react-hot-toast'
import { QRCodeSVG } from 'qrcode.react'
import { Printer, RefreshCw } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import { useTranslation } from '@xenia/i18n'
import { Button, Dialog, EmptyState, Spinner, Switch } from '@xenia/ui'
import { QrCode } from '@xenia/ui/qr'
import client from '../../api/client'
export default function QrCodesPage() {
@@ -60,7 +60,7 @@ export default function QrCodesPage() {
<li key={tb.id} className="p-4 rounded-card border border-line bg-surface grid justify-items-center gap-2 break-inside-avoid" data-testid="qr-table" data-table={tb.id} data-url={tb.url}>
<span className="text-title font-semibold text-ink">{t('qr.table', { name: tb.name })}</span>
{tb.group && <span className="text-label text-ink-2">{tb.group}</span>}
<QRCodeSVG value={tb.url} size={168} includeMargin={false} />
<QrCode value={tb.url} size={168} framed={false} />
<span className="text-caption text-ink-3 text-center">{t(data.ordering ? 'qr.scanOrder' : 'qr.scanRead')}</span>
<Button size="sm" variant="ghost" icon={<RefreshCw size={14} />} disabled={busy} className="print:hidden"
onClick={() => act(() => client.post(`/api/connect/qr/tables/${tb.id}/rotate`), t('qr.rotated', { name: tb.name }))}
+9 -2
View File
@@ -10,7 +10,8 @@
"./tokens.css": "./src/tokens.css",
"./styles.css": "./src/styles.css",
"./tailwind-preset": "./tailwind-preset.js",
"./gallery": "./gallery/Gallery.jsx"
"./gallery": "./gallery/Gallery.jsx",
"./qr": "./src/components/QrCode.jsx"
},
"sideEffects": [
"*.css"
@@ -20,6 +21,12 @@
},
"peerDependencies": {
"react": "^19.0.0",
"react-dom": "^19.0.0"
"react-dom": "^19.0.0",
"qrcode.react": "^4.2.0"
},
"peerDependenciesMeta": {
"qrcode.react": {
"optional": true
}
}
}
+6
View File
@@ -328,3 +328,9 @@
.x-reasons__option:hover { background: var(--x-surface-3); }
.x-reasons__option:focus-visible { outline: none; box-shadow: var(--x-focus-ring); }
.x-reasons__option--on, .x-reasons__option--on:hover { background: var(--x-accent); color: var(--x-accent-fg); }
/* ── QR code (QrCode, @xenia/ui/qr; plan step 6.14c) ─────────────────────── */
.x-qr { display: grid; justify-items: center; gap: var(--x-space-2); }
/* always light behind the code, in dark themes too: scanners need the contrast */
.x-qr__tile { padding: var(--x-space-3); border-radius: var(--x-radius-card); border: 1px solid var(--x-line); background: var(--x-on-colour); line-height: 0; }
.x-qr__caption { font-size: var(--x-text-label); color: var(--x-ink-2); text-align: center; }
+21
View File
@@ -0,0 +1,21 @@
// A QR code on a light tile (plan step 6.14c; moved here from the terminal's customer display and
// the manager's pages, where it was written four times). Its own subpath, `@xenia/ui/qr`, so only
// the apps that show one need `qrcode.react` (the waiter app doesn't).
//
// <QrCode value={url} size={220} /> framed: a tile with padding and a line
// <QrCode value={url} size={168} framed={false} /> just the code (in a card of its own)
// <QrCode value={url} caption="Order online" /> a caption under the tile
//
// The code is always dark on light (scanners need the contrast), in light and dark themes alike.
import { QRCodeSVG } from 'qrcode.react'
import { cx } from '../internal/cx.js'
export function QrCode({ value, size = 160, framed = true, caption, className, captionClassName, ...rest }) {
const code = <QRCodeSVG value={value} size={size} includeMargin={false} />
return (
<div className={cx('x-qr', className)} data-link={value} {...rest}>
{framed ? <div className="x-qr__tile">{code}</div> : code}
{caption && <p className={cx('x-qr__caption', captionClassName)}>{caption}</p>}
</div>
)
}
@@ -6,9 +6,9 @@
// The POS's state arrives live (`display.state`, addressed to this screen only); a settings
// change re-reads it (`display.settings`). GET /api/display/state on start and reconnect.
import { useCallback, useEffect, useRef, useState } from 'react'
import { QRCodeSVG } from 'qrcode.react'
import { useFormat, useTranslation } from '@xenia/i18n'
import { applyTheme, getStoredTheme } from '@xenia/ui'
import { QrCode } from '@xenia/ui/qr'
import client from '../../api/client'
import { useLiveEvent, useLiveEvents } from '../../device/context'
import { idleParts, PAID_MS, slideAt, viewOf } from './logic'
@@ -117,7 +117,7 @@ function IdleView({ idle, venue, now, linked }) {
{p.name && <h1 className="text-7xl font-semibold" data-testid="display-name">{p.name}</h1>}
{p.qr && (
<div className="grid justify-items-center gap-4" data-testid="display-qr" data-link={p.qr}>
<div className="p-5 rounded-card bg-surface shadow-raised"><QRCodeSVG value={p.qr} size={320} includeMargin={false} /></div>
<QrCode value={p.qr} size={320} className="shadow-raised rounded-card" />
{p.caption && <p className="text-4xl font-semibold">{p.caption}</p>}
</div>
)}