Activity rings
Three nested progress rings for daily goals that sweep to their value, overlap past 100% with a darker second lap, and let you log progress with a tap.
"use client";
import { useState, type CSSProperties } from "react";
import "./activity-rings.css";
type Goal = {
id: string;
label: string;
unit: string;
step: number;
goal: number;
color: string;
};
const GOALS: Goal[] = [
{
id: "move",
label: "Move",
unit: "kcal",
step: 60,
goal: 500,
color: "#ff5a1f",
},
{
id: "focus",
label: "Focus",
unit: "min",
step: 15,
goal: 120,
color: "#d7ff3a",
},
{
id: "water",
label: "Water",
unit: "glasses",
step: 1,
goal: 8,
color: "#2b35ff",
},
];
const R = [86, 62, 38]; // ring radii, outer to inner
const STROKE = 18;
/**
* ActivityRings
* - Each ring is a circle with pathLength=1, so dashoffset = 1 - progress (0–1) for the first lap.
* - Past 100% a second circle draws the overflow on top with a small shadow at its head.
*/
export function ActivityRings({
theme = "light",
}: {
theme?: "light" | "dark";
}) {
const [values, setValues] = useState<Record<string, number>>({
move: 380,
focus: 150,
water: 3,
});
return (
<div className="gu-rings" data-theme={theme}>
<svg
viewBox="0 0 200 200"
className="gu-rings__svg"
role="img"
aria-label={GOALS.map(
(g) => `${g.label} ${Math.round((values[g.id] / g.goal) * 100)}%`,
).join(", ")}
>
{GOALS.map((g, i) => {
const p = values[g.id] / g.goal;
return (
<g
key={g.id}
style={{ "--c": g.color } as CSSProperties}
transform="rotate(-90 100 100)"
>
<circle
cx="100"
cy="100"
r={R[i]}
className="gu-rings__track"
strokeWidth={STROKE}
/>
<circle
cx="100"
cy="100"
r={R[i]}
className="gu-rings__fill"
strokeWidth={STROKE}
pathLength={1}
style={{ "--p": Math.min(1, p) } as CSSProperties}
/>
{p > 1 && (
<circle
cx="100"
cy="100"
r={R[i]}
className="gu-rings__lap"
strokeWidth={STROKE}
pathLength={1}
style={{ "--p": Math.min(1, p - 1) } as CSSProperties}
/>
)}
</g>
);
})}
</svg>
<ul className="gu-rings__list">
{GOALS.map((g) => {
const v = values[g.id];
const change = (d: number) =>
setValues((x) => ({ ...x, [g.id]: Math.max(0, x[g.id] + d) }));
return (
<li key={g.id} style={{ "--c": g.color } as CSSProperties}>
<span className="gu-rings__dot" aria-hidden="true" />
<span className="gu-rings__text">
<b>{g.label}</b>
<small>
<span className="gu-rings__num">{v}</span> / {g.goal} {g.unit}
{v >= g.goal && <em> · Goal met</em>}
</small>
</span>
<span className="gu-rings__btns">
<button
type="button"
onClick={() => change(-g.step)}
aria-label={`Remove ${g.step} ${g.unit} from ${g.label}`}
disabled={v === 0}
>
−
</button>
<button
type="button"
onClick={() => change(g.step)}
aria-label={`Add ${g.step} ${g.unit} to ${g.label}`}
>
+
</button>
</span>
</li>
);
})}
</ul>
</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: Activity rings
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 daily goals widget with three nested progress rings (Move, Focus, Water) and a list where you can add or remove progress. Rings sweep in on load, animate to new values and draw a darker second lap when a goal passes 100%.
## Layout and look
- Card 620px max, radius 32px, Ink background in dark mode (default) and card Cream with a border in light mode. Rings on the left (220px), list on the right; stacked under 540px.
- Rings: radii 86/62/38 in a 200 viewBox, 18px stroke, round caps, starting at 12 o'clock. Colors: orange #ff5a1f, lime #d7ff3a, blue #2b35ff; tracks are the same color at 18% opacity.
- List rows: 12px color dot, name, "380 / 500 kcal" (value bold, tabular), "· Goal met" when reached, and two 44px rounded −/+ buttons that tint with the ring color on hover.
## Behavior and motion
1. Each ring uses pathLength=1, dasharray 1, dashoffset 1 − min(1, p).
2. Overflow: a second circle with dashoffset 1 − (p − 1), slightly darker with a drop shadow.
3. Initial sweep from empty (1.4s) and transitions on change (1.1s cubic-bezier(0.16, 1, 0.3, 1)).
## Accessibility
- The SVG is role="img" with a label like "Move 76%, Focus 125%, Water 38%". Buttons say "Add 60 kcal to Move".
- prefers-reduced-motion: no sweeping.
## Props
theme. Edit GOALS (colors, steps, units) and initial values.
## 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.
### ActivityRings.tsx
```tsx
"use client";
import { useState, type CSSProperties } from "react";
import "./activity-rings.css";
type Goal = {
id: string;
label: string;
unit: string;
step: number;
goal: number;
color: string;
};
const GOALS: Goal[] = [
{
id: "move",
label: "Move",
unit: "kcal",
step: 60,
goal: 500,
color: "#ff5a1f",
},
{
id: "focus",
label: "Focus",
unit: "min",
step: 15,
goal: 120,
color: "#d7ff3a",
},
{
id: "water",
label: "Water",
unit: "glasses",
step: 1,
goal: 8,
color: "#2b35ff",
},
];
const R = [86, 62, 38]; // ring radii, outer to inner
const STROKE = 18;
/**
* ActivityRings
* - Each ring is a circle with pathLength=1, so dashoffset = 1 - progress (0–1) for the first lap.
* - Past 100% a second circle draws the overflow on top with a small shadow at its head.
*/
export function ActivityRings({
theme = "light",
}: {
theme?: "light" | "dark";
}) {
const [values, setValues] = useState<Record<string, number>>({
move: 380,
focus: 150,
water: 3,
});
return (
<div className="gu-rings" data-theme={theme}>
<svg
viewBox="0 0 200 200"
className="gu-rings__svg"
role="img"
aria-label={GOALS.map(
(g) => `${g.label} ${Math.round((values[g.id] / g.goal) * 100)}%`,
).join(", ")}
>
{GOALS.map((g, i) => {
const p = values[g.id] / g.goal;
return (
<g
key={g.id}
style={{ "--c": g.color } as CSSProperties}
transform="rotate(-90 100 100)"
>
<circle
cx="100"
cy="100"
r={R[i]}
className="gu-rings__track"
strokeWidth={STROKE}
/>
<circle
cx="100"
cy="100"
r={R[i]}
className="gu-rings__fill"
strokeWidth={STROKE}
pathLength={1}
style={{ "--p": Math.min(1, p) } as CSSProperties}
/>
{p > 1 && (
<circle
cx="100"
cy="100"
r={R[i]}
className="gu-rings__lap"
strokeWidth={STROKE}
pathLength={1}
style={{ "--p": Math.min(1, p - 1) } as CSSProperties}
/>
)}
</g>
);
})}
</svg>
<ul className="gu-rings__list">
{GOALS.map((g) => {
const v = values[g.id];
const change = (d: number) =>
setValues((x) => ({ ...x, [g.id]: Math.max(0, x[g.id] + d) }));
return (
<li key={g.id} style={{ "--c": g.color } as CSSProperties}>
<span className="gu-rings__dot" aria-hidden="true" />
<span className="gu-rings__text">
<b>{g.label}</b>
<small>
<span className="gu-rings__num">{v}</span> / {g.goal} {g.unit}
{v >= g.goal && <em> · Goal met</em>}
</small>
</span>
<span className="gu-rings__btns">
<button
type="button"
onClick={() => change(-g.step)}
aria-label={`Remove ${g.step} ${g.unit} from ${g.label}`}
disabled={v === 0}
>
−
</button>
<button
type="button"
onClick={() => change(g.step)}
aria-label={`Add ${g.step} ${g.unit} to ${g.label}`}
>
+
</button>
</span>
</li>
);
})}
</ul>
</div>
);
}
```
### activity-rings.css
```css
/* ActivityRings: change these colors to match your brand (ring colors live in GOALS). */
.gu-rings {
--card: #0e0e10;
--text: #f3eee3;
--muted: #aea89c;
--line: rgb(243 238 227 / 0.12);
--focus: #d7ff3a;
--ease: cubic-bezier(0.16, 1, 0.3, 1);
container-type: inline-size;
display: grid;
grid-template-columns: 220px 1fr;
align-items: center;
gap: 28px;
width: min(100%, 620px);
padding: 28px;
border-radius: 32px;
background: var(--card);
color: var(--text);
font-family: system-ui, sans-serif;
}
.gu-rings[data-theme="light"] {
--card: #fbf8f2;
--text: #0e0e10;
--muted: #57534b;
--line: rgb(14 14 16 / 0.1);
--focus: #2b35ff;
border: 1px solid var(--line);
}
.gu-rings__svg {
width: 100%;
overflow: visible;
}
.gu-rings__svg circle {
fill: none;
stroke-linecap: round;
}
.gu-rings__track {
stroke: var(--c);
opacity: 0.18;
}
.gu-rings__fill,
.gu-rings__lap {
stroke: var(--c);
stroke-dasharray: 1;
stroke-dashoffset: calc(1 - var(--p));
transition: stroke-dashoffset 1.1s var(--ease);
animation: gu-rings-sweep 1.4s var(--ease);
}
/* Second lap is slightly darker with a shadow so the overlap reads */
.gu-rings__lap {
filter: brightness(0.82) drop-shadow(0 0 3px rgb(0 0 0 / 0.45));
}
@keyframes gu-rings-sweep {
from {
stroke-dashoffset: 1;
}
}
.gu-rings__list {
display: grid;
gap: 10px;
margin: 0;
padding: 0;
list-style: none;
}
.gu-rings__list li {
display: grid;
grid-template-columns: 12px 1fr auto;
align-items: center;
gap: 12px;
padding: 10px 6px 10px 14px;
border: 1px solid var(--line);
border-radius: 18px;
}
.gu-rings__dot {
width: 12px;
height: 12px;
border-radius: 50%;
background: var(--c);
}
.gu-rings__text {
display: grid;
}
.gu-rings__text small {
color: var(--muted);
font-variant-numeric: tabular-nums;
}
.gu-rings__num {
color: var(--text);
font-weight: 800;
}
.gu-rings__text em {
color: var(--text);
font-style: normal;
font-weight: 700;
}
.gu-rings__btns {
display: flex;
gap: 4px;
}
.gu-rings__btns button {
width: 44px;
height: 44px;
border: 0;
border-radius: 14px;
background: var(--line);
color: inherit;
font: inherit;
font-size: 1.2rem;
font-weight: 800;
cursor: pointer;
transition:
background-color 0.2s,
transform 0.15s;
}
.gu-rings__btns button:hover {
background: color-mix(in srgb, var(--c) 30%, transparent);
}
.gu-rings__btns button:active {
transform: scale(0.92);
}
.gu-rings__btns button:disabled {
opacity: 0.35;
cursor: not-allowed;
}
.gu-rings__btns button:focus-visible {
outline: 3px solid var(--focus);
outline-offset: 2px;
}
@container (max-width: 540px) {
/* The root is the container, so it cannot query itself: its children span the full row instead */
.gu-rings > * {
grid-column: 1 / -1;
justify-self: center;
}
.gu-rings__svg {
width: 200px;
}
.gu-rings__list {
width: 100%;
}
}
@media (prefers-reduced-motion: reduce) {
.gu-rings__fill,
.gu-rings__lap {
transition: none;
animation: none;
}
}
```
You might also want
Next piece: Agency page with stacking casesStat cards with sparklines
Components, intermediate
Activity heatmap
Components, intermediate
Cart drawer
Components, advanced