|
1 | 1 | import React from 'react'; |
2 | 2 | import type { DateRange as RdpRange } from 'react-day-picker'; |
3 | 3 | import { getLocalTimeZone, today } from '@internationalized/date'; |
4 | | -import { Meta, StoryObj } from '@storybook/react'; |
| 4 | +import type { Meta, StoryObj } from '@storybook/react'; |
5 | 5 | import { DatePicker } from '../DatePicker'; |
| 6 | +import type { |
| 7 | + DatePickerProps, |
| 8 | + SingleProps, |
| 9 | + MultipleProps, |
| 10 | + RangeProps, |
| 11 | + LegacyCompatProps // <-- import |
| 12 | +} from '../DatePicker'; |
6 | 13 |
|
7 | | -const meta: Meta = { |
| 14 | +const meta = { |
8 | 15 | title: 'Experimental/Components/DatePicker', |
9 | | - component: DatePicker, |
10 | | - parameters: { |
11 | | - layout: 'centered' |
12 | | - }, |
13 | | - args: { |
14 | | - label: 'Pickup date' |
15 | | - } |
16 | | -}; |
| 16 | + component: DatePicker as unknown as React.ComponentType<DatePickerProps>, |
| 17 | + parameters: { layout: 'centered' }, |
| 18 | + args: { label: 'Pickup date' } |
| 19 | +} satisfies Meta<DatePickerProps>; |
17 | 20 |
|
18 | 21 | export default meta; |
19 | 22 |
|
20 | | -type Story = StoryObj<typeof DatePicker>; |
| 23 | +type SingleStory = StoryObj<SingleProps & LegacyCompatProps>; |
| 24 | +type MultipleStory = StoryObj<MultipleProps & LegacyCompatProps>; |
| 25 | +type RangeStory = StoryObj<RangeProps & LegacyCompatProps>; |
21 | 26 |
|
22 | 27 | const TZ = getLocalTimeZone(); |
23 | 28 | const TODAY = today(TZ); |
24 | 29 |
|
25 | | -export const Default: Story = {}; |
| 30 | +// Single mode |
| 31 | +export const Default: SingleStory = { args: { mode: 'single' } }; |
26 | 32 |
|
27 | | -export const WithDefaultValue: Story = { |
28 | | - args: { |
29 | | - defaultValue: TODAY |
30 | | - } |
| 33 | +export const WithDefaultValue: SingleStory = { |
| 34 | + args: { mode: 'single', defaultValue: TODAY } |
31 | 35 | }; |
32 | 36 |
|
33 | | -export const WithDescription: Story = { |
34 | | - args: { |
35 | | - description: 'Enter current date' |
36 | | - } |
| 37 | +export const WithDescription: SingleStory = { |
| 38 | + args: { mode: 'single', description: 'Enter current date' } |
37 | 39 | }; |
38 | 40 |
|
39 | | -export const WithValidation: Story = { |
40 | | - args: { |
41 | | - label: 'Only from today' |
42 | | - }, |
| 41 | +export const WithValidation: SingleStory = { |
| 42 | + args: { mode: 'single', label: 'Only from today' }, |
43 | 43 | render: args => <DatePicker {...args} minValue={TODAY} /> |
44 | 44 | }; |
45 | 45 |
|
46 | | -export const MultipleSelection: Story = { |
47 | | - render: args => { |
48 | | - const [dates, setDates] = React.useState<Date[]>([]); |
49 | | - return <DatePicker {...args} mode="multiple" visibleMonths={2} value={dates} onChange={setDates} />; |
50 | | - } |
| 46 | +export const AutoFocus: SingleStory = { |
| 47 | + args: { mode: 'single', autoFocus: true, defaultValue: TODAY } |
51 | 48 | }; |
52 | 49 |
|
53 | | -export const RangeSelection: Story = { |
54 | | - render: args => { |
55 | | - const [range, setRange] = React.useState<RdpRange | undefined>(undefined); |
56 | | - return <DatePicker {...args} mode="range" visibleMonths={2} value={range} onChange={setRange} />; |
57 | | - } |
| 50 | +export const Disabled: SingleStory = { |
| 51 | + args: { mode: 'single', isDisabled: true } |
| 52 | +}; |
| 53 | + |
| 54 | +export const Invalid: SingleStory = { |
| 55 | + args: { mode: 'single', isInvalid: true, errorMessage: 'Error' } |
58 | 56 | }; |
59 | | -export const Disabled: Story = { |
60 | | - args: { |
61 | | - isDisabled: true |
| 57 | + |
| 58 | +export const MultipleSelection: MultipleStory = { |
| 59 | + args: { mode: 'multiple', visibleMonths: 2 }, |
| 60 | + render: args => { |
| 61 | + const [dates, setDates] = React.useState<Date[]>([]); |
| 62 | + return <DatePicker {...args} value={dates} onChange={setDates} />; |
62 | 63 | } |
63 | 64 | }; |
64 | 65 |
|
65 | | -export const Invalid: Story = { |
66 | | - args: { |
67 | | - isInvalid: true, |
68 | | - errorMessage: 'Error' |
| 66 | +export const RangeSelection: RangeStory = { |
| 67 | + args: { mode: 'range', visibleMonths: 2 }, |
| 68 | + render: args => { |
| 69 | + const [range, setRange] = React.useState<RdpRange | undefined>(); |
| 70 | + return <DatePicker {...args} value={range} onChange={setRange} />; |
69 | 71 | } |
70 | 72 | }; |
0 commit comments