{"name":"calendar","type":"registry:ui","files":[{"path":"calendar.tsx","type":"registry:ui","content":"\"use client\"\n\nimport * as React from \"react\"\nimport { DayPicker, getDefaultClassNames } from \"react-day-picker\"\nimport type { ChevronProps, DropdownProps } from \"react-day-picker\"\nimport {\n  ChevronDown as ChevronDownIcon,\n  ChevronLeft as ChevronLeftIcon,\n  ChevronRight as ChevronRightIcon,\n} from \"honestui/icons\"\n\nimport { cn } from \"@/lib/utils\"\nimport { buttonVariants } from \"@/components/ui/button\"\nimport {\n  Select,\n  SelectItem,\n  SelectPopup,\n  SelectTrigger,\n  SelectValue,\n} from \"@/components/ui/select\"\n\n/**\n * The day button fills its 36px grid cell so the clickable area and any\n * selection fill cover the whole square. These are the same cell metrics as\n * the Date Range Picker, so a calendar and a range picker on one screen line\n * up exactly.\n */\nconst DAY_BUTTON_CLASS =\n  \"relative inline-flex h-full w-full cursor-pointer select-none items-center justify-center whitespace-nowrap rounded-[var(--hui-radius-1)] border-0 bg-transparent p-0 text-[var(--hui-color-foreground-base-primary)] tabular-nums [font-size:13px] [font-weight:var(--hui-font-weight-regular)] [letter-spacing:var(--hui-letter-spacing-small)] [line-height:var(--hui-line-height-small)] outline-none motion-safe:[transition:background-color_var(--hui-duration-fast)_var(--hui-ease-out),color_var(--hui-duration-fast)_var(--hui-ease-out)] hover:bg-[var(--hui-color-background-base-primary-hover)] focus-visible:[outline:var(--hui-focus-ring)] focus-visible:[outline-offset:-1px] disabled:cursor-not-allowed forced-colors:border forced-colors:border-transparent\"\n\n/*\n * Day states arrive as class names and data attributes on the grid cell, so\n * every state targets the cell's button. Today carries a small dot under the\n * number instead of a ring, so it never competes with the selection.\n */\nconst DAY_CELL_CLASS = cn(\n  \"size-(--hui-space-9) p-0 text-center align-middle\",\n  \"[&[data-today]>button]:after:pointer-events-none [&[data-today]>button]:after:absolute [&[data-today]>button]:after:bottom-[3px] [&[data-today]>button]:after:left-1/2 [&[data-today]>button]:after:size-1 [&[data-today]>button]:after:-translate-x-1/2 [&[data-today]>button]:after:rounded-full [&[data-today]>button]:after:bg-current [&[data-today]>button]:after:content-['']\",\n  \"[&[data-today]:not([data-selected])>button]:[font-weight:var(--hui-font-weight-medium)]\",\n  \"[&[data-disabled]>button]:pointer-events-none [&[data-disabled]>button]:text-[var(--hui-color-foreground-base-tertiary)]! [&[data-disabled]>button]:line-through [&[data-disabled]>button]:decoration-[var(--hui-color-foreground-base-tertiary)]\",\n  \"[&[data-outside]:not([data-disabled]):not([data-selected])>button]:text-[var(--hui-color-foreground-base-secondary)]\"\n)\n\n// Selected days are solid ink, the same fill as the default Button.\nconst SELECTED_CLASS =\n  \"[&>button]:bg-[var(--hui-color-background-neutral-emphasis)] [&>button]:text-[var(--hui-color-foreground-base-emphasis)] [&>button]:[font-weight:var(--hui-font-weight-medium)] [&>button:hover]:bg-[color-mix(in_oklch,var(--hui-color-background-neutral-emphasis)_86%,var(--hui-color-background-base-primary))] forced-colors:[&>button]:bg-[Highlight] forced-colors:[&>button]:text-[HighlightText]\"\n\n// Ranges read as one flat band: square middle cells on a neutral tint and\n// ink endpoints rounded only on their outer edge. A one-day range carries\n// both endpoint keys, and the opposite-side resets leave a square ink cell.\nconst RANGE_START_CLASS =\n  \"[&>button]:rounded-s-[var(--hui-radius-1)]! [&>button]:rounded-e-none!\"\nconst RANGE_END_CLASS =\n  \"[&>button]:rounded-e-[var(--hui-radius-1)]! [&>button]:rounded-s-none!\"\nconst RANGE_MIDDLE_CLASS =\n  \"[&>button]:rounded-none! [&>button]:bg-[color-mix(in_oklch,var(--hui-color-foreground-base-primary)_8%,transparent)]! [&>button]:text-[var(--hui-color-foreground-base-primary)]! [&>button]:[font-weight:var(--hui-font-weight-regular)]! [&>button:hover]:bg-[color-mix(in_oklch,var(--hui-color-foreground-base-primary)_14%,transparent)]!\"\n\nfunction CalendarChevron({ className, orientation, size }: ChevronProps) {\n  const iconClassName = cn(\"size-4\", className)\n  void size\n\n  if (orientation === \"left\") {\n    return <ChevronLeftIcon aria-hidden=\"true\" className={cn(iconClassName, \"rtl:rotate-180\")} />\n  }\n  if (orientation === \"right\") {\n    return <ChevronRightIcon aria-hidden=\"true\" className={cn(iconClassName, \"rtl:rotate-180\")} />\n  }\n  if (orientation === \"up\") {\n    return <ChevronDownIcon aria-hidden=\"true\" className={cn(iconClassName, \"rotate-180\")} />\n  }\n  return <ChevronDownIcon aria-hidden=\"true\" className={iconClassName} />\n}\n\n/**\n * Month and year pickers use Honest UI Select instead of the browser's\n * <select>, so the open list matches every other menu. DayPicker only reads\n * `event.target.value` from its change handler, so a minimal event is enough.\n */\nfunction CalendarDropdown({\n  options = [],\n  value,\n  onChange,\n  disabled,\n  \"aria-label\": ariaLabel,\n}: DropdownProps) {\n  const items = React.useMemo(\n    () => options.map((option) => ({ label: option.label, value: String(option.value) })),\n    [options]\n  )\n\n  return (\n    <Select\n      items={items}\n      value={value == null ? null : String(value)}\n      disabled={disabled}\n      onValueChange={(next) => {\n        if (next == null) return\n        onChange?.({\n          target: { value: next },\n          currentTarget: { value: next },\n        } as unknown as React.ChangeEvent<HTMLSelectElement>)\n      }}\n    >\n      <SelectTrigger\n        size=\"sm\"\n        aria-label={ariaLabel}\n        className=\"gap-(--hui-space-1) [font-weight:var(--hui-font-weight-medium)]\"\n      >\n        <SelectValue />\n      </SelectTrigger>\n      {/* The year list is long, so it scrolls. The scrollbar is hidden like the\n          Carousel's (!important beats unlayered global scrollbar rules). The\n          list padding scrolls with the items, so sticky 8px gradients in the\n          popup's own fill sit on both edges, with matching scroll padding: a\n          half-scrolled year fades out instead of being cut flush at the\n          border, the popup's border stays crisp, and the selected year opens\n          inset. */}\n      <SelectPopup className=\"max-h-[min(280px,var(--available-height))] [scroll-padding-block:var(--hui-space-3)] [scrollbar-width:none]! [&::-webkit-scrollbar]:hidden! before:pointer-events-none before:sticky before:top-0 before:z-1 before:-mb-(--hui-space-3) before:block before:h-(--hui-space-3) before:bg-linear-to-b before:from-[var(--hui-color-background-overlay)] before:to-transparent before:content-[''] after:pointer-events-none after:sticky after:bottom-0 after:z-1 after:-mt-(--hui-space-3) after:block after:h-(--hui-space-3) after:bg-linear-to-t after:from-[var(--hui-color-background-overlay)] after:to-transparent after:content-['']\">\n        {options.map((option) => (\n          <SelectItem\n            key={option.value}\n            value={String(option.value)}\n            disabled={option.disabled}\n            // A trailing check reserves space on every row but fills only one,\n            // so short labels sat off-center. Rows are centered instead, and\n            // the selected one takes the same ink fill as a selected day.\n            // aria-selected, because this project's data-selected variant\n            // expects data-selected=\"true\" and Base UI sets it empty.\n            className=\"justify-center tabular-nums [&>svg]:hidden aria-selected:bg-[var(--hui-color-background-neutral-emphasis)]! aria-selected:text-[var(--hui-color-foreground-base-emphasis)]! aria-selected:[font-weight:var(--hui-font-weight-medium)] aria-selected:data-[highlighted]:bg-[color-mix(in_oklch,var(--hui-color-background-neutral-emphasis)_86%,var(--hui-color-background-base-primary))]! forced-colors:aria-selected:bg-[Highlight]! forced-colors:aria-selected:text-[HighlightText]!\"\n          >\n            {option.label}\n          </SelectItem>\n        ))}\n      </SelectPopup>\n    </Select>\n  )\n}\n\ntype CalendarProps = React.ComponentProps<typeof DayPicker>\n\nfunction Calendar({\n  className,\n  classNames,\n  components,\n  showOutsideDays = true,\n  fixedWeeks = true,\n  captionLayout = \"label\",\n  hideNavigation,\n  ...props\n}: CalendarProps) {\n  const defaults = getDefaultClassNames()\n  const navButton = cn(\n    buttonVariants({ variant: \"link\", size: \"icon-sm\" }),\n    \"pointer-events-auto size-7 rounded-[var(--hui-radius-1)] text-[var(--hui-color-foreground-base-secondary)] hover:text-[var(--hui-color-foreground-base-primary)] aria-disabled:pointer-events-none aria-disabled:opacity-40\"\n  )\n  // DayPicker marks an unavailable previous or next month with aria-disabled\n  // (and removes it from the tab order) rather than the disabled attribute.\n\n  return (\n    <DayPicker\n      data-slot=\"calendar\"\n      showOutsideDays={showOutsideDays}\n      // Every month renders six weeks, so the calendar keeps one height\n      // while paging between months that span five or six rows.\n      fixedWeeks={fixedWeeks}\n      captionLayout={captionLayout}\n      hideNavigation={hideNavigation}\n      className={cn(\"w-fit p-[var(--hui-space-3)]\", className)}\n      classNames={{\n        root: cn(defaults.root, \"relative\"),\n        months: \"relative flex flex-col gap-y-(--hui-space-6) sm:flex-row sm:items-start sm:gap-x-(--hui-space-7)\",\n        month: \"flex flex-col\",\n        // The nav overlays the first caption row, so previous and next sit on\n        // either side of the month names however many months are shown.\n        nav: \"pointer-events-none absolute inset-x-0 top-0 z-10 flex h-(--hui-space-9) items-center justify-between\",\n        button_previous: navButton,\n        button_next: navButton,\n        month_caption: cn(\n          \"mb-(--hui-space-2) flex h-(--hui-space-9) items-center justify-center text-center text-[var(--hui-color-foreground-base-primary)] [font-size:var(--hui-font-size-regular)] [font-weight:var(--hui-font-weight-medium)] [letter-spacing:var(--hui-letter-spacing-regular)]\",\n          // Room for the overlaid arrows only when they are shown.\n          !hideNavigation && \"px-(--hui-space-9)\"\n        ),\n        caption_label: \"select-none\",\n        dropdowns: \"flex items-center gap-(--hui-space-2)\",\n        weekdays: \"\",\n        weekday:\n          \"h-(--hui-space-8) w-(--hui-space-9) text-center align-middle text-[var(--hui-color-foreground-base-secondary)] [font-size:var(--hui-font-size-small)] [font-weight:var(--hui-font-weight-regular)] [letter-spacing:var(--hui-letter-spacing-small)]\",\n        month_grid: \"border-collapse\",\n        weeks: \"\",\n        week: \"\",\n        week_number:\n          \"w-(--hui-space-9) text-center align-middle text-[var(--hui-color-foreground-base-tertiary)] [font-size:var(--hui-font-size-small)]\",\n        week_number_header: \"w-(--hui-space-9)\",\n        day: DAY_CELL_CLASS,\n        day_button: DAY_BUTTON_CLASS,\n        selected: SELECTED_CLASS,\n        range_start: RANGE_START_CLASS,\n        range_end: RANGE_END_CLASS,\n        range_middle: RANGE_MIDDLE_CLASS,\n        today: \"\",\n        outside: \"\",\n        disabled: \"\",\n        hidden: \"invisible\",\n        footer:\n          \"pt-(--hui-space-3) text-[var(--hui-color-foreground-base-secondary)] [font-size:var(--hui-font-size-small)] [line-height:var(--hui-line-height-small)]\",\n        ...classNames,\n      }}\n      components={{\n        Chevron: CalendarChevron,\n        Dropdown: CalendarDropdown,\n        ...components,\n      }}\n      {...props}\n    />\n  )\n}\n\nexport { Calendar }\nexport type { CalendarProps }\n","target":"components/ui/calendar.tsx"}],"dependencies":["honestui","react-day-picker"],"registryDependencies":["https://www.honestui.com/r/button.json","https://www.honestui.com/r/select.json"]}