feat(signage): look rows that wrap, one colour field with opacity, badges' text, several widgets per stack part, pages up to 2200 px (owner review 4)
- Menu text look: each field names its part ("Headings size"), rows wrap in aligned columns on
alternating bands; names align left / right; line and letter spacing as lists (Auto default);
each field changes only itself (followers frozen before the other changes); badge colour +
badge text colour (auto: readableOn); "Reset the look" with a question.
- ColourField everywhere in signage: a Popover panel (new @xenia/ui Popover, portal, kept in the
window) with 12 presets, picker, opacity (#rrggbbaa) and typed code; HEX accepts 8 digits.
- Stacks: Cell.widgets (a stored `widget` still reads), several widgets per part laid across the
stack's direction; extras by path stack.part.place; Add a widget adds, each removable / ordered.
- Page rule: --x-page-max is 2200px (no longer follows the window height).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,108 +1,154 @@
|
||||
// A menu's look, part by part (owner review 3, 2026-11-21), for menu slides and menu widgets alike:
|
||||
// one row each for the headings, the product names and the prices (size, colour, font, bold /
|
||||
// italic / underline, alignment), the dots between name and price (size, colour, style), and the
|
||||
// spacing (line and letter spacing: empty = auto) with the photos' size and shape and the accent
|
||||
// (badges, page dots). The names' row sets the board's own text size, colour and font; headings and
|
||||
// prices follow them (the accent colour) until given their own. The player draws it (menuLook).
|
||||
import { AlignCenter, AlignLeft, AlignRight, Bold, Italic, Underline } from 'lucide-react'
|
||||
// headings, product names and prices (size, colour, font, bold / italic / underline, alignment),
|
||||
// the dots between name and price with the badges' colours, the spacing (line and letter spacing:
|
||||
// Auto or a choice) with the photos' size and shape. The player draws it (menuLook).
|
||||
// Owner review 4 (2026-11-21): every field says what it sets ("Headings size"), so a row needs no
|
||||
// title; fields keep their width and wrap to a second line, each row on its own band. Every field
|
||||
// changes only itself: a part that still follows another (headings and prices take the names' size
|
||||
// and the accent colour, the dots the text colour) is given that value before the other changes.
|
||||
// Names align left or right; "Reset the look" puts every part back.
|
||||
import { AlignCenter, AlignLeft, AlignRight, Bold, Italic, RotateCcw, Underline } from 'lucide-react'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Dropdown, Field, Input, Segmented } from '@xenia/ui'
|
||||
import { FONT_KEYS, MENU_COLOURS } from './signageLogic'
|
||||
import { Button, Dropdown, Field, Segmented, useConfirm } from '@xenia/ui'
|
||||
import { readableOn } from '@xenia/signage'
|
||||
import { FONT_KEYS, joinAlpha, LETTER_SPACINGS, LINE_HEIGHTS, MENU_COLOURS, MENU_LOOK_DEFAULTS, splitAlpha } from './signageLogic'
|
||||
import { ColourField, Range, Section } from './SignageFields'
|
||||
|
||||
const ROW = 'grid gap-3 items-end grid-cols-2 lg:grid-cols-[7rem_repeat(5,minmax(0,1fr))]'
|
||||
|
||||
const ALIGN_ICONS = { left: AlignLeft, center: AlignCenter, right: AlignRight }
|
||||
export default function MenuLook({ c, setC }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const [confirm, confirmDialog] = useConfirm()
|
||||
const base = c.text_size || 100
|
||||
const accent = c.accent_colour || MENU_COLOURS.accent
|
||||
const text = c.text_colour || MENU_COLOURS.text
|
||||
const style = key => c[key] || {}
|
||||
const setStyle = (key, patch) => setC({ [key]: { ...style(key), ...patch } })
|
||||
const h = style('heading_style')
|
||||
const p = style('price_style')
|
||||
const d = style('dot_style')
|
||||
const dotsAuto = joinAlpha(splitAlpha(text).rgb, 35) // the player's faint text colour
|
||||
const L = (part, field) => t(`signage.look.f.${part}.${field}`)
|
||||
const fontOptions = inherit => [...(inherit ? [{ value: '', label: t('signage.look.sameFont') }] : []), ...FONT_KEYS.map(x => ({ value: x, label: t(`signage.fonts.${x}`) }))]
|
||||
const num = (v, lo, hi) => {
|
||||
const n = Number(String(v).replace(',', '.'))
|
||||
return v === '' || Number.isNaN(n) ? null : Math.min(hi, Math.max(lo, n))
|
||||
|
||||
// each changes only itself: what followed it keeps what it showed
|
||||
const setNamesSize = v => setC({ text_size: v, heading_style: { ...h, size: h.size || base }, price_style: { ...p, size: p.size || base } })
|
||||
const setNamesColour = v => setC({ text_colour: v, dot_style: { ...d, colour: d.colour || dotsAuto } })
|
||||
const setAccent = v => setC({ accent_colour: v, heading_style: { ...h, colour: h.colour || accent }, price_style: { ...p, colour: p.colour || accent } })
|
||||
|
||||
const reset = async () => {
|
||||
if (await confirm({ title: t('signage.look.resetTitle'), body: t('signage.look.resetBody'), confirmLabel: t('signage.look.reset'), testId: 'signage-look-reset-confirm' })) {
|
||||
setC(MENU_LOOK_DEFAULTS)
|
||||
}
|
||||
}
|
||||
|
||||
/** A row for headings / names / prices: size, colour, font, style, alignment. */
|
||||
const partRow = (key, label, { size, colour, font, onSize, onColour, onFont, inherit, align }) => {
|
||||
const cell = (_w, node) => <div className="min-w-0">{node}</div>
|
||||
|
||||
/** Headings, names or prices: size, colour, font, style, alignment. */
|
||||
const partRow = (part, key, { size, colour, font, onSize, onColour, onFont, inherit, align, aligns = ['left', 'center', 'right'] }) => {
|
||||
const s = style(key)
|
||||
return (
|
||||
<div className={ROW} data-testid={`signage-look-${key}`}>
|
||||
<RowLabel>{label}</RowLabel>
|
||||
<Range label={t('signage.look.size')} value={size} min={50} max={300} step={10} suffix="%" onChange={onSize} testid={`signage-look-${key}-size`} />
|
||||
<ColourField compact label={t('signage.look.colour')} value={colour} onChange={onColour} testid={`signage-look-${key}-colour`} />
|
||||
<Field label={t('signage.look.font')}>
|
||||
<Dropdown value={font} onChange={onFont} options={fontOptions(inherit)} data-testid={`signage-look-${key}-font`} />
|
||||
</Field>
|
||||
<Field label={t('signage.look.style')}>
|
||||
<TextToggles s={s} onChange={patch => setStyle(key, patch)} testid={`signage-look-${key}`} />
|
||||
</Field>
|
||||
<Field label={t('signage.look.align')}>
|
||||
<Segmented value={s.align || align} onChange={v => setStyle(key, { align: v })} fill data-testid={`signage-look-${key}-align`}
|
||||
options={[['left', AlignLeft], ['center', AlignCenter], ['right', AlignRight]].map(([v, Icon]) => (
|
||||
{ value: v, icon: <Icon size={16} aria-hidden="true" />, ariaLabel: t(`signage.aligns.${v}`), testId: `signage-look-${key}-align-${v}` }))} />
|
||||
</Field>
|
||||
</div>
|
||||
<Band testid={`signage-look-${key}`}>
|
||||
{cell('size', <Range label={L(part, 'size')} value={size} min={50} max={300} step={10} suffix="%" onChange={onSize} testid={`signage-look-${key}-size`} />)}
|
||||
{cell('colour', <ColourField label={L(part, 'colour')} value={colour} onChange={onColour} testid={`signage-look-${key}-colour`} />)}
|
||||
{cell('font', (
|
||||
<Field label={L(part, 'font')}>
|
||||
<Dropdown value={font} onChange={onFont} options={fontOptions(inherit)} data-testid={`signage-look-${key}-font`} />
|
||||
</Field>
|
||||
))}
|
||||
{cell('style', (
|
||||
<Field label={L(part, 'style')}>
|
||||
<TextToggles s={s} onChange={patch => setStyle(key, patch)} testid={`signage-look-${key}`} />
|
||||
</Field>
|
||||
))}
|
||||
{cell('align', (
|
||||
<Field label={L(part, 'align')}>
|
||||
<Segmented value={aligns.includes(s.align) ? s.align : align} onChange={v => setStyle(key, { align: v })} fill data-testid={`signage-look-${key}-align`}
|
||||
options={aligns.map(v => {
|
||||
const Icon = ALIGN_ICONS[v]
|
||||
return { value: v, icon: <Icon size={16} aria-hidden="true" />, ariaLabel: t(`signage.aligns.${v}`), testId: `signage-look-${key}-align-${v}` }
|
||||
})} />
|
||||
</Field>
|
||||
))}
|
||||
</Band>
|
||||
)
|
||||
}
|
||||
|
||||
const d = style('dot_style')
|
||||
const choices = (list, current, label) => {
|
||||
const values = current != null && !list.includes(current) ? [...list, current].sort((a, b) => a - b) : list
|
||||
return [{ value: '', label: t('signage.look.auto') }, ...values.map(x => ({ value: String(x), label: label(x) }))]
|
||||
}
|
||||
|
||||
return (
|
||||
<Section title={t('signage.textLook')} testid="signage-text-look">
|
||||
<div className="grid gap-5">
|
||||
{partRow('heading_style', t('signage.look.headings'), {
|
||||
size: style('heading_style').size || base, onSize: v => setStyle('heading_style', { size: v }),
|
||||
colour: style('heading_style').colour || accent, onColour: v => setStyle('heading_style', { colour: v }),
|
||||
font: style('heading_style').font || '', onFont: v => setStyle('heading_style', { font: v || null }), inherit: true,
|
||||
<Section title={t('signage.textLook')} testid="signage-text-look"
|
||||
aside={<Button size="sm" variant="ghost" icon={<RotateCcw size={14} />} onClick={reset} data-testid="signage-look-reset">{t('signage.look.reset')}</Button>}>
|
||||
<div className="grid gap-2">
|
||||
{partRow('heading', 'heading_style', {
|
||||
size: h.size || base, onSize: v => setStyle('heading_style', { size: v }),
|
||||
colour: h.colour || accent, onColour: v => setStyle('heading_style', { colour: v }),
|
||||
font: h.font || '', onFont: v => setStyle('heading_style', { font: v || null }), inherit: true,
|
||||
align: c.board_align || 'left',
|
||||
})}
|
||||
{partRow('item_style', t('signage.look.names'), {
|
||||
size: base, onSize: v => setC({ text_size: v }),
|
||||
colour: c.text_colour || MENU_COLOURS.text, onColour: v => setC({ text_colour: v }),
|
||||
font: c.font || 'sans', onFont: v => setC({ font: v }), inherit: false, align: 'left',
|
||||
{partRow('item', 'item_style', {
|
||||
size: base, onSize: setNamesSize,
|
||||
colour: text, onColour: setNamesColour,
|
||||
font: c.font || 'sans', onFont: v => setC({ font: v }), inherit: false, align: 'left', aligns: ['left', 'right'],
|
||||
})}
|
||||
{partRow('price_style', t('signage.look.prices'), {
|
||||
size: style('price_style').size || base, onSize: v => setStyle('price_style', { size: v }),
|
||||
colour: style('price_style').colour || accent, onColour: v => setStyle('price_style', { colour: v }),
|
||||
font: style('price_style').font || '', onFont: v => setStyle('price_style', { font: v || null }), inherit: true, align: 'right',
|
||||
{partRow('price', 'price_style', {
|
||||
size: p.size || base, onSize: v => setStyle('price_style', { size: v }),
|
||||
colour: p.colour || accent, onColour: v => setStyle('price_style', { colour: v }),
|
||||
font: p.font || '', onFont: v => setStyle('price_style', { font: v || null }), inherit: true, align: 'right',
|
||||
})}
|
||||
<div className={ROW} data-testid="signage-look-dots">
|
||||
<RowLabel>{t('signage.look.dots')}</RowLabel>
|
||||
<Range label={t('signage.look.size')} value={d.size || 100} min={50} max={300} step={10} suffix="%" onChange={v => setStyle('dot_style', { size: v })} testid="signage-look-dots-size" />
|
||||
<ColourField compact label={t('signage.look.colour')} value={d.colour || c.text_colour || MENU_COLOURS.text} onChange={v => setStyle('dot_style', { colour: v })} testid="signage-look-dots-colour" />
|
||||
<Field label={t('signage.look.dotStyle')}>
|
||||
<Dropdown value={d.style || 'dotted'} onChange={v => setStyle('dot_style', { style: v })} data-testid="signage-look-dots-style"
|
||||
options={['dotted', 'dashed', 'solid', 'none'].map(x => ({ value: x, label: t(`signage.look.dotStyles.${x}`) }))} />
|
||||
</Field>
|
||||
</div>
|
||||
<div className={ROW} data-testid="signage-look-spacing">
|
||||
<RowLabel>{t('signage.look.spacing')}</RowLabel>
|
||||
<Field label={t('signage.look.lineHeight')}>
|
||||
<Input inputMode="decimal" value={c.line_height ?? ''} placeholder={t('signage.look.auto')} data-testid="signage-look-line-height"
|
||||
onChange={e => setC({ line_height: num(e.target.value, 0.8, 3) })} />
|
||||
</Field>
|
||||
<Field label={t('signage.look.letterSpacing')}>
|
||||
<Input inputMode="decimal" value={c.letter_spacing ?? ''} placeholder={t('signage.look.auto')} data-testid="signage-look-letter-spacing"
|
||||
onChange={e => setC({ letter_spacing: num(e.target.value, -0.1, 0.5) })} />
|
||||
</Field>
|
||||
{c.show_photos ? <>
|
||||
<Range label={t('signage.look.photoSize')} value={c.photo_size || 100} min={50} max={250} step={10} suffix="%" onChange={v => setC({ photo_size: v })} testid="signage-look-photo-size" />
|
||||
<Field label={t('signage.look.photoShape')}>
|
||||
<Dropdown value={c.photo_shape || 'rounded'} onChange={v => setC({ photo_shape: v })} data-testid="signage-look-photo-shape"
|
||||
options={['square', 'rounded', 'round'].map(x => ({ value: x, label: t(`signage.look.shapes.${x}`) }))} />
|
||||
<Band testid="signage-look-dots">
|
||||
{cell('size', <Range label={L('dots', 'size')} value={d.size || 100} min={50} max={300} step={10} suffix="%" onChange={v => setStyle('dot_style', { size: v })} testid="signage-look-dots-size" />)}
|
||||
{cell('colour', <ColourField label={L('dots', 'colour')} value={d.colour || dotsAuto} onChange={v => setStyle('dot_style', { colour: v })} testid="signage-look-dots-colour" />)}
|
||||
{cell('font', (
|
||||
<Field label={L('dots', 'line')}>
|
||||
<Dropdown value={d.style || 'dotted'} onChange={v => setStyle('dot_style', { style: v })} data-testid="signage-look-dots-style"
|
||||
options={['dotted', 'dashed', 'solid', 'none'].map(x => ({ value: x, label: t(`signage.look.dotStyles.${x}`) }))} />
|
||||
</Field>
|
||||
</> : <><span className="hidden lg:block" /><span className="hidden lg:block" /></>}
|
||||
<ColourField compact label={t('signage.look.accent')} value={accent} onChange={v => setC({ accent_colour: v })} testid="signage-accent" />
|
||||
</div>
|
||||
<p className="text-caption text-ink-3 -mt-2">{t('signage.look.hint')}</p>
|
||||
))}
|
||||
{cell('colour', <ColourField label={t('signage.look.badgeColour')} value={accent} onChange={setAccent} testid="signage-accent" />)}
|
||||
{cell('colour', <ColourField label={t('signage.look.badgeText')} value={c.badge_text_colour || readableOn(accent)} onChange={v => setC({ badge_text_colour: v })}
|
||||
testid="signage-badge-text" auto={{ label: t('signage.look.badgeTextAuto'), on: !c.badge_text_colour, pick: () => setC({ badge_text_colour: null }) }} />)}
|
||||
</Band>
|
||||
<Band testid="signage-look-spacing">
|
||||
{cell('font', (
|
||||
<Field label={t('signage.look.lineHeight')}>
|
||||
<Dropdown value={c.line_height != null ? String(c.line_height) : ''} onChange={v => setC({ line_height: v === '' ? null : Number(v) })} data-testid="signage-look-line-height"
|
||||
options={choices(LINE_HEIGHTS, c.line_height, x => `${x}×`)} />
|
||||
</Field>
|
||||
))}
|
||||
{cell('font', (
|
||||
<Field label={t('signage.look.letterSpacing')}>
|
||||
<Dropdown value={c.letter_spacing != null ? String(c.letter_spacing) : ''} onChange={v => setC({ letter_spacing: v === '' ? null : Number(v) })} data-testid="signage-look-letter-spacing"
|
||||
options={choices(LETTER_SPACINGS, c.letter_spacing, x => `${x > 0 ? '+' : ''}${Math.round(x * 100)}%`)} />
|
||||
</Field>
|
||||
))}
|
||||
{c.show_photos && <>
|
||||
{cell('size', <Range label={t('signage.look.photoSize')} value={c.photo_size || 100} min={50} max={250} step={10} suffix="%" onChange={v => setC({ photo_size: v })} testid="signage-look-photo-size" />)}
|
||||
{cell('font', (
|
||||
<Field label={t('signage.look.photoShape')}>
|
||||
<Dropdown value={c.photo_shape || 'rounded'} onChange={v => setC({ photo_shape: v })} data-testid="signage-look-photo-shape"
|
||||
options={['square', 'rounded', 'round'].map(x => ({ value: x, label: t(`signage.look.shapes.${x}`) }))} />
|
||||
</Field>
|
||||
))}
|
||||
</>}
|
||||
</Band>
|
||||
<p className="text-caption text-ink-3 mt-1">{t('signage.look.hint')}</p>
|
||||
</div>
|
||||
{confirmDialog}
|
||||
</Section>
|
||||
)
|
||||
}
|
||||
|
||||
function RowLabel({ children }) {
|
||||
return <span className="col-span-2 lg:col-span-1 lg:h-control flex items-center text-label font-semibold text-ink">{children}</span>
|
||||
/** A row of the look: its fields keep their least width and wrap to a second line, in columns that
|
||||
* line up from row to row; rows alternate shades. */
|
||||
function Band({ testid, children }) {
|
||||
return (
|
||||
<div className="grid gap-3 items-end grid-cols-[repeat(auto-fill,minmax(10.5rem,1fr))] rounded-control border border-line p-3 bg-surface even:bg-surface-2" data-testid={testid}>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** Bold, italic, underline: three toggles as tall as a field. */
|
||||
@@ -114,7 +160,7 @@ function TextToggles({ s, onChange, testid }) {
|
||||
{items.map(([k, Icon, on]) => (
|
||||
<button key={k} type="button" aria-pressed={on} aria-label={t(`signage.look.${k}`)} title={t(`signage.look.${k}`)}
|
||||
onClick={() => onChange({ [k]: !on })} data-testid={`${testid}-${k}`}
|
||||
className={`flex-1 grid place-items-center rounded-[calc(var(--x-radius-control)-2px)] transition-colors duration-fast
|
||||
className={`flex-1 min-w-[2rem] grid place-items-center rounded-[calc(var(--x-radius-control)-2px)] transition-colors duration-fast
|
||||
${on ? 'bg-accent-soft text-accent-ink' : 'text-ink-2 hover:bg-surface-2'}`}>
|
||||
<Icon size={16} aria-hidden="true" />
|
||||
</button>
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
// a background (colour or photo with darkening), a slider with its value.
|
||||
// 2026-11-21 (owner review 2): the slider framed like the fields beside it; a colour as a field
|
||||
// (its swatch and code) that opens the ready colours and the picker, so it fits a row of fields.
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
// Owner review 4: that colour field everywhere, its panel over the page, see-through colours.
|
||||
import { useCallback, useRef, useState } from 'react'
|
||||
import { AlertTriangle, Film, ImageIcon, X } from 'lucide-react'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dropdown, Field, IconButton } from '@xenia/ui'
|
||||
import { Button, Dropdown, Field, IconButton, Input, Popover } from '@xenia/ui'
|
||||
import MediaPicker from '../media/MediaPicker'
|
||||
import { COLOUR_PRESETS } from './signageLogic'
|
||||
import { COLOUR_PRESETS, joinAlpha, splitAlpha, typedColour } from './signageLogic'
|
||||
|
||||
/** A part of the slide editor: its title over a thin line, then its fields (DESIGN.md §3). */
|
||||
export function Section({ title, aside, children, testid, className = '' }) {
|
||||
@@ -69,66 +70,71 @@ export function MediaPick({ kind = 'image', value, entry, onChange, onRemove, mi
|
||||
)
|
||||
}
|
||||
|
||||
/** A colour the venue chooses for its TV (stored as #rrggbb: data, not a theme colour): a few
|
||||
* ready colours with one click, and the picker for any other (2026-11-21). `compact`: a field
|
||||
* (swatch and code) that opens them, as tall and as wide as the fields beside it. */
|
||||
export function ColourField({ label, value, onChange, testid, presets = COLOUR_PRESETS, compact = false }) {
|
||||
/**
|
||||
* A colour the venue chooses for its TV (data, not a theme colour: #rrggbb, or #rrggbbaa when
|
||||
* see-through): a field (its swatch and code) that opens a small panel over the page (owner review
|
||||
* 4, 2026-11-21: every signage colour): twelve ready colours, then the picker, the opacity and the
|
||||
* code typed by hand. Each field changes only its own colour. `auto` ({ label, on, pick }): a first
|
||||
* choice that lets the TV choose (a badge's text: white or black, whichever reads).
|
||||
*/
|
||||
export function ColourField({ label, value, onChange, testid, presets = COLOUR_PRESETS, auto, className }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const [open, setOpen] = useState(false)
|
||||
const [typed, setTyped] = useState(null)
|
||||
const btn = useRef(null)
|
||||
const v = (value || '#000000').toLowerCase()
|
||||
if (compact) return <ColourPick label={label} value={v} onChange={onChange} testid={testid} presets={presets} />
|
||||
const { rgb, alpha } = splitAlpha(v)
|
||||
const close = useCallback(() => { setOpen(false); setTyped(null) }, [])
|
||||
return (
|
||||
<div className="grid gap-1.5" role="group" aria-label={label}>
|
||||
<span className="text-label font-medium text-ink">{label}</span>
|
||||
<span className="min-h-control flex flex-wrap items-center gap-1.5">
|
||||
{presets.map(c => (
|
||||
<button key={c} type="button" onClick={() => onChange(c)} aria-label={c} aria-pressed={v === c} title={c}
|
||||
className={`w-7 h-7 rounded-full border border-line-strong shrink-0 transition-transform duration-fast ${v === c ? 'ring-2 ring-accent ring-offset-2 ring-offset-surface' : 'hover:scale-110'}`}
|
||||
style={{ background: c }} data-testid={testid ? `${testid}-preset` : undefined} />
|
||||
))}
|
||||
<input type="color" value={v} onChange={e => onChange(e.target.value)} data-testid={testid} aria-label={label}
|
||||
className="w-9 h-9 rounded-control border border-line bg-surface cursor-pointer p-0.5 ml-1" />
|
||||
<span className="text-caption text-ink-3 font-mono">{v}</span>
|
||||
</span>
|
||||
</div>
|
||||
<>
|
||||
<Field label={label} className={className}>
|
||||
<button ref={btn} type="button" onClick={() => setOpen(o => !o)} aria-expanded={open} aria-haspopup="dialog" data-testid={testid ? `${testid}-open` : undefined}
|
||||
className="w-full min-w-0 h-control flex items-center gap-2.5 px-3 rounded-control border border-line bg-surface text-label text-ink hover:border-line-strong transition-colors duration-fast">
|
||||
<Swatch colour={v} className="w-6 h-6" />
|
||||
<span className={`truncate ${auto?.on ? 'text-ink-2' : 'font-mono text-ink-2'}`}>{auto?.on ? auto.label : v}</span>
|
||||
</button>
|
||||
</Field>
|
||||
<Popover open={open} anchor={btn} onClose={close} aria-label={label} className="grid gap-3 p-3 w-[17.5rem]"
|
||||
data-testid={testid ? `${testid}-panel` : 'signage-colour-panel'}>
|
||||
{auto && (
|
||||
<button type="button" onClick={() => { auto.pick(); close() }} aria-pressed={!!auto.on} data-testid={testid ? `${testid}-auto` : undefined}
|
||||
className={`h-control px-3 rounded-control border text-label text-left transition-colors duration-fast ${auto.on ? 'border-accent bg-accent-soft text-accent-ink' : 'border-line text-ink hover:bg-surface-2'}`}>
|
||||
{auto.label}
|
||||
</button>
|
||||
)}
|
||||
<div className="grid grid-cols-6 gap-2 justify-items-center">
|
||||
{presets.map(c => (
|
||||
<button key={c} type="button" onClick={() => { onChange(joinAlpha(c, alpha)); close() }} aria-label={c} aria-pressed={!auto?.on && rgb === c} title={c}
|
||||
className={`w-8 h-8 rounded-full transition-transform duration-fast ${!auto?.on && rgb === c ? 'ring-2 ring-accent ring-offset-2 ring-offset-surface' : 'hover:scale-110'}`}
|
||||
data-testid={testid ? `${testid}-preset` : undefined}>
|
||||
<Swatch colour={c} className="w-8 h-8" />
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<div className="grid gap-2.5 border-t border-line pt-3">
|
||||
<span className="text-overline font-semibold uppercase tracking-wide text-ink-3">{t('signage.colourPick.custom')}</span>
|
||||
<div className="flex items-center gap-2">
|
||||
<input type="color" value={rgb} onChange={e => { setTyped(null); onChange(joinAlpha(e.target.value, alpha)) }} data-testid={testid} aria-label={label}
|
||||
className="w-10 h-control shrink-0 rounded-control border border-line bg-surface cursor-pointer p-0.5" />
|
||||
<Input value={typed ?? v} maxLength={9} spellCheck={false} aria-label={t('signage.colourPick.code')} className="font-mono min-w-0 flex-1" data-testid={testid ? `${testid}-code` : undefined}
|
||||
onChange={e => { setTyped(e.target.value); const c = typedColour(e.target.value); if (c) onChange(c) }} onBlur={() => setTyped(null)} />
|
||||
</div>
|
||||
<label className="grid gap-1 text-caption text-ink-2">
|
||||
<span className="flex justify-between"><span>{t('signage.colourPick.opacity')}</span><span className="tabular-nums">{alpha}%</span></span>
|
||||
<input type="range" min={0} max={100} step={5} value={alpha} onChange={e => { setTyped(null); onChange(joinAlpha(rgb, Number(e.target.value))) }}
|
||||
className="accent-accent" data-testid={testid ? `${testid}-opacity` : undefined} />
|
||||
</label>
|
||||
</div>
|
||||
</Popover>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
function ColourPick({ label, value, onChange, testid, presets }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const box = useRef(null)
|
||||
useEffect(() => {
|
||||
if (!open) return undefined
|
||||
const away = e => { if (!box.current?.contains(e.target)) setOpen(false) }
|
||||
const esc = e => { if (e.key === 'Escape') setOpen(false) }
|
||||
window.addEventListener('pointerdown', away)
|
||||
window.addEventListener('keydown', esc)
|
||||
return () => { window.removeEventListener('pointerdown', away); window.removeEventListener('keydown', esc) }
|
||||
}, [open])
|
||||
/** A colour's swatch, over a checkerboard so a see-through colour shows as one. */
|
||||
function Swatch({ colour, className = '' }) {
|
||||
return (
|
||||
<Field label={label}>
|
||||
<div ref={box} className="relative">
|
||||
<button type="button" onClick={() => setOpen(o => !o)} aria-expanded={open} aria-label={label} data-testid={testid ? `${testid}-open` : undefined}
|
||||
className="w-full h-control flex items-center gap-2.5 px-3 rounded-control border border-line bg-surface text-label text-ink hover:border-line-strong transition-colors duration-fast">
|
||||
<span className="w-6 h-6 rounded-full border border-line-strong shrink-0" style={{ background: value }} aria-hidden="true" />
|
||||
<span className="font-mono text-ink-2 truncate">{value}</span>
|
||||
</button>
|
||||
{open && (
|
||||
<div className="absolute z-30 left-0 top-full mt-1.5 grid gap-3 p-3 rounded-card border border-line bg-surface shadow-lg w-max" role="dialog" aria-label={label}>
|
||||
<div className="grid grid-cols-5 gap-2">
|
||||
{presets.map(c => (
|
||||
<button key={c} type="button" onClick={() => { onChange(c); setOpen(false) }} aria-label={c} aria-pressed={value === c} title={c}
|
||||
className={`w-8 h-8 rounded-full border border-line-strong transition-transform duration-fast ${value === c ? 'ring-2 ring-accent ring-offset-2 ring-offset-surface' : 'hover:scale-110'}`}
|
||||
style={{ background: c }} data-testid={testid ? `${testid}-preset` : undefined} />
|
||||
))}
|
||||
</div>
|
||||
<label className="flex items-center gap-2 text-label text-ink-2">
|
||||
<input type="color" value={value} onChange={e => onChange(e.target.value)} data-testid={testid} aria-label={label}
|
||||
className="w-9 h-9 rounded-control border border-line bg-surface cursor-pointer p-0.5" />
|
||||
<span className="font-mono">{value}</span>
|
||||
</label>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Field>
|
||||
<span className={`block rounded-full border border-line-strong shrink-0 ${className}`} aria-hidden="true" data-venue-colour=""
|
||||
style={{ background: `linear-gradient(${colour}, ${colour}), repeating-conic-gradient(#d1d5db 0 25%, #ffffff 0 50%) 0 0 / 8px 8px` }} />
|
||||
)
|
||||
}
|
||||
|
||||
@@ -145,7 +151,7 @@ export function BackgroundField({ value, onChange, media, onMedia, misfit, testi
|
||||
options={[{ value: 'colour', label: t('signage.bgColour') }, { value: 'media', label: t('signage.bgPhoto') }]} />
|
||||
</Field>
|
||||
{bg.kind === 'colour'
|
||||
? <ColourField label={t('signage.colour')} value={bg.colour} onChange={colour => set({ colour })} testid={`${testid}-colour`} />
|
||||
? <ColourField label={t('signage.colour')} value={bg.colour} onChange={colour => set({ colour })} testid={`${testid}-colour`} className="max-w-xs" />
|
||||
: (
|
||||
<div className="grid gap-4 sm:grid-cols-[auto_minmax(0,1fr)_12rem] items-end">
|
||||
<MediaPick kind="image" value={bg.media_id} entry={media?.[String(bg.media_id)]} misfit={misfit} testid={`${testid}-photo`}
|
||||
|
||||
@@ -96,7 +96,7 @@ export default function SlideEditor({ slide, onChange, media, onMedia, misfit =
|
||||
onChange={item => { onMedia(item); setC({ media_id: item.id }) }} testid="signage-picture" />
|
||||
<div className="grid gap-4 md:grid-cols-[16rem_minmax(0,1fr)] items-start">
|
||||
{fit}
|
||||
<ColourField label={t('signage.around')} value={c.background_colour || '#000000'} onChange={v => setC({ background_colour: v })} />
|
||||
<ColourField label={t('signage.around')} value={c.background_colour || '#000000'} onChange={v => setC({ background_colour: v })} testid="signage-around" className="max-w-xs" />
|
||||
</div>
|
||||
</Section>
|
||||
)}
|
||||
@@ -162,7 +162,7 @@ export function TextLook({ c, setC, align = true, children }) {
|
||||
</Field>
|
||||
<Range label={t('signage.textSizeLabel')} value={c.text_size || 100} min={50} max={250} step={10} suffix="%"
|
||||
onChange={v => setC({ text_size: v })} testid="signage-text-size" />
|
||||
<ColourField compact label={t('signage.textColour')} value={c.text_colour || '#ffffff'} onChange={v => setC({ text_colour: v })} testid="signage-text-colour" />
|
||||
<ColourField label={t('signage.textColour')} value={c.text_colour || '#ffffff'} onChange={v => setC({ text_colour: v })} testid="signage-text-colour" />
|
||||
{children}
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
@@ -12,15 +12,16 @@
|
||||
// level deep) or a whole slide from the Slides library.
|
||||
// Owner review 3 (2026-11-21): a stack's parts sized by dragging the lines between them on its bar;
|
||||
// "Add a widget" beside what a part shows; Delete removes the picked widget (WidgetCanvas).
|
||||
// Owner review 4 (2026-11-21): a part holds several widgets, added with "Add a widget".
|
||||
// Up to 10 (the server's limit).
|
||||
import { Fragment, useEffect, useRef, useState } from 'react'
|
||||
import {
|
||||
AlignCenter, AlignLeft, AlignRight, ArrowDown, ArrowUp, BookImage, CalendarDays, ChevronDown, Clock, CloudSun, Columns3, GripVertical,
|
||||
ImageIcon, LayoutList, MessageSquare, Plus, QrCode, Rows3, Store, Trash2, Type, UtensilsCrossed,
|
||||
} from 'lucide-react'
|
||||
import { evenShares, setShare } from '@xenia/signage'
|
||||
import { cellWidgets, evenShares, setShare } from '@xenia/signage'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dropdown, Field, IconButton, Input, Segmented, Switch } from '@xenia/ui'
|
||||
import { Button, Dropdown, Field, IconButton, Input, Popover, Segmented, Switch } from '@xenia/ui'
|
||||
import * as api from './signageApi'
|
||||
import MenuEditor from './MenuEditor'
|
||||
import { MediaPick, Section } from './SignageFields'
|
||||
@@ -255,8 +256,9 @@ function MenuBoardFields({ w, set, extras, path }) {
|
||||
/**
|
||||
* A stack's parts: side by side or one over the other, how many (2–6), their sizes (drag the lines
|
||||
* between them on the bar, or focus one and use the arrow keys; "Split evenly"), and what each
|
||||
* shows: a widget (picked from the list or with "Add a widget"), another stack (one level deep),
|
||||
* a slide from the Slides library, or nothing.
|
||||
* shows: widgets added with "Add a widget" (several share the part, owner review 4: one over the
|
||||
* other in a side-by-side stack, side by side in the other; each with its settings, moved up or
|
||||
* down, removed), another stack (one level deep), or a slide from the Slides library.
|
||||
*/
|
||||
function StackFields({ w, set, media, onMedia, extras, path, depth }) {
|
||||
const { t } = useTranslation('manager')
|
||||
@@ -264,22 +266,27 @@ function StackFields({ w, set, media, onMedia, extras, path, depth }) {
|
||||
const cells = w.cells || []
|
||||
const shares = cells.map(c => Math.round(c.share || 0))
|
||||
const setCells = next => set({ cells: next })
|
||||
const setCell = (j, patch) => setCells(cells.map((c, k) => (k === j ? { ...c, ...patch } : c)))
|
||||
const setCell = (j, patch) => setCells(cells.map((c, k) => {
|
||||
if (k !== j) return c
|
||||
const { widget: _old, ...rest } = { ...c, ...patch } // a part stored with one `widget`: now `widgets`
|
||||
return rest
|
||||
}))
|
||||
const setShares = next => setCells(cells.map((c, k) => ({ ...c, share: next[k] })))
|
||||
const count = n => {
|
||||
const even = evenShares(n)
|
||||
setCells(Array.from({ length: n }, (_, k) => ({ ...(cells[k] || {}), share: even[k] })))
|
||||
}
|
||||
const shows = c => (c.slide_id ? 'slide' : c.widget ? (c.widget.kind === 'stack' ? (c.widget.direction === 'column' ? 'vstack' : 'hstack') : c.widget.kind) : '')
|
||||
const pick = (j, v) => {
|
||||
if (!v) setCell(j, { widget: null, slide_id: null })
|
||||
else if (v === 'slide') setCell(j, { widget: null, slide_id: slides[0]?.id ?? null })
|
||||
else setCell(j, { widget: cellWidget(v), slide_id: null })
|
||||
const setWidgets = (j, list) => setCell(j, { widgets: list, slide_id: null })
|
||||
const add = (j, v) => {
|
||||
if (v === 'slide') setCell(j, { widgets: [], slide_id: slides[0]?.id ?? null })
|
||||
else setWidgets(j, [...cellWidgets(cells[j]), cellWidget(v)])
|
||||
}
|
||||
const kinds = [...CELL_KINDS, ...(depth === 0 ? ['hstack', 'vstack'] : [])]
|
||||
const label = c => {
|
||||
const v = shows(c)
|
||||
return !v ? t('signage.widgets.stack.nothing') : v === 'slide' ? (slides.find(x => x.id === c.slide_id)?.name || t('signage.widgets.stack.slide')) : t(`signage.widgets.kinds.${v}`)
|
||||
const ws = cellWidgets(c)
|
||||
if (ws.length) return ws.map(x => kindLabel(t, x)).join(' · ')
|
||||
if (c.slide_id != null) return slides.find(x => x.id === c.slide_id)?.name || t('signage.widgets.stack.slide')
|
||||
return t('signage.widgets.stack.nothing')
|
||||
}
|
||||
return (
|
||||
<div className="grid gap-3 rounded-control border border-line bg-surface p-3" data-testid="signage-stack-editor" data-depth={depth}>
|
||||
@@ -298,37 +305,59 @@ function StackFields({ w, set, media, onMedia, extras, path, depth }) {
|
||||
</div>
|
||||
</div>
|
||||
<ShareBar column={w.direction === 'column'} shares={shares} labels={cells.map(label)} onChange={setShares} />
|
||||
<p className="text-caption text-ink-3 -mt-1">{t('signage.widgets.stack.barHint')}</p>
|
||||
<p className="text-caption text-ink-3 -mt-1">{t(w.direction === 'column' ? 'signage.widgets.stack.barHintColumn' : 'signage.widgets.stack.barHint')}</p>
|
||||
{cells.map((c, j) => {
|
||||
const cp = `${path}.${j}`
|
||||
const v = shows(c)
|
||||
const setW = patch => setCell(j, { widget: { ...c.widget, ...patch } })
|
||||
const ws = cellWidgets(c)
|
||||
const slide = !ws.length && c.slide_id != null
|
||||
const setOne = (k, patch) => setWidgets(j, ws.map((x, m) => (m === k ? { ...x, ...patch } : x)))
|
||||
const moveOne = (k, to) => { if (to >= 0 && to < ws.length) setWidgets(j, moved(ws, k, to)) }
|
||||
return (
|
||||
<div key={j} className="grid gap-3 rounded-control border border-line bg-surface-2 p-3" data-testid="signage-stack-cell-editor" data-index={j}>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="text-label font-semibold text-ink">{t('signage.widgets.stack.partTitle', { n: j + 1 })}</span>
|
||||
<span className="text-caption text-ink-3 tabular-nums" data-testid="signage-stack-share">{shares[j]}%</span>
|
||||
{!ws.length && !slide && <span className="text-caption text-ink-3">· {t('signage.widgets.stack.nothing')}</span>}
|
||||
<span className="flex-1" />
|
||||
<AddToPart kinds={kinds} onPick={v => add(j, v)} />
|
||||
</div>
|
||||
<div className={ROW}>
|
||||
<Field label={t('signage.widgets.stack.shows')}>
|
||||
<Dropdown value={v} onChange={x => pick(j, x)} data-testid="signage-stack-shows"
|
||||
options={[{ value: '', label: t('signage.widgets.stack.nothing') },
|
||||
...kinds.map(k => ({ value: k, label: t(`signage.widgets.kinds.${k}`) })),
|
||||
{ value: 'slide', label: t('signage.widgets.stack.aSlide') }]} />
|
||||
</Field>
|
||||
<div className="flex items-end"><AddToPart kinds={kinds} onPick={x => pick(j, x)} filled={!!v} /></div>
|
||||
{c.slide_id != null || v === 'slide' ? (
|
||||
<Field label={t('signage.widgets.stack.slide')} className="col-span-2">
|
||||
<Dropdown value={c.slide_id != null ? String(c.slide_id) : ''} onChange={x => setCell(j, { slide_id: x ? Number(x) : null })} data-testid="signage-stack-slide"
|
||||
{slide && (
|
||||
<div className="flex items-end gap-2">
|
||||
<Field label={t('signage.widgets.stack.slide')} className="flex-1 max-w-md">
|
||||
<Dropdown value={String(c.slide_id)} onChange={x => setCell(j, { slide_id: x ? Number(x) : null })} data-testid="signage-stack-slide"
|
||||
options={slides.length ? slides.map(s => ({ value: String(s.id), label: s.name }))
|
||||
: [{ value: '', label: t('signage.widgets.stack.noSlides') }]} />
|
||||
: [{ value: String(c.slide_id), label: t('signage.widgets.stack.noSlides') }]} />
|
||||
</Field>
|
||||
) : c.widget && <>
|
||||
{c.widget.kind !== 'stack' && <AlignField w={c.widget} set={setW} testid="signage-cell-align" />}
|
||||
<InlineFields w={c.widget} set={setW} />
|
||||
</>}
|
||||
</div>
|
||||
{c.widget && <BelowFields w={c.widget} set={setW} media={media} onMedia={onMedia} extras={extras} path={cp} depth={depth + 1} />}
|
||||
<IconButton variant="ghost" label={t('signage.widgets.stack.removeSlide')} onClick={() => setCell(j, { slide_id: null })} data-testid="signage-stack-slide-remove">
|
||||
<Trash2 size={15} />
|
||||
</IconButton>
|
||||
</div>
|
||||
)}
|
||||
{ws.map((x, k) => {
|
||||
const Icon = iconOf(x)
|
||||
const setW = patch => setOne(k, patch)
|
||||
return (
|
||||
<div key={k} className="grid gap-3 rounded-control border border-line bg-surface p-3" data-testid="signage-stack-part-widget" data-kind={x.kind}>
|
||||
<div className="flex items-center gap-2">
|
||||
<Icon size={15} className="text-ink-2 shrink-0" aria-hidden="true" />
|
||||
<span className="text-label font-semibold text-ink flex-1 min-w-0 truncate">{kindLabel(t, x)}</span>
|
||||
{ws.length > 1 && <>
|
||||
<IconButton size="sm" variant="ghost" label={t('signage.widgets.stack.before')} disabled={k === 0} onClick={() => moveOne(k, k - 1)}><ArrowUp size={14} /></IconButton>
|
||||
<IconButton size="sm" variant="ghost" label={t('signage.widgets.stack.after')} disabled={k === ws.length - 1} onClick={() => moveOne(k, k + 1)}><ArrowDown size={14} /></IconButton>
|
||||
</>}
|
||||
<IconButton size="sm" variant="ghost" label={t('signage.widgets.stack.removeWidget')} onClick={() => setWidgets(j, ws.filter((_, m) => m !== k))}
|
||||
data-testid="signage-stack-part-remove"><Trash2 size={14} /></IconButton>
|
||||
</div>
|
||||
{x.kind !== 'stack' && (
|
||||
<div className={ROW}>
|
||||
<AlignField w={x} set={setW} testid="signage-cell-align" />
|
||||
<InlineFields w={x} set={setW} />
|
||||
</div>
|
||||
)}
|
||||
<BelowFields w={x} set={setW} media={media} onMedia={onMedia} extras={extras} path={`${cp}.${k}`} depth={depth + 1} />
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
@@ -390,39 +419,30 @@ function ShareBar({ column, shares, labels, onChange }) {
|
||||
)
|
||||
}
|
||||
|
||||
/** "Add a widget" to a part: every widget (and a slide from the Slides library) in a small panel. */
|
||||
function AddToPart({ kinds, onPick, filled }) {
|
||||
/** "Add a widget" to a part: every widget (and a slide from the Slides library) in a small panel
|
||||
* over the page; widgets add up, a slide takes the part's place. */
|
||||
function AddToPart({ kinds, onPick }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const [open, setOpen] = useState(false)
|
||||
const box = useRef(null)
|
||||
useEffect(() => {
|
||||
if (!open) return undefined
|
||||
const away = e => { if (!box.current?.contains(e.target)) setOpen(false) }
|
||||
const esc = e => { if (e.key === 'Escape') setOpen(false) }
|
||||
window.addEventListener('pointerdown', away)
|
||||
window.addEventListener('keydown', esc)
|
||||
return () => { window.removeEventListener('pointerdown', away); window.removeEventListener('keydown', esc) }
|
||||
}, [open])
|
||||
const btn = useRef(null)
|
||||
const choose = k => { onPick(k); setOpen(false) }
|
||||
return (
|
||||
<div ref={box} className="relative">
|
||||
<Button variant="secondary" icon={<Plus size={14} />} onClick={() => setOpen(o => !o)} aria-expanded={open} data-testid="signage-stack-add">
|
||||
{t(filled ? 'signage.widgets.stack.replace' : 'signage.widgets.stack.add')}
|
||||
<>
|
||||
<Button ref={btn} size="sm" variant="secondary" icon={<Plus size={14} />} onClick={() => setOpen(o => !o)} aria-expanded={open} aria-haspopup="menu" data-testid="signage-stack-add">
|
||||
{t('signage.widgets.stack.add')}
|
||||
</Button>
|
||||
{open && (
|
||||
<div className="absolute z-30 left-0 top-full mt-1.5 w-[22rem] grid grid-cols-2 gap-1.5 p-2 rounded-card border border-line bg-surface shadow-lg" role="menu">
|
||||
{[...kinds, 'slide'].map(k => {
|
||||
const Icon = k === 'slide' ? BookImage : ICON[k]
|
||||
return (
|
||||
<button key={k} type="button" role="menuitem" onClick={() => choose(k)} data-testid={`signage-stack-add-${k}`}
|
||||
className="flex items-center gap-2 px-2.5 py-2 rounded-control text-left text-label text-ink hover:bg-surface-2">
|
||||
<Icon size={15} className="text-ink-2 shrink-0" aria-hidden="true" />
|
||||
{k === 'slide' ? t('signage.widgets.stack.aSlide') : t(`signage.widgets.kinds.${k}`)}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<Popover open={open} anchor={btn} onClose={() => setOpen(false)} role="menu" className="w-[22rem] grid grid-cols-2 gap-1.5 p-2" data-testid="signage-stack-add-menu">
|
||||
{[...kinds, 'slide'].map(k => {
|
||||
const Icon = k === 'slide' ? BookImage : ICON[k]
|
||||
return (
|
||||
<button key={k} type="button" role="menuitem" onClick={() => choose(k)} data-testid={`signage-stack-add-${k}`}
|
||||
className={`flex items-center gap-2 px-2.5 py-2 rounded-control text-left text-label text-ink hover:bg-surface-2 ${k === 'slide' ? 'col-span-2' : ''}`}>
|
||||
<Icon size={15} className="text-ink-2 shrink-0" aria-hidden="true" />
|
||||
{k === 'slide' ? t('signage.widgets.stack.aSlideInstead') : t(`signage.widgets.kinds.${k}`)}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</Popover>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -206,8 +206,33 @@ export function slideFromSaved(saved) {
|
||||
return { kind: saved.kind, ...slideBody(saved), content: JSON.parse(JSON.stringify(saved.content || {})) }
|
||||
}
|
||||
|
||||
/** Colours offered with one click beside the colour picker (the venue's TV: data, not the theme). */
|
||||
export const COLOUR_PRESETS = ['#ffffff', '#111827', '#fde68a', '#f59e0b', '#ef4444', '#22c55e', '#38bdf8', '#a78bfa', '#f472b6']
|
||||
/** Colours offered with one click in the colour picker (the venue's TV: data, not the theme):
|
||||
* two rows of six (owner review 4, 2026-11-21). */
|
||||
export const COLOUR_PRESETS = [
|
||||
'#ffffff', '#d1d5db', '#6b7280', '#111827', '#000000', '#fde68a',
|
||||
'#f59e0b', '#ef4444', '#f472b6', '#a78bfa', '#38bdf8', '#22c55e',
|
||||
]
|
||||
|
||||
/** A colour as its #rrggbb and its opacity (0–100 %): #rrggbbaa is see-through (2026-11-21). */
|
||||
export function splitAlpha(hex) {
|
||||
const h = String(hex || '#000000').toLowerCase()
|
||||
const rgb = /^#[0-9a-f]{6}/.test(h) ? h.slice(0, 7) : '#000000'
|
||||
const a = /^#[0-9a-f]{8}$/.test(h) ? Math.round((parseInt(h.slice(7, 9), 16) / 255) * 100) : 100
|
||||
return { rgb, alpha: a }
|
||||
}
|
||||
|
||||
/** #rrggbb with an opacity: #rrggbb when it is solid, #rrggbbaa otherwise. */
|
||||
export function joinAlpha(rgb, alpha) {
|
||||
const a = Math.max(0, Math.min(100, Math.round(alpha)))
|
||||
return a >= 100 ? rgb : `${rgb}${Math.round((a / 100) * 255).toString(16).padStart(2, '0')}`
|
||||
}
|
||||
|
||||
/** A colour typed by hand: #rgb, #rrggbb or #rrggbbaa (the # optional) → #rrggbb(aa), or null. */
|
||||
export function typedColour(text) {
|
||||
let h = String(text || '').trim().toLowerCase().replace(/^#/, '')
|
||||
if (/^[0-9a-f]{3}$/.test(h)) h = h.split('').map(x => x + x).join('')
|
||||
return /^[0-9a-f]{6}([0-9a-f]{2})?$/.test(h) ? `#${h}` : null
|
||||
}
|
||||
|
||||
// ── widgets moved and sized on the preview (2026-11-21) ──────────────────────
|
||||
|
||||
@@ -309,3 +334,14 @@ export function toggleMonthDay(line, key) {
|
||||
|
||||
/** A menu's colours until the venue picks its own (the TV's data, as the player draws them). */
|
||||
export const MENU_COLOURS = { accent: '#f59e0b', text: '#ffffff' }
|
||||
|
||||
/** A menu's look as new ("Reset the look", owner review 4): every part back to the board's. */
|
||||
export const MENU_LOOK_DEFAULTS = {
|
||||
font: 'sans', text_size: 100, text_colour: MENU_COLOURS.text, accent_colour: MENU_COLOURS.accent, badge_text_colour: null,
|
||||
heading_style: {}, item_style: {}, price_style: {}, dot_style: {},
|
||||
line_height: null, letter_spacing: null, photo_size: 100, photo_shape: 'rounded',
|
||||
}
|
||||
|
||||
/** Line spacing (× the text) and letter spacing (em) offered beside "Auto". */
|
||||
export const LINE_HEIGHTS = [0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.75, 2, 2.5]
|
||||
export const LETTER_SPACINGS = [-0.05, -0.02, 0.02, 0.05, 0.1, 0.15, 0.2, 0.3]
|
||||
|
||||
@@ -7,7 +7,8 @@ import { placeWidget } from './signageLogic'
|
||||
|
||||
// what doesn't change what the server adds (where things sit, how they look): left out of the key
|
||||
const LOOK = new Set(['box', 'position', 'size', 'align', 'background', 'text_colour', 'accent_colour', 'font', 'text_size',
|
||||
'board_width', 'board_align', 'title', 'body', 'vertical', 'columns', 'page_seconds', 'direction', 'share', 'clock_seconds', 'date_style'])
|
||||
'board_width', 'board_align', 'title', 'body', 'vertical', 'columns', 'page_seconds', 'direction', 'share', 'clock_seconds', 'date_style',
|
||||
'heading_style', 'item_style', 'price_style', 'dot_style', 'line_height', 'letter_spacing', 'photo_size', 'photo_shape', 'badge_text_colour'])
|
||||
|
||||
/**
|
||||
* The draft as the server resolves it for the preview (2026-11-21): a menu board's products
|
||||
|
||||
@@ -101,3 +101,16 @@ test('the Slides library: what is saved, and a copy for a playlist', async () =>
|
||||
copy.content.widgets[0].kind = 'clock'
|
||||
assert.equal(saved.content.widgets[0].kind, 'name') // a copy, never the kept slide
|
||||
})
|
||||
|
||||
test('a colour with its opacity: #rrggbbaa, typed by hand (owner review 4)', async () => {
|
||||
const { COLOUR_PRESETS, joinAlpha, splitAlpha, typedColour } = await import('../src/pages/signage/signageLogic.js')
|
||||
assert.equal(COLOUR_PRESETS.length, 12)
|
||||
assert.deepEqual(splitAlpha('#FF0000'), { rgb: '#ff0000', alpha: 100 })
|
||||
assert.deepEqual(splitAlpha('#ff000080'), { rgb: '#ff0000', alpha: 50 })
|
||||
assert.equal(joinAlpha('#ff0000', 100), '#ff0000')
|
||||
assert.equal(joinAlpha('#ff0000', 50), '#ff000080')
|
||||
assert.equal(joinAlpha('#ff0000', 0), '#ff000000')
|
||||
assert.equal(typedColour('abc'), '#aabbcc')
|
||||
assert.equal(typedColour(' #11223344 '), '#11223344')
|
||||
assert.equal(typedColour('#12345'), null)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user