AddToCalendar is a button with a menu: open the event in Google Calendar or Outlook on the web, add it to Apple Calendar, or download an .ics file for any other app. Apple Calendar has no web link, so its item downloads the same .ics file and Calendar opens it on macOS and iOS. The component ships no JavaScript: the menu is a native popover, and the file is built on the server by the ics utility and embedded as a data: link with the download attribute. It works with JavaScript turned off. Service logos are inlined from simple-icons.
Browser Support
Opens and closes the popup
Positions the popup near its trigger
Animates the initial appearance
Turns the arrow when the menu opens
Animates the menu closing
Preview
Installation
Usage
import { AddToCalendar } from "@/components/ui/add-to-calendar"
export function EventCard() {
return (
<AddToCalendar
event={{
uid: "meetup-2027-04@example.com",
title: "Design systems meetup",
start: "2027-04-15T19:00:00+02:00",
duration: 120,
location: "Main hall, 12 Example Street",
reminder: 60,
}}
/>
)
}Examples
Choose providers
List the menu items in the order you want. apple and ics download the same file. office365 opens Outlook for work and school accounts.
<AddToCalendar
event={event}
providers={["google", "apple", "outlook", "office365", "ics"]}
variant="outline"
size="sm"
/>All-day event
With allDay only the dates count. end is the last day of the event, inclusive.
<AddToCalendar
event={{
title: "Team offsite",
start: "2027-06-10",
end: "2027-06-11", // two days, inclusive
allDay: true,
}}
providers={["google", "ics"]}
/>Your own texts
All texts are English by default and can be replaced through labels. The Russian version of this page does exactly that.
<AddToCalendar
event={event}
filename="meetup"
labels={{
trigger: "Save the date",
apple: "Add to Apple Calendar",
ics: "Download file",
}}
/>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| event | CalendarEvent | - | The event: title, start, end or duration, description, location, reminder |
| providers | ("google" | "apple" | "outlook" | "office365" | "ics")[] | ["google", "apple", "outlook", "ics"] | Menu items in order |
| filename | string | - | Name of the downloaded file without .ics. Defaults to the title |
| labels | Partial<AddToCalendarLabels> | - | Texts of the button and menu items: trigger, google, apple, outlook, office365, ics |
| variant | "default" | "outline" | "default" | Button style |
| size | "sm" | "md" | "md" | Button size |
| align | "start" | "center" | "end" | "start" | Menu alignment relative to the button |
| disabled | boolean | false | Disable the button |
| className | string | - | Extra classes for the button |
| contentClassName | string | - | Extra classes for the menu panel |
CalendarEvent
The same object goes to the component and to every function of the ics utility.
| Name | Type | Default | Description |
|---|---|---|---|
| title | string | - | Event name |
| start | Date | string | number | - | Start: Date, ISO string or timestamp. Stored in UTC |
| end | Date | string | number | - | End. For allDay, the last day of the event |
| duration | number | 60 | Length in minutes when end is missing |
| allDay | boolean | false | Whole-day event |
| description, location, url | string | - | Shown in the event details. URL goes into the description for Google and Outlook |
| uid | string | random | Stable id. Keep it to update or cancel the event later |
| reminder | number | IcsReminder | - | Minutes before the start, or { minutesBefore, description }. Becomes a VALARM |
| sequence | number | 0 | Revision number. Bump it every time you resend a changed event |
| cancelled | boolean | false | Adds STATUS:CANCELLED and sends METHOD:CANCEL |
ics utility
The component depends on @gooseui/ics, a small iCalendar builder with no dependencies. It works on the server too, for example to attach an invite to an email.
Install it on its own:
import { buildIcs } from "@/lib/ics"
const ics = buildIcs(
{
uid: "booking-4821@example.com",
title: "Consultation",
start: new Date("2027-04-15T10:00:00Z"),
duration: 50,
description: "Video call. The link comes an hour before the start.",
reminder: { minutesBefore: 60, description: "Consultation in an hour" },
},
{ method: "REQUEST" },
)
// send it as an email attachment: text/calendar; method=REQUEST| Name | Type | Description |
|---|---|---|
| buildIcs(events, options?) | string | Full calendar file with one or more events |
| googleCalendarUrl(event) | string | Link that opens a prefilled event in Google Calendar |
| outlookCalendarUrl(event, account?) | string | Same for Outlook on the web. Pass "office" for work accounts |
| escapeIcsText(value) | string | Escapes backslashes, commas, semicolons and line breaks |
| foldIcsLine(line) | string | Splits lines longer than 75 octets without breaking UTF-8 characters |
| formatIcsDate(date) | string | UTC timestamp like 20270415T160000Z |
Cancelling an event
Send a file with the same uid and cancelled: true. Its SEQUENCE is higher than the original one, so the calendar marks the event as cancelled or removes it.
const cancel = buildIcs({
uid: "booking-4821@example.com", // same uid as the invite
title: "Consultation",
start: new Date("2027-04-15T10:00:00Z"),
duration: 50,
cancelled: true, // SEQUENCE:1, STATUS:CANCELLED, METHOD:CANCEL
})Features
- RFC 5545. Text escaping, line folding at 75 octets, CRLF endings and UTC times
- Reminders. VALARM with your own text, the event title by default
- No JavaScript. A server component. The download is a data: link, so there is no blob to clean up
- Keyboard. Tab reaches the button, Enter opens the menu, Tab moves through the items, Escape closes it and returns focus to the button
- Server rendering. Render it from a server component. Without a uid the file gets a random id and the current time, which would differ between the server and the client render