仕組み
An HTML grid rather than SVG, so cells and dots are plain elements placed by grid row and column. The calendar fits as many weeks as the width allows (a ResizeObserver measures it), keeps the last day in the last column and labels months only where they fit. Colours come from --ds-chart-seq-* in four steps over a neutral track, so dark mode flips the ramp with the tokens. Dots are 8px, neutral when empty and the category colour when filled. Both shapes pop in by column with transform and opacity only; new data recolours cells in place.
向いている場面
- A habit or streak over months: reading, workouts, commits, days a shop was open.
- Spotting weekday patterns, such as quiet weekends or busy Mondays.
- Dots: what happened when over a few days, by category, beside one headline number.
向かない場面
- Exact daily values that people need to compare: use a bar or line chart.
- A few weeks of data: the grid looks empty; use a column chart.
- Dots with many categories: more than three or four colours stop reading at a glance.
使い方
import { HeatmapCalendar } from './HeatmapCalendar.jsx'
// One entry per day: { date: 'YYYY-MM-DD', value: number }
export function ReadingCard({ days }) {
return (
<HeatmapCalendar
title="Reading"
subtitle="Last 24 weeks"
onOpen={() => {}}
caption="Current streak"
value={12}
unit="days"
data={days}
endDate="2026-11-17"
formatValue={(n) => n + ' min'}
/>
)
}
export function ActivityCard() {
return (
<HeatmapCalendar
variant="dots"
title="Activity"
chip={{ label: 'Goal', value: 2500 }}
value={1648}
unit="kcal"
caption="Avg on recent days"
categories={[
{ name: 'Run', color: 5 },
{ name: 'Cycle', color: 4 },
{ name: 'Yoga', color: 6 },
]}
rowLabels={['6 am', '12 pm', '6 pm']}
dots={[
{ label: 'Mon', values: [0, null, 2] },
{ label: 'Tue', values: [null, 1, null] },
{ label: 'Wed', values: [2, null, 0] },
]}
/>
)
}プロパティ
| プロパティ | 型 | 既定値 | 説明 |
|---|---|---|---|
variant | 'calendar' | 'dots' | 'calendar' | calendar draws one cell per day on a ramp; dots draws a days-by-slots matrix coloured by category beside the hero. |
data | { date: string | Date, value: number }[] | — | Calendar: values by day (YYYY-MM-DD). Several entries for one day add up; days with no entry show as no data. |
endDate | string | Date | — | Calendar: the last day, in the last column. Defaults to the latest date in data. |
weeks | number | — | Calendar: number of week columns. By default as many as the data needs and the width allows. |
cellSize / gap | number | 14 / 3 | Calendar: cell size and gap in px. Corners are 30% of the cell. |
levels | number[] | — | Calendar: three thresholds between the four colour steps. By default quarters of the largest visible value. |
weekStart | 0 | 1 | 1 | Calendar: first row of each column. 1 is Monday, 0 is Sunday. |
showWeekdays / showLegend | boolean | true | Calendar: weekday labels on the left; the Less to More legend, whose steps isolate their cells on hover. |
dots | { label: string, values: (number | null)[] }[] | — | Dots: one column each, such as a day. values holds one category index per row, or null for a neutral dot. |
categories | { name: string, color?: number | string }[] | — | Dots: the categories, listed beside the hero with their colours (1–8 for --ds-chart-N or a CSS colour). |
rowLabels | string[] | — | Dots: names of the rows, such as time slots, used in the tooltip and for screen readers. |
chip | { label: string, value: number | string } | — | Dots: a small chip above the hero, such as a goal. A number counts up. |
title / subtitle / icon | ReactNode | — | Card header: a tinted icon tile, a 15px title and a quieter subtitle after it. |
onOpen / action | () => void / ReactNode | — | onOpen adds a chevron button at the end of the header. action replaces it with any node. |
caption / value / unit | string / number | string / string | — | Hero: a small caption, a big value that counts up, and its unit. |
delta | { value: number, label?: string, positive?: 'up' | 'down', format?: (n) => string } | — | Change badge after the hero. |
color | number | string | 1 | Accent for the icon tile and the chip value. Calendar cells always use the --ds-chart-seq ramp. |
formatValue / formatHero | (n: number) => string | (n) => n.toLocaleString('en-US') | formatValue formats day values (tooltip, table); formatHero formats the hero and chip, which often have a different unit. |
label | string | — | Accessible name of the grid and caption of the hidden table. Defaults to the title. |
labels | object | — | Replaces built-in text: weekdays, months, day(month, date, weekday), noData, none, open, plot(label, from, to), dotsPlot(label, cols, rows), dot(column, row, category), less, more, tableCaption, colDate, colValue. |
replayKey | string | number | — | Change it to play the entrance again. A different date range or matrix size also replays it; new values recolour in place. |
className / style / ...rest | HTMLAttributes | — | Passed to the card root, which fills its container width. |
アクセシビリティ
- The grid is a focusable group with a name that says how to move. In the calendar Up and Down step one day and Left and Right one week; in the dots matrix the arrows move by row and column. Home and End jump to the ends and Escape hides the tooltip.
- Each move is announced through a polite live region with the date or slot and its value or category.
- A visually hidden table lists every day (calendar) or every slot (dots); the cells themselves are hidden from screen readers.
- The ramp runs light to dark and the legend names its ends, so levels are not told apart by hue alone.
- Reduced motion shows every cell at once and the numbers do not count.
モーション
Entrance waits until 30% of the card is visible. Calendar cells pop on a spring (560ms) column by column, 22ms apart; dots pop 45ms apart; legend steps follow from 420ms. The hero and chip count over 900ms on cubic-bezier(0.22, 1, 0.36, 1) and side text rises 60ms apart. Hover rings a cell or enlarges a dot in 160ms and the tooltip follows in the same 160ms.
プロジェクトに追加
Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。
HeatmapCalendar.jsxheatmap-calendar.csstokens.cssREADME.md
2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。



