Files
xenia-pos-local/packages/ui/src/components/Controls.jsx
T
bonaminandClaude Opus 5.5 83551714f7 feat(signage): Slides library, widgets placed on the preview, blank slides, slide editor rework
- Slides library (Alembic 0044, /api/signage/library): slides kept with a name and a
  description, added to playlists as copies ("Add a slide" → Your slides, "Keep in Slides"),
  or shown alone as a screen's default (device config `slide`, played as "slide:<id>",
  also as a schedule's fallback). Signage → Slides: gallery + a two-pane editor.
- Widgets moved and sized by hand on the preview (WidgetCanvas: handles, snapping, arrow
  keys): position/size "custom" with a box the TV draws the same; alignment per widget.
- Blank slides (background + widgets); menu boards narrower and placed left/centre/right.
- Slide editor reworked: name | show, transition effect | seconds; sections; text look on
  one row with ready colours; one card per widget, settings on one row.
- Questions inside the page (@xenia/ui ConfirmDialog/useConfirm), Switch boxed, Segmented
  fill; the timeline's drop line; schedule lines run on weekdays or smart days, not both;
  the playlist editor stays within 1080p with a long timeline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 07:53:27 +02:00

87 lines
4.4 KiB
React

import { cx } from '../internal/cx.js'
import { useLabels } from './labels.js'
const SearchIcon = () => (
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7" /><path d="M20 20l-3.5-3.5" /></svg>
)
const ClearIcon = () => (
<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18" /></svg>
)
/**
* A search box: icon, input, a clear button while there is text. Same heights as <Input>.
* <SearchInput value={q} onChange={setQ} placeholder="Search contacts" />
* onChange receives the text (not an event). Grows to fill a <Toolbar>.
*/
export function SearchInput({ value = '', onChange, placeholder, size = 'md', className, 'aria-label': ariaLabel, ...rest }) {
const labels = useLabels()
return (
<div className={cx('x-search', className)}>
<span className="x-search__icon"><SearchIcon /></span>
<input type="search" className={cx('x-input', `x-input--${size}`, 'x-search__input')} value={value} placeholder={placeholder ?? labels.search}
aria-label={ariaLabel ?? placeholder ?? labels.search} onChange={e => onChange?.(e.target.value)} {...rest} />
{value && (
<button type="button" className="x-search__clear" aria-label={labels.clear} onClick={() => onChange?.('')}><ClearIcon /></button>
)}
</div>
)
}
/**
* A toggle filter in a toolbar: a state, a status… with an optional coloured dot and a count.
* tone: 'success' | 'info' | 'accent' | 'warning' | 'danger' | 'neutral' (the dot and the "on" look).
*/
export function FilterChip({ pressed = false, tone = 'neutral', count, size = 'md', className, children, ...rest }) {
return (
<button type="button" aria-pressed={pressed} className={cx('x-chip', `x-chip--${size}`, `x-chip--${tone}`, pressed && 'x-chip--on', className)} {...rest}>
<span className="x-chip__dot" aria-hidden="true" />
{children}
{count != null && <span className="x-chip__count">{count}</span>}
</button>
)
}
/**
* A few mutually exclusive views (List / Map). options: [{ value, label, icon?, ariaLabel? }]
* (ariaLabel: the name of an option shown as an icon only). fill: as wide as its column, the options sharing it.
* <Segmented value={view} onChange={setView} options={[…]} aria-label="View" />
*/
export function Segmented({ options = [], value, onChange, size = 'md', fill = false, className, ...rest }) {
return (
<div role="group" className={cx('x-segmented', `x-segmented--${size}`, fill && 'x-segmented--fill', className)} {...rest}>
{options.map(o => (
<button key={o.value} type="button" aria-pressed={o.value === value} className={cx('x-segmented__item', o.value === value && 'x-segmented__item--on')}
onClick={() => onChange?.(o.value)} data-testid={o.testId} aria-label={o.ariaLabel} title={o.ariaLabel}>
{o.icon}{o.label}
</button>
))}
</div>
)
}
/**
* Tabs with an underline: a page's or a dialog's sections. Scrolls sideways when they don't fit,
* never up and down. tabs: [{ id, label, badge?, warn?, testId? }].
* <Tabs tabs={tabs} value={tab} onChange={setTab} />
* end: an element at the right end of the strip (a refresh button…).
* inset: the strip is the header of a card / panel: the card's padding at the sides, and the same
* room above and below `end` (a button never touches the card's edge or the line).
* fill: the tabs share the width equally, each label centred (a narrow column's tabs).
*/
export function Tabs({ tabs = [], value, onChange, size = 'md', end, inset = false, fill = false, className, ...rest }) {
return (
<div className={cx('x-tabs', `x-tabs--${size}`, inset && 'x-tabs--inset', fill && 'x-tabs--fill', className)} {...rest}>
<div className="x-tabs__list" role="tablist">
{tabs.map(tb => (
<button key={tb.id} type="button" role="tab" aria-selected={tb.id === value} data-testid={tb.testId}
className={cx('x-tabs__tab', tb.id === value && 'x-tabs__tab--on')} onClick={() => onChange?.(tb.id)}>
{tb.icon}{tb.label}
{tb.badge != null && tb.badge !== false && <span className={cx('x-tabs__badge', tb.warn && 'x-tabs__badge--warn')}>{tb.badge}</span>}
</button>
))}
</div>
{end && <div className="x-tabs__end">{end}</div>}
</div>
)
}