feat(signage): menu look part by part, board-only names, stack bar, Delete key (owner review 3)
- Menus (slides and widgets): headings / names / prices each with size, colour, font, bold / italic / underline and alignment; dots size, colour and style; line and letter spacing; photo size and shape (menuLook) - Names aligned right end together, prices in a page-wide column - Names for one board only (names, category_names) with a pencil on the board's list; the catalogue name stays for the waiters - Fixed: menu lists inherited the page's fixed line height (big text overlapped); a menu slide's list grew past the screen (no 2nd column) - Stacks: parts sized by dragging the lines on the bar; "Add a widget" - Delete / Backspace removes the picked widget Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
import { Cloud, CloudFog, CloudLightning, CloudMoon, CloudRain, CloudSnow, CloudSun, Moon, Sun } from 'lucide-react'
|
||||
import { QRCodeSVG } from 'qrcode.react'
|
||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { fitUnit, FONTS, menuPages, pageAt, textWidth, visibleGroups, weatherIcon, widgetAlign } from './logic'
|
||||
import { fitUnit, FONTS, menuLook, menuPages, pageAt, priceChars, textWidth, visibleGroups, weatherIcon, widgetAlign } from './logic'
|
||||
|
||||
/** A slide's background: a colour, or a photo (cover / contain) with a darkening layer. */
|
||||
export function Background({ bg, media }) {
|
||||
@@ -66,8 +66,9 @@ export function MenuSlide({ slide, media, venue, now, page, pages, extras, embed
|
||||
alignSelf: BOARD_ALIGN[c.board_align] || 'flex-start' }} data-testid="signage-menu-board" data-align={c.board_align || 'left'}>
|
||||
{c.title && <h1 style={{ fontSize: `${7 * scale}cqmin`, fontWeight: 800, margin: '0 0 2cqmin', color: accent, lineHeight: 1.1,
|
||||
textAlign: c.board_align || 'left' }}>{c.title}</h1>}
|
||||
<div style={{ columnCount: c.columns || 2, columnGap: '5cqmin', fontSize: `${3.2 * scale}cqmin`, flex: 1, columnFill: 'auto' }}>
|
||||
<MenuGroups c={c} groups={groups} accent={accent} />
|
||||
<div style={{ columnCount: c.columns || 2, columnGap: '5cqmin', fontSize: `${3.2 * scale}cqmin`, flex: 1, minHeight: 0, overflow: 'hidden', columnFill: 'auto', ...listSpacing(c) }}
|
||||
data-testid="signage-menu-list">
|
||||
<MenuGroups c={c} groups={groups} />
|
||||
</div>
|
||||
{pages.length > 1 && (
|
||||
<div style={{ display: 'flex', gap: '1cqmin', justifyContent: 'center', paddingTop: '1cqmin' }} aria-hidden="true">
|
||||
@@ -83,42 +84,63 @@ export function MenuSlide({ slide, media, venue, now, page, pages, extras, embed
|
||||
|
||||
/**
|
||||
* A board's groups of items (a menu slide's page, a menu widget's page). Sizes are em of the
|
||||
* list's text, so the same rows fit a whole screen or a widget's box.
|
||||
* list's text, so the same rows fit a whole screen or a widget's box. Each part has its own look
|
||||
* (menuLook, owner review 3): headings, names and prices (size, colour, font, bold / italic /
|
||||
* underline, alignment), the dots between them, line and letter spacing, photos' size and shape.
|
||||
* Prices sit in a column as wide as the page's widest price, so names aligned right end at the
|
||||
* same point and the dots are all equal.
|
||||
*/
|
||||
export function MenuGroups({ c, groups, accent }) {
|
||||
/** A list's own line and letter spacing (never the page's fixed line height). */
|
||||
const listSpacing = c => {
|
||||
const look = menuLook(c)
|
||||
return { lineHeight: look.lineHeight, letterSpacing: look.letterSpacing }
|
||||
}
|
||||
|
||||
export function MenuGroups({ c, groups }) {
|
||||
const { t } = useTranslation('terminal')
|
||||
const { formatMoney } = useFormat()
|
||||
return groups.map((g, i) => (
|
||||
<div key={`${g.category?.id ?? 'all'}-${i}`} style={{ marginBottom: '0.5em' }}>
|
||||
{g.category && c.category_titles !== false && (
|
||||
<h2 style={{ fontSize: '1.15em', color: accent, margin: '0 0 0.19em', fontWeight: 700, breakAfter: 'avoid' }}
|
||||
data-testid="signage-menu-heading">{g.category.name}</h2>
|
||||
)}
|
||||
{g.items.map(it => (
|
||||
<div key={it.id} data-testid="signage-menu-item" data-id={it.id} data-available={it.available ? 'true' : 'false'}
|
||||
style={{ display: 'flex', alignItems: 'center', gap: '0.47em', breakInside: 'avoid', padding: '0.16em 0',
|
||||
opacity: it.available ? 1 : 0.5 }}>
|
||||
{c.show_photos && (it.image
|
||||
? <img src={it.image} alt="" style={{ width: '2.2em', height: '2.2em', objectFit: 'cover', borderRadius: '0.3em', flexShrink: 0 }} />
|
||||
: <span style={{ width: '2.2em', height: '2.2em', flexShrink: 0 }} />)}
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
<div style={{ display: 'flex', alignItems: 'baseline', gap: '0.3em' }}>
|
||||
<span style={{ textDecoration: it.available ? 'none' : 'line-through', fontWeight: 600 }}>{it.name}</span>
|
||||
{it.badge && (
|
||||
<span style={{ background: accent, color: '#111', fontSize: '0.55em', fontWeight: 800, padding: '0.1em 0.5em', borderRadius: '99em',
|
||||
textTransform: 'uppercase', letterSpacing: '0.05em', whiteSpace: 'nowrap' }} data-testid="signage-badge">{t(`signage.badges.${it.badge}`)}</span>
|
||||
)}
|
||||
{!it.available && <span style={{ fontSize: '0.6em', whiteSpace: 'nowrap' }} data-testid="signage-sold-out">{t('signage.soldOut')}</span>}
|
||||
<span style={{ flex: 1, borderBottom: '0.08em dotted currentColor', opacity: 0.35, minWidth: '0.6em' }} />
|
||||
{it.price != null && <span style={{ color: accent, fontVariantNumeric: 'tabular-nums', fontWeight: 700, whiteSpace: 'nowrap' }}
|
||||
data-testid="signage-menu-price">{formatMoney(it.price)}</span>}
|
||||
const look = menuLook(c)
|
||||
const accent = c.accent_colour || '#f59e0b'
|
||||
const priceW = `${(priceChars(groups, formatMoney) * 0.62).toFixed(2)}em`
|
||||
const nameFills = look.itemAlign !== 'left'
|
||||
return (
|
||||
<>
|
||||
{groups.map((g, i) => (
|
||||
<div key={`${g.category?.id ?? 'all'}-${i}`} style={{ marginBottom: '0.5em' }}>
|
||||
{g.category && c.category_titles !== false && (
|
||||
<h2 style={{ ...look.heading, lineHeight: 1.15, margin: '0 0 0.19em', breakAfter: 'avoid' }}
|
||||
data-testid="signage-menu-heading">{g.category.name}</h2>
|
||||
)}
|
||||
{g.items.map(it => (
|
||||
<div key={it.id} data-testid="signage-menu-item" data-id={it.id} data-available={it.available ? 'true' : 'false'}
|
||||
style={{ display: 'flex', alignItems: 'center', gap: '0.47em', breakInside: 'avoid', padding: '0.16em 0',
|
||||
opacity: it.available ? 1 : 0.5 }}>
|
||||
{c.show_photos && (it.image
|
||||
? <img src={it.image} alt="" style={{ width: look.photo.size, height: look.photo.size, objectFit: 'cover', borderRadius: look.photo.radius, flexShrink: 0 }} />
|
||||
: <span style={{ width: look.photo.size, height: look.photo.size, flexShrink: 0 }} />)}
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
<div style={{ display: 'flex', alignItems: 'baseline', gap: '0.3em' }}>
|
||||
<span style={{ ...look.item, textDecoration: it.available ? look.item.textDecoration : 'line-through',
|
||||
...(nameFills ? { flex: 1, minWidth: 0, textAlign: look.itemAlign } : {}) }} data-testid="signage-menu-name">{it.name}</span>
|
||||
{it.badge && (
|
||||
<span style={{ background: accent, color: '#111', fontSize: '0.55em', fontWeight: 800, padding: '0.1em 0.5em', borderRadius: '99em',
|
||||
textTransform: 'uppercase', letterSpacing: '0.05em', whiteSpace: 'nowrap', lineHeight: 1.4 }} data-testid="signage-badge">{t(`signage.badges.${it.badge}`)}</span>
|
||||
)}
|
||||
{!it.available && <span style={{ fontSize: '0.6em', whiteSpace: 'nowrap' }} data-testid="signage-sold-out">{t('signage.soldOut')}</span>}
|
||||
{it.price != null && <>
|
||||
<span style={{ ...look.dots, ...(nameFills ? { flex: '0 0 2em' } : { flex: 1, minWidth: '0.6em' }) }} data-testid="signage-menu-dots" />
|
||||
<span style={{ ...look.price, fontVariantNumeric: 'tabular-nums', whiteSpace: 'nowrap', minWidth: priceW, textAlign: look.priceAlign }}
|
||||
data-testid="signage-menu-price">{formatMoney(it.price)}</span>
|
||||
</>}
|
||||
</div>
|
||||
{it.description && <div style={{ fontSize: '0.7em', opacity: 0.75, lineHeight: 1.25, textAlign: nameFills ? look.itemAlign : undefined }}>{it.description}</div>}
|
||||
</div>
|
||||
</div>
|
||||
{it.description && <div style={{ fontSize: '0.7em', opacity: 0.75, lineHeight: 1.25 }}>{it.description}</div>}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
))
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
// ── widgets (5.5b; placed by hand on the editor's preview, text / menu / stacks: owner 2026-11-21) ──
|
||||
@@ -298,7 +320,7 @@ function MenuWidget({ board: b, menu, now }) {
|
||||
const page = pageAt(pages.length, b.page_seconds, now.getTime())
|
||||
const cols = b.columns || 1
|
||||
const scale = (b.text_size || 100) / 100
|
||||
const rowH = b.show_photos ? 2.6 : b.show_descriptions ? 2.1 : 1.5
|
||||
const rowH = (b.show_photos ? 2.6 * (b.photo_size || 100) / 100 : b.show_descriptions ? 2.1 : 1.5) * menuLook(b).rowScale
|
||||
const lines = Math.ceil(per / cols) + (headings ? 1 : 0)
|
||||
const fontSize = `calc(${scale} * min(${(100 / (lines * rowH + (b.title ? 2 : 0) + 0.8)).toFixed(3)}cqh, ${(100 / (cols * 15)).toFixed(3)}cqw))`
|
||||
const accent = b.accent_colour || '#f59e0b'
|
||||
@@ -306,8 +328,8 @@ function MenuWidget({ board: b, menu, now }) {
|
||||
<div style={{ width: '100%', height: '100%', overflow: 'hidden', fontSize, color: b.text_colour || '#fff', fontFamily: FONTS[b.font] || FONTS.sans, textAlign: 'left' }}
|
||||
data-testid="signage-w-menu" data-page={page} data-pages={pages.length}>
|
||||
{b.title && <div style={{ fontSize: '1.5em', fontWeight: 800, color: accent, lineHeight: 1.15, marginBottom: '0.3em' }}>{b.title}</div>}
|
||||
<div style={{ columnCount: cols, columnGap: '1.2em', columnFill: 'auto' }}>
|
||||
<MenuGroups c={b} groups={pages[page] || []} accent={accent} />
|
||||
<div style={{ columnCount: cols, columnGap: '1.2em', columnFill: 'auto', ...listSpacing(b) }} data-testid="signage-menu-list">
|
||||
<MenuGroups c={b} groups={pages[page] || []} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -243,7 +243,8 @@ export function boardPages(slide, rotation, w, h) {
|
||||
const c = slide.content || {}
|
||||
const widgets = c.widgets || []
|
||||
const bars = ['top-bar', 'bottom-bar'].filter(p => widgets.some(x => x.position === p)).length
|
||||
const rows = rowsPerColumn({ heightVmin: frameHeightVmin(rotation, w, h), textSize: c.text_size, photos: c.show_photos,
|
||||
const look = menuLook(c)
|
||||
const rows = rowsPerColumn({ heightVmin: frameHeightVmin(rotation, w, h), textSize: (c.text_size || 100) * look.rowScale, photos: c.show_photos,
|
||||
descriptions: c.show_descriptions, title: !!c.title, bars })
|
||||
const per = c.page_size || rows * (c.columns || 2)
|
||||
return menuPages(visibleGroups(slide.menu?.groups), per, c.category_titles !== false)
|
||||
@@ -308,3 +309,54 @@ export function fitUnit(height, width) {
|
||||
export function textWidth(chars, size) {
|
||||
return Math.max(1, chars) * size * 0.6
|
||||
}
|
||||
|
||||
// ── a menu's look, part by part (owner review 3, 2026-11-21) ──────────────────
|
||||
|
||||
const WEIGHT = { heading: 700, item: 600, price: 700 }
|
||||
const RADIUS = { square: '0', rounded: '0.3em', round: '50%' }
|
||||
const DOTS = { dotted: 'dotted', dashed: 'dashed', solid: 'solid' }
|
||||
|
||||
/**
|
||||
* How a menu's parts look, as CSS for MenuGroups (sizes in em of the list's text, which is the
|
||||
* board's text size): headings, names and prices each their own size, colour, font, bold / italic /
|
||||
* underline and alignment (empty: the board's text size and font, the text colour for names and the
|
||||
* accent colour for headings and prices); the dots between name and price; line and letter spacing
|
||||
* (auto: 1.25 and normal; set on the list, never inherited from the page); photos' size and shape.
|
||||
*/
|
||||
export function menuLook(c = {}) {
|
||||
const base = c.text_size || 100
|
||||
const accent = c.accent_colour || '#f59e0b'
|
||||
const text = c.text_colour || '#fff'
|
||||
const part = (s = {}, kind, colour, scale) => ({
|
||||
fontSize: `${+(((s.size || base) / base) * scale).toFixed(3)}em`,
|
||||
color: s.colour || colour,
|
||||
fontFamily: s.font ? FONTS[s.font] : undefined,
|
||||
fontWeight: s.bold === false ? 400 : WEIGHT[kind],
|
||||
fontStyle: s.italic ? 'italic' : undefined,
|
||||
textDecoration: s.underline ? 'underline' : undefined,
|
||||
})
|
||||
const d = c.dot_style || {}
|
||||
return {
|
||||
heading: { ...part(c.heading_style, 'heading', accent, 1.15), textAlign: c.heading_style?.align || undefined },
|
||||
item: part(c.item_style, 'item', text, 1),
|
||||
itemAlign: c.item_style?.align || 'left',
|
||||
price: part(c.price_style, 'price', accent, 1),
|
||||
priceAlign: c.price_style?.align || 'right',
|
||||
dots: d.style === 'none'
|
||||
? { borderBottom: 'none' }
|
||||
: { borderBottom: `${+(0.08 * (d.size || 100) / 100).toFixed(3)}em ${DOTS[d.style] || 'dotted'} ${d.colour || 'currentColor'}`, opacity: d.colour ? 1 : 0.35 },
|
||||
lineHeight: c.line_height || 1.25,
|
||||
letterSpacing: c.letter_spacing != null ? `${c.letter_spacing}em` : 'normal',
|
||||
photo: { size: `${+(2.2 * (c.photo_size || 100) / 100).toFixed(3)}em`, radius: RADIUS[c.photo_shape] || RADIUS.rounded },
|
||||
// how much taller a row is than the usual (for the pages' sums)
|
||||
rowScale: Math.max(1, (c.price_style?.size || base) / base, (c.item_style?.size || base) / base, (c.heading_style?.size || base) / base)
|
||||
* ((c.line_height || 1.25) / 1.25),
|
||||
}
|
||||
}
|
||||
|
||||
/** A page's widest price, in characters: the price column's width, so names and dots line up. */
|
||||
export function priceChars(groups, format) {
|
||||
let n = 0
|
||||
for (const g of groups || []) for (const it of g.items || []) if (it.price != null) n = Math.max(n, String(format(it.price)).length)
|
||||
return n
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user