{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "calendar-story",
  "title": "Calendar Story",
  "author": "Lloyd Richards <lloyd.d.richards@gmail.com>",
  "description": "Interactive Storybook stories demonstrating calendar component usage and variants",
  "dependencies": [
    "@internationalized/date",
    "react-aria-components"
  ],
  "registryDependencies": [
    "calendar",
    "card"
  ],
  "files": [
    {
      "path": "registry/ui/calendar-story/calendar-aria.stories.tsx",
      "content": "import { expect, userEvent, waitFor } from \"storybook/test\";\nimport type { Meta, StoryObj } from \"@storybook/nextjs-vite\";\nimport * as React from \"react\";\nimport {\n  CalendarDate,\n  getLocalTimeZone,\n  isSameDay,\n  today,\n} from \"@internationalized/date\";\nimport { I18nProvider, type DateRange } from \"react-aria-components\";\nimport { Calendar, RangeCalendar } from \"@/components/ui/calendar\";\nimport { Card, CardContent } from \"@/components/ui/card\";\n\nfunction CalendarSingle() {\n  const [date, setDate] = React.useState<CalendarDate | undefined>(\n    new CalendarDate(new Date().getFullYear(), new Date().getMonth() + 1, 12),\n  );\n  return (\n    <Card className=\"mx-auto w-fit p-0\">\n      <CardContent className=\"p-0\">\n        <Calendar value={date} onChange={setDate} />\n      </CardContent>\n    </Card>\n  );\n}\n\nfunction CalendarMultiple() {\n  return (\n    <Card className=\"mx-auto w-fit p-0\">\n      <CardContent className=\"p-0\">\n        <Calendar selectionMode=\"multiple\" />\n      </CardContent>\n    </Card>\n  );\n}\n\nfunction CalendarRange() {\n  const [dateRange, setDateRange] = React.useState<DateRange | undefined>({\n    start: new CalendarDate(new Date().getFullYear(), 1, 12),\n    end: new CalendarDate(new Date().getFullYear(), 1, 12).add({ days: 30 }),\n  });\n\n  return (\n    <Card className=\"mx-auto w-fit p-0\">\n      <CardContent className=\"p-0\">\n        <RangeCalendar\n          value={dateRange}\n          onChange={setDateRange}\n          numberOfMonths={2}\n          maxValue={today(getLocalTimeZone())}\n        />\n      </CardContent>\n    </Card>\n  );\n}\n\nfunction CalendarRangeMultipleMonths() {\n  const [range, setRange] = React.useState<DateRange | undefined>({\n    start: new CalendarDate(new Date().getFullYear(), 4, 12),\n    end: new CalendarDate(new Date().getFullYear(), 4, 12).add({ days: 60 }),\n  });\n\n  return (\n    <Card className=\"mx-auto w-fit p-0\">\n      <CardContent className=\"p-0\">\n        <I18nProvider locale=\"es\">\n          <RangeCalendar\n            value={range}\n            onChange={setRange}\n            numberOfMonths={3}\n            weeksInMonth={6}\n          />\n        </I18nProvider>\n      </CardContent>\n    </Card>\n  );\n}\n\nfunction CalendarBookedDates() {\n  const [date, setDate] = React.useState<CalendarDate | undefined>(\n    new CalendarDate(new Date().getFullYear(), 2, 3),\n  );\n  const bookedDates = Array.from(\n    { length: 15 },\n    (_, i) => new CalendarDate(new Date().getFullYear(), 2, 12 + i),\n  );\n\n  return (\n    <Card className=\"mx-auto w-fit p-0\">\n      <CardContent className=\"p-0\">\n        <Calendar\n          value={date}\n          onChange={setDate}\n          isDateUnavailable={(date) =>\n            bookedDates.some((d) => isSameDay(date, d))\n          }\n        />\n      </CardContent>\n    </Card>\n  );\n}\n\n/** Choose a date, multiple dates, or a range using the calendar grid. */\nconst meta = {\n  id: \"ui-aria-calendar\",\n  title: \"ui/Calendar\",\n  component: Calendar,\n  tags: [\"autodocs\"],\n  parameters: { layout: \"centered\" },\n  render: () => <CalendarSingle />,\n} satisfies Meta<typeof Calendar>;\nexport default meta;\ntype Story = StoryObj<typeof meta>;\n\n/** Choose a date, multiple dates, or a range using the calendar grid. */\nexport const Default: Story = {};\n\n/** Choose more than one date. */\nexport const Multiple: Story = { render: () => <CalendarMultiple /> };\n\n/** Select a start date and an end date. */\nexport const Range: Story = { render: () => <CalendarRange /> };\n\n/** Display adjacent months when selecting a range. */\nexport const MultipleMonths: Story = {\n  render: () => <CalendarRangeMultipleMonths />,\n};\n\n/** Block dates that are already booked. */\nexport const Disabled: Story = { render: () => <CalendarBookedDates /> };\n\n/** Move forward one month and return to the original calendar grid. */\nexport const ShouldNavigateMonthsWhenClicked: Story = {\n  tags: [\"!dev\", \"!autodocs\"],\n  play: async ({ canvas }) => {\n    const navigationButton = (name: string) => {\n      const button = canvas\n        .getAllByRole(\"button\", { name })\n        .find((button) => button.tabIndex === 0);\n      if (!button) throw new Error(`No focusable ${name} navigation button`);\n      return button;\n    };\n    const first = canvas.getByRole(\"grid\").getAttribute(\"aria-label\");\n    await userEvent.click(navigationButton(\"Next\"));\n    await waitFor(() =>\n      expect(canvas.getByRole(\"grid\").getAttribute(\"aria-label\")).not.toEqual(\n        first,\n      ),\n    );\n    await userEvent.click(navigationButton(\"Previous\"));\n    await expect(canvas.getByRole(\"grid\").getAttribute(\"aria-label\")).toEqual(\n      first,\n    );\n  },\n};\n",
      "type": "registry:component",
      "target": "@ui/calendar.stories.tsx"
    }
  ],
  "categories": [
    "ui",
    "storybook",
    "calendar",
    "date"
  ],
  "type": "registry:component"
}