# Event Calendar

> React week and day event calendar: events placed by time, side by side overlaps, an all-day row, a live time line and click or keyboard to create events.

- Kind: Component (Dashboard)
- Docs: https://ui.minidev.pro/docs/event-calendar
- Source (registry JSON with the full file): https://ui.minidev.pro/r/event-calendar.json
- License: MIT. One file, yours to edit after install.

## When to use

Use for meeting and shift schedules. Events are plain objects with Date `start` and `end`; `calendars` set their colours. Click an empty slot (or focus a day column and use Up/Down then Enter) to fire `onCreate`. For a month grid use [`CalendarMonth`](https://ui.minidev.pro/docs/calendar-month); for a list of upcoming events use [`CalendarAgenda`](https://ui.minidev.pro/docs/calendar-agenda); for project timelines use [`GanttChart`](https://ui.minidev.pro/docs/gantt-chart).

## Installation

### shadcn CLI (copies the source into your project)

```bash
npx shadcn@latest add @minidev/event-calendar
```

Writes `components/ui/event-calendar.tsx` plus the MiniDev files it is built from (button, segmented-control) and installs its npm dependencies. Older CLI versions: `npx shadcn@latest add https://ui.minidev.pro/r/event-calendar.json`.

### npm package

```bash
npm i minidev-ui-kit lucide-react
```

Add the tokens to your global stylesheet once:

```css
@import "tailwindcss";
@import "minidev-ui-kit/styles.css";
@source "../node_modules/minidev-ui-kit";
```

Next.js also needs `transpilePackages: ["minidev-ui-kit"]` in next.config.

## Import

After the shadcn install:

```tsx
import { EventCalendar } from "@/components/ui/event-calendar"
```

From the npm package:

```tsx
import { EventCalendar } from "minidev-ui-kit/ui/event-calendar"
```

## Usage

```tsx
import { EventCalendar } from "@/components/ui/event-calendar"

export function Example() {
  return (
    <EventCalendar />
  )
}
```

## Props

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `events` | `CalendarEvent[]` | - | no | Events to place. Defaults to a sample Lumen work week around today. |
| `calendars` | `CalendarSource[]` | `CALENDARS` | no | Calendars that colour events and fill the legend. |
| `view` | `CalendarView` | - | no | Controlled view. |
| `defaultView` | `CalendarView \| "auto"` | `"auto"` | no | "auto" picks Day under 600px of width and Week above. |
| `onViewChange` | `(view: CalendarView) => void` | - | no | Called when the Week/Day control or a day header changes the view. |
| `defaultDate` | `Date` | - | no | Any date inside the first week or day shown. Defaults to today. |
| `onDateChange` | `(date: Date) => void` | - | no |  |
| `weekStartsOn` | `0 \| 1` | `1` | no | 0 for Sunday, 1 for Monday. |
| `scrollToHour` | `number` | `8` | no | Hour the grid scrolls to on mount. |
| `hourHeight` | `number` | `48` | no | Pixel height of one hour row. |
| `height` | `number` | `520` | no | Pixel height of the scrolling time grid. |
| `slotMinutes` | `number` | `30` | no | Minutes a click on an empty slot snaps to. |
| `onCreate` | `(range: { start: Date; end: Date }) => void` | - | no | Called when an empty slot is clicked or chosen with the keyboard. |
| `onEventClick` | `(event: CalendarEvent) => void` | - | no | Called when an event block is clicked or activated with the keyboard. |
| `locale` | `string` | `"en-US"` | no | BCP 47 locale for dates and times, e.g. "en-GB". |
| `className` | `string` | - | no |  |

## Examples

### Day view

defaultView picks the layout, scrollToHour sets where the grid starts and locale drives the time format.

```tsx
<EventCalendar defaultView="day" height={360} scrollToHour={9} locale="en-GB" />
```

### Custom events and calendars

Events reference a calendar id for their colour; defaultDate opens the week that holds them.

```tsx
const monday = new Date(2026, 9, 12)
const at = (day: number, hour: number, minute = 0) => new Date(2026, 9, 12 + day, hour, minute)

const calendars: CalendarSource[] = [
  { id: "support", label: "Support", tone: "info" },
  { id: "launch", label: "Launch", tone: "warning" },
]

const events: CalendarEvent[] = [
  { id: "1", title: "Onboarding: Northwind", start: at(0, 10), end: at(0, 11), calendar: "support", location: "Zoom" },
  { id: "2", title: "Launch review", start: at(1, 14), end: at(1, 15, 30), calendar: "launch", location: "Room Atlas" },
  { id: "3", title: "Support rota", start: at(2, 9), end: at(2, 12), calendar: "support" },
  { id: "4", title: "Lumen 2.4 ships", start: at(3, 0), end: at(4, 0), calendar: "launch", allDay: true },
  { id: "5", title: "Office hours", start: at(4, 15), end: at(4, 16), calendar: "support", location: "Google Meet" },
]

<EventCalendar events={events} calendars={calendars} defaultDate={monday} defaultView="week" height={400} />
```

### Create and click handlers

onCreate receives the snapped range for an empty slot and onEventClick the event, with slotMinutes setting the snap.

```tsx
function HandlersDemo() {
  const [message, setMessage] = React.useState("Click an empty slot or an event.")
  return (
    <div className="flex w-full max-w-4xl flex-col gap-3">
      <EventCalendar
        height={360}
        slotMinutes={15}
        onCreate={({ start }) => setMessage("New event at " + start.toLocaleTimeString("en-US", { hour: "numeric", minute: "2-digit" }))}
        onEventClick={(ev) => setMessage("Opened " + ev.title)}
      />
      <p aria-live="polite" className="text-xs text-fg-muted">{message}</p>
    </div>
  )
}
```

## Keyboard interactions

| Key | Action |
| --- | --- |
| `Tab` | Moves through the toolbar, the day headers, the all-day events, then one slot target per day column and its events. |
| `ArrowDown` or `ArrowUp` | On a day column, moves the proposed start time by `slotMinutes` (30 by default). |
| `Enter` or `Space` | On a day column, calls `onCreate` for the proposed time. On an event, calls `onEventClick`. |
| `Enter` or `Space` | On a day header in week view, opens that day. |

## Accessibility

- The heading has `aria-live="polite"`, so the new range is announced after Previous, Next or Today. Those buttons are labelled "Previous week" or "Next day" to match the view.
- Each event is a button named with its title, date, time range, location and calendar, for example "Design review, Tuesday, November 17, 10:00 AM to 11:30 AM, Room Atlas, Northwind".
- Each day column is a `role="button"` slot target whose name explains the arrow keys; a visually hidden live region reads the chosen time as it changes.
- Hour labels, grid lines and the current-time line are `aria-hidden`.

## FAQ

### Why doesn't a new event stay after I click a slot?

EventCalendar does not store events. A click calls `onCreate` with a one-hour `{ start, end }` and shows a "New event" preview; add the event to the array you pass as `events` and it renders like the others.

### Is there a month view or drag to move events?

No. It has week and day views only, and events can't be dragged or resized. For a month grid use [`CalendarMonth`](https://ui.minidev.pro/docs/calendar-month).

### Can I control the date shown?

Only the view is controllable (`view` and `onViewChange`). The date starts at `defaultDate` and reports changes through `onDateChange`. To jump to a date from outside, change the component's `key` with a new `defaultDate`.

### How do I show 24-hour times or start weeks on Sunday?

Pass `locale="en-GB"` (or any BCP 47 locale) for times and dates, and `weekStartsOn={0}` for Sunday. The default is Monday.

## Rules for generating code

- Use semantic tokens only (bg, surface, sunken, border, fg, fg-muted, fg-subtle, ink, accent, success, warning, danger). Never raw hex or palette steps like blue-500.
- Shadows only from the set: shadow-xs, shadow-sm, shadow-raised, shadow-md, shadow-lg, shadow-overlay.
- Numbers use tabular-nums. Dark mode is the `dark` class on <html>; components never branch on theme.

## Dependencies

- npm: `lucide-react`
- Built from: [button](https://ui.minidev.pro/docs/button/md), [segmented-control](https://ui.minidev.pro/docs/segmented-control/md)

## Related

- [Calendar Month](https://ui.minidev.pro/docs/calendar-month/md): Month calendar grid with weekday headers and clickable day cells that highlight the selected date. A simple Tailwind base for date views and schedulers.
- [Calendar Agenda](https://ui.minidev.pro/docs/calendar-agenda/md): React agenda list of the day's events with a fixed time column, title and optional meta line such as location or attendees, divided inside one card.
- [Gantt Chart](https://ui.minidev.pro/docs/gantt-chart/md): React Gantt chart for project timelines with day and week scales, a today line, progress fills, dependency arrows, a fixed task column and focusable bars.
- [Calendar](https://ui.minidev.pro/docs/calendar/md): React calendar for Tailwind and shadcn: single, range or multiple dates, two months, preset ranges, a hover preview of the range and full arrow-key support.
- [Account Setup Progress](https://ui.minidev.pro/docs/account-setup-progress/md): React onboarding card that shows account setup as completed steps out of a total, with a labelled progress bar and a hint for the next step to finish.
- [Activity Feed](https://ui.minidev.pro/docs/activity-feed/md): React activity feed that lists who did what and when, with initials avatars, muted action text and tabular timestamps in a single bordered card.

---

All 557 components: https://ui.minidev.pro/llms.txt (full text: https://ui.minidev.pro/llms-full.txt).
