Smart home dial app
A thermostat screen with a dial you turn with your thumb: the ticks between the room and the target light up, and the room warms or cools towards it live.
"use client";
import {
useEffect,
useRef,
useState,
type CSSProperties,
type KeyboardEvent,
type PointerEvent,
} from "react";
import "./home-dial.css";
export type Room = { name: string; current: number; target: number };
type Mode = "heat" | "cool" | "auto" | "off";
type Device = "lights" | "blinds" | "fan";
type HomeDialProps = {
rooms: Room[];
/** Temperature outside, shown as a chip. */
outside?: number;
min?: number;
max?: number;
};
const SWEEP = 270; // the dial runs from -135° to +135°, measured clockwise from the top
const TICKS = 54;
const C = 150; // centre of the 300 x 300 dial
const polar = (deg: number, r: number) => {
const a = (deg * Math.PI) / 180;
return [C + r * Math.sin(a), C - r * Math.cos(a)] as const;
};
const MODES: { id: Mode; label: string }[] = [
{ id: "heat", label: "Heat" },
{ id: "cool", label: "Cool" },
{ id: "auto", label: "Auto" },
{ id: "off", label: "Off" },
];
/** Small animated icons: the bulb glows, the blinds close slat by slat, the fan spins. */
function DeviceIcon({ id }: { id: Device }) {
if (id === "lights")
return (
<svg
viewBox="0 0 24 24"
className="gu-dial__icon gu-dial__icon--bulb"
aria-hidden="true"
>
<circle className="gu-dial__halo" cx="12" cy="10" r="9" />
<path d="M9 17h6M10 20h4M12 3a6 6 0 0 0-3.5 10.9c.6.5 1 1.2 1 2.1h5c0-.9.4-1.6 1-2.1A6 6 0 0 0 12 3Z" />
</svg>
);
if (id === "blinds")
return (
<svg
viewBox="0 0 24 24"
className="gu-dial__icon gu-dial__icon--blinds"
aria-hidden="true"
>
<path d="M4 4h16" />
{[0, 1, 2, 3].map((i) => (
<rect
key={i}
x="5"
y={6.5 + i * 3.6}
width="14"
height="2.2"
rx="1"
style={{ "--s": i } as CSSProperties}
/>
))}
</svg>
);
return (
<svg
viewBox="0 0 24 24"
className="gu-dial__icon gu-dial__icon--fan"
aria-hidden="true"
>
<g className="gu-dial__blades">
{[0, 120, 240].map((r) => (
<path
key={r}
d="M12 12c-1-4 0-7.5 2.5-8.5 1.8-.6 2.5 1.6 1.2 3.3L12 12Z"
transform={`rotate(${r} 12 12)`}
/>
))}
</g>
<circle cx="12" cy="12" r="1.6" />
</svg>
);
}
/**
* HomeDial: a thermostat screen with a dial you turn with a finger.
* - Drag anywhere on the ring (or use the arrow keys). The knob travels along the arc and clicks at every half degree.
* - The ticks between the room and the target light up, with a wave running towards the target while the room heats or cools.
* - The number rolls up or down, the screen glows and breathes in the mode's colour, and the colour itself fades between modes.
*/
export function HomeDial({
rooms: start,
outside = 7,
min = 10,
max = 30,
}: HomeDialProps) {
const [rooms, setRooms] = useState(start);
const [at, setAt] = useState(0);
const [mode, setMode] = useState<Mode>("heat");
const [devices, setDevices] = useState<Record<Device, boolean>>({
lights: true,
blinds: false,
fan: false,
});
const [turning, setTurning] = useState(false);
const [roll, setRoll] = useState<"up" | "down">("up");
const [clicks, setClicks] = useState(0);
const dial = useRef<HTMLDivElement>(null);
const room = rooms[at];
const range = max - min;
const toDeg = (t: number) => -SWEEP / 2 + ((t - min) / range) * SWEEP;
// The rooms slowly reach their targets: 0.1° every second, like a real house (only faster).
useEffect(() => {
if (mode === "off") return;
const id = window.setInterval(() => {
setRooms((rs) =>
rs.map((r) => {
const gap = r.target - r.current;
if (Math.abs(gap) < 0.05) return r;
if ((mode === "heat" && gap < 0) || (mode === "cool" && gap > 0))
return r;
return {
...r,
current: Math.round((r.current + Math.sign(gap) * 0.1) * 10) / 10,
};
}),
);
}, 1000);
return () => window.clearInterval(id);
}, [mode]);
const setTarget = (t: number) => {
const v = Math.min(max, Math.max(min, Math.round(t * 2) / 2));
if (v === room.target) return;
setRoll(v > room.target ? "up" : "down");
setClicks((c) => c + 1);
// A real detent: phones that can vibrate give a tiny tick.
if (turning && "vibrate" in navigator) navigator.vibrate?.(4);
setRooms((rs) => rs.map((r, i) => (i === at ? { ...r, target: v } : r)));
};
// Angle of the pointer around the centre, turned into a temperature.
const fromPointer = (e: PointerEvent<HTMLDivElement>) => {
const box = dial.current!.getBoundingClientRect();
const x = e.clientX - box.left - box.width / 2;
const y = e.clientY - box.top - box.height / 2;
let deg = (Math.atan2(x, -y) * 180) / Math.PI;
if (Math.abs(deg) > SWEEP / 2) deg = deg > 0 ? SWEEP / 2 : -SWEEP / 2; // the gap at the bottom snaps to the nearest end
setTarget(min + ((deg + SWEEP / 2) / SWEEP) * range);
};
const onKey = (e: KeyboardEvent<HTMLDivElement>) => {
const step: Record<string, number> = {
ArrowUp: 0.5,
ArrowRight: 0.5,
ArrowDown: -0.5,
ArrowLeft: -0.5,
PageUp: 2,
PageDown: -2,
};
if (e.key in step) setTarget(room.target + step[e.key]);
else if (e.key === "Home") setTarget(min);
else if (e.key === "End") setTarget(max);
else return;
e.preventDefault();
};
const off = mode === "off";
const gap = room.target - room.current;
const working =
!off &&
Math.abs(gap) >= 0.05 &&
!(mode === "heat" && gap < 0) &&
!(mode === "cool" && gap > 0);
const status = off
? "Off"
: !working
? "Holding at"
: gap > 0
? "Heating to"
: "Cooling to";
const tone = off
? "off"
: mode === "auto"
? gap < 0
? "cool"
: "heat"
: mode;
const lo = Math.min(room.current, room.target);
const hi = Math.max(room.current, room.target);
const litFrom = gap >= 0 ? lo : hi; // the wave starts at the room and runs to the target
return (
<div
className="gu-dial"
data-tone={tone}
data-working={working}
style={
{
"--glow": off ? 0 : Math.min(1, 0.35 + Math.abs(gap) / 4),
} as CSSProperties
}
>
<div className="gu-dial__bg" aria-hidden="true" />
<header className="gu-dial__top">
<div>
<p className="gu-dial__eyebrow">Home</p>
<h2 className="gu-dial__title" key={room.name}>
{room.name}
</h2>
</div>
<span className="gu-dial__chip">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M7 18h10a4 4 0 0 0 .6-8 5.5 5.5 0 0 0-10.7 1.4A3.3 3.3 0 0 0 7 18Z" />
</svg>
{outside}° outside
</span>
</header>
<div className="gu-dial__rooms" role="group" aria-label="Rooms">
{rooms.map((r, i) => (
<button
key={r.name}
type="button"
aria-pressed={i === at}
onClick={() => setAt(i)}
style={{ "--i": i } as CSSProperties}
>
{r.name}
<span>{r.current.toFixed(1)}°</span>
</button>
))}
</div>
<div
ref={dial}
className="gu-dial__dial"
data-turning={turning}
role="slider"
tabIndex={0}
aria-label={`${room.name} temperature`}
aria-valuemin={min}
aria-valuemax={max}
aria-valuenow={room.target}
aria-valuetext={`${room.target.toFixed(1)} degrees, room is ${room.current.toFixed(1)}`}
aria-disabled={off}
onKeyDown={off ? undefined : onKey}
onPointerDown={(e) => {
if (off) return;
e.currentTarget.setPointerCapture(e.pointerId);
setTurning(true);
fromPointer(e);
}}
onPointerMove={(e) => turning && fromPointer(e)}
onPointerUp={() => setTurning(false)}
onPointerCancel={() => setTurning(false)}
>
<svg viewBox="0 0 300 300" aria-hidden="true">
{Array.from({ length: TICKS + 1 }, (_, i) => {
const t = min + (i / TICKS) * range;
const deg = toDeg(t);
const [x1, y1] = polar(deg, 132);
const [x2, y2] = polar(deg, i % 6 === 0 ? 146 : 141);
const lit = !off && t >= lo - 0.01 && t <= hi + 0.01;
const w = Math.round((Math.abs(t - litFrom) / range) * TICKS);
return (
<line
key={i}
x1={x1}
y1={y1}
x2={x2}
y2={y2}
className="gu-dial__tick"
data-lit={lit}
style={{ "--t": i, "--w": w } as CSSProperties}
/>
);
})}
<circle className="gu-dial__face" cx={C} cy={C} r="114" />
<circle className="gu-dial__shine" cx={C} cy={C} r="113" />
{/* Knob and room dot live at the top of the dial and are rotated into place, so they travel along the arc. */}
<g
className="gu-dial__arm gu-dial__arm--now"
style={
{
"--deg": `${toDeg(Math.min(max, Math.max(min, room.current)))}deg`,
} as CSSProperties
}
>
<circle className="gu-dial__now" cx={C} cy={C - 104} r="4" />
</g>
<g
className="gu-dial__arm"
style={{ "--deg": `${toDeg(room.target)}deg` } as CSSProperties}
>
<circle
key={clicks}
className="gu-dial__click"
cx={C}
cy={C - 122}
r="11"
/>
<circle className="gu-dial__knob" cx={C} cy={C - 122} r="11" />
</g>
</svg>
<div className="gu-dial__read">
<span className="gu-dial__status" key={status}>
{status}
</span>
<span className="gu-dial__value" data-roll={roll}>
{off ? (
<span key="off">--</span>
) : (
<>
<span key={`${room.name}-${Math.floor(room.target)}`}>
{Math.floor(room.target)}
</span>
<small key={`${room.name}-${room.target % 1}`}>
{room.target % 1 ? ".5" : ""}°
</small>
</>
)}
</span>
<span className="gu-dial__current">
Now {room.current.toFixed(1)}°
</span>
</div>
</div>
<div className="gu-dial__modes" role="radiogroup" aria-label="Mode">
{MODES.map((m) => (
<button
key={m.id}
type="button"
role="radio"
aria-checked={mode === m.id}
onClick={() => setMode(m.id)}
>
{m.label}
</button>
))}
<span
className="gu-dial__mode-pill"
style={
{ "--m": MODES.findIndex((m) => m.id === mode) } as CSSProperties
}
aria-hidden="true"
/>
</div>
<div className="gu-dial__devices">
{(
[
["lights", "Lights", devices.lights ? "On · 60%" : "Off"],
["blinds", "Blinds", devices.blinds ? "Closed" : "Open"],
["fan", "Ceiling fan", devices.fan ? "On · low" : "Off"],
] as const
).map(([id, label, state], i) => (
<button
key={id}
type="button"
className="gu-dial__device"
aria-pressed={devices[id]}
style={{ "--i": i } as CSSProperties}
onClick={() => setDevices((d) => ({ ...d, [id]: !d[id] }))}
>
<span className="gu-dial__device-top">
<DeviceIcon id={id} />
<span className="gu-dial__switch" aria-hidden="true" />
</span>
<strong>{label}</strong>
<span key={state}>{state}</span>
</button>
))}
</div>
</div>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Smart home dial app
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
A smart home thermostat screen for phones. A big round dial sets the temperature of the selected room; you turn it by dragging your thumb around the ring. The screen glows in the colour of the mode, and the room temperature drifts towards the target live.
## Layout and look
- Fills its parent; warm near-black background #121110, translucent white tiles rgb(255 255 255 / 0.06), text #f5f1ea, muted #9b958c. Heat is orange #ff5a1f, cool is blue #5b8cff, off is grey #6c6862. System font.
- Safe areas: top padding = safe-area-inset-top + 10px, bottom = safe-area-inset-bottom + 12px.
- Header: "Home" (14px muted) above the room name (30px, weight 750), and a "6° outside" chip with a cloud icon on the right.
- Room chips: a sideways scrolling row of 52px tiles with the room name and its current temperature; the active one is filled cream.
- Dial: 300px circle. 55 tick marks around a 270° arc (gap at the bottom), every sixth one longer. Ticks between the current and target temperature are lit in the mode colour. A dark face with a soft drop shadow, a small grey dot for the room's temperature and a white knob with a glowing coloured ring for the target. In the middle: "Heating to" (mode colour), the target in 84px light numerals with a small ".5°", and "Now 19.4°".
- Background: a radial glow of the mode colour behind the dial; it gets stronger the further the room is from the target.
- Mode switch: Heat / Cool / Auto / Off in a pill track; the chosen one gets a tinted fill and a 1px ring in the mode colour.
- Device tiles at the bottom: Lights, Blinds, Ceiling fan, each a 96px tile with a small switch; on tiles turn cream.
## Behavior and motion
1. Pointer down on the dial captures the pointer; the angle around the centre (atan2) maps to a temperature in 0.5° steps. Dragging into the gap at the bottom snaps to the nearest end.
2. The knob grows from 11 to 14px while you turn it.
3. Every second each room moves 0.1° towards its target (Heat only warms, Cool only cools, Auto does both, Off does nothing).
4. Status reads "Heating to", "Cooling to", "Holding at" or "Off".
5. Each room keeps its own target.
Extra motion that makes it feel finished:
- Ticks fade in around the ring one after another when the screen opens.
- The knob and the room dot are drawn at the top of the dial and rotated into place, so they travel along the arc (spring easing). Every half-degree step sends a small ring out from the knob, and phones that support it give a 4ms vibration.
- The big number rolls up when you turn up and down when you turn down.
- While heating or cooling, a wave of brightness runs along the lit ticks towards the target, and the background glow breathes.
- The mode colour is a registered custom property, so the whole screen fades between orange, blue and grey over 0.8s. A tinted pill springs under the chosen mode.
- Device tiles: the bulb blooms a warm halo, the blind slats tilt shut one by one, the fan spins. Switch knobs stretch while pressed.
## Accessibility
- The dial is role="slider" with aria-valuemin/max/now and a valuetext like "21.5 degrees, room is 19.4". Arrow keys change it by 0.5°, Page Up/Down by 2°, Home/End jump to the ends.
- Modes are a radiogroup; room chips and device tiles use aria-pressed.
- prefers-reduced-motion: colours, ticks and switches change instantly.
## Props
rooms: { name, current, target }[], outside?: number, min?: number (10), max?: number (30)
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### HomeDial.tsx
```tsx
"use client";
import {
useEffect,
useRef,
useState,
type CSSProperties,
type KeyboardEvent,
type PointerEvent,
} from "react";
import "./home-dial.css";
export type Room = { name: string; current: number; target: number };
type Mode = "heat" | "cool" | "auto" | "off";
type Device = "lights" | "blinds" | "fan";
type HomeDialProps = {
rooms: Room[];
/** Temperature outside, shown as a chip. */
outside?: number;
min?: number;
max?: number;
};
const SWEEP = 270; // the dial runs from -135° to +135°, measured clockwise from the top
const TICKS = 54;
const C = 150; // centre of the 300 x 300 dial
const polar = (deg: number, r: number) => {
const a = (deg * Math.PI) / 180;
return [C + r * Math.sin(a), C - r * Math.cos(a)] as const;
};
const MODES: { id: Mode; label: string }[] = [
{ id: "heat", label: "Heat" },
{ id: "cool", label: "Cool" },
{ id: "auto", label: "Auto" },
{ id: "off", label: "Off" },
];
/** Small animated icons: the bulb glows, the blinds close slat by slat, the fan spins. */
function DeviceIcon({ id }: { id: Device }) {
if (id === "lights")
return (
<svg
viewBox="0 0 24 24"
className="gu-dial__icon gu-dial__icon--bulb"
aria-hidden="true"
>
<circle className="gu-dial__halo" cx="12" cy="10" r="9" />
<path d="M9 17h6M10 20h4M12 3a6 6 0 0 0-3.5 10.9c.6.5 1 1.2 1 2.1h5c0-.9.4-1.6 1-2.1A6 6 0 0 0 12 3Z" />
</svg>
);
if (id === "blinds")
return (
<svg
viewBox="0 0 24 24"
className="gu-dial__icon gu-dial__icon--blinds"
aria-hidden="true"
>
<path d="M4 4h16" />
{[0, 1, 2, 3].map((i) => (
<rect
key={i}
x="5"
y={6.5 + i * 3.6}
width="14"
height="2.2"
rx="1"
style={{ "--s": i } as CSSProperties}
/>
))}
</svg>
);
return (
<svg
viewBox="0 0 24 24"
className="gu-dial__icon gu-dial__icon--fan"
aria-hidden="true"
>
<g className="gu-dial__blades">
{[0, 120, 240].map((r) => (
<path
key={r}
d="M12 12c-1-4 0-7.5 2.5-8.5 1.8-.6 2.5 1.6 1.2 3.3L12 12Z"
transform={`rotate(${r} 12 12)`}
/>
))}
</g>
<circle cx="12" cy="12" r="1.6" />
</svg>
);
}
/**
* HomeDial: a thermostat screen with a dial you turn with a finger.
* - Drag anywhere on the ring (or use the arrow keys). The knob travels along the arc and clicks at every half degree.
* - The ticks between the room and the target light up, with a wave running towards the target while the room heats or cools.
* - The number rolls up or down, the screen glows and breathes in the mode's colour, and the colour itself fades between modes.
*/
export function HomeDial({
rooms: start,
outside = 7,
min = 10,
max = 30,
}: HomeDialProps) {
const [rooms, setRooms] = useState(start);
const [at, setAt] = useState(0);
const [mode, setMode] = useState<Mode>("heat");
const [devices, setDevices] = useState<Record<Device, boolean>>({
lights: true,
blinds: false,
fan: false,
});
const [turning, setTurning] = useState(false);
const [roll, setRoll] = useState<"up" | "down">("up");
const [clicks, setClicks] = useState(0);
const dial = useRef<HTMLDivElement>(null);
const room = rooms[at];
const range = max - min;
const toDeg = (t: number) => -SWEEP / 2 + ((t - min) / range) * SWEEP;
// The rooms slowly reach their targets: 0.1° every second, like a real house (only faster).
useEffect(() => {
if (mode === "off") return;
const id = window.setInterval(() => {
setRooms((rs) =>
rs.map((r) => {
const gap = r.target - r.current;
if (Math.abs(gap) < 0.05) return r;
if ((mode === "heat" && gap < 0) || (mode === "cool" && gap > 0))
return r;
return {
...r,
current: Math.round((r.current + Math.sign(gap) * 0.1) * 10) / 10,
};
}),
);
}, 1000);
return () => window.clearInterval(id);
}, [mode]);
const setTarget = (t: number) => {
const v = Math.min(max, Math.max(min, Math.round(t * 2) / 2));
if (v === room.target) return;
setRoll(v > room.target ? "up" : "down");
setClicks((c) => c + 1);
// A real detent: phones that can vibrate give a tiny tick.
if (turning && "vibrate" in navigator) navigator.vibrate?.(4);
setRooms((rs) => rs.map((r, i) => (i === at ? { ...r, target: v } : r)));
};
// Angle of the pointer around the centre, turned into a temperature.
const fromPointer = (e: PointerEvent<HTMLDivElement>) => {
const box = dial.current!.getBoundingClientRect();
const x = e.clientX - box.left - box.width / 2;
const y = e.clientY - box.top - box.height / 2;
let deg = (Math.atan2(x, -y) * 180) / Math.PI;
if (Math.abs(deg) > SWEEP / 2) deg = deg > 0 ? SWEEP / 2 : -SWEEP / 2; // the gap at the bottom snaps to the nearest end
setTarget(min + ((deg + SWEEP / 2) / SWEEP) * range);
};
const onKey = (e: KeyboardEvent<HTMLDivElement>) => {
const step: Record<string, number> = {
ArrowUp: 0.5,
ArrowRight: 0.5,
ArrowDown: -0.5,
ArrowLeft: -0.5,
PageUp: 2,
PageDown: -2,
};
if (e.key in step) setTarget(room.target + step[e.key]);
else if (e.key === "Home") setTarget(min);
else if (e.key === "End") setTarget(max);
else return;
e.preventDefault();
};
const off = mode === "off";
const gap = room.target - room.current;
const working =
!off &&
Math.abs(gap) >= 0.05 &&
!(mode === "heat" && gap < 0) &&
!(mode === "cool" && gap > 0);
const status = off
? "Off"
: !working
? "Holding at"
: gap > 0
? "Heating to"
: "Cooling to";
const tone = off
? "off"
: mode === "auto"
? gap < 0
? "cool"
: "heat"
: mode;
const lo = Math.min(room.current, room.target);
const hi = Math.max(room.current, room.target);
const litFrom = gap >= 0 ? lo : hi; // the wave starts at the room and runs to the target
return (
<div
className="gu-dial"
data-tone={tone}
data-working={working}
style={
{
"--glow": off ? 0 : Math.min(1, 0.35 + Math.abs(gap) / 4),
} as CSSProperties
}
>
<div className="gu-dial__bg" aria-hidden="true" />
<header className="gu-dial__top">
<div>
<p className="gu-dial__eyebrow">Home</p>
<h2 className="gu-dial__title" key={room.name}>
{room.name}
</h2>
</div>
<span className="gu-dial__chip">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M7 18h10a4 4 0 0 0 .6-8 5.5 5.5 0 0 0-10.7 1.4A3.3 3.3 0 0 0 7 18Z" />
</svg>
{outside}° outside
</span>
</header>
<div className="gu-dial__rooms" role="group" aria-label="Rooms">
{rooms.map((r, i) => (
<button
key={r.name}
type="button"
aria-pressed={i === at}
onClick={() => setAt(i)}
style={{ "--i": i } as CSSProperties}
>
{r.name}
<span>{r.current.toFixed(1)}°</span>
</button>
))}
</div>
<div
ref={dial}
className="gu-dial__dial"
data-turning={turning}
role="slider"
tabIndex={0}
aria-label={`${room.name} temperature`}
aria-valuemin={min}
aria-valuemax={max}
aria-valuenow={room.target}
aria-valuetext={`${room.target.toFixed(1)} degrees, room is ${room.current.toFixed(1)}`}
aria-disabled={off}
onKeyDown={off ? undefined : onKey}
onPointerDown={(e) => {
if (off) return;
e.currentTarget.setPointerCapture(e.pointerId);
setTurning(true);
fromPointer(e);
}}
onPointerMove={(e) => turning && fromPointer(e)}
onPointerUp={() => setTurning(false)}
onPointerCancel={() => setTurning(false)}
>
<svg viewBox="0 0 300 300" aria-hidden="true">
{Array.from({ length: TICKS + 1 }, (_, i) => {
const t = min + (i / TICKS) * range;
const deg = toDeg(t);
const [x1, y1] = polar(deg, 132);
const [x2, y2] = polar(deg, i % 6 === 0 ? 146 : 141);
const lit = !off && t >= lo - 0.01 && t <= hi + 0.01;
const w = Math.round((Math.abs(t - litFrom) / range) * TICKS);
return (
<line
key={i}
x1={x1}
y1={y1}
x2={x2}
y2={y2}
className="gu-dial__tick"
data-lit={lit}
style={{ "--t": i, "--w": w } as CSSProperties}
/>
);
})}
<circle className="gu-dial__face" cx={C} cy={C} r="114" />
<circle className="gu-dial__shine" cx={C} cy={C} r="113" />
{/* Knob and room dot live at the top of the dial and are rotated into place, so they travel along the arc. */}
<g
className="gu-dial__arm gu-dial__arm--now"
style={
{
"--deg": `${toDeg(Math.min(max, Math.max(min, room.current)))}deg`,
} as CSSProperties
}
>
<circle className="gu-dial__now" cx={C} cy={C - 104} r="4" />
</g>
<g
className="gu-dial__arm"
style={{ "--deg": `${toDeg(room.target)}deg` } as CSSProperties}
>
<circle
key={clicks}
className="gu-dial__click"
cx={C}
cy={C - 122}
r="11"
/>
<circle className="gu-dial__knob" cx={C} cy={C - 122} r="11" />
</g>
</svg>
<div className="gu-dial__read">
<span className="gu-dial__status" key={status}>
{status}
</span>
<span className="gu-dial__value" data-roll={roll}>
{off ? (
<span key="off">--</span>
) : (
<>
<span key={`${room.name}-${Math.floor(room.target)}`}>
{Math.floor(room.target)}
</span>
<small key={`${room.name}-${room.target % 1}`}>
{room.target % 1 ? ".5" : ""}°
</small>
</>
)}
</span>
<span className="gu-dial__current">
Now {room.current.toFixed(1)}°
</span>
</div>
</div>
<div className="gu-dial__modes" role="radiogroup" aria-label="Mode">
{MODES.map((m) => (
<button
key={m.id}
type="button"
role="radio"
aria-checked={mode === m.id}
onClick={() => setMode(m.id)}
>
{m.label}
</button>
))}
<span
className="gu-dial__mode-pill"
style={
{ "--m": MODES.findIndex((m) => m.id === mode) } as CSSProperties
}
aria-hidden="true"
/>
</div>
<div className="gu-dial__devices">
{(
[
["lights", "Lights", devices.lights ? "On · 60%" : "Off"],
["blinds", "Blinds", devices.blinds ? "Closed" : "Open"],
["fan", "Ceiling fan", devices.fan ? "On · low" : "Off"],
] as const
).map(([id, label, state], i) => (
<button
key={id}
type="button"
className="gu-dial__device"
aria-pressed={devices[id]}
style={{ "--i": i } as CSSProperties}
onClick={() => setDevices((d) => ({ ...d, [id]: !d[id] }))}
>
<span className="gu-dial__device-top">
<DeviceIcon id={id} />
<span className="gu-dial__switch" aria-hidden="true" />
</span>
<strong>{label}</strong>
<span key={state}>{state}</span>
</button>
))}
</div>
</div>
);
}
```
### home-dial.css
```css
/* HomeDial: a dark room lit by the thermostat. Orange heats, blue cools, grey is off. */
/* Registered so the whole screen fades between mode colours instead of snapping. */
@property --gu-dial-tone {
syntax: "<color>";
inherits: true;
initial-value: #ff5a1f;
}
.gu-dial {
--bg: #121110;
--card: rgb(255 255 255 / 0.06);
--text: #f5f1ea;
--muted: #9b958c;
--line: rgb(255 255 255 / 0.09);
--gu-dial-tone: #ff5a1f;
--tone: var(--gu-dial-tone);
--tone-soft: color-mix(in srgb, var(--gu-dial-tone) 16%, transparent);
--focus: #f5f1ea;
--ease: cubic-bezier(0.16, 1, 0.3, 1);
--spring: cubic-bezier(0.34, 1.45, 0.5, 1);
position: relative;
display: flex;
flex-direction: column;
height: 100%;
min-height: 640px;
overflow: hidden;
padding: calc(var(--gu-safe-top, env(safe-area-inset-top, 0px)) + 10px) 20px
calc(var(--gu-safe-bottom, env(safe-area-inset-bottom, 0px)) + 12px);
background: var(--bg);
color: var(--text);
font-family: -apple-system, "SF Pro Text", system-ui, sans-serif;
-webkit-font-smoothing: antialiased;
transition: --gu-dial-tone 0.8s ease;
}
.gu-dial[data-tone="cool"] {
--gu-dial-tone: #5b8cff;
}
.gu-dial[data-tone="off"] {
--gu-dial-tone: #6c6862;
}
.gu-dial button {
font: inherit;
color: inherit;
border: 0;
background: none;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
}
.gu-dial :focus-visible {
outline: 2px solid var(--focus);
outline-offset: 3px;
}
/* The room glows in the mode's colour, stronger when there is far to go, and breathes while working. */
.gu-dial__bg {
position: absolute;
inset: -10%;
background:
radial-gradient(circle at 50% 44%, var(--tone) 0, transparent 50%),
radial-gradient(circle at 50% 120%, var(--tone) 0, transparent 45%);
opacity: calc(var(--glow) * 0.32);
transition: opacity 0.8s;
pointer-events: none;
}
.gu-dial[data-working="true"] .gu-dial__bg {
animation: gu-dial-breathe 3.2s ease-in-out infinite;
}
@keyframes gu-dial-breathe {
50% {
opacity: calc(var(--glow) * 0.46);
scale: 1.06;
}
}
.gu-dial__top {
position: relative;
display: flex;
align-items: flex-start;
justify-content: space-between;
}
.gu-dial__eyebrow {
margin: 0;
font-size: 14px;
color: var(--muted);
}
.gu-dial__title {
margin: 2px 0 0;
font-size: 30px;
font-weight: 750;
letter-spacing: -0.03em;
animation: gu-dial-in 0.5s var(--ease) both;
}
@keyframes gu-dial-in {
from {
opacity: 0;
translate: 0 8px;
filter: blur(4px);
}
}
.gu-dial__chip {
display: inline-flex;
align-items: center;
gap: 6px;
margin-top: 6px;
padding: 8px 12px;
border-radius: 999px;
background: var(--card);
box-shadow: inset 0 0 0 1px var(--line);
font-size: 13px;
font-weight: 600;
}
.gu-dial__chip svg {
width: 16px;
height: 16px;
fill: none;
stroke: currentColor;
stroke-width: 1.8;
}
.gu-dial__rooms {
position: relative;
display: flex;
gap: 8px;
margin: 16px -20px 0;
padding: 0 20px;
overflow-x: auto;
scrollbar-width: none;
}
.gu-dial__rooms button {
display: grid;
flex-shrink: 0;
min-height: 52px;
padding: 7px 14px !important;
border-radius: 16px;
background: var(--card) !important;
box-shadow: inset 0 0 0 1px var(--line);
text-align: left;
font-size: 14px !important;
font-weight: 650 !important;
transition:
background-color 0.35s,
color 0.35s,
scale 0.25s var(--spring);
animation: gu-dial-in 0.5s var(--ease) both;
animation-delay: calc(var(--i) * 60ms + 100ms);
}
.gu-dial__rooms button:active {
scale: 0.94;
}
.gu-dial__rooms button span {
font-size: 12px;
font-weight: 500;
color: var(--muted);
font-variant-numeric: tabular-nums;
}
.gu-dial__rooms button[aria-pressed="true"] {
background: var(--text) !important;
color: var(--bg) !important;
}
.gu-dial__rooms button[aria-pressed="true"] span {
color: rgb(18 17 16 / 0.6);
}
/* The dial */
.gu-dial__dial {
position: relative;
width: 300px;
max-width: 100%;
aspect-ratio: 1;
margin: 18px auto 0;
border-radius: 50%;
touch-action: none;
cursor: grab;
-webkit-user-select: none;
user-select: none;
}
.gu-dial__dial[data-turning="true"] {
cursor: grabbing;
}
.gu-dial__dial[aria-disabled="true"] {
cursor: default;
}
.gu-dial__dial svg {
width: 100%;
height: 100%;
display: block;
overflow: visible;
}
/* Ticks sweep in around the ring when the screen opens. */
.gu-dial__tick {
stroke: rgb(255 255 255 / 0.16);
stroke-width: 2.5;
stroke-linecap: round;
transition: stroke 0.35s;
animation: gu-dial-tick-in 0.5s var(--ease) backwards;
animation-delay: calc(var(--t) * 12ms);
}
@keyframes gu-dial-tick-in {
from {
opacity: 0;
}
}
.gu-dial__tick[data-lit="true"] {
stroke: var(--tone);
}
/* While heating or cooling, a wave runs along the lit ticks towards the target. */
.gu-dial[data-working="true"] .gu-dial__tick[data-lit="true"] {
animation: gu-dial-wave 1.6s ease-in-out infinite;
animation-delay: calc(var(--w) * 70ms);
}
@keyframes gu-dial-wave {
0%,
100% {
opacity: 0.55;
}
30% {
opacity: 1;
stroke-width: 3.5;
}
}
.gu-dial__face {
fill: #1a1917;
stroke: var(--line);
stroke-width: 1;
filter: drop-shadow(0 18px 30px rgb(0 0 0 / 0.55));
}
/* A soft reflection on the face, like a glass cover. */
.gu-dial__shine {
fill: none;
stroke: rgb(255 255 255 / 0.07);
stroke-width: 1.5;
stroke-dasharray: 160 600;
stroke-dashoffset: -440;
}
.gu-dial__arm {
transform-box: view-box;
transform-origin: 150px 150px;
rotate: var(--deg);
transition: rotate 0.35s var(--spring);
}
.gu-dial__dial[data-turning="true"] .gu-dial__arm:not(.gu-dial__arm--now) {
transition-duration: 0.18s;
}
.gu-dial__arm--now {
transition: rotate 1s var(--ease);
}
.gu-dial__now {
fill: var(--muted);
}
.gu-dial__knob {
fill: var(--text);
stroke: var(--tone);
stroke-width: 4;
filter: drop-shadow(0 0 10px var(--tone));
transition: r 0.3s var(--spring);
}
.gu-dial__dial[data-turning="true"] .gu-dial__knob {
r: 14;
}
/* Each half-degree detent sends a small ring out from the knob. */
.gu-dial__click {
fill: none;
stroke: var(--tone);
stroke-width: 2;
opacity: 0;
transform-box: fill-box;
transform-origin: center;
animation: gu-dial-click 0.45s ease-out;
}
@keyframes gu-dial-click {
from {
opacity: 0.9;
scale: 1;
}
to {
opacity: 0;
scale: 2;
}
}
.gu-dial__read {
position: absolute;
inset: 0;
display: grid;
place-content: center;
justify-items: center;
pointer-events: none;
}
.gu-dial__status {
font-size: 14px;
font-weight: 600;
color: var(--tone);
animation: gu-dial-in 0.45s var(--ease) both;
}
/* The number rolls: up when you turn it up, down when you turn it down. */
.gu-dial__value {
display: flex;
align-items: flex-start;
height: 84px;
overflow: hidden;
font-size: 84px;
font-weight: 300;
letter-spacing: -0.05em;
line-height: 1;
font-variant-numeric: tabular-nums;
}
.gu-dial__value > * {
display: inline-block;
animation: gu-dial-roll-up 0.4s var(--ease) both;
}
.gu-dial__value[data-roll="down"] > * {
animation-name: gu-dial-roll-down;
}
@keyframes gu-dial-roll-up {
from {
translate: 0 60%;
opacity: 0;
filter: blur(3px);
}
}
@keyframes gu-dial-roll-down {
from {
translate: 0 -60%;
opacity: 0;
filter: blur(3px);
}
}
.gu-dial__value small {
margin-top: 10px;
font-size: 30px;
font-weight: 400;
letter-spacing: 0;
}
.gu-dial__current {
margin-top: 4px;
font-size: 14px;
color: var(--muted);
font-variant-numeric: tabular-nums;
}
/* Mode switch: a tinted pill slides under the chosen mode. */
.gu-dial__modes {
position: relative;
display: grid;
grid-template-columns: repeat(4, 1fr);
margin-top: 18px;
padding: 4px;
border-radius: 999px;
background: var(--card);
box-shadow: inset 0 0 0 1px var(--line);
}
.gu-dial__modes button {
position: relative;
z-index: 1;
min-height: 42px;
border-radius: 999px;
font-size: 14px !important;
font-weight: 650 !important;
color: var(--muted) !important;
transition: color 0.3s;
}
.gu-dial__modes button[aria-checked="true"] {
color: var(--text) !important;
}
.gu-dial__mode-pill {
position: absolute;
top: 4px;
bottom: 4px;
left: 4px;
width: calc((100% - 8px) / 4);
border-radius: 999px;
background: var(--tone-soft);
box-shadow:
inset 0 0 0 1px var(--tone),
0 0 18px -4px var(--tone);
translate: calc(var(--m) * 100%) 0;
transition: translate 0.55s var(--spring);
}
/* Devices */
.gu-dial__devices {
position: relative;
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-top: auto;
padding-top: 14px;
}
.gu-dial__device {
display: grid;
justify-items: start;
gap: 2px;
min-height: 104px;
padding: 12px !important;
border-radius: 20px;
background: var(--card) !important;
box-shadow: inset 0 0 0 1px var(--line);
text-align: left;
transition:
background-color 0.35s,
color 0.35s,
scale 0.25s var(--spring);
animation: gu-dial-in 0.6s var(--ease) both;
animation-delay: calc(var(--i) * 70ms + 250ms);
}
.gu-dial__device:active {
scale: 0.94;
}
.gu-dial__device-top {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
}
.gu-dial__device strong {
margin-top: auto;
font-size: 14px;
font-weight: 650;
}
.gu-dial__device > span:last-child {
font-size: 12px;
color: var(--muted);
animation: gu-dial-in 0.35s var(--ease) both;
}
.gu-dial__device[aria-pressed="true"] {
background: var(--text) !important;
color: var(--bg) !important;
}
.gu-dial__device[aria-pressed="true"] > span:last-child {
color: rgb(18 17 16 / 0.6);
}
.gu-dial__icon {
width: 24px;
height: 24px;
fill: none;
stroke: currentColor;
stroke-width: 1.7;
stroke-linecap: round;
stroke-linejoin: round;
overflow: visible;
}
/* Bulb: a warm halo blooms when on. */
.gu-dial__halo {
fill: #ffc85a;
stroke: none;
opacity: 0;
scale: 0.4;
transform-box: fill-box;
transform-origin: center;
filter: blur(3px);
transition:
opacity 0.4s,
scale 0.5s var(--spring);
}
.gu-dial__device[aria-pressed="true"] .gu-dial__halo {
opacity: 0.55;
scale: 1;
}
.gu-dial__device[aria-pressed="true"] .gu-dial__icon--bulb path {
fill: #ffd77a;
}
/* Blinds: slats tilt shut one after another. */
.gu-dial__icon--blinds rect {
fill: currentColor;
stroke: none;
transform-box: fill-box;
transform-origin: center;
scale: 1 0.35;
transition: scale 0.35s var(--ease);
transition-delay: calc(var(--s) * 60ms);
}
.gu-dial__device[aria-pressed="true"] .gu-dial__icon--blinds rect {
scale: 1 1;
}
/* Fan: spins up when on. */
.gu-dial__icon--fan path,
.gu-dial__icon--fan circle {
fill: currentColor;
stroke: none;
}
.gu-dial__blades {
transform-box: view-box;
transform-origin: 12px 12px;
}
.gu-dial__device[aria-pressed="true"] .gu-dial__blades {
animation: gu-dial-spin 1.1s linear infinite;
}
@keyframes gu-dial-spin {
to {
rotate: 360deg;
}
}
.gu-dial__switch {
position: relative;
width: 34px;
height: 20px;
border-radius: 999px;
background: rgb(255 255 255 / 0.16);
transition: background-color 0.3s;
}
.gu-dial__switch::after {
content: "";
position: absolute;
top: 2px;
left: 2px;
width: 16px;
height: 16px;
border-radius: 50%;
background: #fff;
box-shadow: 0 1px 3px rgb(0 0 0 / 0.3);
transition:
translate 0.4s var(--spring),
width 0.2s;
}
.gu-dial__device:active .gu-dial__switch::after {
width: 20px;
}
.gu-dial__device[aria-pressed="true"] .gu-dial__switch {
background: var(--tone);
}
.gu-dial__device[aria-pressed="true"] .gu-dial__switch::after {
translate: 14px 0;
}
.gu-dial__device[aria-pressed="true"]:active .gu-dial__switch::after {
translate: 10px 0;
}
@media (prefers-reduced-motion: reduce) {
.gu-dial,
.gu-dial *,
.gu-dial *::before,
.gu-dial *::after {
animation-duration: 0.01ms !important;
animation-delay: 0ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
.gu-dial__click {
display: none;
}
}
```
You might also want
Next piece: Split bills appLiquid glass tab bar app
Apps, advanced
Music player
Apps, advanced
Split bills app
Apps, intermediate