import CalendarHeatmap from 'react-calendar-heatmap'; import dayjs from 'dayjs'; import { formatActivityDate } from '../../lib/date'; import { Tooltip as ReactTooltip } from 'react-tooltip'; import 'react-calendar-heatmap/dist/styles.css'; import './AccountStreakHeatmap.css'; const legends = [ { count: 1, color: 'bg-slate-600' }, { count: 3, color: 'bg-slate-500' }, { count: 5, color: 'bg-slate-400' }, { count: 10, color: 'bg-slate-300' }, { count: 20, color: 'bg-slate-200' }, ]; type AccountStreakHeatmapProps = {}; export function AccountStreakHeatmap(props: AccountStreakHeatmapProps) { const startDate = dayjs().subtract(6, 'months').toDate(); const endDate = dayjs().toDate(); return (
{ if (!value) { return 'fill-slate-700 rounded-md [rx:2px] focus:outline-none'; } const { count } = value; if (count >= 20) { return 'fill-slate-200 rounded-md [rx:2px] focus:outline-none'; } else if (count >= 10) { return 'fill-slate-300 rounded-md [rx:2px] focus:outline-none'; } else if (count >= 5) { return 'fill-slate-400 rounded-md [rx:2px] focus:outline-none'; } else if (count >= 3) { return 'fill-slate-500 rounded-md [rx:2px] focus:outline-none'; } else { return 'fill-slate-600 rounded-md [rx:2px] focus:outline-none'; } }} tooltipDataAttrs={(value: any) => { if (!value || !value.date) { return null; } const formattedDate = formatActivityDate(value.date); return { 'data-tooltip-id': 'user-activity-tip', 'data-tooltip-content': `${value.count} Updates - ${formattedDate}`, }; }} />
Less {legends.map((legend) => (
))} More
); }