|
1
|
import { Button } from "@/components/button" |
|
2
|
import { Drawer } from "@/components/drawer" |
|
3
|
import { Label } from "@/components/label" |
|
4
|
import type { Meta, StoryObj } from "@storybook/react" |
|
5
|
import * as React from "react" |
|
6
|
import { ComponentPropsWithoutRef } from "react" |
|
7
|
import { DatePicker } from "./date-picker" |
|
8
|
|
|
9
|
const meta: Meta<typeof DatePicker> = { |
|
10
|
title: "Components/DatePickerNew", |
|
11
|
component: DatePicker, |
|
12
|
parameters: { |
|
13
|
layout: "centered", |
|
14
|
}, |
|
15
|
} |
|
16
|
|
|
17
|
export default meta |
|
18
|
|
|
19
|
type Story = StoryObj<typeof DatePicker> |
|
20
|
|
|
21
|
export const Default: Story = { |
|
22
|
args: { |
|
23
|
"aria-label": "Select a date", |
|
24
|
}, |
|
25
|
} |
|
26
|
|
|
27
|
const today = new Date() // Today |
|
28
|
const oneWeekFromToday = new Date(new Date(today as Date).setDate(today.getDate() + 7)) // Today + 7 days |
|
29
|
|
|
30
|
const ControlledDemo = (args: ComponentPropsWithoutRef<typeof DatePicker>) => { |
|
31
|
const [startDate, setStartDate] = React.useState<Date | null>(today) |
|
32
|
const [endDate, setEndDate] = React.useState<Date | null>(oneWeekFromToday) |
|
33
|
|
|
34
|
return ( |
|
35
|
<div className="text-ui-fg-subtle grid max-w-[576px] gap-4 md:grid-cols-2"> |
|
36
|
<fieldset className="flex flex-col gap-y-0.5"> |
|
37
|
<Label id="starts_at:r1:label" htmlFor="starts_at:r1">Starts at</Label> |
|
38
|
<DatePicker |
|
39
|
id="starts_at:r1" |
|
40
|
aria-labelledby="starts_at:r1:label" |
|
41
|
{...args} |
|
42
|
maxValue={endDate || undefined} |
|
43
|
value={startDate} |
|
44
|
onChange={setStartDate} |
|
45
|
/> |
|
46
|
</fieldset> |
|
47
|
<fieldset className="flex flex-col gap-y-0.5"> |
|
48
|
<Label id="ends_at:r1:label" htmlFor="ends_at:r1">Ends at</Label> |
|
49
|
<DatePicker |
|
50
|
id="ends_at:r1" |
|
51
|
name="ends_at" |
|
52
|
aria-labelledby="ends_at:r1:label" |
|
53
|
minValue={startDate || undefined} |
|
54
|
{...args} |
|
55
|
value={endDate} |
|
56
|
onChange={setEndDate} |
|
57
|
/> |
|
58
|
</fieldset> |
|
59
|
</div> |
|
60
|
) |
|
61
|
} |
|
62
|
|
|
63
|
export const Controlled: Story = { |
|
64
|
render: ControlledDemo, |
|
65
|
args: { |
|
66
|
className: "w-[230px]", |
|
67
|
}, |
|
68
|
} |
|
69
|
|
|
70
|
export const MinValue: Story = { |
|
71
|
args: { |
|
72
|
"aria-label": "Select a date", |
|
73
|
className: "w-[230px]", |
|
74
|
minValue: new Date(), |
|
75
|
}, |
|
76
|
} |
|
77
|
|
|
78
|
export const MaxValue: Story = { |
|
79
|
args: { |
|
80
|
"aria-label": "Select a date", |
|
81
|
className: "w-[230px]", |
|
82
|
maxValue: new Date(), |
|
83
|
}, |
|
84
|
} |
|
85
|
|
|
86
|
export const DisabledDates: Story = { |
|
87
|
args: { |
|
88
|
isDateUnavailable: (date: Date) => { |
|
89
|
const unavailable = date.getDay() === 0 |
|
90
|
|
|
91
|
return unavailable |
|
92
|
}, |
|
93
|
"aria-label": "Select a date", |
|
94
|
className: "w-[230px]", |
|
95
|
}, |
|
96
|
} |
|
97
|
|
|
98
|
export const WithTime: Story = { |
|
99
|
args: { |
|
100
|
granularity: "minute", |
|
101
|
"aria-label": "Select a date", |
|
102
|
className: "w-[230px]", |
|
103
|
value: new Date(), |
|
104
|
}, |
|
105
|
} |
|
106
|
|
|
107
|
export const Small: Story = { |
|
108
|
args: { |
|
109
|
size: "small", |
|
110
|
"aria-label": "Select a date", |
|
111
|
className: "w-[230px]", |
|
112
|
}, |
|
113
|
} |
|
114
|
|
|
115
|
const InDrawerDemo = (args: ComponentPropsWithoutRef<typeof DatePicker>) => { |
|
116
|
return ( |
|
117
|
<Drawer> |
|
118
|
<Drawer.Trigger asChild> |
|
119
|
<Button size="small">Open Drawer</Button> |
|
120
|
</Drawer.Trigger> |
|
121
|
<Drawer.Content> |
|
122
|
<Drawer.Header> |
|
123
|
<Drawer.Title>Select a date</Drawer.Title> |
|
124
|
</Drawer.Header> |
|
125
|
<Drawer.Body> |
|
126
|
<div className="p-4"> |
|
127
|
<DatePicker {...args} /> |
|
128
|
</div> |
|
129
|
</Drawer.Body> |
|
130
|
</Drawer.Content> |
|
131
|
</Drawer> |
|
132
|
) |
|
133
|
} |
|
134
|
|
|
135
|
export const InDrawer: Story = { |
|
136
|
render: InDrawerDemo, |
|
137
|
} |