# Calendar Heatmap (/docs/calendar-heatmap)





`CalendarHeatmap` shows anything counted per day over a long window: attendance, commits, exercises submitted. Hand it a list of `{ date, value }` and it lays out the year ending today.

```tsx
import { CalendarHeatmap } from '@42-central/ui-react/calendar-heatmap';

<CalendarHeatmap data={[{ date: new Date(), value: 3 }]} color="green" />
```

Entries on the same day add up, so a raw event list works as well as daily totals: `events.map((e) => ({ date: e.createdAt, value: 1 }))`.

<Preview code="&#x22;<Card>\n  <Card.Header>\n    <Card.Title>{total} activities in the last year</Card.Title>\n  </Card.Header>\n  <Card.Content>\n    <CalendarHeatmap data={data} color=\&#x22;brand\&#x22; />\n  </Card.Content>\n</Card>&#x22;">
  <CalendarHeatmapDemo />
</Preview>

Like every chart in the kit, it belongs inside a [`Card`](/docs/card): it has no surface of its own. The squares keep their size, whatever the container: when the weeks don't fit, they scroll sideways and open on the latest week, while the weekday labels stay pinned beside them. That is what makes it work on a phone, and at any range length.

## Colors [#colors]

The ramp is the palette's solid color at four strengths, so every `color`, custom palettes included, makes its own ramp. Without `color` it inherits the nearest `data-color`, like every colored component.

<Preview code="&#x22;<CalendarHeatmap data={data} color=\&#x22;green\&#x22; />\n<CalendarHeatmap data={data} color=\&#x22;blue\&#x22; />\n<CalendarHeatmap data={data} color=\&#x22;orange\&#x22; />\n<CalendarHeatmap data={data} color=\&#x22;neutral\&#x22; />&#x22;">
  <CalendarHeatmapColorsDemo />
</Preview>

## Levels [#levels]

By default the busiest day is split into quarters, the way GitHub does it. Pass `thresholds` to fix the levels yourself: each number is the lowest value of a level, so `[1, 3, 6, 10]` reads 1–2, 3–5, 6–9 and 10+. One to four of them, never more, since a reader can't rank more than four shades. With fewer, they spread across the ramp and the busiest level is always the full color.

Counts are whole numbers, so the default levels are too. Data on another scale (hours, a score) should pass its own `thresholds`.

<Preview code="&#x22;<CalendarHeatmap data={data} color=\&#x22;green\&#x22; thresholds={[1, 10]} />\n<CalendarHeatmap data={data} color=\&#x22;green\&#x22; thresholds={[1, 3, 6, 10]} />&#x22;">
  <CalendarHeatmapThresholdsDemo />
</Preview>

## Range and week start [#range-and-week-start]

`range` sets the first and last day shown, both included. Weeks start on the locale's first day of the week; `startOfWeek` overrides it.

<Preview code="&#x22;<CalendarHeatmap\n  data={data}\n  range={{ start: new Date(2026, 7, 1), end: new Date(2026, 9, 31) }}\n  startOfWeek=\&#x22;mon\&#x22;\n  color=\&#x22;blue\&#x22;\n/>&#x22;">
  <CalendarHeatmapRangeDemo />
</Preview>

## Long ranges [#long-ranges]

Any length works, since the weeks scroll rather than shrink. Here, three years:

<Preview code="&#x22;<CalendarHeatmap\n  data={data}\n  range={{ start: threeYearsAgo, end: today }}\n  color=\&#x22;green\&#x22;\n/>&#x22;">
  <CalendarHeatmapLongRangeDemo />
</Preview>

## Size [#size]

The squares follow Figma's 12px cell and 4px gap, set as the custom properties `--cell` and `--gap`. Override them from `className` to resize the whole heatmap, legend included.

<Preview code="&#x22;<CalendarHeatmap data={data} className=\&#x22;[--cell:0.5rem] [--gap:2px]\&#x22; />\n<CalendarHeatmap data={data} className=\&#x22;[--cell:1rem] [--gap:0.25rem]\&#x22; />&#x22;">
  <CalendarHeatmapSizeDemo />
</Preview>

## Locale, time zone and direction [#locale-time-zone-and-direction]

