feat(signage): venue badges, widgets' own look, widgets placed inside stacks, Save and leave, shared controls (owner review 5)
- Badges: the venue's list (setting signage.badges: names el/en, colours, an icon from a food and drink set) edited under Signage -> "Message & settings"; sent with the venue to screens and previews; several badges per product (MenuList.badges lists, a single one still read) in the shared multiple Dropdown; a board's badge colour / text colour override them (None = each own). - Widgets: colour, background plate, font, bold / italic / underline, text size, QR colours; widgets in a stack's part get every setting, vertical alignment, and a custom box inside their place, picked (stack, then widget) and dragged on the preview (selection by path "2.1.0"). - Menu slides: vertical alignment of the list (board_valign); "Where the list sits" is now "Horizontal alignment". - Message of the day: one component in the settings tab, on the Overview and from its widget. - Leaving a slide with changes: "Save and leave" (ConfirmDialog altLabel). - @xenia/ui: ColourField (with colour.js helpers), FieldRow (framed only while wrapped), Slider, IconPicker, Segmented multiple; native selects on the Overview and signage replaced by Dropdown, the device settings' colour input by ColourField. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,20 +13,26 @@
|
||||
// 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".
|
||||
// Owner review 5 (2026-11-21): each widget's own look ("Text and colours": colour, a plate behind
|
||||
// it, font, bold / italic / underline, text size; a QR code's colours); a widget in a stack's part
|
||||
// has every setting a slide's widget has, aligned both ways in its place or moved and sized there on
|
||||
// the preview (Custom); the message of the day changed from its widget. The picked widget is a path
|
||||
// ("2", "2.1.0": see WidgetCanvas).
|
||||
// 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,
|
||||
AlignCenter, AlignLeft, AlignRight, AlignVerticalJustifyCenter, AlignVerticalJustifyEnd, AlignVerticalJustifyStart, ArrowDown, ArrowUp, Bold, Italic, Palette, RotateCcw, Underline, BookImage, CalendarDays, ChevronDown, Clock, CloudSun, Columns3, GripVertical,
|
||||
ImageIcon, LayoutList, MessageSquare, Plus, QrCode, Rows3, Store, Trash2, Type, UtensilsCrossed,
|
||||
} from 'lucide-react'
|
||||
import { cellWidgets, evenShares, setShare } from '@xenia/signage'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dropdown, Field, IconButton, Input, Popover, Segmented, Switch } from '@xenia/ui'
|
||||
import { Button, ColourField, Dialog, Dropdown, Field, FieldRow, IconButton, Input, Popover, Segmented, Slider, Switch } from '@xenia/ui'
|
||||
import MessageOfTheDay from './MessageOfTheDay'
|
||||
import * as api from './signageApi'
|
||||
import MenuEditor from './MenuEditor'
|
||||
import { MediaPick, Section } from './SignageFields'
|
||||
import {
|
||||
CELL_KINDS, cellWidget, moved, newWidget, pickedAfterMove, presetWidget, WEATHER_CHOICES, weatherChoice, WIDGET_KINDS, WIDGET_POSITIONS,
|
||||
CELL_KINDS, cellWidget, fillPlace, FONT_KEYS, WIDGET_COLOURS, moved, newWidget, pickedAfterMove, presetWidget, WEATHER_CHOICES, weatherChoice, WIDGET_KINDS, WIDGET_POSITIONS,
|
||||
} from './signageLogic'
|
||||
|
||||
const ICON = { logo: ImageIcon, name: Store, date: CalendarDays, clock: Clock, message: MessageSquare, text: Type, qr: QrCode, weather: CloudSun, menu: UtensilsCrossed, hstack: Columns3, vstack: Rows3 }
|
||||
@@ -50,12 +56,13 @@ export default function WidgetsEditor({ widgets = [], onChange, media, onMedia,
|
||||
const set = (i, patch) => onChange(widgets.map((w, j) => (j === i ? { ...w, ...patch } : w)))
|
||||
const add = kind => {
|
||||
onChange([...widgets, newWidget(kind)])
|
||||
onSelect?.(widgets.length)
|
||||
onSelect?.(String(widgets.length))
|
||||
}
|
||||
const move = (from, to) => {
|
||||
if (to < 0 || to >= widgets.length || from === to) return
|
||||
onChange(moved(widgets, from, to))
|
||||
onSelect?.(pickedAfterMove(selected, from, to))
|
||||
const top = selected != null && !String(selected).includes('.') ? Number(selected) : null
|
||||
onSelect?.(top == null ? null : String(pickedAfterMove(top, from, to)))
|
||||
}
|
||||
const over = (e, i) => {
|
||||
if (!drag) return
|
||||
@@ -77,11 +84,11 @@ export default function WidgetsEditor({ widgets = [], onChange, media, onMedia,
|
||||
{widgets.map((w, i) => {
|
||||
const Icon = iconOf(w)
|
||||
const custom = w.position === 'custom'
|
||||
const on = selected === i
|
||||
const on = selected != null && (String(selected) === String(i) || String(selected).startsWith(`${i}.`))
|
||||
return (
|
||||
<div key={i} className="grid gap-3">
|
||||
{line(i)}
|
||||
<div onPointerDown={() => onSelect?.(i)} onDragOver={e => over(e, i)} onDrop={drop}
|
||||
<div onPointerDown={() => onSelect?.(String(i))} onDragOver={e => over(e, i)} onDrop={drop}
|
||||
className={`grid gap-4 rounded-card border p-4 transition-colors duration-fast ${on ? 'border-accent bg-accent-soft/40 ring-1 ring-accent' : 'border-line bg-surface-2'}
|
||||
${drag?.from === i ? 'opacity-50' : ''}`}
|
||||
data-testid="signage-widget" data-kind={w.kind} data-index={i} data-selected={on ? 'true' : undefined}>
|
||||
@@ -114,7 +121,9 @@ export default function WidgetsEditor({ widgets = [], onChange, media, onMedia,
|
||||
{w.kind !== 'stack' && <AlignField w={w} set={patch => set(i, patch)} />}
|
||||
<InlineFields w={w} set={patch => set(i, patch)} />
|
||||
</div>
|
||||
<BelowFields w={w} set={patch => set(i, patch)} media={media} onMedia={onMedia} extras={extras} path={String(i)} depth={0} />
|
||||
<LookFields w={w} set={patch => set(i, patch)} />
|
||||
<BelowFields w={w} set={patch => set(i, patch)} media={media} onMedia={onMedia} extras={extras} path={String(i)} depth={0}
|
||||
selected={selected} onSelect={onSelect} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
@@ -152,6 +161,88 @@ function AlignField({ w, set, testid = 'signage-widget-align' }) {
|
||||
)
|
||||
}
|
||||
|
||||
/** How a widget in a stack's part lines up from top to bottom in its place. */
|
||||
function VerticalField({ w, set }) {
|
||||
const { t } = useTranslation('manager')
|
||||
return (
|
||||
<Field label={t('signage.widgets.vertical')}>
|
||||
<Segmented value={w.vertical && w.vertical !== 'auto' ? w.vertical : 'middle'} onChange={vertical => set({ vertical })} fill data-testid="signage-cell-vertical"
|
||||
options={[['top', AlignVerticalJustifyStart], ['middle', AlignVerticalJustifyCenter], ['bottom', AlignVerticalJustifyEnd]].map(([v, Icon]) => (
|
||||
{ value: v, icon: <Icon size={16} aria-hidden="true" />, ariaLabel: t(`signage.verticals.${v}`), testId: `signage-cell-vertical-${v}` }))} />
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
|
||||
// which widgets have text (their colour, font, style and size), a QR code's own colours, a plate
|
||||
const TEXT_KINDS = ['name', 'date', 'clock', 'message', 'text', 'qr', 'weather']
|
||||
|
||||
/**
|
||||
* A widget's own look (owner review 5), folded under "Text and colours": its colour (text and
|
||||
* pictures; empty = the slide's), a plate behind it, its font, bold / italic / underline and text
|
||||
* size; a QR code's dots and background. A logo has only the plate; a menu has its own look.
|
||||
*/
|
||||
function LookFields({ w, set }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const [open, setOpen] = useState(false)
|
||||
if (w.kind === 'menu' || w.kind === 'stack') return null
|
||||
const text = TEXT_KINDS.includes(w.kind)
|
||||
const changed = !!(w.colour || w.background_colour || w.font || w.bold != null || w.italic || w.underline || (w.text_size && w.text_size !== 100) || w.qr_colour || w.qr_background)
|
||||
const styles = [w.bold !== false && 'bold', w.italic && 'italic', w.underline && 'underline'].filter(Boolean)
|
||||
return (
|
||||
<div className="grid gap-2" data-testid="signage-widget-look">
|
||||
<button type="button" onClick={() => setOpen(o => !o)} aria-expanded={open} data-testid="signage-widget-look-toggle"
|
||||
className="justify-self-start flex items-center gap-1.5 text-label font-medium text-ink-2 hover:text-ink">
|
||||
<Palette size={15} aria-hidden="true" />{t(text ? 'signage.widgets.look' : 'signage.widgets.plateOnly')}
|
||||
{changed && <span className="w-1.5 h-1.5 rounded-full bg-accent" aria-hidden="true" />}
|
||||
<ChevronDown size={15} className={`transition-transform duration-fast ${open ? 'rotate-180' : ''}`} aria-hidden="true" />
|
||||
</button>
|
||||
{open && (
|
||||
<FieldRow className="-mx-3" min="10rem">
|
||||
{text && <ColourField label={t('signage.widgets.colour')} value={w.colour || WIDGET_COLOURS.text} onChange={colour => set({ colour })} testId="signage-widget-colour"
|
||||
auto={{ label: t('signage.widgets.asSlide'), on: !w.colour, pick: () => set({ colour: null }) }} />}
|
||||
<ColourField label={t('signage.widgets.plate')} value={w.background_colour || WIDGET_COLOURS.plate} onChange={background_colour => set({ background_colour })} testId="signage-widget-plate"
|
||||
auto={{ label: t('signage.widgets.noPlate'), on: !w.background_colour, pick: () => set({ background_colour: null }) }} />
|
||||
{text && <>
|
||||
<Field label={t('signage.font')}>
|
||||
<Dropdown value={w.font || ''} onChange={v => set({ font: v || null })} data-testid="signage-widget-font"
|
||||
options={[{ value: '', label: t('signage.widgets.asSlide') }, ...FONT_KEYS.map(x => ({ value: x, label: t(`signage.fonts.${x}`) }))]} />
|
||||
</Field>
|
||||
<Field label={t('signage.look.f.widget.style')}>
|
||||
<Segmented multiple fill value={styles} data-testid="signage-widget-style"
|
||||
onChange={list => set({ bold: list.includes('bold') ? null : false, italic: list.includes('italic'), underline: list.includes('underline') })}
|
||||
options={[['bold', Bold], ['italic', Italic], ['underline', Underline]].map(([v, Icon]) => (
|
||||
{ value: v, icon: <Icon size={16} aria-hidden="true" />, ariaLabel: t(`signage.look.${v}`), testId: `signage-widget-${v}` }))} />
|
||||
</Field>
|
||||
<Slider label={t('signage.widgets.textSize')} value={w.text_size || 100} min={50} max={200} step={10} suffix="%" onChange={text_size => set({ text_size })} testId="signage-widget-text-size" />
|
||||
</>}
|
||||
{w.kind === 'qr' && <>
|
||||
<ColourField label={t('signage.widgets.qrColour')} value={w.qr_colour || WIDGET_COLOURS.qr} onChange={qr_colour => set({ qr_colour })} testId="signage-widget-qr-colour" opacity={false} />
|
||||
<ColourField label={t('signage.widgets.qrBackground')} value={w.qr_background || WIDGET_COLOURS.qrBackground} onChange={qr_background => set({ qr_background })} testId="signage-widget-qr-background" />
|
||||
</>}
|
||||
</FieldRow>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** The message of the day's hint, and the message itself changed right here (owner review 5). */
|
||||
function MessageHint() {
|
||||
const { t } = useTranslation('manager')
|
||||
const [open, setOpen] = useState(false)
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-2 -mt-2">
|
||||
<p className="text-caption text-ink-3 flex-1 min-w-[12rem]">{t('signage.widgets.ownTextHint')}</p>
|
||||
<Button size="sm" variant="secondary" onClick={() => setOpen(true)} data-testid="signage-widget-message-open">{t('signage.widgets.changeMessage')}</Button>
|
||||
{open && (
|
||||
<Dialog open size="md" title={t('signage.settings.message')} onClose={() => setOpen(false)}
|
||||
footer={<Button variant="secondary" onClick={() => setOpen(false)}>{t('overview.close')}</Button>}>
|
||||
<MessageOfTheDay onSaved={() => setOpen(false)} />
|
||||
</Dialog>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** The options only some widgets have, on the same row as where / size / alignment. */
|
||||
function InlineFields({ w, set }) {
|
||||
const { t } = useTranslation('manager')
|
||||
@@ -209,13 +300,13 @@ function InlineFields({ w, set }) {
|
||||
}
|
||||
|
||||
/** What needs more room, under the row: the picture, hints, the QR's own link, a menu's list, a stack's parts. */
|
||||
function BelowFields({ w, set, media, onMedia, extras, path, depth }) {
|
||||
function BelowFields({ w, set, media, onMedia, extras, path, depth, selected, onSelect }) {
|
||||
const { t } = useTranslation('manager')
|
||||
if (w.kind === 'logo') {
|
||||
return <MediaPick kind="image" value={w.media_id} entry={media[String(w.media_id)]} testid="signage-widget-logo"
|
||||
onChange={item => { onMedia(item); set({ media_id: item.id }) }} />
|
||||
}
|
||||
if (w.kind === 'message') return <p className="text-caption text-ink-3 -mt-2">{t('signage.widgets.ownTextHint')}</p>
|
||||
if (w.kind === 'message') return <MessageHint />
|
||||
if (w.kind === 'weather') return <p className="text-caption text-ink-3 -mt-2">{t('signage.widgets.weatherNeedsInternet')}</p>
|
||||
if (w.kind === 'qr') {
|
||||
return (
|
||||
@@ -228,7 +319,7 @@ function BelowFields({ w, set, media, onMedia, extras, path, depth }) {
|
||||
)
|
||||
}
|
||||
if (w.kind === 'menu') return <MenuBoardFields w={w} set={set} extras={extras} path={path} />
|
||||
if (w.kind === 'stack') return <StackFields w={w} set={set} media={media} onMedia={onMedia} extras={extras} path={path} depth={depth} />
|
||||
if (w.kind === 'stack') return <StackFields w={w} set={set} media={media} onMedia={onMedia} extras={extras} path={path} depth={depth} selected={selected} onSelect={onSelect} />
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -260,7 +351,7 @@ function MenuBoardFields({ w, set, extras, path }) {
|
||||
* 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 }) {
|
||||
function StackFields({ w, set, media, onMedia, extras, path, depth, selected, onSelect }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const slides = useLibrary()
|
||||
const cells = w.cells || []
|
||||
@@ -305,7 +396,7 @@ 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(w.direction === 'column' ? 'signage.widgets.stack.barHintColumn' : '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')} {t('signage.widgets.stack.pickHint')}</p>
|
||||
{cells.map((c, j) => {
|
||||
const cp = `${path}.${j}`
|
||||
const ws = cellWidgets(c)
|
||||
@@ -336,8 +427,13 @@ function StackFields({ w, set, media, onMedia, extras, path, depth }) {
|
||||
{ws.map((x, k) => {
|
||||
const Icon = iconOf(x)
|
||||
const setW = patch => setOne(k, patch)
|
||||
const wp = `${cp}.${k}`
|
||||
const on = selected != null && (String(selected) === wp || String(selected).startsWith(`${wp}.`))
|
||||
const custom = x.position === 'custom' && x.box
|
||||
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 key={k} onPointerDown={e => { e.stopPropagation(); onSelect?.(wp) }}
|
||||
className={`grid gap-3 rounded-control border p-3 transition-colors duration-fast ${on ? 'border-accent ring-1 ring-accent bg-surface' : 'border-line bg-surface'}`}
|
||||
data-testid="signage-stack-part-widget" data-kind={x.kind} data-path={wp} data-selected={on ? 'true' : undefined}>
|
||||
<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>
|
||||
@@ -350,11 +446,18 @@ function StackFields({ w, set, media, onMedia, extras, path, depth }) {
|
||||
</div>
|
||||
{x.kind !== 'stack' && (
|
||||
<div className={ROW}>
|
||||
<Field label={t('signage.widgets.inPart')}>
|
||||
{custom
|
||||
? <Button variant="secondary" icon={<RotateCcw size={14} />} onClick={() => setW(fillPlace(x))} data-testid="signage-cell-fill">{t('signage.widgets.backInPlace')}</Button>
|
||||
: <span className="h-control flex items-center text-label text-ink-2" data-testid="signage-cell-place">{t('signage.widgets.fillsPlace')}</span>}
|
||||
</Field>
|
||||
<AlignField w={x} set={setW} testid="signage-cell-align" />
|
||||
<VerticalField w={x} set={setW} />
|
||||
<InlineFields w={x} set={setW} />
|
||||
</div>
|
||||
)}
|
||||
<BelowFields w={x} set={setW} media={media} onMedia={onMedia} extras={extras} path={`${cp}.${k}`} depth={depth + 1} />
|
||||
<LookFields w={x} set={setW} />
|
||||
<BelowFields w={x} set={setW} media={media} onMedia={onMedia} extras={extras} path={wp} depth={depth + 1} selected={selected} onSelect={onSelect} />
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
|
||||
Reference in New Issue
Block a user