-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathDatepicker.stories.tsx
More file actions
64 lines (53 loc) · 1.65 KB
/
Datepicker.stories.tsx
File metadata and controls
64 lines (53 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { useState } from 'react';
import type { MonthCaptionProps } from 'react-day-picker';
import type { Meta, StoryObj } from '@storybook/react-vite';
import 'react-day-picker/style.css';
import { DatePickerControl } from './Datepicker';
import { fn } from 'storybook/test';
const NoopDropdownCaption = ({ calendarMonth }: MonthCaptionProps) => (
<div style={{ padding: 8, fontWeight: 600 }}>
{calendarMonth.date.toLocaleString('en', { month: 'long', year: 'numeric' })}
</div>
);
const meta = {
title: 'AppComponents/DatePickerControl',
component: DatePickerControl,
} satisfies Meta<typeof DatePickerControl>;
export default meta;
type Story = StoryObj<typeof meta>;
const Wrapper = (args: React.ComponentProps<typeof DatePickerControl>) => {
const [value, setValue] = useState(args.value);
const handleValueChange = (newValue: string) => {
args.onValueChange(newValue);
setValue(newValue);
};
return <DatePickerControl {...args} value={value} onValueChange={handleValueChange} />;
};
export const Preview: Story = {
args: {
id: 'datepicker-preview',
value: '2025-03-15',
dateFormat: 'dd.MM.yyyy',
locale: 'nb',
buttonAriaLabel: 'Open date picker',
calendarIconTitle: 'Calendar',
onValueChange: fn(),
DropdownCaption: NoopDropdownCaption,
},
render: (args) => <Wrapper {...args} />,
};
export const ReadOnly: Story = {
args: {
...Preview.args,
readOnly: true,
},
render: (args) => <Wrapper {...args} />,
};
export const WithMinMax: Story = {
args: {
...Preview.args,
minDate: new Date('2025-01-01'),
maxDate: new Date('2025-12-31'),
},
render: (args) => <Wrapper {...args} />,
};