feat(signage): menus play whole rounds, seconds fields with − / +, widget limit setting, widgets as big as their content (owner review 6)
- A menu board with pages plays whole rounds (menuMs rounds its seconds up); the editor says how long it really plays under "Seconds on screen", the card and the playlist total use it. - Seconds on screen / per page: shared NumberInput (− / +, may be emptied: an error under the field and Save blocked until filled; 1 s at least, server ge=1). - Performance (Signage -> Message & settings): widgets per slide (signage.max_widgets, 10 recommended, up to 50), checked by the server (signage.too_many_widgets) and the editor. - Text, clock, date, QR, weather, logo placed by hand: the box is exactly the content (its height x text size sets the size, the width follows; handles scale keeping the shape; text size grows the box); a slide's widget may run off the slide while 5 % stays on it. - Slider: the value as close to the slider as the frame's padding; floor and table-colour sliders use the shared Slider. Timeline cards' ring no longer clipped; larger playlist buttons. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -189,7 +189,8 @@
|
||||
"weather_offline": "Η υπηρεσία καιρού δεν είναι διαθέσιμη: ο διακομιστής του καταστήματος χρειάζεται internet γι' αυτήν.",
|
||||
"schedule_unknown": "Το πρόγραμμα {{schedule_id}} δεν βρέθηκε.",
|
||||
"scene_unknown": "Αυτή η σκηνή δεν υπάρχει πια.",
|
||||
"screen_unknown": "Αυτή η οθόνη δεν υπάρχει πια."
|
||||
"screen_unknown": "Αυτή η οθόνη δεν υπάρχει πια.",
|
||||
"too_many_widgets": "Μια διαφάνεια έχει το πολύ {{max}} widgets (Προβολή → Μήνυμα & ρυθμίσεις → Απόδοση)."
|
||||
},
|
||||
"menu_tablet": {
|
||||
"no_table": "Αυτό το tablet δεν είναι σε τραπέζι, οπότε δεν καλεί σερβιτόρο.",
|
||||
|
||||
@@ -1557,7 +1557,9 @@
|
||||
"textSize": "Μέγεθος κειμένου",
|
||||
"qrColour": "Χρώμα κωδικού QR",
|
||||
"qrBackground": "Φόντο κωδικού QR",
|
||||
"changeMessage": "Αλλαγή μηνύματος"
|
||||
"changeMessage": "Αλλαγή μηνύματος",
|
||||
"full_one": "Αυτή η διαφάνεια έχει τα περισσότερα widgets που επιτρέπονται ({{count}}). Προβολή → Μήνυμα & ρυθμίσεις → Απόδοση.",
|
||||
"full_other": "Αυτή η διαφάνεια έχει τα περισσότερα widgets που επιτρέπονται ({{count}}). Προβολή → Μήνυμα & ρυθμίσεις → Απόδοση."
|
||||
},
|
||||
"tabs": {
|
||||
"playlists": "Λίστες",
|
||||
@@ -1768,6 +1770,16 @@
|
||||
"removeTitle": "Αφαίρεση του σήματος «{{name}}»;",
|
||||
"removeBody": "Οι πίνακες που το χρησιμοποιούν σταματούν να το δείχνουν. Τίποτα δεν αλλάζει μέχρι να αποθηκεύσετε.",
|
||||
"needName": "Κάθε σήμα χρειάζεται όνομα (στα ελληνικά ή στα αγγλικά)."
|
||||
},
|
||||
"secondsEmpty": "Συμπληρώστε τα δευτερόλεπτα (1 ή περισσότερα) για να αποθηκεύσετε.",
|
||||
"playNote": "Παίζει {{real}} δλ., όχι {{set}} δλ.: ένα μενού με σελίδες παίζει ολόκληρους γύρους ({{rounds}} × {{pages}} σελίδες των {{per}} δλ.), ώστε να μη σταματά στη μέση.",
|
||||
"performance": {
|
||||
"title": "Απόδοση",
|
||||
"hint": "Πόσα widgets μπορεί να έχει μια διαφάνεια. Συνιστούμε έντονα {{n}}: κάθε widget ξανασχεδιάζεται συνεχώς στην τηλεόραση, και οι μικροί υπολογιστές των τηλεοράσεων καθυστερούν με πολλά.",
|
||||
"maxWidgets": "Widgets ανά διαφάνεια",
|
||||
"empty": "Συμπληρώστε έναν αριθμό (1 ή περισσότερα).",
|
||||
"backTo": "Πίσω στα {{n}}",
|
||||
"warning": "Πάνω από {{n}} widgets μπορεί να κάνουν τις τηλεοράσεις να κολλάνε (διαφάνειες που αλλάζουν αργά, βίντεο που κόβονται). Ελέγξτε τις οθόνες σας αφού τα προσθέσετε."
|
||||
}
|
||||
},
|
||||
"overview": {
|
||||
@@ -2855,7 +2867,6 @@
|
||||
"width": "Πλάτος",
|
||||
"height": "Ύψος",
|
||||
"background": "Εικόνα φόντου",
|
||||
"backgroundOpacity": "Ένταση: {{value}}%",
|
||||
"table": "Τραπέζι {{name}}",
|
||||
"shape": "Σχήμα",
|
||||
"shapes": {
|
||||
@@ -2896,7 +2907,8 @@
|
||||
"decimal": ",",
|
||||
"length": "Μήκος",
|
||||
"thickness": "Πάχος",
|
||||
"cellsHint": "Σε κελιά του πλέγματος (ανά μισό κελί): ένα κελί είναι το μέγεθος του πλέγματος, οπότε τα μεγέθη ακολουθούν την ανάλυσή του. Ή σύρετε τις λαβές στις πλευρές και τις γωνίες."
|
||||
"cellsHint": "Σε κελιά του πλέγματος (ανά μισό κελί): ένα κελί είναι το μέγεθος του πλέγματος, οπότε τα μεγέθη ακολουθούν την ανάλυσή του. Ή σύρετε τις λαβές στις πλευρές και τις γωνίες.",
|
||||
"backgroundOpacityLabel": "Ένταση"
|
||||
},
|
||||
"orders": {
|
||||
"back": "Πίσω",
|
||||
|
||||
@@ -189,7 +189,8 @@
|
||||
"weather_offline": "The weather service can't be reached: the venue's server needs internet for it.",
|
||||
"schedule_unknown": "Schedule {{schedule_id}} not found.",
|
||||
"scene_unknown": "That scene doesn't exist any more.",
|
||||
"screen_unknown": "That screen doesn't exist any more."
|
||||
"screen_unknown": "That screen doesn't exist any more.",
|
||||
"too_many_widgets": "A slide holds at most {{max}} widgets (Signage → Message & settings → Performance)."
|
||||
},
|
||||
"menu_tablet": {
|
||||
"no_table": "This tablet isn't at a table, so it can't call a waiter.",
|
||||
|
||||
@@ -1557,7 +1557,9 @@
|
||||
"textSize": "Text size",
|
||||
"qrColour": "QR code colour",
|
||||
"qrBackground": "QR code background",
|
||||
"changeMessage": "Change the message"
|
||||
"changeMessage": "Change the message",
|
||||
"full_one": "This slide holds the most widgets allowed ({{count}}). Signage → Message & settings → Performance.",
|
||||
"full_other": "This slide holds the most widgets allowed ({{count}}). Signage → Message & settings → Performance."
|
||||
},
|
||||
"tabs": {
|
||||
"playlists": "Playlists",
|
||||
@@ -1768,6 +1770,16 @@
|
||||
"removeTitle": "Remove the badge \"{{name}}\"?",
|
||||
"removeBody": "Boards that use it stop showing it. Nothing changes until you save.",
|
||||
"needName": "Every badge needs a name (in Greek or in English)."
|
||||
},
|
||||
"secondsEmpty": "Fill in the seconds (1 or more) to save.",
|
||||
"playNote": "Plays {{real}} s, not {{set}} s: a menu with pages plays whole rounds ({{rounds}} × {{pages}} pages of {{per}} s), so it never stops in the middle of one.",
|
||||
"performance": {
|
||||
"title": "Performance",
|
||||
"hint": "How many widgets a slide may hold. We strongly recommend {{n}}: every widget is redrawn on the TV all the time, and small TV computers slow down with many.",
|
||||
"maxWidgets": "Widgets per slide",
|
||||
"empty": "Fill in a number (1 or more).",
|
||||
"backTo": "Back to {{n}}",
|
||||
"warning": "More than {{n}} widgets can make the TVs stutter (slides turning late, videos jerking). Check your screens after you add them."
|
||||
}
|
||||
},
|
||||
"overview": {
|
||||
@@ -2855,7 +2867,6 @@
|
||||
"width": "Width",
|
||||
"height": "Height",
|
||||
"background": "Background picture",
|
||||
"backgroundOpacity": "How strong: {{value}}%",
|
||||
"table": "Table {{name}}",
|
||||
"shape": "Shape",
|
||||
"shapes": {
|
||||
@@ -2896,7 +2907,8 @@
|
||||
"decimal": ".",
|
||||
"length": "Length",
|
||||
"thickness": "Thickness",
|
||||
"cellsHint": "In grid cells (by half cells): a cell is the grid's size, so sizes follow the grid resolution. Or drag the handles on its sides and corners."
|
||||
"cellsHint": "In grid cells (by half cells): a cell is the grid's size, so sizes follow the grid resolution. Or drag the handles on its sides and corners.",
|
||||
"backgroundOpacityLabel": "How strong"
|
||||
},
|
||||
"orders": {
|
||||
"back": "Back",
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Cloud, CloudFog, CloudLightning, CloudMoon, CloudRain, CloudSnow, Cloud
|
||||
import { QRCodeSVG } from 'qrcode.react'
|
||||
import { BADGE_ICONS } from './badges'
|
||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { badgeColours, badgeName, cellWidgets, fitUnit, FONTS, itemBadges, menuLook, menuPages, pageAt, priceChars, textWidth, visibleGroups, weatherIcon, widgetAlign } from './logic'
|
||||
import { badgeColours, badgeName, cellWidgets, TIGHT, fitUnit, FONTS, itemBadges, 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 }) {
|
||||
@@ -165,6 +165,7 @@ const CORNER = {
|
||||
'bottom-right': { bottom: '3cqmin', right: '3cqmin', alignItems: 'flex-end' },
|
||||
}
|
||||
const SELF = { left: 'flex-start', center: 'center', right: 'flex-end' }
|
||||
const placedBy = w => (w.position === 'custom' && w.box ? (TIGHT.includes(w.kind) ? 'tight' : true) : false)
|
||||
const VSELF = { top: 'flex-start', middle: 'center', bottom: 'flex-end', auto: 'center' }
|
||||
/** A widget's own colour and the plate behind it (owner review 5); `pad`: a plate that hugs it. */
|
||||
const plate = (w, pad) => ({
|
||||
@@ -186,7 +187,7 @@ export function Widgets({ widgets, media, venue, now, colour, extras, embed }) {
|
||||
const fmt = useFormat()
|
||||
if (!widgets?.length) return null
|
||||
const ctx = { media, venue, now, fmt, extras: extras || {}, embed }
|
||||
const shown = widgets.map((w, i) => [w, i, widgetBody(w, ctx, w.position === 'custom' && !!w.box, String(i))]).filter(([, , body]) => body)
|
||||
const shown = widgets.map((w, i) => [w, i, widgetBody(w, ctx, placedBy(w), String(i))]).filter(([, , body]) => body)
|
||||
const bar = where => shown.filter(([w]) => w.position === where)
|
||||
const bars = [['top-bar', { top: 0 }], ['bottom-bar', { bottom: 0 }]]
|
||||
return (
|
||||
@@ -201,6 +202,16 @@ export function Widgets({ widgets, media, venue, now, colour, extras, embed }) {
|
||||
</div>
|
||||
))}
|
||||
{shown.filter(([w]) => CORNER[w.position] || (w.position === 'custom' && w.box)).map(([w, i, body]) => {
|
||||
if (w.position === 'custom' && TIGHT.includes(w.kind)) {
|
||||
// as big as what it shows, from its box's top-left corner (it may run off the slide)
|
||||
return (
|
||||
<div key={i} data-widget={i} className="absolute" data-testid="signage-w-box" data-tight=""
|
||||
style={{ left: `${w.box.x}%`, top: `${w.box.y}%`, width: 'max-content', color: colour || '#fff', display: 'flex', flexDirection: 'column',
|
||||
alignItems: SELF[widgetAlign(w)], textAlign: widgetAlign(w), ...plate(w, true) }}>
|
||||
{body}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
if (w.position === 'custom') {
|
||||
return (
|
||||
<div key={i} data-widget={i} className="absolute" data-testid="signage-w-box"
|
||||
@@ -226,8 +237,10 @@ const OBJECT_POSITION = { left: 'left center', center: 'center', right: 'right c
|
||||
|
||||
/**
|
||||
* What one widget shows, or null when it has nothing to show. Sizes are "usual units" (cqmin of
|
||||
* the slide at size medium); `fit`: the widget fills its own box instead (fitUnit). `path`: the
|
||||
* widget's place in the slide ("2", "2.1" inside a stack), for its extras.
|
||||
* the slide at size medium); `fit`: the widget fills its place instead (fitUnit: a stack's part);
|
||||
* fit 'tight' (owner review 6): placed by hand, its box is exactly its content: the box's height
|
||||
* (× its text size) sets the size and its width follows. `path`: the widget's place in the slide
|
||||
* ("2", "2.1.0" inside a stack), for its extras.
|
||||
*/
|
||||
function widgetBody(w, ctx, fit, path) {
|
||||
const { media, venue, now, fmt, extras } = ctx
|
||||
@@ -238,6 +251,7 @@ function widgetBody(w, ctx, fit, path) {
|
||||
// in a box of its own the box sets the size: its text size can only make it smaller there
|
||||
const unit = (height, width) => {
|
||||
if (!fit) return n => `${+(n * s).toFixed(3)}cqmin`
|
||||
if (fit === 'tight') return n => `${+(n * (w.box.h / height) * ts).toFixed(4)}cqh`
|
||||
const f = fitUnit(height, width)
|
||||
return n => f(n * Math.min(1, ts))
|
||||
}
|
||||
@@ -255,6 +269,7 @@ function widgetBody(w, ctx, fit, path) {
|
||||
if (w.kind === 'logo') {
|
||||
const m = media(w.media_id)
|
||||
if (!m) return null
|
||||
if (fit === 'tight') return <img src={m.src} alt="" style={{ height: `${+(w.box.h * ts).toFixed(4)}cqh`, width: 'auto', display: 'block' }} data-testid="signage-w-logo" />
|
||||
return fit
|
||||
? <img src={m.src} alt="" style={{ width: '100%', height: '100%', objectFit: 'contain', objectPosition: OBJECT_POSITION[widgetAlign(w)] }} data-testid="signage-w-logo" />
|
||||
: <img src={m.src} alt="" style={{ height: `${9 * s}cqmin`, maxWidth: `${30 * s}cqmin`, objectFit: 'contain' }} data-testid="signage-w-logo" />
|
||||
@@ -381,12 +396,15 @@ function Stack({ w, path, ctx }) {
|
||||
const wp = `${cp}.${k}`
|
||||
const own = cw.position === 'custom' && cw.box
|
||||
const align = cw.align && cw.align !== 'auto' ? cw.align : 'center'
|
||||
const body = widgetBody(cw, ctx, true, wp)
|
||||
const body = widgetBody(cw, ctx, own && TIGHT.includes(cw.kind) ? 'tight' : true, wp)
|
||||
return (
|
||||
<div key={k} style={{ flex: '1 1 0%', minWidth: 0, minHeight: 0, overflow: 'hidden', containerType: 'size', position: 'relative',
|
||||
...(own ? {} : { display: 'flex', alignItems: VSELF[cw.vertical] || 'center', justifyContent: SELF[align], textAlign: align }) }}
|
||||
data-testid="signage-stack-place" data-place={wp}>
|
||||
{body && (own ? (
|
||||
{body && (own && TIGHT.includes(cw.kind) ? (
|
||||
<div data-widget={wp} style={{ position: 'absolute', left: `${cw.box.x}%`, top: `${cw.box.y}%`, width: 'max-content', display: 'flex', flexDirection: 'column',
|
||||
alignItems: SELF[align], textAlign: align, ...plate(cw, true) }} data-testid="signage-w-box" data-tight="">{body}</div>
|
||||
) : own ? (
|
||||
<div data-widget={wp} style={{ position: 'absolute', left: `${cw.box.x}%`, top: `${cw.box.y}%`, width: `${cw.box.w}%`, height: `${cw.box.h}%`,
|
||||
containerType: 'size', display: 'flex', alignItems: VSELF[cw.vertical] || 'center', justifyContent: SELF[align], textAlign: align, ...plate(cw) }}
|
||||
data-testid="signage-w-box">{body}</div>
|
||||
|
||||
@@ -130,7 +130,7 @@ export function nextSlide(slides, current, local) {
|
||||
/** How long a slide stays, in ms; null = until its video ends (with a safety limit in the player). */
|
||||
export function slideMs(slide) {
|
||||
if (slide.kind === 'video' && slide.video_to_end) return null
|
||||
return Math.max(2, slide.duration_s || 10) * 1000
|
||||
return Math.max(1, slide.duration_s || 10) * 1000
|
||||
}
|
||||
|
||||
/** The frame's size and turn for a screen: CSS for the box that holds the slides. */
|
||||
@@ -215,14 +215,17 @@ export function menuPages(groups, perPage, headings = true) {
|
||||
|
||||
/** A menu slide's time: every page for its seconds, at least the slide's own time. */
|
||||
export function menuMs(slide, pageCount) {
|
||||
const per = Math.max(3, slide.content?.page_seconds || 10) * 1000
|
||||
return Math.max(slideMs(slide), pageCount > 1 ? pageCount * per : 0)
|
||||
// owner review 6 (2026-11-21): a board with pages plays whole rounds of them, never cut in the
|
||||
// middle: its seconds on screen rounded up to the next full round (10 s, 2 pages of 3 s → 12 s)
|
||||
if (!(pageCount > 1)) return slideMs(slide)
|
||||
const round = pageCount * Math.max(1, slide.content?.page_seconds || 10) * 1000
|
||||
return Math.max(1, Math.ceil(slideMs(slide) / round)) * round
|
||||
}
|
||||
|
||||
/** The page on screen `elapsedMs` into the slide (the pages go round while the slide lasts). */
|
||||
export function pageAt(pageCount, pageSeconds, elapsedMs) {
|
||||
if (pageCount <= 1 || !(elapsedMs > 0)) return 0 // the clock's last tick may be just before the slide began
|
||||
return Math.floor(elapsedMs / (Math.max(3, pageSeconds || 10) * 1000)) % pageCount // round and round while the slide lasts
|
||||
return Math.floor(elapsedMs / (Math.max(1, pageSeconds || 10) * 1000)) % pageCount // round and round while the slide lasts
|
||||
}
|
||||
|
||||
/** A weather code (WMO, as Open-Meteo sends it) → an icon name for the widget. */
|
||||
@@ -258,6 +261,10 @@ export function visibleGroups(groups) {
|
||||
|
||||
// ── widgets placed by hand (owner 2026-11-21) ─────────────────────────────────
|
||||
|
||||
/** Widgets whose box, placed by hand, is exactly their content (owner review 6): its height (× the
|
||||
* widget's text size) sets the size, its width follows. A menu or a stack fills its box. */
|
||||
export const TIGHT = ['logo', 'name', 'date', 'clock', 'message', 'text', 'qr', 'weather']
|
||||
|
||||
/** The slide kinds that carry widgets. */
|
||||
export const WIDGET_HOSTS = ['text', 'menu', 'blank']
|
||||
|
||||
|
||||
@@ -101,6 +101,11 @@ test('a menu slide stays for all its pages; the page on screen', () => {
|
||||
const slide = { kind: 'menu', duration_s: 10, content: { page_seconds: 8 } }
|
||||
assert.equal(menuMs(slide, 1), 10_000)
|
||||
assert.equal(menuMs(slide, 3), 24_000)
|
||||
// owner review 6: whole rounds only (10 s, 2 pages of 3 s → 2 rounds of 6 s = 12 s; 7 s of 2 × 3 s → 12 s; 12 s → 12 s)
|
||||
assert.equal(menuMs({ kind: 'menu', duration_s: 10, content: { page_seconds: 3 } }, 2), 12_000)
|
||||
assert.equal(menuMs({ kind: 'menu', duration_s: 7, content: { page_seconds: 3 } }, 2), 12_000)
|
||||
assert.equal(menuMs({ kind: 'menu', duration_s: 12, content: { page_seconds: 3 } }, 2), 12_000)
|
||||
assert.equal(menuMs({ kind: 'menu', duration_s: 2, content: { page_seconds: 5 } }, 3), 15_000)
|
||||
assert.equal(pageAt(3, 8, 0), 0)
|
||||
assert.equal(pageAt(3, 8, 8_100), 1)
|
||||
assert.equal(pageAt(3, 8, 16_500), 2)
|
||||
|
||||
@@ -475,13 +475,35 @@
|
||||
.x-field-row--wrapped { border-color: var(--x-line); background: var(--x-surface); }
|
||||
.x-field-row--wrapped.x-field-row--shade { background: var(--x-surface-2); }
|
||||
|
||||
/* ── NumberInput (2026-11-21): a whole number with − / + on its sides ──────────── */
|
||||
.x-number {
|
||||
display: flex; align-items: stretch; width: 100%; min-width: 0; min-height: var(--x-control-md); box-sizing: border-box;
|
||||
border: var(--x-border-width) solid var(--x-line-strong); border-radius: var(--x-radius-control); background: var(--x-surface); overflow: hidden;
|
||||
}
|
||||
.x-number--sm { min-height: var(--x-control-sm); }
|
||||
.x-number:hover:not(.x-number--disabled) { border-color: var(--x-ink-3); }
|
||||
.x-number--focus { border-color: var(--x-accent); box-shadow: var(--x-focus-ring); }
|
||||
.x-number--invalid { border-color: var(--x-danger); }
|
||||
.x-number--invalid.x-number--focus { box-shadow: 0 0 0 3px rgb(var(--x-danger-rgb) / 0.3); }
|
||||
.x-number--disabled { background: var(--x-surface-2); }
|
||||
.x-number__btn {
|
||||
flex-shrink: 0; width: var(--x-control-sm); display: grid; place-items: center; border: 0; background: none; color: var(--x-ink-2); cursor: pointer;
|
||||
}
|
||||
.x-number__btn:hover:not(:disabled) { background: var(--x-surface-2); color: var(--x-ink); }
|
||||
.x-number__btn:disabled { opacity: 0.4; cursor: default; }
|
||||
.x-number__input {
|
||||
flex: 1; min-width: 0; width: 100%; border: 0; outline: none; background: transparent; color: var(--x-ink);
|
||||
font: inherit; font-size: var(--x-text-body); text-align: center; font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.x-number__suffix { align-self: center; padding-right: var(--x-space-1); color: var(--x-ink-3); font-size: var(--x-text-label); }
|
||||
|
||||
/* ── Slider (2026-11-21): framed like a field, its value beside it ──────────────── */
|
||||
.x-slider {
|
||||
min-height: var(--x-control-md); display: flex; align-items: center; gap: var(--x-space-3); padding: 0 var(--x-space-3);
|
||||
border: var(--x-border-width) solid var(--x-line); border-radius: var(--x-radius-control); background: var(--x-surface);
|
||||
}
|
||||
.x-slider__input { flex: 1; min-width: 0; accent-color: var(--x-accent); }
|
||||
.x-slider__value { width: 3rem; text-align: right; font-size: var(--x-text-label); color: var(--x-ink-2); font-variant-numeric: tabular-nums; }
|
||||
.x-slider__value { flex-shrink: 0; text-align: right; font-size: var(--x-text-label); color: var(--x-ink-2); font-variant-numeric: tabular-nums; }
|
||||
|
||||
/* ── ColourField (2026-11-21): a colour as a field; its panel over the page ──────── */
|
||||
.x-swatch {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import { useState } from 'react'
|
||||
import { cx } from '../internal/cx.js'
|
||||
import { useLabels } from './labels.js'
|
||||
|
||||
const Icon = ({ d }) => (
|
||||
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" strokeWidth="2.25" strokeLinecap="round" aria-hidden="true"><path d={d} /></svg>
|
||||
)
|
||||
|
||||
/**
|
||||
* A whole number typed or stepped with − / + on its sides (2026-11-21), as tall as an input.
|
||||
* <NumberInput value={seconds} min={1} max={3600} onChange={setSeconds} suffix="s" />
|
||||
* The field may be emptied while typing: onChange(null). The form shows its own error for an empty
|
||||
* value and keeps it from being saved. A value over `max` is brought down; under `min`, brought up
|
||||
* when the field is left. Inside a <Field> it takes the field's id.
|
||||
*/
|
||||
export function NumberInput({ value, onChange, min = 0, max = Infinity, step = 1, suffix, size = 'md', invalid = false, disabled = false, className, id, ...rest }) {
|
||||
const labels = useLabels()
|
||||
const [focus, setFocus] = useState(false)
|
||||
const n = value === '' || value == null ? null : Number(value)
|
||||
const clamp = v => Math.min(max, Math.max(min, v))
|
||||
const stepBy = d => onChange?.(clamp((n ?? min) + d))
|
||||
return (
|
||||
<span className={cx('x-number', `x-number--${size}`, (invalid || rest['aria-invalid']) && 'x-number--invalid', focus && 'x-number--focus', disabled && 'x-number--disabled', className)}>
|
||||
<button type="button" className="x-number__btn" onClick={() => stepBy(-step)} disabled={disabled || (n != null && n <= min)} aria-label={labels.decrease} tabIndex={-1}>
|
||||
<Icon d="M5 12h14" />
|
||||
</button>
|
||||
<input id={id} type="text" inputMode="numeric" className="x-number__input" value={n == null ? '' : String(n)} disabled={disabled}
|
||||
aria-invalid={invalid || undefined}
|
||||
onChange={e => {
|
||||
const digits = e.target.value.replace(/\D/g, '')
|
||||
onChange?.(digits === '' ? null : Math.min(max, Number(digits)))
|
||||
}}
|
||||
onFocus={() => setFocus(true)}
|
||||
onBlur={() => { setFocus(false); if (n != null && n < min) onChange?.(min) }}
|
||||
onKeyDown={e => {
|
||||
if (e.key === 'ArrowUp') { e.preventDefault(); stepBy(step) }
|
||||
if (e.key === 'ArrowDown') { e.preventDefault(); stepBy(-step) }
|
||||
}}
|
||||
{...rest} />
|
||||
{suffix && <span className="x-number__suffix" aria-hidden="true">{suffix}</span>}
|
||||
<button type="button" className="x-number__btn" onClick={() => stepBy(step)} disabled={disabled || (n != null && n >= max)} aria-label={labels.increase} tabIndex={-1}>
|
||||
<Icon d="M12 5v14M5 12h14" />
|
||||
</button>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
@@ -11,7 +11,8 @@ export function Slider({ label, value, min = 0, max = 100, step = 1, onChange, s
|
||||
<span className="x-slider">
|
||||
<input type="range" min={min} max={max} step={step} value={value} onChange={e => onChange?.(Number(e.target.value))}
|
||||
className="x-slider__input" aria-label={label} data-testid={testId} />
|
||||
<span className="x-slider__value">{value}{suffix}</span>
|
||||
{/* as wide as its widest value, no wider: the gap to it is the frame's padding (owner review 6) */}
|
||||
<span className="x-slider__value" style={{ minWidth: `${String(max).length + String(suffix).length}ch` }}>{value}{suffix}</span>
|
||||
</span>
|
||||
</Field>
|
||||
)
|
||||
|
||||
@@ -27,6 +27,7 @@ export { ColourField, Swatch } from './components/ColourField.jsx'
|
||||
export { COLOUR_PRESETS, joinAlpha, splitAlpha, typedColour } from './components/colour.js'
|
||||
export { FieldRow } from './components/FieldRow.jsx'
|
||||
export { Slider } from './components/Slider.jsx'
|
||||
export { NumberInput } from './components/NumberInput.jsx'
|
||||
export { IconPicker } from './components/IconPicker.jsx'
|
||||
export { Page, PageHeader, Pane, Toolbar, ToolbarSpacer } from './components/Page.jsx'
|
||||
export { SearchInput, FilterChip, Segmented, Tabs } from './components/Controls.jsx'
|
||||
|
||||
Reference in New Issue
Block a user