Round faces: a bar as concentric arcs with a legend in the middle; larger title, gap line and face text; Read-only in the ring's gap; a round dashboard unpadded on a phone; reduced-motion ring assertion
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f5412d2f7d
commit
541dbce584
@@ -1,3 +1,4 @@
|
||||
import { Lock } from "lucide-react"
|
||||
import { type MotionValue, motion, useTransform } from "motion/react"
|
||||
import { useEffect, useId, useRef } from "react"
|
||||
|
||||
@@ -5,6 +6,7 @@ import type { WidgetDef } from "@/client"
|
||||
import { cn } from "@/lib/utils"
|
||||
import { useBoundValue } from "./dataContext"
|
||||
import { usePublish } from "./publish"
|
||||
import { useLocked } from "./settings"
|
||||
import {
|
||||
colorFormatOf,
|
||||
cssOf,
|
||||
@@ -21,6 +23,7 @@ import {
|
||||
showTitle,
|
||||
text,
|
||||
} from "./ui/core/config"
|
||||
import { TESTID } from "./ui/core/contract"
|
||||
import { tickIntervals } from "./ui/core/controls"
|
||||
import {
|
||||
CENTRE_LABEL,
|
||||
@@ -183,6 +186,12 @@ function dialOf(widget: WidgetDef, live: unknown): Dial {
|
||||
}
|
||||
}
|
||||
|
||||
/** A slider that reads something beside its value, which then takes the
|
||||
* middle and moves the slider's own title and value to the gap's line. */
|
||||
export const hasGapLine = (widget: WidgetDef) =>
|
||||
widget.type === "slider" &&
|
||||
Boolean(((config(widget).reading ?? {}) as Series).message)
|
||||
|
||||
/**
|
||||
* A face's title: one slot, above the middle, whichever widget it is.
|
||||
*
|
||||
@@ -191,17 +200,20 @@ function dialOf(widget: WidgetDef, live: unknown): Dial {
|
||||
*/
|
||||
export function FaceTitle({
|
||||
size,
|
||||
width = TITLE_WIDTH,
|
||||
children,
|
||||
}: {
|
||||
size: number
|
||||
/** Narrower where something is drawn inside the ring beside it. */
|
||||
width?: number
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
return (
|
||||
<p
|
||||
className="pointer-events-none absolute truncate text-center text-muted-foreground"
|
||||
style={{
|
||||
left: size / 2 - TITLE_WIDTH / 2,
|
||||
width: TITLE_WIDTH,
|
||||
left: size / 2 - width / 2,
|
||||
width,
|
||||
top: size / 2 - TITLE_RISE - TITLE_SIZE,
|
||||
lineHeight: `${TITLE_SIZE * 2}px`,
|
||||
fontSize: TITLE_SIZE,
|
||||
@@ -273,6 +285,9 @@ export function Ring({
|
||||
onPick?: () => void
|
||||
}) {
|
||||
const { value, send, locked } = usePublish(widget, dashboard)
|
||||
// The dashboard's own lock, which the gap's line leads with when it holds
|
||||
// the gap (`RoundView` writes it there otherwise).
|
||||
const readOnly = useLocked()
|
||||
const cfg = config(widget)
|
||||
// A gauge reads its message rather than publishing to a target.
|
||||
const bound = useBoundValue(
|
||||
@@ -517,6 +532,15 @@ export function Ring({
|
||||
fontSize: GAP_SIZE,
|
||||
}}
|
||||
>
|
||||
{readOnly ? (
|
||||
<Lock
|
||||
role="img"
|
||||
aria-label="Read-only"
|
||||
data-testid={TESTID.locked}
|
||||
className="shrink-0 text-muted-foreground"
|
||||
style={{ width: GAP_SIZE, height: GAP_SIZE }}
|
||||
/>
|
||||
) : null}
|
||||
{title ? (
|
||||
<span className="min-w-0 truncate text-muted-foreground">
|
||||
{title}
|
||||
|
||||
Reference in New Issue
Block a user