Counter widget: one to three linked counters are the digits of one number, published on one message in the finest counter's unit (hours and minutes send 07:30 as 450, 07:55 + 5 min carries to 08:00); wraps or stops at the coarsest's min/max. The arithmetic is one pure module, ui/core/counter.ts, with counter.check.ts. A tile steps each counter with a press up and down and publishes once 300 ms after the last; a round face turns the selected counter on the ring (wheel, keys, a drag counted in steps), its arc where that counter stands in its turn, and a press on a counter's digits selects it. Default config is the time picker. Editor rows, widgetIssue, server type and dtype, docs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016ezWcLmBCtTVKFPxfdK2MK
This commit is contained in:
Melvin Strobl
2026-10-16 08:58:42 +02:00
co-authored by Claude Opus 5.5
parent 0c7f8bde82
commit 3105505192
16 changed files with 745 additions and 33 deletions
@@ -8,6 +8,7 @@ import { BarWidget } from "./BarWidget"
import { ChartWidget } from "./ChartWidget"
import { ClockWidget } from "./ClockWidget"
import { ColorWidget } from "./ColorWidget"
import { CounterWidget } from "./CounterWidget"
import { useBoundValue } from "./dataContext"
// The grid's own rules live beside the components that use them; CSS is
// chunked per entry, so the sheet is pulled in wherever a widget is drawn.
@@ -22,6 +23,7 @@ import { COLOR_DTYPES, colorFormatOf } from "./ui/core/color"
import {
buttonsOf,
config,
countersOf,
decimalsOf,
num,
rowsOf,
@@ -37,6 +39,7 @@ export const INPUT_WIDGETS = new Set([
"input",
"dropdown",
"color",
"counter",
])
export type WidgetKind = WidgetDef["type"]
@@ -55,6 +58,8 @@ export const WIDGET_DTYPES: Partial<Record<WidgetKind, string[]>> = {
// answer and a `record` request instead, checked in `widgetIssue`.
chart: ["float", "int"],
slider: ["float", "int"],
// One number, the digits of which its counters are.
counter: ["float", "int"],
switch: ["bool"],
agenda: ["list"],
notification: ["record"],
@@ -102,6 +107,7 @@ export const WIDGET_LABELS: Record<WidgetKind, string> = {
input: "Input",
dropdown: "Selector",
color: "Colour",
counter: "Counter",
}
/** One line per type for the add palette, which searches these too. */
@@ -126,6 +132,7 @@ export const WIDGET_DESCRIPTIONS: Record<WidgetKind, string> = {
input: "Sends what is typed",
dropdown: "Picks one of a list of options",
color: "Picks a colour or brightness",
counter: "Sets a number by its digits, such as a time",
}
/** Default footprint per type, in grid units. */
@@ -150,6 +157,7 @@ export const WIDGET_SIZES: Record<WidgetKind, { w: number; h: number }> = {
input: { w: 4, h: 2 },
dropdown: { w: 4, h: 2 },
color: { w: 4, h: 4 },
counter: { w: 3, h: 3 },
}
/** One line of a chart, as the document stores it. */
@@ -269,6 +277,21 @@ export function widgetIssue(widget: WidgetDef): string | null {
if (widget.type === "icon" && !(cfg.rules as unknown[] | undefined)?.length) {
return "This icon has nothing mapped yet."
}
if (widget.type === "counter") {
const counters = countersOf(widget)
const name = (index: number) =>
counters[index].label || `Counter ${index + 1}`
// A size is what carries into the counter before it; without one there
// is nothing to carry at.
const unsized = counters.findIndex(
(counter, index) => index > 0 && !(Number(counter.size) >= 1),
)
if (unsized > 0) return `${name(unsized)} needs a size.`
const stalled = counters.findIndex(
(counter) => Number(counter.step ?? 1) < 1,
)
if (stalled >= 0) return `${name(stalled)} needs a step of 1 or more.`
}
return null
}
@@ -869,6 +892,7 @@ const RENDERERS: Partial<
input: InputWidget,
dropdown: DropdownWidget,
color: ColorWidget,
counter: CounterWidget,
}
function WidgetBodyComponent({ widget, dashboard }: WidgetProps) {