|
| 1 | +# Calendar View Component |
| 2 | + |
| 3 | +The `calendar-view` component is an Airtable-style calendar for displaying records as events. It provides three view modes: Month, Week, and Day. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Multiple View Modes**: Switch between Month, Week, and Day views |
| 8 | +- **Flexible Data Mapping**: Map your data fields to event properties |
| 9 | +- **Color Coding**: Support for color-coded events with custom color mappings |
| 10 | +- **Interactive**: Click on events and dates (with callbacks) |
| 11 | +- **Responsive**: Works seamlessly on different screen sizes |
| 12 | + |
| 13 | +## Basic Usage |
| 14 | + |
| 15 | +```json |
| 16 | +{ |
| 17 | + "type": "calendar-view", |
| 18 | + "data": [ |
| 19 | + { |
| 20 | + "id": 1, |
| 21 | + "title": "Team Meeting", |
| 22 | + "start": "2026-01-13T10:00:00.000Z", |
| 23 | + "end": "2026-01-13T11:00:00.000Z", |
| 24 | + "color": "#3b82f6" |
| 25 | + } |
| 26 | + ] |
| 27 | +} |
| 28 | +``` |
| 29 | + |
| 30 | +## Properties |
| 31 | + |
| 32 | +| Property | Type | Default | Description | |
| 33 | +|:---|:---|:---|:---| |
| 34 | +| `data` | `array` | `[]` | Array of record objects to display as events | |
| 35 | +| `view` | `'month' \| 'week' \| 'day'` | `'month'` | Default view mode | |
| 36 | +| `titleField` | `string` | `'title'` | Field name to use for event title | |
| 37 | +| `startDateField` | `string` | `'start'` | Field name for event start date | |
| 38 | +| `endDateField` | `string` | `'end'` | Field name for event end date (optional) | |
| 39 | +| `allDayField` | `string` | `'allDay'` | Field name for all-day flag | |
| 40 | +| `colorField` | `string` | `'color'` | Field name for event color | |
| 41 | +| `colorMapping` | `object` | `{}` | Map field values to colors | |
| 42 | +| `allowCreate` | `boolean` | `false` | Allow creating events by clicking on dates | |
| 43 | +| `className` | `string` | - | Additional CSS classes | |
| 44 | + |
| 45 | +## Data Structure |
| 46 | + |
| 47 | +Each event object in the `data` array should have the following structure: |
| 48 | + |
| 49 | +```typescript |
| 50 | +{ |
| 51 | + id: string | number; // Unique identifier |
| 52 | + title: string; // Event title (or use custom titleField) |
| 53 | + start: string | Date; // Start date/time (ISO string or Date) |
| 54 | + end?: string | Date; // End date/time (optional) |
| 55 | + allDay?: boolean; // Whether it's an all-day event |
| 56 | + color?: string; // Event color (hex or CSS color) |
| 57 | + [key: string]: any; // Any other custom data |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +## Examples |
| 62 | + |
| 63 | +### Month View with Color Mapping |
| 64 | + |
| 65 | +```json |
| 66 | +{ |
| 67 | + "type": "calendar-view", |
| 68 | + "className": "h-[600px] border rounded-lg", |
| 69 | + "view": "month", |
| 70 | + "colorField": "type", |
| 71 | + "colorMapping": { |
| 72 | + "meeting": "#3b82f6", |
| 73 | + "deadline": "#ef4444", |
| 74 | + "event": "#10b981" |
| 75 | + }, |
| 76 | + "data": [ |
| 77 | + { |
| 78 | + "id": 1, |
| 79 | + "title": "Team Standup", |
| 80 | + "start": "2026-01-13T09:00:00.000Z", |
| 81 | + "end": "2026-01-13T09:30:00.000Z", |
| 82 | + "type": "meeting" |
| 83 | + }, |
| 84 | + { |
| 85 | + "id": 2, |
| 86 | + "title": "Project Deadline", |
| 87 | + "start": "2026-01-20T00:00:00.000Z", |
| 88 | + "type": "deadline", |
| 89 | + "allDay": true |
| 90 | + } |
| 91 | + ] |
| 92 | +} |
| 93 | +``` |
| 94 | + |
| 95 | +## View Modes |
| 96 | + |
| 97 | +### Month View |
| 98 | +Displays a full month calendar grid with events shown as colored bars on their respective dates. Perfect for getting a high-level overview of the month. |
| 99 | + |
| 100 | +### Week View |
| 101 | +Shows a week at a time with each day in a column. Events display with their times, ideal for detailed weekly planning. |
| 102 | + |
| 103 | +### Day View |
| 104 | +Displays a single day with hourly time slots from 12 AM to 11 PM. Events are positioned at their scheduled times, great for detailed daily schedules. |
| 105 | + |
| 106 | +## Events & Callbacks |
| 107 | + |
| 108 | +The calendar view supports several event callbacks through the `onAction` mechanism: |
| 109 | + |
| 110 | +- `event_click`: Triggered when an event is clicked |
| 111 | +- `date_click`: Triggered when a date cell is clicked |
| 112 | +- `view_change`: Triggered when the view mode changes |
| 113 | +- `navigate`: Triggered when navigating between dates |
| 114 | + |
| 115 | +## Styling |
| 116 | + |
| 117 | +The calendar view is fully styled with Tailwind CSS and supports custom styling through the `className` prop. |
| 118 | + |
| 119 | +## Integration with ObjectQL |
| 120 | + |
| 121 | +When used with ObjectQL, the calendar view can automatically fetch and display records from your database. |
0 commit comments