# Month calendar

A product team’s March 2027: previous and next month `Button`s, weekday headers, a marker on today, tinted weekends and event chips colored by category. A day with more than three events shows two and a “+3 more” `Popover` that lists them all. On a phone the grid gives way to an agenda.

**Example: Fernhill product team, March 2027** (`examples/recipes/month-calendar.tsx`)

```tsx
'use client'

import { BodySmall, Button, Heading, Popover, Stack, Text } from '@blocks/design-system'
import { ChevronLeft, ChevronRight } from 'lucide-react'
import { useId, useState } from 'react'
import styles from './month-calendar.module.css'

type Category = 'launch' | 'design' | 'ops' | 'team'

const categories: Record<Category, string> = { launch: 'Launch', design: 'Design', ops: 'Operations', team: 'Team' }

interface CalendarEvent {
  id: string
  date: string
  time: string
  title: string
  category: Category
}

const events: CalendarEvent[] = [
  { id: 'design-crit-feb', date: '2027-02-24', time: '14:00', title: 'Design critique', category: 'design' },
  { id: 'planning-q2', date: '2027-03-01', time: '10:00', title: 'Q2 planning kickoff', category: 'team' },
  { id: 'oncall-handoff-1', date: '2027-03-02', time: '09:30', title: 'On-call handoff', category: 'ops' },
  { id: 'design-crit-1', date: '2027-03-03', time: '14:00', title: 'Design critique', category: 'design' },
  { id: 'beta-invites', date: '2027-03-04', time: '11:00', title: 'Beta invites go out', category: 'launch' },
  { id: 'offsite', date: '2027-03-06', time: 'All day', title: 'Team hike, Larch Ridge', category: 'team' },
  { id: 'oncall-handoff-2', date: '2027-03-09', time: '09:30', title: 'On-call handoff', category: 'ops' },
  { id: 'usability-1', date: '2027-03-09', time: '13:00', title: 'Usability sessions', category: 'design' },
  { id: 'design-crit-2', date: '2027-03-10', time: '14:00', title: 'Design critique', category: 'design' },
  { id: 'freeze', date: '2027-03-12', time: '17:00', title: 'Code freeze for 4.0', category: 'launch' },
  { id: 'oncall-handoff-3', date: '2027-03-16', time: '09:30', title: 'On-call handoff', category: 'ops' },
  { id: 'launch-review', date: '2027-03-16', time: '10:30', title: 'Launch readiness review', category: 'launch' },
  { id: 'press-brief', date: '2027-03-16', time: '12:00', title: 'Press briefing prep', category: 'launch' },
  { id: 'icons', date: '2027-03-16', time: '14:00', title: 'Icon set handoff', category: 'design' },
  { id: 'failover-drill', date: '2027-03-16', time: '16:00', title: 'Database failover drill', category: 'ops' },
  { id: 'launch', date: '2027-03-18', time: '09:00', title: 'Fernhill 4.0 launch', category: 'launch' },
  { id: 'launch-party', date: '2027-03-19', time: '17:30', title: 'Launch party', category: 'team' },
  { id: 'retro', date: '2027-03-23', time: '15:00', title: 'Launch retrospective', category: 'team' },
  { id: 'design-crit-3', date: '2027-03-24', time: '14:00', title: 'Design critique', category: 'design' },
  { id: 'cert-renewal', date: '2027-03-29', time: '12:00', title: 'TLS certificate renewal', category: 'ops' },
  { id: 'all-hands', date: '2027-03-31', time: '16:00', title: 'All-hands', category: 'team' },
  { id: 'design-crit-apr', date: '2027-04-07', time: '14:00', title: 'Design critique', category: 'design' },
]

const weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
const today = '2027-03-09'
const maxChips = 2

const isoDate = (date: Date) => date.toISOString().slice(0, 10)

// Six-or-fewer Monday-first weeks covering the month, in UTC so every
// runtime computes the same days.
function monthGrid(year: number, month: number) {
  const first = new Date(Date.UTC(year, month, 1))
  const leading = (first.getUTCDay() + 6) % 7
  const daysInMonth = new Date(Date.UTC(year, month + 1, 0)).getUTCDate()
  const cells = Math.ceil((leading + daysInMonth) / 7) * 7
  return Array.from({ length: cells }, (_, index) => {
    const date = new Date(Date.UTC(year, month, index - leading + 1))
    return {
      iso: isoDate(date),
      day: date.getUTCDate(),
      weekday: index % 7,
      inMonth: date.getUTCMonth() === month,
      label: `${weekdays[index % 7]}, ${months[date.getUTCMonth()]} ${date.getUTCDate()}`,
    }
  })
}

export default function MonthCalendar() {
  // Months after March 2027, the team's current month.
  const [offset, setOffset] = useState(0)
  const id = useId()
  const year = 2027 + Math.floor((2 + offset) / 12)
  const month = (((2 + offset) % 12) + 12) % 12
  const days = monthGrid(year, month)
  const eventsOn = (iso: string) => events.filter((event) => event.date === iso)
  const agenda = days.filter((day) => day.inMonth && eventsOn(day.iso).length > 0)

  return (
    <Stack as="section" gap="md" aria-labelledby={`${id}-month`} dangerouslySetClassName={styles.calendar}>
      <Stack direction="row" justify="space-between" align="center" gap="md" wrap="wrap">
        <Stack gap="none">
          <Heading as="h2" id={`${id}-month`} fontSize="xl" aria-live="polite">
            {months[month]} {year}
          </Heading>
          <BodySmall color="text-muted" margin="none">
            Fernhill product team
          </BodySmall>
        </Stack>
        <Stack direction="row" gap="sm">
          <Button type="button" size="sm" onClick={() => setOffset(0)} disabled={offset === 0}>
            Today
          </Button>
          <Button type="button" size="sm" variant="ghost" aria-label="Previous month" onClick={() => setOffset(offset - 1)}>
            <ChevronLeft aria-hidden size={16} />
          </Button>
          <Button type="button" size="sm" variant="ghost" aria-label="Next month" onClick={() => setOffset(offset + 1)}>
            <ChevronRight aria-hidden size={16} />
          </Button>
        </Stack>
      </Stack>

      <div className={styles.month}>
        <div className={styles.weekdays} aria-hidden>
          {weekdays.map((weekday) => (
            <span key={weekday}>{weekday.slice(0, 3)}</span>
          ))}
        </div>
        <ol className={styles.grid}>
          {days.map((day) => {
            const dayEvents = day.inMonth ? eventsOn(day.iso) : []
            // A lone third event shows in full rather than as “+1 more”.
            const hidden = dayEvents.length - maxChips
            return (
              <li
                key={day.iso}
                className={styles.day}
                data-outside={!day.inMonth || undefined}
                data-weekend={day.weekday >= 5 || undefined}
                data-today={day.iso === today || undefined}
              >
                <time dateTime={day.iso} className={styles.date}>
                  <span aria-hidden>{day.day}</span>
                  <span className="visually-hidden">
                    {day.label}
                    {day.iso === today && ', today'}
                  </span>
                </time>
                {dayEvents.length > 0 && (
                  <ul className={styles.chips}>
                    {dayEvents.slice(0, hidden > 1 ? maxChips : maxChips + 1).map((event) => (
                      <li key={event.id}>
                        <EventChip event={event} />
                      </li>
                    ))}
                    {hidden > 1 && (
                      <li>
                        <Popover>
                          <Popover.Trigger render={<button type="button" className={styles.more} aria-label={`${hidden} more events on ${day.label}`} />}>
                            +{hidden} more
                          </Popover.Trigger>
                          <Popover.Content side="bottom" align="start">
                            <Popover.Title>{day.label}</Popover.Title>
                            <ul className={styles.popoverList}>
                              {dayEvents.map((event) => (
                                <li key={event.id}>
                                  <EventChip event={event} showTime />
                                </li>
                              ))}
                            </ul>
                          </Popover.Content>
                        </Popover>
                      </li>
                    )}
                  </ul>
                )}
              </li>
            )
          })}
        </ol>
      </div>

      {/* On a narrow screen the grid gives way to a list of the days that have events. */}
      <ol className={styles.agenda} aria-label={`${months[month]} ${year} agenda`}>
        {agenda.map((day) => (
          <li key={day.iso} className={styles.agendaDay} data-today={day.iso === today || undefined}>
            <Text fontSize="sm" fontWeight="semibold">
              <time dateTime={day.iso}>{day.label}</time>
              {day.iso === today && ' · Today'}
            </Text>
            <ul className={styles.popoverList}>
              {eventsOn(day.iso).map((event) => (
                <li key={event.id}>
                  <EventChip event={event} showTime />
                </li>
              ))}
            </ul>
          </li>
        ))}
        {agenda.length === 0 && (
          <li>
            <BodySmall color="text-muted" margin="none">
              Nothing scheduled this month.
            </BodySmall>
          </li>
        )}
      </ol>

      <ul className={styles.legend} aria-label="Categories">
        {(Object.keys(categories) as Category[]).map((category) => (
          <li key={category}>
            <span className={styles.dot} data-category={category} aria-hidden />
            {categories[category]}
          </li>
        ))}
      </ul>
    </Stack>
  )
}

// The category is in the dot's color and, for screen readers, in words.
function EventChip({ event, showTime = false }: { event: CalendarEvent; showTime?: boolean }) {
  return (
    <a href={`#event-${event.id}`} className={styles.chip} title={`${event.time} · ${event.title}`}>
      <span className={styles.dot} data-category={event.category} aria-hidden />
      {showTime && <span className={styles.time}>{event.time}</span>}
      <span className={styles.title}>{event.title}</span>
      <span className="visually-hidden"> ({categories[event.category]})</span>
    </a>
  )
}
```

## How it works

- **Dates are computed in UTC.** The grid is built from `Date.UTC`, so every runtime lays out the same Monday-first weeks and the page hydrates without mismatches. Navigation moves month by month and the heading is a polite live region.
- **Each day reads as a sentence.** The visible number is hidden from screen readers and replaced by the full date (“Tuesday, March 9, today”) inside a `<time dateTime>`. The weekday header row is decorative.
- **Category isn’t color alone.** Each chip’s dot carries the category color (indigo, slate, amber and green, chosen to stay apart), the legend names the colors, and a visually hidden suffix names the category. Chips are a dot and up to two lines of text with no fill, so a narrow day still shows words; the time and full title stay in the `title` attribute.
- **The layout follows the calendar’s width.** A container query swaps the seven-column grid for an agenda list of the days that have events. The hidden view uses `display: none`, so it also leaves the accessibility tree.

## App-owned CSS

The grid with hairline gaps, the today marker, event chips, category dots and the agenda.

`examples/recipes/month-calendar.module.css`:

```css
/* The calendar lays out by its own width: a grid when there is room, an agenda when not. */
.calendar {
  container-type: inline-size;
}

