{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "date-calendar",
  "type": "registry:ui",
  "title": "Date Calendar",
  "description": "Inline month calendar for a date or a range, on Date Picker's month panel, with today marked and unavailable days struck through, on React Aria's Calendar.",
  "dependencies": [
    "@internationalized/date@^3.12.1",
    "react-aria-components@^1.17.0"
  ],
  "registryDependencies": [
    "cx"
  ],
  "files": [
    {
      "path": "components/base/date-picker/date-calendar.tsx",
      "content": "\"use client\";\n\nimport { Calendar as AriaCalendar, RangeCalendar as AriaRangeCalendar } from \"react-aria-components\";\nimport type {\n  CalendarProps as AriaCalendarProps,\n  DateValue,\n  RangeCalendarProps as AriaRangeCalendarProps,\n} from \"react-aria-components\";\nimport { MonthPanel } from \"@/components/base/date-picker/shared\";\nimport { cx } from \"@/utils/cx\";\n\n/**\n * Date calendar — a month on the page rather than in a popover: pick a day\n * for a booking, a deadline, a range of nights.\n *\n *   <DateCalendar aria-label=\"Delivery date\" value={date} onChange={setDate} />\n *   <DateRangeCalendar aria-label=\"Stay\" value={range} onChange={setRange} />\n *\n * Date Picker's month panel, as is: the card, the 16px month chevrons, the\n * 32px day cells 12px apart with the selected day's accent pill and the\n * range band that bridges the gaps. Today carries a small accent dot, and\n * days ruled out by `isDateUnavailable` are struck through.\n *\n * Built on React Aria's Calendar and RangeCalendar: arrows move by day,\n * Page Up and Page Down by month (with Shift, by year), Home and End to the\n * month's first and last day, and Enter picks. `minValue` and `maxValue`\n * fade the days outside them. Values are dates from @internationalized/date.\n */\n\nexport interface DateCalendarProps<T extends DateValue> extends Omit<AriaCalendarProps<T>, \"className\" | \"children\" | \"visibleDuration\"> {\n  /** Mark today with a dot. Default true. */\n  showToday?: boolean;\n  className?: string;\n}\n\nexport function DateCalendar<T extends DateValue>({ showToday = true, className, ...props }: DateCalendarProps<T>) {\n  return (\n    <AriaCalendar {...props} className={cx(\"inline-flex outline-none\", className)}>\n      <MonthPanel offset={0} showPrev showNext showToday={showToday} />\n    </AriaCalendar>\n  );\n}\n\nexport interface DateRangeCalendarProps<T extends DateValue>\n  extends Omit<AriaRangeCalendarProps<T>, \"className\" | \"children\" | \"visibleDuration\"> {\n  /** One month, or two side by side (default). They stack when the space is narrow. */\n  visibleMonths?: 1 | 2;\n  /** Mark today with a dot. Default true. */\n  showToday?: boolean;\n  className?: string;\n}\n\nexport function DateRangeCalendar<T extends DateValue>({\n  visibleMonths = 2,\n  showToday = true,\n  className,\n  ...props\n}: DateRangeCalendarProps<T>) {\n  return (\n    <AriaRangeCalendar\n      {...props}\n      visibleDuration={{ months: visibleMonths }}\n      className={cx(\"inline-flex outline-none\", className)}\n    >\n      <div className=\"flex flex-wrap justify-center gap-2\">\n        {visibleMonths === 2 ? (\n          <>\n            <MonthPanel offset={0} showPrev showToday={showToday} />\n            <MonthPanel offset={1} showNext showToday={showToday} />\n          </>\n        ) : (\n          <MonthPanel offset={0} showPrev showNext showToday={showToday} />\n        )}\n      </div>\n    </AriaRangeCalendar>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/base/date-picker/date-calendar.tsx"
    },
    {
      "path": "components/base/date-picker/shared.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useState, useContext } from \"react\";\nimport {\n  Button as RACButton,\n  CalendarCell,\n  CalendarGrid,\n  CalendarGridBody,\n  CalendarGridHeader,\n  CalendarHeaderCell,\n  CalendarStateContext,\n  RangeCalendarStateContext,\n  useLocale,\n} from \"react-aria-components\";\nimport type { CalendarCellRenderProps } from \"react-aria-components\";\nimport { CalendarDate, endOfWeek, getLocalTimeZone, isSameDay, startOfWeek } from \"@internationalized/date\";\nimport { cx } from \"@/utils/cx\";\n\n/**\n * Shared building blocks for the base/date-picker family — `DateRangePicker`\n * (dual-month, node 3871:5738) and `DatePicker` (single-month, node\n * 3879:6708) are the same visual system (month panel, day cell, editable\n * date chip) around two different react-aria-components roots\n * (`RangeCalendar` vs `Calendar`). Keeping the pieces here means a Figma\n * fidelity fix only has to happen once.\n */\n\n/** Exact paths from Figma's month-nav chevrons (node 3869:5461 / 3869:5528) — a\n *  16×16 glyph, 2px round-capped stroke, mirrored around x=8. */\nexport function ChevronLeft16({ className }: { className?: string }) {\n  return (\n    <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" className={cx(\"rtl:rotate-180\", className)} aria-hidden>\n      <path\n        d=\"M9 4L5.70711 7.29289C5.31658 7.68342 5.31658 8.31658 5.70711 8.70711L9 12\"\n        stroke=\"currentColor\"\n        strokeWidth=\"2\"\n        strokeLinecap=\"round\"\n      />\n    </svg>\n  );\n}\n\nexport function ChevronRight16({ className }: { className?: string }) {\n  return (\n    <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" className={cx(\"rtl:rotate-180\", className)} aria-hidden>\n      <path\n        d=\"M7 4L10.2929 7.29289C10.6834 7.68342 10.6834 8.31658 10.2929 8.70711L7 12\"\n        stroke=\"currentColor\"\n        strokeWidth=\"2\"\n        strokeLinecap=\"round\"\n      />\n    </svg>\n  );\n}\n\nexport function formatTriggerDate(date: CalendarDate, locale?: string) {\n  return new Intl.DateTimeFormat(locale, { month: \"short\", day: \"numeric\", year: \"numeric\" }).format(\n    date.toDate(getLocalTimeZone()),\n  );\n}\n\nexport function formatChipDate(date: CalendarDate) {\n  return `${String(date.day).padStart(2, \"0\")}/${String(date.month).padStart(2, \"0\")}/${date.year}`;\n}\n\n/** Parses the chip's own \"DD/MM/YYYY\" format back into a CalendarDate, or\n *  null if the text isn't a valid date (out-of-range day/month is rejected\n *  up front; CalendarDate itself constrains impossible day-in-month combos\n *  like Feb 30). */\nexport function parseChipDate(text: string): CalendarDate | null {\n  const match = /^(\\d{1,2})\\/(\\d{1,2})\\/(\\d{4})$/.exec(text.trim());\n  if (!match) return null;\n  const day = Number(match[1]);\n  const month = Number(match[2]);\n  const year = Number(match[3]);\n  if (month < 1 || month > 12 || day < 1 || day > 31) return null;\n  return new CalendarDate(year, month, day);\n}\n\nexport function DayCell(props: CalendarCellRenderProps & { isRange: boolean; showToday?: boolean }) {\n  const { locale } = useLocale();\n  const { date, formattedDate, isSelected, isSelectionStart, isSelectionEnd, isHovered, isFocusVisible, isDisabled, isUnavailable, isToday, isOutsideMonth, isRange, showToday = false } = props;\n\n  if (isOutsideMonth) {\n    return <div className=\"size-8\" />;\n  }\n\n  const isWeekStart = isSameDay(date, startOfWeek(date, locale));\n  const isWeekEnd = isSameDay(date, endOfWeek(date, locale));\n\n  // A plain (non-range) Calendar never sets isSelectionStart/isSelectionEnd —\n  // those are range-only concepts, so they stay false even for the one\n  // selected day. Without isRange, that day would fall through to the\n  // \"middle of a range\" backdrop path instead of rendering as its own pill.\n  const isSingleDay = isRange ? isSelectionStart && isSelectionEnd : isSelected;\n  const isEdge = isRange ? isSelectionStart || isSelectionEnd : isSelected;\n\n  // Cells sit 12px apart (Figma's row/column gap). A selected range should\n  // still read as one continuous band, so the background bridges that gap by\n  // extending half of it (6px) toward each selected neighbor — never past\n  // the first/last column of a row, where there's no neighbor to bridge to.\n  // Only meaningful for a RangeCalendar; a plain Calendar never bridges.\n  const extendStart = isRange && isSelected && !isSelectionStart && !isWeekStart;\n  const extendEnd = isRange && isSelected && !isSelectionEnd && !isWeekEnd;\n\n  // The blue backgrounds fade in/out on opacity instead of popping instantly.\n  // Both layers always render (geometry computed regardless of selection) so\n  // toggling opacity is a plain CSS transition, not a mount/unmount — that\n  // keeps ~70 cells worth of range changes cheap and reliably animated.\n  // border-radius rides the same transition as opacity: the rounding classes\n  // still flip instantly on deselect (the shape a cell \"should\" have has no\n  // in-between state), but transitioning the property means it eases toward\n  // square in sync with the fade instead of snapping to square immediately\n  // while the color is still visible.\n  return (\n    <div className=\"relative size-8\">\n      <span\n        aria-hidden\n        className={cx(\n          \"absolute inset-y-0 bg-date-range-background transition-[opacity,border-radius] duration-100 ease-out\",\n          isSelectionStart ? \"start-1/2\" : extendStart ? \"-start-1.5\" : \"start-0\",\n          isSelectionEnd ? \"end-1/2\" : extendEnd ? \"-end-1.5\" : \"end-0\",\n          !isSelectionStart && isWeekStart && \"rounded-s-lg\",\n          !isSelectionEnd && isWeekEnd && \"rounded-e-lg\",\n          isSelected && !isSingleDay ? \"opacity-100\" : \"opacity-0\",\n        )}\n      />\n      <div\n        className={cx(\n          \"relative flex size-8 items-center justify-center rounded-lg outline-none\",\n          !isSelected && isHovered && \"bg-background-secondary-hover\",\n          \"transition-colors duration-100 ease-out\",\n          isFocusVisible && \"ring-2 ring-inset ring-border-focus-ring\",\n        )}\n      >\n        <span\n          aria-hidden\n          className={cx(\n            \"absolute inset-0 bg-date-range-edge-background transition-[opacity,border-radius] duration-100 ease-out\",\n            isSingleDay && \"rounded-lg\",\n            isSelectionStart && !isSingleDay && \"rounded-s-lg\",\n            isSelectionEnd && !isSingleDay && \"rounded-e-lg\",\n            isEdge ? \"opacity-100\" : \"opacity-0\",\n          )}\n        />\n        <span\n          className={cx(\n            \"relative text-body-medium text-text-primary\",\n            (isDisabled || isUnavailable) && \"text-text-tertiary\",\n            // Unavailable days (isDateUnavailable) can be focused but not\n            // picked, so they read as struck out rather than just faded.\n            isUnavailable && \"line-through\",\n          )}\n        >\n          {formattedDate}\n        </span>\n        {/* Opt-in (the standalone Calendar): a dot under today's date. */}\n        {showToday && isToday ? (\n          <span\n            aria-hidden\n            className={cx(\"absolute bottom-1 left-1/2 size-1 -translate-x-1/2 rounded-full\", isEdge ? \"bg-text-primary\" : \"bg-accent-500\")}\n          />\n        ) : null}\n      </div>\n    </div>\n  );\n}\n\nexport function MonthPanel({\n  offset,\n  showPrev,\n  showNext,\n  bare = false,\n  hideHeader = false,\n  showToday = false,\n}: {\n  offset: number;\n  showPrev?: boolean;\n  showNext?: boolean;\n  /** Skip the panel's own card chrome (width, bg, padding, shadow) so it can\n   *  be embedded directly inside a caller-styled container instead — used by\n   *  the calendar template's inline month switcher, which supplies its own\n   *  card (matching a different surface's border/shadow). */\n  bare?: boolean;\n  /** Skip the title + prev/next row entirely — used when a caller already\n   *  renders its own single month title/nav (the calendar template's month\n   *  switcher pill) and only needs the day grid underneath it. */\n  hideHeader?: boolean;\n  /** Mark today with a dot under its date (the standalone Calendar does). */\n  showToday?: boolean;\n}) {\n  const { locale } = useLocale();\n  // Works inside either a RangeCalendar (DateRangePicker) or a plain Calendar\n  // (DatePicker) — exactly one of these contexts is non-null depending on\n  // which root rendered it, and both expose the same `visibleRange` shape.\n  const rangeState = useContext(RangeCalendarStateContext);\n  const singleState = useContext(CalendarStateContext);\n  const state = rangeState ?? singleState;\n  const isRange = rangeState != null;\n  const panelDate = state ? state.visibleRange.start.add({ months: offset }) : null;\n  const title = panelDate\n    ? new Intl.DateTimeFormat(locale, { month: \"long\", year: \"numeric\" }).format(panelDate.toDate(getLocalTimeZone()))\n    : \"\";\n  // Two-letter weekdays (\"Su\", \"Mo\") only work in Latin scripts: cut down,\n  // every Arabic name keeps just its article. Other scripts take the\n  // locale's narrow names instead.\n  const latinWeekdays = /^\\p{Script=Latin}/u.test(\n    new Intl.DateTimeFormat(locale, { weekday: \"short\" }).format(new Date(2024, 0, 7)),\n  );\n\n  return (\n    <div className={bare ? \"w-[296px] shrink-0\" : \"w-[326px] shrink-0 rounded-2xl bg-background-primary-default p-[15px] shadow-xs\"}>\n      <div className=\"flex flex-col gap-5\">\n        {!hideHeader && (\n          <div className=\"flex items-center justify-between\">\n            {showPrev ? (\n              <RACButton\n                slot=\"previous\"\n                className=\"flex size-4 cursor-pointer items-center justify-center rounded-[3px] text-text-secondary outline-none transition-colors duration-150 ease hover:bg-background-secondary-hover\"\n              >\n                <ChevronLeft16 />\n              </RACButton>\n            ) : (\n              <span className=\"size-4\" aria-hidden />\n            )}\n            <span className=\"flex-1 text-center text-body-medium text-text-primary\">{title}</span>\n            {showNext ? (\n              <RACButton\n                slot=\"next\"\n                className=\"flex size-4 cursor-pointer items-center justify-center rounded-[3px] text-text-secondary outline-none transition-colors duration-150 ease hover:bg-background-secondary-hover\"\n              >\n                <ChevronRight16 />\n              </RACButton>\n            ) : (\n              <span className=\"size-4\" aria-hidden />\n            )}\n          </div>\n        )}\n        <CalendarGrid\n          offset={{ months: offset }}\n          weekdayStyle={latinWeekdays ? \"short\" : \"narrow\"}\n          className=\"-m-3 self-start border-separate outline-none\"\n          style={{ borderSpacing: \"12px 12px\" }}\n        >\n          <CalendarGridHeader>\n            {(day) => (\n              <CalendarHeaderCell className=\"size-6 pb-0 text-center text-body-medium text-text-secondary\">\n                {latinWeekdays ? day.slice(0, 2) : day}\n              </CalendarHeaderCell>\n            )}\n          </CalendarGridHeader>\n          <CalendarGridBody>\n            {(date) => (\n              <CalendarCell date={date} className=\"p-0 outline-none\">\n                {(cellProps) => <DayCell {...cellProps} isRange={isRange} showToday={showToday} />}\n              </CalendarCell>\n            )}\n          </CalendarGridBody>\n        </CalendarGrid>\n      </div>\n    </div>\n  );\n}\n\n/** One editable \"DD/MM/YYYY\" chip. Keeps its own draft text while typing so\n *  the field doesn't reformat on every keystroke; commits on blur/Enter,\n *  reverting to the last valid value if the text doesn't parse. */\nexport function DateChipInput({\n  date,\n  label,\n  onCommit,\n}: {\n  date: CalendarDate;\n  label: string;\n  onCommit: (date: CalendarDate) => void;\n}) {\n  const formatted = formatChipDate(date);\n  const [text, setText] = useState(formatted);\n\n  useEffect(() => {\n    setText(formatted);\n  }, [formatted]);\n\n  const commit = () => {\n    const parsed = parseChipDate(text);\n    if (parsed) {\n      onCommit(parsed);\n    } else {\n      setText(formatted);\n    }\n  };\n\n  return (\n    <input\n      type=\"text\"\n      dir=\"ltr\"\n      inputMode=\"numeric\"\n      value={text}\n      onChange={(event) => setText(event.target.value)}\n      onBlur={commit}\n      onKeyDown={(event) => {\n        if (event.key === \"Enter\") event.currentTarget.blur();\n        if (event.key === \"Escape\") setText(formatted);\n      }}\n      aria-label={label}\n      className=\"w-[104px] rounded-2lg border border-border-button-default bg-background-primary-default px-2 py-2 text-body-medium text-text-primary shadow-xs outline-none transition-colors duration-100 ease-out focus-visible:border-border-button-active\"\n    />\n  );\n}\n\n/** Shared trigger-button chrome for both pickers (Figma's \"Primary\" button —\n *  calendar icon + formatted-value text, white surface, radius/2lg). */\nexport const triggerButtonClassName = cx(\n  \"inline-flex shrink-0 cursor-pointer items-center gap-0.5 rounded-2lg border border-border-button-default bg-background-primary-default p-2 shadow-xs outline-none\",\n  \"transition-[background-color,border-color,box-shadow] duration-150 ease\",\n  \"hover:bg-background-primary-hover hover:border-border-button-hover\",\n  \"focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-border-focus-ring\",\n  \"disabled:cursor-not-allowed disabled:bg-background-primary-disabled disabled:text-text-tertiary disabled:shadow-none\",\n);\n\n/** Shared popover chrome (Figma's rounded/3xl, background/secondary/default\n *  \"Calendar component\" surface) for both pickers. */\nexport const popoverClassName = cx(\n  // Above the modal layer (z-100), like the menu surfaces.\n  \"z-110 origin-top rounded-3xl bg-background-secondary-default shadow-dropdown\",\n  \"transition duration-150 ease-out\",\n  \"data-[entering]:opacity-0 data-[entering]:scale-95 data-[entering]:blur-[2px]\",\n  \"data-[exiting]:opacity-0 data-[exiting]:scale-95 data-[exiting]:blur-[2px]\",\n);\n",
      "type": "registry:component",
      "target": "components/base/date-picker/shared.tsx"
    }
  ],
  "meta": {
    "docsUrl": "https://www.boardui.com/components/date-calendar",
    "example": "import { useState } from \"react\";\nimport { getLocalTimeZone, today } from \"@internationalized/date\";\nimport { DateCalendar } from \"@/components/base/date-picker/date-calendar\";\n\nexport function Example() {\n  const [date, setDate] = useState(today(getLocalTimeZone()).add({ days: 2 }));\n  return (\n    <DateCalendar\n      aria-label=\"Delivery date\"\n      value={date}\n      onChange={setDate}\n      minValue={today(getLocalTimeZone())}\n    />\n  );\n}",
    "snippets": [
      {
        "label": "range",
        "code": "import { DateRangeCalendar } from \"@/components/base/date-picker/date-calendar\";\n\nconst [range, setRange] = useState({ start: nextWeek, end: nextWeek.add({ days: 4 }) });\n\n<DateRangeCalendar aria-label=\"Stay\" value={range} onChange={setRange} minValue={today(getLocalTimeZone())} />"
      },
      {
        "label": "availability",
        "code": "import { getLocalTimeZone, isWeekend, today } from \"@internationalized/date\";\nimport { useLocale } from \"react-aria-components\";\n\nconst { locale } = useLocale();\nconst now = today(getLocalTimeZone());\n\n<DateCalendar\n  aria-label=\"Appointment date\"\n  minValue={now}\n  maxValue={now.add({ weeks: 6 })}\n  isDateUnavailable={(date) => isWeekend(date, locale)}\n/>"
      },
      {
        "label": "rtl",
        "code": "import { DirectionProvider } from \"@/components/foundations/direction/direction\";\n\n<DirectionProvider locale=\"ar\">\n  <DateCalendar aria-label=\"تاريخ التسليم\" />\n</DirectionProvider>"
      }
    ]
  }
}
