# Steps chart

> A week against a daily goal: days that make it fill in, a wave runs the way you step through the weeks, the totals roll.

Fitness and habit cards usually redraw the whole week when you go back one. Here the seven days stay put and change: step to last week and each day eases to its new height in a wave that runs the way you went, days that reached the goal turn your primary colour, and the total, the daily average and "goal met on 4 of 7 days" all roll to their new figures while the week’s name morphs between the arrows. The goal is a line across the chart in your primary colour, a day still under way is drawn as an outline holding its fill so far, and the first time the card scrolls into view the days grow out of the baseline one after another. Point at a day and a hairline column follows you with a readout riding its top.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/steps-chart.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: none
- Hairline UI components it needs (the CLI installs them too): `number-roll`, `text-morph`
- Docs and live preview: https://hairlineui.com/ui/steps-chart
- Registry item (source): https://hairlineui.com/r/steps-chart.json

## Usage

```tsx
import { StepsChart } from "@/components/steps-chart";

<StepsChart
  goal={10000}
  weeks={[
    { id: "w40", label: "Last week", days: lastWeek },
    { id: "w41", label: "This week", days: thisWeek }, // { key: "fri", label: "Fri", value: 6180, today: true }
  ]}
/>
```

## From a health or habit API

Bucket the samples by day on the server, key each day by its weekday so it keeps its bar from week to week, and mark today as under way.

```tsx
import { StepsChart, type StepsWeek } from "@/components/steps-chart";
import { getDailySteps } from "@/lib/health";

const KEYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];

export async function StepsCard({ userId }: { userId: string }) {
  const weeks = await getDailySteps(userId, { weeks: 4 }); // [{ start: "2026-10-05", days: [11320, 8760, …] }]
  const today = new Date().toISOString().slice(0, 10);
  const data: StepsWeek[] = weeks.map((w, i) => ({
    id: w.start,
    label: i === weeks.length - 1 ? "This week" : i === weeks.length - 2 ? "Last week" : w.start,
    days: KEYS.map((key, d) => {
      const date = new Date(w.start);
      date.setDate(date.getDate() + d);
      return {
        key,
        label: date.toLocaleDateString("en-GB", { weekday: "short" }),
        title: date.toLocaleDateString("en-GB", { weekday: "long", day: "numeric", month: "long" }),
        value: w.days[d] ?? 0,
        today: date.toISOString().slice(0, 10) === today,
      };
    }),
  }));
  return <StepsChart weeks={data} goal={10000} />;
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `weeks` | `StepsWeek[]` | – | Oldest first, each with id, label and seven days ({ key, label, value, title?, today? }). It opens on the last. |
| `goal` | `number` | `10000` | Steps a day; the goal line and the colour of the days that reach it. |
| `value / defaultValue` | `string` | `the last week` | The week on show, by id; controlled or not. |
| `onValueChange` | `(id: string) => void` | – | Called when the week changes. |
| `title` | `string` | `"Steps"` | Above the total. |
| `locales` | `string \| string[]` | – | For number formatting. |

## States

- **arrive**: In view for the first time, each day grows from the baseline (620ms, 34ms apart) and the total rolls up from zero.
- **week**: ‹ and › step through the weeks; the label morphs, rising from below going forward and dropping from above going back. Days ease to their new heights in a wave from the side you moved toward; the total, average and days met roll. The arrows fade at the first and last week.
- **goal**: A line in your primary colour at the goal, with its figure in the scale. Days at or over it are filled with your primary colour; a day still under way is a primary outline with a light fill.
- **hover**: A hairline column glides to the day under the pointer (380ms, slight overshoot) and the readout at its top slides along, the date morphing and the steps rolling. On touch, tap or drag across the days.

## What it handles

Fitness and habit cards usually redraw the whole week when you go back one. Here the seven days stay put and change, so people can see how this week compares with the last.

- **Step through the weeks**: The arrows move between weeks. The days ease to their new heights in a wave that runs the way you went, and the week’s name morphs.
- **A daily goal line**: Days at or over the goal are filled with your primary colour, and the goal is a line across the chart.
- **Totals that roll**: The total, the daily average and “goal met on 4 of 7 days” all roll to their new figures.
- **Today in progress**: A day still under way is drawn as an outline holding its fill so far.
- **One scale across weeks**: The scale is set by the busiest week, so a bar’s height means the same thing in every week.
- **Readout and accessibility**: A readout follows the pointer or a touch drag. Arrow keys read each day, and every day is also in a hidden table.

## Replaces

a chart library, week navigation, goal line logic, a hover readout, weekly totals and averages

## Where it fits

- **Fitness and health apps**: Steps or workouts for the week against a daily goal.
- **Habit trackers**: Water, reading minutes or sleep, with the days that hit the target marked.
- **Wellbeing challenges**: A weekly view for a team or a community challenge.
- **Usage against a daily limit**: API calls or messages per day against a quota.

## Notes

- The arrows are buttons labelled "Previous week" and "Next week"; at either end they are aria-disabled, so focus stays on them. The week’s name is announced when it changes.
- The plot is one tab stop: arrow keys, Home and End move the readout between days and it is announced politely, saying when the goal was met.
- The scale holds still across weeks (set by the busiest one), so a bar’s height means the same in every week.
- Every day is in a visually hidden table with the week’s total and the days met in its caption.
- Installs Number roll and Text morph. With reduced motion every change happens in place.

License: MIT (https://hairlineui.com/license#components)
