GooseUI

Components

Add to Calendar

New

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

Popover

Opens and closes the popup

Your browser:
Anchor positioning

Positions the popup near its trigger

Your browser:
@starting-style

Animates the initial appearance

Your browser:
:has()

Turns the arrow when the menu opens

Your browser:
transition-behavior

Animates the menu closing

Your browser:

Preview

Design systems meetup
Thu, April 15 · 19:00–21:00 local time

Installation

npx shadcn@latest add @gooseui/add-to-calendar
pnpm dlx shadcn@latest add @gooseui/add-to-calendar
yarn dlx shadcn@latest add @gooseui/add-to-calendar
bunx --bun shadcn@latest add @gooseui/add-to-calendar

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

PropTypeDefaultDescription
eventCalendarEvent-The event: title, start, end or duration, description, location, reminder
providers("google" | "apple" | "outlook" | "office365" | "ics")[]["google", "apple", "outlook", "ics"]Menu items in order
filenamestring-Name of the downloaded file without .ics. Defaults to the title
labelsPartial<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
disabledbooleanfalseDisable the button
classNamestring-Extra classes for the button
contentClassNamestring-Extra classes for the menu panel

CalendarEvent

The same object goes to the component and to every function of the ics utility.

NameTypeDefaultDescription
titlestring-Event name
startDate | string | number-Start: Date, ISO string or timestamp. Stored in UTC
endDate | string | number-End. For allDay, the last day of the event
durationnumber60Length in minutes when end is missing
allDaybooleanfalseWhole-day event
description, location, urlstring-Shown in the event details. URL goes into the description for Google and Outlook
uidstringrandomStable id. Keep it to update or cancel the event later
remindernumber | IcsReminder-Minutes before the start, or { minutesBefore, description }. Becomes a VALARM
sequencenumber0Revision number. Bump it every time you resend a changed event
cancelledbooleanfalseAdds 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:

npx shadcn@latest add @gooseui/ics
pnpm dlx shadcn@latest add @gooseui/ics
yarn dlx shadcn@latest add @gooseui/ics
bunx --bun shadcn@latest add @gooseui/ics
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
NameTypeDescription
buildIcs(events, options?)stringFull calendar file with one or more events
googleCalendarUrl(event)stringLink that opens a prefilled event in Google Calendar
outlookCalendarUrl(event, account?)stringSame for Outlook on the web. Pass "office" for work accounts
escapeIcsText(value)stringEscapes backslashes, commas, semicolons and line breaks
foldIcsLine(line)stringSplits lines longer than 75 octets without breaking UTF-8 characters
formatIcsDate(date)stringUTC 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