import type { Meta, StoryObj } from '@storybook/react' import * as React from 'react' import type { DateRange } from 'react-day-picker' import { Calendar } from './Calendar' const meta: Meta = { title: 'Form/Calendar', component: Calendar, argTypes: { mode: { control: { type: 'select' }, options: ['single', 'multiple', 'range', 'default'], table: { type: { summary: 'single | multiple | range | default' }, defaultValue: { summary: 'single' }, }, }, showOutsideDays: { control: 'boolean', description: 'Whether to display days outside the current month.', table: { type: { summary: 'boolean' }, defaultValue: { summary: 'true' }, }, }, // Behavior props onSelect: { control: false }, selected: { control: false }, }, args: { mode: 'single', showOutsideDays: true, }, } satisfies Meta export default meta type Story = StoryObj export const Default: Story = { render: function DefaultStory(args) { const mode = (args.mode as string) === 'default' ? 'single' : (args.mode ?? 'single') // State management based on mode - using fixed dates for Chromatic const [singleDate, setSingleDate] = React.useState( new Date(2025, 9, 15), // October 15, 2025 ) const [multipleDates, setMultipleDates] = React.useState< Date[] | undefined >([new Date(2025, 9, 15)]) // October 15, 2025 const [range, setRange] = React.useState({ from: new Date(2025, 9, 15), // October 15, 2025 }) // Select appropriate state and handler based on mode const selected = mode === 'multiple' ? multipleDates : mode === 'range' ? range : singleDate const onSelect = mode === 'multiple' ? setMultipleDates : mode === 'range' ? setRange : setSingleDate return ( ) }, } export const Range: Story = { render: function RangeStory(args) { const [range, setRange] = React.useState({ from: new Date(2025, 8, 4), // September 4, 2025 to: new Date(2025, 9, 3), // October 3, 2025 (outside month) }) return ( setRange(value)} defaultMonth={new Date(2025, 8, 1)} // September 2025 /> ) }, } export const Multiple: Story = { render: function MultipleStory(args) { const [dates, setDates] = React.useState([ new Date(2025, 9, 5), // October 5, 2025 new Date(2025, 9, 12), // October 12, 2025 new Date(2025, 9, 20), // October 20, 2025 new Date(2025, 8, 30), // September 30, 2025 (outside month) ]) return ( ) }, } export const WithoutOutsideDays: Story = { render: function WithoutOutsideDaysStory(args) { const [date, setDate] = React.useState( new Date(2025, 9, 15), // October 15, 2025 ) return ( ) }, }