# React Native Event Calendar, month week and day views (Pro)

> A React Native event calendar for iOS, Android and the web: month, week and day views, overlapping events side by side, all-day events, a now line, +N more, period navigation, and press an empty time to add an event. Accessible, animated, zero native code.

# Event calendar Pro

A calendar of events by month, week or day, as Google Calendar and Apple Calendar draw them. Month shows each day's first events and "+N more"; week and day place events by time, side by side when they overlap, with all-day events on top and a red line at now. Step through periods with the arrows, jump to Today, press an event to open it or an empty time (to the half hour) to add one there. Each new period slides in from the side it came from.

```tsx
import { EventCalendar } from '@patine-ui/pro';
```

```tsx live full
import { EventCalendar } from '@patine-ui/pro';

const at = (days, h = 9, m = 0) => {
  const d = new Date();
  d.setHours(h, m, 0, 0);
  d.setDate(d.getDate() + days);
  return d;
};
const events = [
  { id: '1', title: 'Standup', start: at(0, 9), end: at(0, 9, 15), color: 'success' },
  { id: '2', title: 'Design review', start: at(0, 11), end: at(0, 12), location: 'Room 2' },
  { id: '3', title: '1:1 with Omer', start: at(0, 11, 30), end: at(0, 12, 15), color: '#8B5CF6' },
  { id: '4', title: 'Lunch', start: at(0, 12, 30), end: at(0, 13, 30), color: 'warning' },
  { id: '5', title: 'Sprint planning', start: at(1, 10), end: at(1, 11, 30) },
  { id: '6', title: 'Company offsite', start: at(2), end: at(4), allDay: true, color: 'danger' },
  { id: '7', title: 'Release v2', start: at(6, 14), end: at(6, 15), color: 'success' },
];

export default function Example() {
  return <EventCalendar events={events} defaultView="week" onEventPress={(e) => alert(e.title)} onSlotPress={(date) => alert(`New event at ${date.toLocaleString()}`)} style={{ width: '100%' }} />;
}
```

## Example: book a meeting room

An office's room calendar: the week's bookings for Room Atlas, and pressing a free slot books it for an hour under your name. Bookings can't start in the past.

```tsx live wide
import { useState } from 'react';
import { View } from 'react-native';
import { Text } from 'patine-ui';
import { EventCalendar } from '@patine-ui/pro';

const at = (days: number, h: number, m = 0) => {
  const d = new Date();
  d.setDate(d.getDate() + days);
  d.setHours(h, m, 0, 0);
  return d;
};
const START = [
  { id: 'b1', title: 'Sales weekly', start: at(0, 9), end: at(0, 10), color: 'warning' },
  { id: 'b2', title: 'Interview: iOS', start: at(0, 13), end: at(0, 14), color: '#8B5CF6' },
  { id: 'b3', title: 'Board prep', start: at(1, 10), end: at(1, 12), color: 'danger' },
  { id: 'b4', title: 'Design crit', start: at(2, 15), end: at(2, 16) },
];

export default function Example() {
  const [bookings, setBookings] = useState(START);
  const [note, setNote] = useState('Press a free slot to book it.');
  const book = (start: Date) => {
    if (start < new Date()) return setNote('That time has passed.');
    const end = new Date(start.getTime() + 3600000);
    if (bookings.some((b) => b.start < end && b.end > start)) return setNote('Room Atlas is taken then.');
    setBookings((all) => [...all, { id: String(all.length + 1), title: 'Booked by you', start, end, color: 'success' }]);
    setNote(`Booked ${start.toLocaleString(undefined, { weekday: 'short', hour: 'numeric', minute: '2-digit' })} for an hour.`);
  };
  return (
    <View style={{ width: '100%', gap: 8 }}>
      <Text weight="semibold">Room Atlas · 8 seats · screen</Text>
      <EventCalendar events={bookings} defaultView="week" views={['week', 'day']} startHour={8} onSlotPress={book} onEventPress={(e) => setNote(`${e.title}, ${e.start.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' })}`)} />
      <Text size="sm" color="textSecondary">{note}</Text>
    </View>
  );
}
```

## Views and dates

`view` is `'month'`, `'week'` or `'day'` (controlled with `onViewChange`, or `defaultView`); `views` picks which the switch offers. `date` is a day in the period shown (controlled with `onDateChange`, or `defaultDate`). In month view "+N more" opens that day, and in week view so does a day's heading.

```tsx live full
import { EventCalendar } from '@patine-ui/pro';

