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 <noreply@anthropic.com>
168 lines
9.0 KiB
React
168 lines
9.0 KiB
React
// 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 <html> 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 = () => (
|
|
<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" aria-hidden="true"><path d="M12 5v14M5 12h14" /></svg>
|
|
)
|
|
const Trash = () => (
|
|
<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M3 6h18M8 6V4h8v2M6 6l1 14h10l1-14" /></svg>
|
|
)
|
|
const Inbox = () => (
|
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M22 12h-6l-2 3h-4l-2-3H2" /><path d="M5.45 5.11L2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z" /></svg>
|
|
)
|
|
|
|
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 <section style={card} data-section={title}><h2 style={h2}>{title}</h2>{children}</section>
|
|
}
|
|
|
|
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 (
|
|
<div style={page}>
|
|
<div style={{ ...row, justifyContent: 'space-between', marginBottom: 'var(--x-space-6)' }}>
|
|
<h1 style={{ margin: 0, fontSize: 'var(--x-text-heading)', fontWeight: 700 }}>@xenia/ui gallery</h1>
|
|
<div style={row}>
|
|
<Select aria-label="Theme" size="sm" value={theme} onChange={e => setTheme(e.target.value)} options={THEMES.map(t => ({ value: t, label: `Theme: ${t}` }))} />
|
|
<Select aria-label="Venue theme" size="sm" value={venue} onChange={e => setVenue(e.target.value)} options={VENUES.map(v => ({ value: v, label: `Venue: ${v}` }))} />
|
|
</div>
|
|
</div>
|
|
|
|
<Section title="Buttons">
|
|
<div style={row}>
|
|
<Button>Primary</Button>
|
|
<Button variant="secondary">Secondary</Button>
|
|
<Button variant="ghost">Ghost</Button>
|
|
<Button variant="danger" icon={<Trash />}>Delete</Button>
|
|
<Button loading>Saving</Button>
|
|
<Button disabled>Disabled</Button>
|
|
<Button size="sm" icon={<Plus />}>Small</Button>
|
|
<Button size="lg">Large</Button>
|
|
<IconButton label="Add"><Plus /></IconButton>
|
|
<IconButton label="Delete" variant="danger"><Trash /></IconButton>
|
|
</div>
|
|
</Section>
|
|
|
|
<Section title="Dialog, Sheet, Toast">
|
|
<div style={row}>
|
|
<Button variant="secondary" onClick={() => setDialog(true)}>Open dialog</Button>
|
|
<Button variant="secondary" onClick={() => setLocked(true)}>Non-dismissible dialog</Button>
|
|
<Button variant="secondary" onClick={() => setSheet('bottom')}>Bottom sheet</Button>
|
|
<Button variant="secondary" onClick={() => setSheet('right')}>Side sheet</Button>
|
|
<Button variant="ghost" onClick={() => toast.success('Saved', { description: 'Product updated' })}>Toast: success</Button>
|
|
<Button variant="ghost" onClick={() => toast.error('Printer offline', { description: 'Bar printer did not answer' })}>Toast: danger</Button>
|
|
<Button variant="ghost" onClick={() => toast.show({ title: 'Order moved to table 4', action: { label: 'Undo', onClick: () => toast.info('Undone') } })}>Toast: action</Button>
|
|
</div>
|
|
<Dialog
|
|
open={dialog} onClose={() => setDialog(false)} title="Delete product?"
|
|
description="Freddo espresso will be removed from every category."
|
|
footer={<><Button variant="secondary" onClick={() => setDialog(false)}>Cancel</Button><Button variant="danger" onClick={() => { setDialog(false); toast.success('Deleted') }}>Delete</Button></>}
|
|
>
|
|
<Field label="Type DELETE to confirm"><Input placeholder="DELETE" /></Field>
|
|
</Dialog>
|
|
<Dialog
|
|
open={locked} dismissible={false} title="Finish the close of day" size="sm"
|
|
footer={<Button onClick={() => setLocked(false)}>Done</Button>}
|
|
>
|
|
Escape and the backdrop don't close this one.
|
|
</Dialog>
|
|
<Sheet
|
|
open={!!sheet} side={sheet || 'bottom'} onClose={() => setSheet(null)} title="Move order"
|
|
footer={<Button block onClick={() => setSheet(null)}>Move</Button>}
|
|
>
|
|
<Field label="To table"><Select placeholder="Choose…" defaultValue="" options={[1, 2, 3, 4].map(n => ({ value: String(n), label: `Table ${n}` }))} /></Field>
|
|
</Sheet>
|
|
</Section>
|
|
|
|
<Section title="Fields">
|
|
<div style={{ display: 'grid', gap: 'var(--x-space-4)', gridTemplateColumns: 'repeat(auto-fit, minmax(260px, 1fr))' }}>
|
|
<Field label="Product name" hint="Shown on tickets and the QR menu" required>
|
|
<Input value={name} onChange={e => setName(e.target.value)} placeholder="e.g. Freddo espresso" />
|
|
</Field>
|
|
<Field label="Price" error="Enter a price, e.g. 3,50">
|
|
<Input inputMode="decimal" defaultValue="3,5x" />
|
|
</Field>
|
|
<Field label="Language" info={<InfoTip>The language staff screens start in. Each person can change their own.</InfoTip>}>
|
|
<Select value={lang} onChange={e => setLang(e.target.value)} options={[{ value: 'el', label: 'Ελληνικά' }, { value: 'en', label: 'English' }]} />
|
|
</Field>
|
|
<Field label="Notes"><Textarea placeholder="Allergies, preparation…" /></Field>
|
|
<Field label="Disabled"><Input disabled value="Read only" /></Field>
|
|
</div>
|
|
</Section>
|
|
|
|
<Section title="Switch + InfoTip">
|
|
<div style={{ display: 'grid', gap: 'var(--x-space-4)', maxWidth: 520 }}>
|
|
<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}>Alert after <InfoTip side="bottom">How many failed print attempts before managers are notified. 0 turns the alert off.</InfoTip></div>
|
|
</div>
|
|
</Section>
|
|
|
|
<Section title="PinPad (1234 unlocks)">
|
|
<div style={{ ...row, alignItems: 'flex-start', gap: 'var(--x-space-12)' }}>
|
|
<PinPad title="Enter PIN" onComplete={checkPin} error={pinError} />
|
|
<div style={{ color: 'var(--x-ink-2)' }} data-testid="pin-result">{unlocked}</div>
|
|
</div>
|
|
</Section>
|
|
|
|
<Section title="Spinner + EmptyState">
|
|
<div style={row}><Spinner size="sm" /><Spinner /><Spinner size="lg" /></div>
|
|
<EmptyState icon={<Inbox />} title="No online orders yet" description="New orders from the QR menu appear here." action={<Button variant="secondary">Menu settings</Button>} />
|
|
</Section>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default function Gallery() {
|
|
return <ToastProvider><Demo /></ToastProvider>
|
|
}
|