This release is a major version bump with breaking API changes aimed at simplifying i18n and making accessibility the default.
-
weekStartnow uses strings- v1:
weekStart(0)orweekStart(1) - v2:
weekStart('sunday')orweekStart('monday')
- v1:
-
tooltipUnitremoved- Replace with
formatters.tooltip(date, count)
- Replace with
-
localeremoved- Replace with
formatters.dayLabel,formatters.monthLabel, andformatters.legend
- Replace with
-
ariaLabelForDateremoved- Replace with
formatters.ariaLabel(date, count)
- Replace with
-
accessibilityEnabledremoved- Accessibility is always on.
- You can still disable the hidden table via
accessibilityTable(false).
-
Dependencies
@goujon/calendar-heatmapnow bundles d3.@goujon/react-calendar-heatmapdepends on@goujon/calendar-heatmap, so users only install the React package.
| v1 | v2 |
|---|---|
| `weekStart(0 | 1)` |
tooltipUnit(...) |
formatters({ tooltip }) |
locale.months |
formatters({ monthLabel }) |
locale.days |
formatters({ dayLabel }) |
locale.Less / locale.More |
formatters({ legend: { less, more } }) |
ariaLabelForDate(fn) |
formatters({ ariaLabel: fn }) |
accessibilityEnabled(false) |
Removed (a11y always on) |
calendarHeatmap()
.weekStart(1)
.tooltipUnit([
{ min: 0, unit: 'session' },
{ min: 1, max: 1, unit: 'session' },
{ min: 2, max: 'Infinity', unit: 'sessions' }
])
.locale({
months: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
days: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
Less: 'Less',
More: 'More',
No: 'No',
on: 'on'
})
.ariaLabelForDate((date, count) => `${date.toDateString()}: ${count} sessions`);calendarHeatmap()
.weekStart('monday')
.formatters({
tooltip: (date, count) => {
const unit = count === 1 ? 'session' : 'sessions';
return `${count} ${unit} on ${date.toDateString()}`;
},
dayLabel: (weekdayIndex) => {
const base = new Date(2020, 5, 7 + weekdayIndex);
return new Intl.DateTimeFormat(undefined, { weekday: 'narrow' }).format(base);
},
monthLabel: (monthIndex) => {
const base = new Date(2020, monthIndex, 1);
return new Intl.DateTimeFormat(undefined, { month: 'short' }).format(base);
},
legend: { less: 'Less', more: 'More' },
ariaLabel: (date, count) => `${date.toDateString()}: ${count} sessions`
});- Package name:
@goujon/react-calendar-heatmap - It includes
@goujon/calendar-heatmapas a dependency. - You only need to install the React package:
npm install @goujon/react-calendar-heatmap