.weekdays,
.grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.weekdays {
  padding-bottom: var(--ds-space-sm);
  font-size: var(--ds-font-size-xs);
  font-weight: var(--ds-font-weight-semibold);
  color: var(--ds-color-text-muted);
  text-align: center;
}

.grid {
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: var(--ds-border-width-sm) solid var(--ds-color-border-subtle);
  border-radius: var(--ds-border-radius-md);
  list-style: none;
  /* Hairlines between days: the gap shows the border color behind the cells. */
  gap: var(--ds-border-width-sm);
  background-color: var(--ds-color-border-subtle);
}

.day {
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-xs);
  min-width: 0;
  min-height: 6rem;
  padding: var(--ds-space-sm);
  background-color: var(--ds-color-bg);

  &[data-weekend] {
    background-color: var(--ds-color-bg-subtle);
  }

  &[data-outside] .date {
    color: var(--ds-color-text-muted);
    opacity: 0.6;
  }
}

.date {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: flex-start;
  min-width: calc(var(--ds-space-lg) + var(--ds-space-md));
  height: calc(var(--ds-space-lg) + var(--ds-space-md));
  border-radius: var(--ds-border-radius-pill);
  font-size: var(--ds-font-size-xs);
  font-weight: var(--ds-font-weight-medium);
  font-variant-numeric: tabular-nums;

  .day[data-today] & {
    background-color: var(--ds-color-accent);
    color: var(--ds-color-accent-fg);
    font-weight: var(--ds-font-weight-bold);
  }
}