const at = (days, h = 9) => {
  const d = new Date();
  d.setHours(h, 0, 0, 0);
  d.setDate(d.getDate() + days);
  return d;
};
const shifts = Array.from({ length: 18 }, (_, i) => ({
  id: String(i),
  title: ['Morning shift', 'Evening shift', 'Training'][i % 3],
  start: at(i - 6, i % 3 === 1 ? 16 : 8),
  color: ['primary', '#8B5CF6', 'success'][i % 3],
}));

export default function Example() {
  const [view, setView] = React.useState('month');
  const [date, setDate] = React.useState(new Date());
  return (
    <View style={{ gap: 8, width: '100%' }}>
      <EventCalendar events={shifts} view={view} onViewChange={setView} date={date} onDateChange={setDate} maxEventsPerDay={2} />
      <Text>{`${view} of ${date.toDateString()}`}</Text>
    </View>
  );
}
```

## Time grid

`startHour` and `endHour` (0 and 24) bound the week and day grid, `hourHeight` (48) sets its scale, `height` (560) its height, and it opens scrolled to `scrollToHour` (8). Events shorter than 20 minutes still get room for their title. `showNowIndicator={false}` drops the now line.

```tsx live full
import { EventCalendar } from '@patine-ui/pro';

const at = (h, m = 0) => {
  const d = new Date();
  d.setHours(h, m, 0, 0);
  return d;
};
const appointments = [
  { id: 'a', title: 'Haircut', start: at(9), end: at(9, 45), location: 'Chair 1' },
  { id: 'b', title: 'Color', start: at(9, 30), end: at(11), location: 'Chair 2', color: '#EC4899' },
  { id: 'c', title: 'Beard trim', start: at(10), end: at(10, 20), location: 'Chair 3', color: 'success' },
  { id: 'd', title: 'Haircut', start: at(13), end: at(13, 45), location: 'Chair 1' },
];

export default function Example() {
  return <EventCalendar events={appointments} views={['day']} startHour={8} endHour={18} hourHeight={64} height={420} style={{ width: 420 }} />;
}
```

## Your own events

`renderEvent({ event, start, end, time, color, view, theme })` draws an event's content inside its block or pill.

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `events` | `CalendarEvent[]` | — | `{ id, title, start, end?, allDay?, color?, location?, description?, data? }` |
| `view` / `defaultView` / `onViewChange` | `'month'` \| `'week'` \| `'day'` | `'month'` | |
| `views` | `CalendarView[]` | all three | One hides the switch. |
| `date` / `defaultDate` / `onDateChange` | `Date` | today | |
| `onEventPress` | `(event) => void` | — | |
| `onSlotPress` | `(date, allDay) => void` | — | An empty time or day pressed. |
| `firstDayOfWeek` / `locale` / `hour12` / `now` | | | |
| `startHour` / `endHour` / `scrollToHour` / `hourHeight` / `height` | `number` | `0` / `24` / `8` / `48` / `560` | The time grid. |
| `maxEventsPerDay` | `number` | `3` | Month cells. |
| `showHeader` / `showNowIndicator` | `boolean` | `true` | |
| `renderEvent` | `(info) => ReactNode` | — | |
| `loading` / `error` / `onRetry` | | | States. |
| `density` / `animate` / `labels` / `design` / `theme` / `accessibilityLabel` / `style` | | | |
