{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "calendar-03",
  "description": "A content calendar that switches between month and week, with each calendar toggled from a sidebar.",
  "registryDependencies": [
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/calendar.json",
    "https://www.dashboardblocks.com/r/radix/schedule.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/calendar/calendar-03.tsx",
      "content": "'use client'\n\nimport {\n  BlockStateProvider,\n  BlockStateText,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  type CalendarEvent,\n  CalendarEventDetails,\n  CalendarEventList,\n  CalendarLegend,\n  CalendarMonthView,\n  CalendarToolbar,\n  CalendarWeekView,\n  formatDayRange,\n  getEventDays,\n  getEventsForDay,\n  getWeekDays,\n  startOfMonth,\n} from '@/registry/components/dashboardblocks/calendar'\nimport { addDays, getDay } from '@/registry/components/dashboardblocks/schedule'\nimport { formatDate } from '@/registry/lib/dashboardblocks/format'\nimport { useId, useRef, useState } from 'react'\n\ntype View = 'month' | 'week'\n\ninterface Calendar3Props extends BlockStateProps {\n  calendars: { color: string; name: string }[]\n  /** Leave out, or pass none, to show the empty state. */\n  events?: CalendarEvent[]\n  now: Date\n  onSelectEvent?: (event: CalendarEvent) => void\n  /** @default 'UTC' */\n  timeZone?: string\n  /** @default 'month' */\n  view?: View\n  /** 0 for Sunday, 1 for Monday. */\n  weekStartsOn?: 0 | 1\n}\n\nconst NOW = Date.UTC(2026, 8, 28, 9, 40)\nconst at = (month: number, day: number, hour = 0, minute = 0) =>\n  new Date(Date.UTC(2026, month, day, hour, minute))\n\nconst CALENDARS = {\n  campaigns: { calendar: 'Campaigns', color: 'var(--color-chart-2)' },\n  content: { calendar: 'Content', color: 'var(--color-chart-3)' },\n  holidays: { calendar: 'Holidays', color: 'var(--color-chart-1)' },\n  social: { calendar: 'Social', color: 'var(--color-chart-5)' },\n  webinars: { calendar: 'Webinars', color: 'var(--color-chart-4)' },\n}\n\nconst exampleProps: Calendar3Props = {\n  calendars: Object.values(CALENDARS).map(({ calendar, color }) => ({\n    color,\n    name: calendar,\n  })),\n  events: [\n    {\n      ...CALENDARS.holidays,\n      allDay: true,\n      id: 'labor-day',\n      start: at(8, 7),\n      title: 'Labor Day',\n    },\n    {\n      ...CALENDARS.content,\n      allDay: true,\n      attendees: [{ name: 'Hannah Okoro' }],\n      description: 'How we moved 10 TB to partitioned tables without downtime.',\n      id: 'blog-postgres',\n      start: at(8, 8),\n      title: 'Blog: Scaling Postgres',\n    },\n    {\n      ...CALENDARS.social,\n      end: at(8, 10, 16),\n      id: 'linkedin-hiring',\n      start: at(8, 10, 15, 30),\n      title: 'LinkedIn: We’re hiring',\n    },\n    {\n      ...CALENDARS.content,\n      end: at(8, 15, 14, 30),\n      id: 'newsletter-sep',\n      start: at(8, 15, 14),\n      title: 'Newsletter: September',\n    },\n    {\n      ...CALENDARS.webinars,\n      attendees: [{ name: 'Ines Duarte' }, { name: 'Sam Whitaker' }],\n      description: 'Building your first dashboard, for new customers. 340 registered.',\n      end: at(8, 17, 18),\n      id: 'webinar-101',\n      location: 'Zoom Webinar',\n      start: at(8, 17, 17),\n      title: 'Webinar: Dashboards 101',\n    },\n    {\n      ...CALENDARS.campaigns,\n      allDay: true,\n      attendees: [\n        { name: 'Ines Duarte' },\n        { name: 'Rafael Costa' },\n        { name: 'Hannah Okoro' },\n      ],\n      description:\n        'Paid social, search and email for the v4.2 launch. Budget $48,000, goal 1,200 trials.',\n      end: at(9, 10),\n      id: 'fall-launch',\n      start: at(8, 21),\n      title: 'Fall launch campaign',\n    },\n    {\n      ...CALENDARS.social,\n      end: at(8, 23, 16),\n      id: 'teaser',\n      start: at(8, 23, 15, 30),\n      title: 'Teaser video: v4.2',\n    },\n    {\n      ...CALENDARS.content,\n      end: at(8, 28, 10, 30),\n      id: 'content-standup',\n      location: 'Zoom',\n      start: at(8, 28, 10),\n      title: 'Content standup',\n    },\n    {\n      ...CALENDARS.social,\n      end: at(8, 28, 13),\n      id: 'social-planning',\n      location: 'Room 3C',\n      start: at(8, 28, 12),\n      title: 'Social calendar planning',\n    },\n    {\n      ...CALENDARS.campaigns,\n      attendees: [\n        { name: 'Ines Duarte' },\n        { name: 'Rafael Costa' },\n        { name: 'Meera Shah' },\n      ],\n      description:\n        'First week of spend: cost per trial by channel, and where to move budget.',\n      end: at(8, 29, 12),\n      id: 'campaign-review',\n      location: 'Boardroom',\n      start: at(8, 29, 11),\n      title: 'Campaign review',\n    },\n    {\n      ...CALENDARS.social,\n      end: at(8, 29, 15, 30),\n      id: 'carousel',\n      start: at(8, 29, 15),\n      title: 'LinkedIn carousel: 4.2 features',\n    },\n    {\n      ...CALENDARS.social,\n      attendees: [{ name: 'Rafael Costa' }],\n      description: 'Goes live at 12:01 AM PT. Ask the team to comment in the first hour.',\n      end: at(8, 30, 8),\n      id: 'product-hunt',\n      location: 'producthunt.com',\n      start: at(8, 30, 7),\n      title: 'Product Hunt launch',\n    },\n    {\n      ...CALENDARS.webinars,\n      end: at(8, 30, 16),\n      id: 'dry-run',\n      location: 'Zoom',\n      start: at(8, 30, 15),\n      title: 'Webinar dry run',\n    },\n    {\n      ...CALENDARS.webinars,\n      attendees: [\n        { name: 'Ines Duarte' },\n        { name: 'Leo Park' },\n        { name: 'Maya Lindqvist' },\n      ],\n      description: 'Live walkthrough of v4.2 with Q&A. 512 registered.',\n      end: at(8, 30, 18),\n      id: 'webinar-42',\n      location: 'Zoom Webinar',\n      start: at(8, 30, 17),\n      title: \"Webinar: What's new in 4.2\",\n    },\n    {\n      ...CALENDARS.content,\n      allDay: true,\n      attendees: [{ name: 'Hannah Okoro' }],\n      description: 'How Northwind cut reporting time from two days to twenty minutes.',\n      id: 'case-study',\n      start: at(9, 1),\n      title: 'Case study: Northwind',\n    },\n    {\n      ...CALENDARS.campaigns,\n      end: at(9, 1, 13, 45),\n      id: 'agency',\n      location: 'Google Meet',\n      start: at(9, 1, 13),\n      title: 'Agency check-in',\n    },\n    {\n      ...CALENDARS.content,\n      attendees: [{ name: 'Maya Lindqvist' }, { name: 'Hannah Okoro' }],\n      end: at(9, 1, 17),\n      id: 'podcast',\n      location: 'Studio',\n      start: at(9, 1, 16),\n      title: 'Podcast: SaaS Weekly',\n    },\n    {\n      ...CALENDARS.content,\n      end: at(9, 2, 11),\n      id: 'editorial',\n      location: 'Room 3C',\n      start: at(9, 2, 10),\n      title: 'Editorial planning',\n    },\n    {\n      ...CALENDARS.social,\n      end: at(9, 6, 15, 30),\n      id: 'customer-quote',\n      start: at(9, 6, 15),\n      title: 'Customer quote: Acme',\n    },\n    {\n      ...CALENDARS.holidays,\n      allDay: true,\n      id: 'indigenous-peoples-day',\n      start: at(9, 12),\n      title: \"Indigenous Peoples' Day\",\n    },\n    {\n      ...CALENDARS.content,\n      end: at(9, 13, 14, 30),\n      id: 'newsletter-oct',\n      start: at(9, 13, 14),\n      title: 'Newsletter: October',\n    },\n    {\n      ...CALENDARS.webinars,\n      end: at(9, 15, 18),\n      id: 'founders',\n      location: 'YouTube Live',\n      start: at(9, 15, 17),\n      title: 'Live Q&A with the founders',\n    },\n    {\n      ...CALENDARS.campaigns,\n      allDay: true,\n      end: at(9, 31),\n      id: 'black-friday',\n      start: at(9, 26),\n      title: 'Black Friday prep',\n    },\n    {\n      ...CALENDARS.holidays,\n      allDay: true,\n      id: 'halloween',\n      start: at(9, 31),\n      title: 'Halloween',\n    },\n  ],\n  now: new Date(NOW),\n}\n\nconst Calendar3 = (props: Calendar3Props) => {\n  const {\n    calendars,\n    events: data = [],\n    now,\n    onSelectEvent,\n    errorMessage,\n    status,\n    timeZone = 'UTC',\n    weekStartsOn = 0,\n  } = props\n  const state = getBlockState(status, data)\n  const events = state ? [] : data\n  const today = getDay(now, timeZone)\n  const [view, setView] = useState<View>(props.view ?? 'month')\n  const [anchor, setAnchor] = useState(today)\n  const [month, setMonth] = useState(() => startOfMonth(today))\n  const [hidden, setHidden] = useState<string[]>([])\n  const [selectedId, setSelectedId] = useState<string>()\n  const container = useRef<HTMLDivElement>(null)\n  const id = useId()\n\n  const visible = events.filter((event) => !hidden.includes(event.calendar ?? ''))\n  const selected = visible.find((event) => event.id === selectedId)\n  const days = getWeekDays(anchor, weekStartsOn)\n  const monthLabel = formatDate(month, 'month-long-year')\n  const [rangeStart, rangeEnd] =\n    view === 'month' ? [month, startOfMonth(month, 1)] : [days[0], addDays(days[6], 1)]\n  const inView = visible.filter((event) => {\n    const { first, last } = getEventDays(event, timeZone)\n    return first < rangeEnd && last >= rangeStart\n  }).length\n  const items = `${inView} ${inView === 1 ? 'item' : 'items'}`\n  const description =\n    hidden.length === 0\n      ? `${items} across ${calendars.length} calendars.`\n      : `${items}, with ${hidden.length} of ${calendars.length} calendars hidden.`\n\n  const goTo = (day: Date) => {\n    setAnchor(day)\n    setMonth(startOfMonth(day))\n  }\n  const move = (step: 1 | -1) => {\n    if (view === 'week') return goTo(addDays(anchor, step * 7))\n    setMonth(startOfMonth(month, step))\n    setAnchor(startOfMonth(month, step))\n  }\n  const select = (event: CalendarEvent) => {\n    setSelectedId(event.id)\n    onSelectEvent?.(event)\n  }\n  const closeDetails = () => {\n    container.current\n      ?.querySelector<HTMLElement>(`[data-event-id=\"${selectedId}\"]`)\n      ?.focus()\n    setSelectedId(undefined)\n  }\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <section className='@container flex flex-col gap-4 [--calendar-surface:var(--color-background)]'>\n        <CalendarToolbar\n          title={view === 'month' ? monthLabel : formatDayRange(days[0], days[6])}\n          description={state ? <BlockStateText /> : description}\n          onToday={() => goTo(today)}\n          onPrevious={() => move(-1)}\n          onNext={() => move(1)}\n          previousLabel={view === 'month' ? 'Previous month' : 'Previous week'}\n          nextLabel={view === 'month' ? 'Next month' : 'Next week'}\n          view={view}\n          views={[\n            { label: 'Month', value: 'month' },\n            { label: 'Week', value: 'week' },\n          ]}\n          onViewChange={(next) => {\n            if (next === 'month') setMonth(startOfMonth(anchor))\n            setView(next as View)\n          }}\n        />\n        <div className='grid gap-6 @4xl:grid-cols-[13rem_minmax(0,1fr)] @4xl:grid-rows-[auto_1fr]'>\n          <section aria-labelledby={id} className='flex flex-col gap-2'>\n            <h3 id={id} className='px-2 text-sm font-medium'>\n              Calendars\n            </h3>\n            <CalendarLegend\n              calendars={calendars}\n              hidden={hidden}\n              label='Show calendars'\n              onToggle={(name) =>\n                setHidden((current) =>\n                  current.includes(name)\n                    ? current.filter((item) => item !== name)\n                    : [...current, name],\n                )\n              }\n              className='gap-x-0 gap-y-0 @4xl:flex-col'\n            />\n          </section>\n          <div\n            ref={container}\n            className='flex min-w-0 flex-col gap-4 @4xl:col-start-2 @4xl:row-span-2 @4xl:row-start-1'\n          >\n            {view === 'month' ? (\n              <div className='@container flex flex-col gap-4'>\n                <CalendarMonthView\n                  events={visible}\n                  label={monthLabel}\n                  month={month}\n                  now={now}\n                  onMonthChange={setMonth}\n                  onSelectDay={setAnchor}\n                  onSelectEvent={select}\n                  onShowMore={(day) => {\n                    setAnchor(day)\n                    setView('week')\n                  }}\n                  selectedDay={anchor}\n                  selectedEventId={selected?.id}\n                  timeZone={timeZone}\n                  weekStartsOn={weekStartsOn}\n                />\n                <section\n                  aria-labelledby={`${id}-day`}\n                  className='flex flex-col gap-2 @2xl:hidden'\n                >\n                  <h3\n                    id={`${id}-day`}\n                    aria-live='polite'\n                    className='px-2 text-sm font-medium'\n                  >\n                    {formatDate(anchor, 'weekday-long-day')}\n                  </h3>\n                  {!state && (\n                    <CalendarEventList\n                      events={getEventsForDay(visible, anchor, timeZone)}\n                      now={now}\n                      onSelectEvent={select}\n                      selectedEventId={selected?.id}\n                      timeZone={timeZone}\n                    />\n                  )}\n                </section>\n              </div>\n            ) : (\n              <CalendarWeekView\n                days={days}\n                events={visible}\n                now={now}\n                onSelectEvent={select}\n                selectedEventId={selected?.id}\n                timeZone={timeZone}\n                className='h-[34rem]'\n              />\n            )}\n          </div>\n          <div className='min-w-0 border-t pt-4 @4xl:col-start-1 @4xl:row-start-2'>\n            {selected ? (\n              <CalendarEventDetails\n                event={selected}\n                timeZone={timeZone}\n                onClose={closeDetails}\n              />\n            ) : (\n              !state && (\n                <p className='text-muted-foreground text-sm'>\n                  Select an event to see its details.\n                </p>\n              )\n            )}\n          </div>\n        </div>\n      </section>\n    </BlockStateProvider>\n  )\n}\n\nexport { Calendar3, exampleProps as calendar3ExampleProps, type Calendar3Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/calendar/calendar-03.tsx"
    }
  ],
  "meta": {
    "shows": "A content calendar that switches between month and week, with each calendar toggled from a sidebar.",
    "size": "full",
    "usedWith": [
      "calendar-01",
      "kanban-01"
    ],
    "component": "Calendar3",
    "props": "{ calendars: { color: string; name: string }[]; events?: { attendees?: { avatar?: string; name: string }[]; description?: string; resource?: string; allDay?: boolean; calendar?: string; color?: string; end?: Date; id: string; location?: string; start: Date; title: string }[]; now: Date; onSelectEvent?: (event: { attendees?: { avatar?: string; name: string }[]; description?: string; resource?: string; allDay?: boolean; calendar?: string; color?: string; end?: Date; id: string; location?: string; start: Date; title: string }) => void; timeZone?: string; view?: \"month\" | \"week\"; weekStartsOn?: 0 | 1; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