.chips,
.popoverList {
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-xs);
  margin: 0;
  padding: 0;
  list-style: none;
}

.popoverList {
  gap: var(--ds-space-sm);
  min-width: 13rem;
}

/* A dot and up to two lines of text: no fill, so a narrow day keeps room for words. */
.chip {
  display: flex;
  align-items: flex-start;
  gap: var(--ds-space-sm);
  min-width: 0;
  padding: var(--ds-space-xxs) var(--ds-space-xs);
  border-radius: var(--ds-border-radius-sm);
  color: var(--ds-color-text);
  font-size: var(--ds-font-size-xs);
  line-height: var(--ds-line-height-heading);
  text-decoration: none;

  &:hover {
    background-color: var(--ds-color-surface-hover);
  }

  &:focus-visible {
    outline: var(--ds-border-width-md) solid var(--ds-color-focus-ring);
    outline-offset: var(--ds-border-width-sm);
  }
}

.title {
  display: -webkit-box;
  overflow: hidden;
  /* Long words break too, so the clamp always ends in an ellipsis rather than a cut letter. */
  overflow-wrap: anywhere;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.time {
  flex-shrink: 0;
  color: var(--ds-color-text-muted);
  font-variant-numeric: tabular-nums;
}

.dot {
  flex-shrink: 0;
  width: var(--ds-space-md);
  height: var(--ds-space-md);
  margin-top: var(--ds-space-xxs);
  border-radius: var(--ds-border-radius-circle);

  &[data-category="launch"] {
    background-color: var(--ds-color-accent);
  }

  &[data-category="design"] {
    background-color: var(--ds-slate-9);
  }

  &[data-category="ops"] {
    background-color: var(--ds-color-warning);
  }

  &[data-category="team"] {
    background-color: var(--ds-color-success);
  }
}

.more {
  align-self: flex-start;
  padding: var(--ds-space-xxs) var(--ds-space-sm);
  border: none;
  border-radius: var(--ds-border-radius-sm);
  background: none;
  color: var(--ds-color-accent-text);
  font: inherit;
  font-size: var(--ds-font-size-xs);
  font-weight: var(--ds-font-weight-semibold);
  cursor: pointer;

  &:hover {
    background-color: var(--ds-color-surface-hover);
  }

  &:focus-visible {
    outline: var(--ds-border-width-md) solid var(--ds-color-focus-ring);
  }
}

.agenda {
  display: none;
  flex-direction: column;
  gap: var(--ds-space-lg);
  margin: 0;
  padding: 0;
  list-style: none;
}

.agendaDay {
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-sm);
  padding-left: var(--ds-space-md);
  border-left: var(--ds-border-width-md) solid var(--ds-color-border-subtle);

  &[data-today] {
    border-left-color: var(--ds-color-accent);
  }
}

@container (max-width: 30rem) {
  .month {
    display: none;
  }

  .agenda {
    display: flex;
  }
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ds-space-lg);
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--ds-font-size-xs);
  color: var(--ds-color-text-muted);

  & li {
    display: inline-flex;
    align-items: center;
    gap: var(--ds-space-sm);
  }
}
```
