{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "calendar-header",
  "title": "Calendar Header",
  "description": "The live demo's header: month and year with the period on screen, view switcher, today, previous/next and panel toggles.",
  "dependencies": [
    "date-fns",
    "lucide-react"
  ],
  "registryDependencies": [
    "@calendarcn/calendar-core",
    "button",
    "dropdown-menu",
    "kbd",
    "separator",
    "tooltip"
  ],
  "files": [
    {
      "path": "src/components/calendar-header.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { addDays, format } from \"date-fns\";\nimport {\n  ChevronLeftIcon,\n  ChevronRightIcon,\n  PanelLeftIcon,\n  PanelRightIcon,\n} from \"lucide-react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { useCalendar, useCalendarConfig } from \"@/components/calendar-provider\";\nimport { Button } from \"@/components/ui/button\";\nimport { Kbd } from \"@/components/ui/kbd\";\nimport { Separator } from \"@/components/ui/separator\";\nimport {\n  Tooltip,\n  TooltipContent,\n  TooltipProvider,\n  TooltipTrigger,\n} from \"@/components/ui/tooltip\";\nimport { ViewDropdown } from \"@/components/view-dropdown\";\nimport { AGENDA_DAYS } from \"@/lib/event-utils\";\n\nimport type { ViewType } from \"@/components/calendar-types\";\n\n/** What previous and next move by in each view, for their labels */\nconst PERIOD_LABELS: Record<ViewType, string> = {\n  day: \"day\",\n  week: \"week\",\n  month: \"month\",\n  year: \"year\",\n  agenda: `${AGENDA_DAYS} days`,\n};\n\ninterface CalendarHeaderProps {\n  /** Whether the sidebar is open: its toggle's tooltip offers to close or open it */\n  sidebarOpen?: boolean;\n  /** Opens or closes the sidebar. The sidebar toggle shows only when given */\n  onToggleSidebar?: () => void;\n  /** Whether the context panel is open. Its toggle hides while it is */\n  contextPanelOpen?: boolean;\n  /** Opens or closes the context panel. The toggle shows only when given */\n  onToggleContextPanel?: () => void;\n  /** Shown before the view switcher on wide headers, e.g. the signed-in user's avatar */\n  children?: React.ReactNode;\n  className?: string;\n}\n\n/**\n * The live demo's header: the sidebar toggle, the month and year with the\n * period on screen, then the view switcher, today, previous and next, and\n * the context panel toggle. Reads the calendar from `useCalendar()`, so it\n * goes inside `CalendarProvider`; the panels are your app's, so their state\n * comes in as props.\n */\nexport function CalendarHeader({\n  sidebarOpen = false,\n  onToggleSidebar,\n  contextPanelOpen = false,\n  onToggleContextPanel,\n  children,\n  className,\n}: CalendarHeaderProps) {\n  const { monthName, year } = useCalendar();\n\n  return (\n    // Tooltips need a provider with Radix; a closer one (yours) still wins\n    <TooltipProvider>\n      <header\n        className={cn(\n          \"@container/header bg-background sticky top-0 z-30 flex h-14 shrink-0 items-center gap-2\",\n          className,\n        )}\n      >\n        <div className=\"flex min-w-0 flex-1 items-center gap-1 pl-2 @md/header:gap-2 @xl/header:px-4\">\n          {onToggleSidebar && (\n            <>\n              <Tooltip>\n                <TooltipTrigger asChild>\n                  <Button\n                    variant=\"ghost\"\n                    size=\"icon\"\n                    className=\"size-7 text-muted-foreground\"\n                    onClick={onToggleSidebar}\n                  >\n                    <PanelLeftIcon />\n                    <span className=\"sr-only\">Toggle Calendar Sidebar</span>\n                  </Button>\n                </TooltipTrigger>\n                <TooltipContent side=\"bottom\">\n                  {sidebarOpen ? \"Close\" : \"Open\"} sidebar{\" \"}\n                  <Kbd className=\"ml-1\">⌘</Kbd> <Kbd>/</Kbd>\n                </TooltipContent>\n              </Tooltip>\n              <Separator\n                orientation=\"vertical\"\n                className=\"mr-2 hidden data-[orientation=vertical]:h-4 @md/header:block\"\n              />\n            </>\n          )}\n          <h1 className=\"min-w-0 truncate text-sm @xs/header:text-base @xl/header:text-xl\">\n            {/* Narrow headers use the short month (\"Sep\"); en-US \"MMMM\" names abbreviate to their first three letters */}\n            <span className=\"font-extrabold @md/header:hidden\">\n              {monthName.slice(0, 3)}\n            </span>\n            <span className=\"hidden font-extrabold @md/header:inline\">\n              {monthName}\n            </span>{\" \"}\n            <span className=\"font-extrabold\">{year}</span>{\" \"}\n            <CalendarPeriodLabel className=\"text-muted-foreground hidden text-xs @xl/header:inline\" />\n          </h1>\n        </div>\n        <div className=\"flex shrink-0 items-center gap-1 pr-2 @md/header:gap-2 @xl/header:px-4\">\n          {children && <div className=\"hidden @xl/header:flex\">{children}</div>}\n          <div className=\"hidden @xs/header:block\">\n            <CalendarViewSwitcher />\n          </div>\n          <CalendarNavigation buttonClassName=\"size-7 @2xs/header:size-8\" />\n          {onToggleContextPanel && !contextPanelOpen && (\n            <Tooltip>\n              <TooltipTrigger asChild>\n                <Button\n                  variant=\"ghost\"\n                  size=\"icon\"\n                  className=\"size-7 text-muted-foreground\"\n                  onClick={onToggleContextPanel}\n                >\n                  <PanelRightIcon />\n                  <span className=\"sr-only\">Toggle Navigation Sidebar</span>\n                </Button>\n              </TooltipTrigger>\n              <TooltipContent side=\"bottom\">\n                Open context panel <Kbd className=\"ml-1\">/</Kbd>\n              </TooltipContent>\n            </Tooltip>\n          )}\n        </div>\n      </header>\n    </TooltipProvider>\n  );\n}\n\ninterface CalendarPeriodLabelProps {\n  className?: string;\n}\n\n/**\n * The period on screen, for beside the title: the day (\"Thursday, Jun 4\"),\n * the week number (\"Week 23\") or the agenda's range. Empty in month and year view,\n * where the title already says it.\n */\nexport function CalendarPeriodLabel({ className }: CalendarPeriodLabelProps) {\n  const { view, currentDate, weekNumber } = useCalendar();\n  const { locale } = useCalendarConfig();\n\n  return (\n    <span className={className}>\n      {view === \"day\" && format(currentDate, \"EEEE, MMM d\", { locale })}\n      {view === \"week\" && `Week ${weekNumber}`}\n      {view === \"agenda\" &&\n        `${format(currentDate, \"MMM d\", { locale })} – ${format(addDays(currentDate, AGENDA_DAYS - 1), \"MMM d\", { locale })}`}\n    </span>\n  );\n}\n\n/**\n * The view dropdown wired to the provider: day, week, month, year or agenda, the\n * number of days, and the weekend, declined event and week number settings\n */\nexport function CalendarViewSwitcher() {\n  const {\n    view,\n    numberOfDays,\n    viewSettings,\n    switchView,\n    setNumberOfDays,\n    toggleWeekends,\n    toggleDeclinedEvents,\n    toggleWeekNumbers,\n  } = useCalendar();\n\n  return (\n    <ViewDropdown\n      view={view}\n      numberOfDays={numberOfDays}\n      viewSettings={viewSettings}\n      onSwitchView={switchView}\n      onSetNumberOfDays={setNumberOfDays}\n      onToggleWeekends={toggleWeekends}\n      onToggleDeclinedEvents={toggleDeclinedEvents}\n      onToggleWeekNumbers={toggleWeekNumbers}\n    />\n  );\n}\n\ninterface CalendarNavigationProps {\n  /** Classes for the previous and next buttons, e.g. their size */\n  buttonClassName?: string;\n}\n\n/** Today, then previous and next, labelled with the period they move by */\nexport function CalendarNavigation({\n  buttonClassName,\n}: CalendarNavigationProps) {\n  const { view, goToToday, goToPrev, goToNext } = useCalendar();\n  const periodLabel = PERIOD_LABELS[view];\n\n  return (\n    <>\n      <Button\n        variant=\"secondary\"\n        size=\"sm\"\n        className=\"px-2 @md/header:px-3\"\n        onClick={goToToday}\n      >\n        Today\n      </Button>\n      <div className=\"flex items-center\">\n        <Button\n          variant=\"ghost\"\n          size=\"icon\"\n          className={cn(\"text-muted-foreground\", buttonClassName)}\n          onClick={goToPrev}\n        >\n          <ChevronLeftIcon className=\"size-4\" />\n          <span className=\"sr-only\">Previous {periodLabel}</span>\n        </Button>\n        <Button\n          variant=\"ghost\"\n          size=\"icon\"\n          className={cn(\"text-muted-foreground\", buttonClassName)}\n          onClick={goToNext}\n        >\n          <ChevronRightIcon className=\"size-4\" />\n          <span className=\"sr-only\">Next {periodLabel}</span>\n        </Button>\n      </div>\n    </>\n  );\n}\n",
      "type": "registry:component"
    },
    {
      "path": "src/components/view-dropdown.tsx",
      "content": "\"use client\";\n\nimport { CheckIcon, ChevronDownIcon } from \"lucide-react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { Button } from \"@/components/ui/button\";\nimport {\n  DropdownMenu,\n  DropdownMenuCheckboxItem,\n  DropdownMenuContent,\n  DropdownMenuItem,\n  DropdownMenuSeparator,\n  DropdownMenuSub,\n  DropdownMenuSubContent,\n  DropdownMenuSubTrigger,\n  DropdownMenuTrigger,\n} from \"@/components/ui/dropdown-menu\";\nimport { Kbd, KbdGroup } from \"@/components/ui/kbd\";\n\nimport type { ViewSettings, ViewType } from \"@/components/week-view-types\";\n\n/** Display labels for each view type */\nconst VIEW_LABELS: Record<ViewType, string> = {\n  day: \"Day\",\n  week: \"Week\",\n  month: \"Month\",\n  year: \"Year\",\n  agenda: \"Agenda\",\n};\n\n/** View mode options with their shortcut labels */\nconst VIEW_OPTIONS: Array<{\n  value: ViewType;\n  label: string;\n  shortcuts: Array<string>;\n}> = [\n  { value: \"day\", label: \"Day\", shortcuts: [\"1\", \"or\", \"D\"] },\n  { value: \"week\", label: \"Week\", shortcuts: [\"0\", \"or\", \"W\"] },\n  { value: \"month\", label: \"Month\", shortcuts: [\"M\"] },\n  { value: \"year\", label: \"Year\", shortcuts: [\"Y\"] },\n  { value: \"agenda\", label: \"Agenda\", shortcuts: [\"A\"] },\n];\n\n/** Number-of-days options for the submenu */\nconst DAYS_OPTIONS = [2, 3, 4, 5, 6, 7, 8, 9] as const;\n\n/** Views that hide the weekend when \"Weekends\" is off. The rest ignore it for now */\nconst WEEKENDS_SETTING_VIEWS: ViewType[] = [\"month\", \"agenda\"];\n\n/** Views that draw week numbers when \"Week numbers\" is on. The rest ignore it for now */\nconst WEEK_NUMBERS_SETTING_VIEWS: ViewType[] = [\"month\", \"year\"];\n\n/**\n * Shortcut hints inside menu items drop the key-cap background. Classes\n * rather than a Kbd variant, so the file works with the stock shadcn/ui Kbd.\n */\nconst PLAIN_KBD_CLASS = \"h-auto min-w-0 rounded-none bg-transparent px-0\";\n\n/** \"Soon\" badge of a setting the current view doesn't read yet, as in the command menu */\nconst SOON_BADGE = (\n  <span className=\"bg-muted text-muted-foreground ml-auto rounded px-1.5 py-0.5 text-[10px] leading-none font-medium\">\n    Soon\n  </span>\n);\n\n/**\n * A setting marked \"Soon\" stays disabled, but only its label and check dim:\n * the badge keeps its full strength. Both spellings of the variant, because\n * the Radix and Base UI styles of shadcn/ui write it differently.\n */\nconst SOON_ITEM_CLASS =\n  \"data-[disabled]:opacity-100 data-disabled:opacity-100 [&_svg]:opacity-50\";\n\ninterface ViewDropdownProps {\n  view: ViewType;\n  numberOfDays: number;\n  viewSettings: ViewSettings;\n  onSwitchView: (view: ViewType) => void;\n  onSetNumberOfDays: (count: number) => void;\n  onToggleWeekends: () => void;\n  onToggleDeclinedEvents: () => void;\n  onToggleWeekNumbers: () => void;\n}\n\nexport function ViewDropdown({\n  view,\n  numberOfDays,\n  viewSettings,\n  onSwitchView,\n  onSetNumberOfDays,\n  onToggleWeekends,\n  onToggleDeclinedEvents,\n  onToggleWeekNumbers,\n}: ViewDropdownProps) {\n  const weekendsSoon = !WEEKENDS_SETTING_VIEWS.includes(view);\n  const weekNumbersSoon = !WEEK_NUMBERS_SETTING_VIEWS.includes(view);\n\n  return (\n    <DropdownMenu>\n      <DropdownMenuTrigger asChild>\n        <Button variant=\"secondary\" size=\"sm\" className=\"gap-1 px-3\">\n          {VIEW_LABELS[view]}\n          <ChevronDownIcon className=\"size-4 text-muted-foreground\" />\n        </Button>\n      </DropdownMenuTrigger>\n      <DropdownMenuContent align=\"start\" sideOffset={8} className=\"w-56\">\n        {VIEW_OPTIONS.map((option) => (\n          <DropdownMenuItem\n            key={option.value}\n            onClick={() => onSwitchView(option.value)}\n          >\n            <CheckIcon\n              className={cn(\n                \"size-4 shrink-0\",\n                view !== option.value && \"invisible\",\n              )}\n            />\n            {option.label}\n            <KbdGroup className=\"ml-auto\">\n              {option.shortcuts.map((s) =>\n                s === \"or\" ? (\n                  <span key={s} className=\"text-muted-foreground text-xs\">\n                    or\n                  </span>\n                ) : (\n                  <Kbd key={s} className={PLAIN_KBD_CLASS}>\n                    {s}\n                  </Kbd>\n                ),\n              )}\n            </KbdGroup>\n          </DropdownMenuItem>\n        ))}\n\n        <DropdownMenuSeparator />\n\n        {/* Number of days submenu */}\n        <DropdownMenuSub>\n          <DropdownMenuSubTrigger className=\"pl-8\">\n            Number of days\n          </DropdownMenuSubTrigger>\n          <DropdownMenuSubContent>\n            {DAYS_OPTIONS.map((n) => (\n              <DropdownMenuItem key={n} onClick={() => onSetNumberOfDays(n)}>\n                <CheckIcon\n                  className={cn(\n                    \"size-4 shrink-0\",\n                    numberOfDays !== n && \"invisible\",\n                  )}\n                />\n                {n} days\n                <Kbd className={cn(PLAIN_KBD_CLASS, \"ml-auto\")}>{n}</Kbd>\n              </DropdownMenuItem>\n            ))}\n          </DropdownMenuSubContent>\n        </DropdownMenuSub>\n\n        <DropdownMenuSeparator />\n\n        {/* View settings submenu */}\n        <DropdownMenuSub>\n          <DropdownMenuSubTrigger className=\"pl-8\">\n            View settings\n          </DropdownMenuSubTrigger>\n          <DropdownMenuSubContent className=\"w-56\">\n            {/* Day and week view don't hide the weekend yet */}\n            <DropdownMenuCheckboxItem\n              disabled={weekendsSoon}\n              className={cn(weekendsSoon && SOON_ITEM_CLASS)}\n              checked={viewSettings.showWeekends}\n              onCheckedChange={() => onToggleWeekends()}\n            >\n              <span className={cn(weekendsSoon && \"opacity-50\")}>Weekends</span>\n              {weekendsSoon ? (\n                SOON_BADGE\n              ) : (\n                <KbdGroup className=\"ml-auto\">\n                  <Kbd className={PLAIN_KBD_CLASS}>shift</Kbd>\n                  <Kbd className={PLAIN_KBD_CLASS}>&#8984;</Kbd>\n                  <Kbd className={PLAIN_KBD_CLASS}>E</Kbd>\n                </KbdGroup>\n              )}\n            </DropdownMenuCheckboxItem>\n\n            {/* Nothing filters by this setting yet */}\n            <DropdownMenuCheckboxItem\n              disabled\n              className={SOON_ITEM_CLASS}\n              checked={viewSettings.showDeclinedEvents}\n              onCheckedChange={() => onToggleDeclinedEvents()}\n            >\n              <span className=\"opacity-50\">Declined events</span>\n              {SOON_BADGE}\n            </DropdownMenuCheckboxItem>\n\n            {/* Month and year view draw week numbers */}\n            <DropdownMenuCheckboxItem\n              disabled={weekNumbersSoon}\n              className={cn(weekNumbersSoon && SOON_ITEM_CLASS)}\n              checked={viewSettings.showWeekNumbers}\n              onCheckedChange={() => onToggleWeekNumbers()}\n            >\n              <span className={cn(weekNumbersSoon && \"opacity-50\")}>\n                Week numbers\n              </span>\n              {weekNumbersSoon && SOON_BADGE}\n            </DropdownMenuCheckboxItem>\n          </DropdownMenuSubContent>\n        </DropdownMenuSub>\n      </DropdownMenuContent>\n    </DropdownMenu>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}