|
1
|
import { Button } from "@/components/button" |
|
2
|
import { Calendar } from "@/components/calendar/calendar" |
|
3
|
import type { Meta, StoryObj } from "@storybook/react" |
|
4
|
import * as React from "react" |
|
5
|
import { ComponentPropsWithoutRef } from "react" |
|
6
|
|
|
7
|
const meta: Meta<typeof Calendar> = { |
|
8
|
title: "Components/CalendarNew", |
|
9
|
component: Calendar, |
|
10
|
parameters: { |
|
11
|
layout: "centered", |
|
12
|
}, |
|
13
|
} |
|
14
|
|
|
15
|
export default meta |
|
16
|
|
|
17
|
type Story = StoryObj<typeof Calendar> |
|
18
|
|
|
19
|
export const Default: Story = { |
|
20
|
args: {}, |
|
21
|
} |
|
22
|
|
|
23
|
const ControlledDemo = (args: ComponentPropsWithoutRef<typeof Calendar>) => { |
|
24
|
const [date, setDate] = React.useState<Date | null>(new Date()) |
|
25
|
|
|
26
|
return ( |
|
27
|
<div> |
|
28
|
<Calendar {...args} value={date} onChange={setDate} /> |
|
29
|
<div className="flex items-center justify-between"> |
|
30
|
<pre className="font-mono txt-compact-small">{date ? date.toDateString() : "null"}</pre> |
|
31
|
<Button variant="secondary" size="small" onClick={() => setDate(null)}>Reset</Button> |
|
32
|
</div> |
|
33
|
</div> |
|
34
|
) |
|
35
|
} |
|
36
|
|
|
37
|
export const Controlled: Story = { |
|
38
|
render: ControlledDemo, |
|
39
|
} |
|
40
|
|
|
41
|
export const MinValue: Story = { |
|
42
|
args: { |
|
43
|
minValue: new Date(), |
|
44
|
}, |
|
45
|
} |
|
46
|
|
|
47
|
export const MaxValue: Story = { |
|
48
|
args: { |
|
49
|
maxValue: new Date(), |
|
50
|
}, |
|
51
|
} |
|
52
|
|
|
53
|
export const DisabledDates: Story = { |
|
54
|
args: { |
|
55
|
isDateUnavailable: (date: Date) => { |
|
56
|
const unavailable = date.getDay() === 0 |
|
57
|
|
|
58
|
return unavailable |
|
59
|
}, |
|
60
|
}, |
|
61
|
} |