Dates, weekday and month names, and numbers all come from `Intl` in the resolved locale: the component's `locale` prop, else [`IntlProvider`](/docs/internationalization)'s. Each `Date` in `data` is counted on its day in the resolved `timeZone`, so an event at 23:30 in Paris lands on the Paris day, whatever the visitor's own zone.

The only words `Intl` can't produce are in `translations`. `day` is the sentence that names a day, written as one function so the translation keeps its own word order. Under an RTL locale the weeks run right to left and the arrow keys follow.

<Preview code="&#x22;<IntlProvider locale=\&#x22;fr-FR\&#x22;>\n  <CalendarHeatmap\n    data={data}\n    translations={{\n      label: 'Activité',\n      day: ({ value, formattedValue, formattedDate }) =>\n        value === 0\n          ? `Aucune activité le ${formattedDate}`\n          : `${formattedValue} activité${value > 1 ? 's' : ''} le ${formattedDate}`,\n      less: 'Moins',\n      more: 'Plus',\n    }}\n  />\n</IntlProvider>&#x22;">
  <CalendarHeatmapLocaleDemo />
</Preview>

## Clickable days [#clickable-days]

With `onDayClick`, days activate by click, `Enter` or `Space`, and the callback gets the day's midnight (in the heatmap's time zone) and its total.

<Preview code="&#x22;<CalendarHeatmap\n  data={data}\n  onDayClick={(date, value) => setPicked({ date, value })}\n/>&#x22;">
  <CalendarHeatmapClickDemo />
</Preview>

## API [#api]

<TypeTable
  type="{
  data: { type: '{ date: Date; value: number }[]', description: 'One entry per day or per event. Same-day entries add up.', required: true },
  range: { type: '{ start: Date; end: Date }', default: 'the year ending today', description: 'First and last day shown, both included.' },
  color: { type: 'Color', description: &#x22;The ramp's palette. Inherits the nearest data-color when omitted.&#x22; },
  thresholds: { type: '[number] … [number, number, number, number]', default: 'the busiest day in quarters', description: 'Lowest value of levels 1 to 4, ascending.' },
  startOfWeek: { type: '&#x22;sun&#x22; | &#x22;mon&#x22; | … | &#x22;sat&#x22;', default: &#x22;the locale's&#x22;, description: 'The day each column starts on.' },
  locale: { type: 'string | &#x22;auto&#x22;', description: &#x22;Overrides IntlProvider's locale.&#x22; },
  timeZone: { type: 'string | &#x22;auto&#x22;', description: &#x22;The zone data is counted in. Overrides IntlProvider's.&#x22; },
  onDayClick: { type: '(date: Date, value: number) => void', description: 'Makes days activatable by click, Enter or Space.' },
  translations: { type: 'Partial<CalendarHeatmapTranslations>', description: '`label` (the grid\'s name), `day` (a day\'s sentence), `less`, `more`. English by default, exported as CALENDAR_HEATMAP_DEFAULT_TRANSLATIONS.' },
  className: { type: 'string', description: 'Root classes. Set `[--cell:…]` and `[--gap:…]` here to resize the squares (default 12px and 4px).' },
  classNames: { type: '{ grid?, cell?, legend?, tooltip? }', description: 'Per-part class overrides.' },
  testId: { type: 'string', description: 'data-testid on the root. Each day already carries data-date=&#x22;YYYY-MM-DD&#x22; and data-level.' },
}"
/>

## Accessibility [#accessibility]

* A real `role="grid"`, named by `translations.label`, with a single tab stop on the latest day.
  `←`/`→` move a week (mirrored in RTL), `↑`/`↓` a day, `Home`/`End` go along the row,
  `Ctrl`+`Home`/`End` to the first and last day, and `PageUp`/`PageDown` a month.
* Every day names itself in full: "3 activities on Monday, October 26, 2026". Each row has a
  header with the full weekday name. The visible weekday and month labels are decorative, since
  each day already says its date.
* Moving focus to a day scrolls it into view, with room for its focus ring.
* One shared tooltip follows hover and focus, and `Esc` dismisses it. It repeats the focused
  day's name, so it is hidden from assistive technology rather than read twice.
* Color is never the only channel: the exact value is in every day's name and tooltip, the legend
  is always shown with each level's range, and in forced-colors mode the level is drawn as a
  square that grows with it.
