#200
Year toggle
A calendar heatmap with 2026 and 2025 buttons that swap the dataset and date range.
Hand this to your AI. It names the exact library parts, timings and accessibility promises of this demo.
Build the "Year toggle" pattern (@codeatlasdev/ui demo #200, charts/heatmap) in my app.
Call get_demo({ ids: ["#200"] }) first and keep its structure. It needs @codeatlasdev/[email protected] + echarts.
Use: Letting users compare activity across years in the same calendar view.
Keep these library parts, with the props and tokens the demo uses:
- Card, Flex, Button from "@codeatlasdev/ui"
- HeatmapChart, CalendarHeatmapPoint from "@codeatlasdev/ui/charts"
Behaviour to keep:
- `let year = $state<2025 | 2026>(2026)` selects the year
- Two `<Button` elements with `size="sm"` labelled 2026 and 2025, `variant={year === 2026 ? 'filled' : 'glass'}` and `variant={year === 2025 ? 'filled' : 'glass'}`
- `onclick={() => (year = 2026)}` and `onclick={() => (year = 2025)}`
- `data` holds `gen(2026, 258, 1.4)` and `gen(2025, 365, 2.1)`
- `<HeatmapChart variant="calendar" data={data[year]} range={ranges[year]}`
- `tooltipFormatter={(v) => `${v} commits`}` and `height="160px"`
Reduced motion: the demo handles it; keep that branch.
Keyboard: operable; keep the focus order and key handling.
Change only the copy and the data. Use the theme tokens (--ca-*), never raw colours. Library parts
- Card
@codeatlasdev/ui - Flex
@codeatlasdev/ui - Button
@codeatlasdev/ui - HeatmapChart
@codeatlasdev/ui/charts
How it is built
- `let year = $state<2025 | 2026>(2026)` selects the year
- Two `<Button` elements with `size="sm"` labelled 2026 and 2025, `variant={year === 2026 ? 'filled' : 'glass'}` and `variant={year === 2025 ? 'filled' : 'glass'}`
- `onclick={() => (year = 2026)}` and `onclick={() => (year = 2025)}`
- `data` holds `gen(2026, 258, 1.4)` and `gen(2025, 365, 2.1)`
- `<HeatmapChart variant="calendar" data={data[year]} range={ranges[year]}`
- `tooltipFormatter={(v) => `${v} commits`}` and `height="160px"`
Related
Loading source.