{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "calendar-3",
  "title": "Month And Week Toggle",
  "description": "Calendar with a month and week view toggle, previous and next navigation, event chips on days, and an inline day panel.",
  "dependencies": [
    "@base-ui/react"
  ],
  "registryDependencies": [
    "badge",
    "button",
    "separator"
  ],
  "files": [
    {
      "path": "registry/blocks/calendar/3/calendar-block.tsx",
      "content": "\"use client\"\n\nimport { useMemo, useState } from \"react\"\nimport { Badge } from \"@/components/ui/badge\"\nimport { Button } from \"@/components/ui/button\"\nimport { Separator } from \"@/components/ui/separator\"\nimport { cn } from \"@/lib/utils\"\nimport { IconPlaceholder } from \"@/components/icons/icon-placeholder\"\n\nconst WEEKDAYS = [\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"]\n\nconst MONTH_NAMES = [\n  \"January\",\n  \"February\",\n  \"March\",\n  \"April\",\n  \"May\",\n  \"June\",\n  \"July\",\n  \"August\",\n  \"September\",\n  \"October\",\n  \"November\",\n  \"December\",\n]\n\ntype EventTone = \"default\" | \"secondary\" | \"outline\"\n\ntype CalendarEvent = {\n  id: string\n  title: string\n  time: string\n  tone: EventTone\n}\n\nconst EVENTS: Record<string, CalendarEvent[]> = {\n  \"2026-5-3\": [\n    { id: \"e1\", title: \"Team sync\", time: \"9:00 AM\", tone: \"secondary\" },\n    { id: \"e2\", title: \"1:1 with Dana\", time: \"11:30 AM\", tone: \"outline\" },\n  ],\n  \"2026-5-10\": [\n    { id: \"e3\", title: \"Q2 review\", time: \"2:00 PM\", tone: \"secondary\" },\n  ],\n  \"2026-5-18\": [\n    { id: \"e4\", title: \"Acme launch\", time: \"All day\", tone: \"default\" },\n    { id: \"e5\", title: \"Press briefing\", time: \"4:00 PM\", tone: \"outline\" },\n    { id: \"e6\", title: \"Launch party\", time: \"6:30 PM\", tone: \"secondary\" },\n  ],\n  \"2026-5-23\": [\n    { id: \"e7\", title: \"Design sprint\", time: \"10:00 AM\", tone: \"secondary\" },\n  ],\n  \"2026-5-29\": [\n    { id: \"e8\", title: \"Board meeting\", time: \"1:00 PM\", tone: \"outline\" },\n  ],\n}\n\nfunction keyFor(year: number, month: number, day: number) {\n  return `${year}-${month}-${day}`\n}\n\nconst TODAY = { year: 2026, month: 5, day: 18 }\n\nconst TONE_ACCENT: Record<EventTone, string> = {\n  default: \"bg-primary\",\n  secondary: \"bg-muted-foreground\",\n  outline: \"bg-muted-foreground/40\",\n}\n\ntype View = \"month\" | \"week\"\n\nexport default function CalendarBlock() {\n  const [cursor, setCursor] = useState(() => new Date(2026, 5, 18))\n  const [view, setView] = useState<View>(\"month\")\n  const [selected, setSelected] = useState<string | null>(keyFor(2026, 5, 18))\n\n  const year = cursor.getFullYear()\n  const month = cursor.getMonth()\n\n  const monthCells = useMemo(() => {\n    const firstWeekday = new Date(year, month, 1).getDay()\n    const daysInMonth = new Date(year, month + 1, 0).getDate()\n    const cells: (number | null)[] = [\n      ...Array(firstWeekday).fill(null),\n      ...Array.from({ length: daysInMonth }, (_, i) => i + 1),\n    ]\n    while (cells.length % 7 !== 0) cells.push(null)\n    return cells\n  }, [year, month])\n\n  const weekDays = useMemo(() => {\n    const start = new Date(cursor)\n    start.setDate(cursor.getDate() - cursor.getDay())\n    return Array.from({ length: 7 }, (_, i) => {\n      const d = new Date(start)\n      d.setDate(start.getDate() + i)\n      return d\n    })\n  }, [cursor])\n\n  function shift(step: number) {\n    setCursor((prev) => {\n      const next = new Date(prev)\n      if (view === \"month\") next.setMonth(prev.getMonth() + step)\n      else next.setDate(prev.getDate() + step * 7)\n      return next\n    })\n    setSelected(null)\n  }\n\n  function isToday(y: number, m: number, d: number) {\n    return y === TODAY.year && m === TODAY.month && d === TODAY.day\n  }\n\n  const headerLabel =\n    view === \"month\"\n      ? `${MONTH_NAMES[month]} ${year}`\n      : `${MONTH_NAMES[weekDays[0].getMonth()]} ${weekDays[0].getDate()} – ${weekDays[6].getDate()}, ${weekDays[6].getFullYear()}`\n\n  const selectedEvents = selected ? (EVENTS[selected] ?? []) : []\n  const [, selMonth, selDay] = selected\n    ? selected.split(\"-\").map(Number)\n    : [0, 0, 0]\n  const selectedLabel = selected ? `${MONTH_NAMES[selMonth]} ${selDay}` : \"\"\n\n  return (\n    <section className=\"flex min-h-svh w-full items-start justify-center bg-muted/30 px-6 py-16 text-foreground\">\n      <div className=\"w-full max-w-3xl\">\n        <div className=\"overflow-hidden rounded-lg border border-border bg-card text-card-foreground shadow-sm\">\n          <div className=\"flex flex-col gap-3 px-4 py-4 sm:flex-row sm:items-center sm:justify-between\">\n            <div className=\"flex items-center gap-2\">\n              <Button\n                variant=\"outline\"\n                size=\"icon-sm\"\n                aria-label={\n                  view === \"month\" ? \"Previous month\" : \"Previous week\"\n                }\n                onClick={() => shift(-1)}\n              >\n                <IconPlaceholder\n                  lucide=\"ChevronLeft\"\n                  tabler=\"IconChevronLeft\"\n                  hugeicons=\"ArrowLeft01Icon\"\n                  phosphor=\"CaretLeft\"\n                  remixicon=\"RiArrowLeftSLine\"\n                  aria-hidden=\"true\"\n                />\n              </Button>\n              <Button\n                variant=\"outline\"\n                size=\"icon-sm\"\n                aria-label={view === \"month\" ? \"Next month\" : \"Next week\"}\n                onClick={() => shift(1)}\n              >\n                <IconPlaceholder\n                  lucide=\"ChevronRight\"\n                  tabler=\"IconChevronRight\"\n                  hugeicons=\"ArrowRight01Icon\"\n                  phosphor=\"CaretRight\"\n                  remixicon=\"RiArrowRightSLine\"\n                  aria-hidden=\"true\"\n                />\n              </Button>\n              <h2 className=\"ml-1 font-heading text-base font-semibold tracking-tight\">\n                {headerLabel}\n              </h2>\n            </div>\n\n            <div className=\"inline-flex rounded-lg border border-border bg-muted/40 p-0.5\">\n              {([\"month\", \"week\"] as const).map((v) => (\n                <button\n                  key={v}\n                  type=\"button\"\n                  onClick={() => setView(v)}\n                  aria-pressed={view === v}\n                  className={cn(\n                    \"rounded-md px-3 py-1 text-sm font-medium capitalize transition-colors\",\n                    view === v\n                      ? \"bg-card text-foreground shadow-sm\"\n                      : \"text-muted-foreground hover:text-foreground\"\n                  )}\n                >\n                  {v}\n                </button>\n              ))}\n            </div>\n          </div>\n\n          <Separator />\n\n          <div className=\"grid grid-cols-7 border-b border-border bg-muted/20\">\n            {WEEKDAYS.map((d) => (\n              <div\n                key={d}\n                className=\"py-2 text-center text-xs font-medium text-muted-foreground\"\n              >\n                {d}\n              </div>\n            ))}\n          </div>\n\n          {view === \"month\" ? (\n            <div className=\"grid grid-cols-7\">\n              {monthCells.map((day, idx) => {\n                const k = day ? keyFor(year, month, day) : null\n                const events = k ? (EVENTS[k] ?? []) : []\n                const today = day ? isToday(year, month, day) : false\n                const isLastRow = idx >= monthCells.length - 7\n                const isSelected = k !== null && k === selected\n\n                return (\n                  <button\n                    key={idx}\n                    type=\"button\"\n                    disabled={day === null}\n                    onClick={() => k && setSelected(k)}\n                    className={cn(\n                      \"group flex min-h-[5rem] min-w-0 flex-col gap-1 border-border p-1.5 text-left align-top transition-colors sm:min-h-[6rem]\",\n                      idx % 7 !== 6 && \"border-r\",\n                      !isLastRow && \"border-b\",\n                      day === null && \"bg-muted/20\",\n                      day !== null && \"hover:bg-accent/40\",\n                      isSelected && \"bg-accent/60\"\n                    )}\n                  >\n                    {day !== null && (\n                      <>\n                        <span\n                          className={cn(\n                            \"flex size-6 items-center justify-center self-end rounded-md text-xs font-medium\",\n                            today\n                              ? \"bg-primary text-primary-foreground\"\n                              : \"text-foreground\"\n                          )}\n                        >\n                          {day}\n                        </span>\n\n                        <div className=\"flex min-w-0 flex-col gap-1\">\n                          {events.slice(0, 2).map((ev) => (\n                            <span\n                              key={ev.id}\n                              className=\"flex min-w-0 items-center gap-1.5\"\n                            >\n                              <span\n                                className={cn(\n                                  \"size-1.5 shrink-0\",\n                                  TONE_ACCENT[ev.tone]\n                                )}\n                                aria-hidden=\"true\"\n                              />\n                              <span className=\"truncate text-[10px] text-foreground/90\">\n                                {ev.title}\n                              </span>\n                            </span>\n                          ))}\n                          {events.length > 2 && (\n                            <span className=\"pl-3 text-[10px] font-medium text-muted-foreground\">\n                              +{events.length - 2} more\n                            </span>\n                          )}\n                        </div>\n                      </>\n                    )}\n                  </button>\n                )\n              })}\n            </div>\n          ) : (\n            <div className=\"grid grid-cols-7\">\n              {weekDays.map((d, idx) => {\n                const k = keyFor(d.getFullYear(), d.getMonth(), d.getDate())\n                const events = EVENTS[k] ?? []\n                const today = isToday(\n                  d.getFullYear(),\n                  d.getMonth(),\n                  d.getDate()\n                )\n                const isSelected = k === selected\n\n                return (\n                  <button\n                    key={idx}\n                    type=\"button\"\n                    onClick={() => setSelected(k)}\n                    className={cn(\n                      \"flex min-h-[14rem] min-w-0 flex-col gap-2 border-border p-2 text-left transition-colors\",\n                      idx !== 6 && \"border-r\",\n                      \"hover:bg-accent/40\",\n                      isSelected && \"bg-accent/60\"\n                    )}\n                  >\n                    <span\n                      className={cn(\n                        \"flex size-7 items-center justify-center self-start rounded-md text-sm font-semibold\",\n                        today\n                          ? \"bg-primary text-primary-foreground\"\n                          : \"text-foreground\"\n                      )}\n                    >\n                      {d.getDate()}\n                    </span>\n\n                    <div className=\"flex min-w-0 flex-col gap-1.5\">\n                      {events.map((ev) => (\n                        <div\n                          key={ev.id}\n                          className=\"flex min-w-0 items-stretch gap-1.5 overflow-hidden rounded-md bg-muted/40\"\n                        >\n                          <span\n                            className={cn(\n                              \"w-0.5 shrink-0\",\n                              TONE_ACCENT[ev.tone]\n                            )}\n                            aria-hidden=\"true\"\n                          />\n                          <div className=\"min-w-0 py-1 pr-1.5\">\n                            <p className=\"truncate text-xs font-medium\">\n                              {ev.title}\n                            </p>\n                            <p className=\"text-[10px] text-muted-foreground\">\n                              {ev.time}\n                            </p>\n                          </div>\n                        </div>\n                      ))}\n                    </div>\n                  </button>\n                )\n              })}\n            </div>\n          )}\n        </div>\n\n        {selected && (\n          <div className=\"relative mt-4 rounded-lg border border-border bg-card p-4 text-card-foreground shadow-sm\">\n            <button\n              type=\"button\"\n              aria-label=\"Close events\"\n              onClick={() => setSelected(null)}\n              className=\"absolute top-3 right-3 flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground\"\n            >\n              <IconPlaceholder\n                lucide=\"X\"\n                tabler=\"IconX\"\n                hugeicons=\"Cancel01Icon\"\n                phosphor=\"X\"\n                remixicon=\"RiCloseLine\"\n                className=\"size-4\"\n                aria-hidden=\"true\"\n              />\n            </button>\n\n            <div className=\"flex items-center gap-2 pr-8\">\n              <IconPlaceholder\n                lucide=\"CalendarDays\"\n                tabler=\"IconCalendarEvent\"\n                hugeicons=\"CalendarDaysIcon\"\n                phosphor=\"CalendarDots\"\n                remixicon=\"RiCalendarEventLine\"\n                className=\"size-4 text-muted-foreground\"\n                aria-hidden=\"true\"\n              />\n              <h3 className=\"font-heading text-sm font-semibold\">\n                {selectedLabel}\n              </h3>\n              <Badge variant=\"secondary\" className=\"text-[10px]\">\n                {selectedEvents.length}{\" \"}\n                {selectedEvents.length === 1 ? \"event\" : \"events\"}\n              </Badge>\n            </div>\n\n            {selectedEvents.length > 0 ? (\n              <ul className=\"mt-3 flex flex-col gap-2\">\n                {selectedEvents.map((ev) => (\n                  <li\n                    key={ev.id}\n                    className=\"flex items-center gap-3 rounded-lg border border-border bg-muted/30 px-3 py-2.5 transition-colors hover:bg-muted/50\"\n                  >\n                    <span\n                      className={cn(\"size-1.5 shrink-0\", TONE_ACCENT[ev.tone])}\n                      aria-hidden=\"true\"\n                    />\n                    <span className=\"min-w-0 flex-1 truncate text-sm font-medium\">\n                      {ev.title}\n                    </span>\n                    <span className=\"shrink-0 text-xs text-muted-foreground tabular-nums\">\n                      {ev.time}\n                    </span>\n                  </li>\n                ))}\n              </ul>\n            ) : (\n              <p className=\"mt-3 text-sm text-muted-foreground\">\n                No events scheduled. Enjoy the free day.\n              </p>\n            )}\n          </div>\n        )}\n      </div>\n    </section>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/blocks/calendar-3.tsx"
    }
  ],
  "meta": {
    "height": "942px",
    "tier": "free"
  },
  "categories": [
    "calendar"
  ],
  "type": "registry:block"
}