forked from tremorlabs/tremor
/
DateRangePicker.stories.tsx
207 lines (182 loc) · 6.54 KB
/
DateRangePicker.stories.tsx
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import {
Button,
Card,
DateRangePicker,
DateRangePickerItem,
DateRangePickerValue,
Text,
Title,
} from "components";
import { ComponentMeta, ComponentStory } from "@storybook/react";
import React, { useState } from "react";
import { dateRangePickerData } from "stories/input-elements/helpers/testData";
import { fr } from "date-fns/locale";
// More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
export default {
title: "Tremor/InputElements/DateRangePicker",
component: DateRangePicker,
} as ComponentMeta<typeof DateRangePicker>;
// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
const UncontrolledTemplate: ComponentStory<typeof DateRangePicker> = (args) => {
const [value, setValue] = useState<DateRangePickerValue>({});
const startDate = value.from;
const endDate = value.to;
return (
<div className="space-y-4">
<Card>
<DateRangePicker {...args} onValueChange={(value) => setValue(value)} />
<Title>Filtered Data</Title>
<Text>StartDate: {String(startDate)} </Text>
<Text>EndDate: {String(endDate)} </Text>
<div>
{dateRangePickerData
.filter(
(datapoint) =>
startDate && endDate && datapoint.date >= startDate && datapoint.date <= endDate,
)
.map((datapoint) => (
<p key={String(datapoint.date)}>{String(datapoint.date)}</p>
))}
</div>
</Card>
</div>
);
};
const UncontrolledWithChildrenTemplate: ComponentStory<typeof DateRangePicker> = (args) => {
const [value, setValue] = useState<DateRangePickerValue>({});
const startDate = value.from;
const endDate = value.to;
return (
<Card>
<DateRangePicker {...args} onValueChange={(value) => setValue(value)}>
<DateRangePickerItem key="one" value="one" from={new Date(2023, 0, 1)}>
2023/1/1 - Today
</DateRangePickerItem>
<DateRangePickerItem
key="two"
value="two"
from={new Date(2023, 0, 1)}
to={new Date(2023, 4, 1)}
>
2023/1/1 - 2023/5/1
</DateRangePickerItem>
</DateRangePicker>
<Title>Filtered Data</Title>
<Text>StartDate: {String(startDate)} </Text>
<Text>EndDate: {String(endDate)} </Text>
<div>
{dateRangePickerData
.filter(
(datapoint) =>
startDate && endDate && datapoint.date >= startDate && datapoint.date <= endDate,
)
.map((datapoint) => (
<p key={String(datapoint.date)}>{String(datapoint.date)}</p>
))}
</div>
</Card>
);
};
const ControlledTemplate: ComponentStory<typeof DateRangePicker> = (args) => {
const [value, setValue] = useState<DateRangePickerValue>(args.value!);
const startDate = value?.from;
const endDate = value?.to;
return (
<Card>
<DateRangePicker {...args} value={value} onValueChange={(v) => setValue(v)} />
<Button
onClick={() => {
setValue({});
}}
>
Reset
</Button>
<Button
onClick={() => {
setValue({ selectValue: "tdy" });
}}
>
Today
</Button>
<Title>Filtered Data</Title>
<Text>StartDate: {String(startDate)} </Text>
<Text>EndDate: {String(endDate)} </Text>
<div>
{dateRangePickerData
.filter(
(datapoint) =>
startDate && endDate && datapoint.date >= startDate && datapoint.date <= endDate,
)
.map((datapoint) => (
<p key={String(datapoint.date)}>{String(datapoint.date)}</p>
))}
</div>
</Card>
);
};
export const UncontrolledDefault = UncontrolledTemplate.bind({});
export const UncontrolledWithDefaultDateRange = UncontrolledTemplate.bind({});
UncontrolledWithDefaultDateRange.args = {
defaultValue: { from: new Date(2022, 10, 1), to: new Date() },
};
export const UncontrolledWithDefaultFrLocale = UncontrolledTemplate.bind({});
UncontrolledWithDefaultFrLocale.args = {
locale: fr,
selectPlaceholder: "Sélectionnez",
placeholder: "Sélectionnez...",
};
export const UncontrolledWithDefaultSelectOption = UncontrolledTemplate.bind({});
UncontrolledWithDefaultSelectOption.args = {
defaultValue: { selectValue: "tdy" },
};
export const UncontrolledWithDefaultValue = UncontrolledTemplate.bind({});
UncontrolledWithDefaultValue.args = {
defaultValue: { from: new Date(2022, 10, 1), to: new Date() },
};
export const UncontrolledWithSelectDisabled = UncontrolledTemplate.bind({});
UncontrolledWithSelectDisabled.args = {
defaultValue: { from: new Date(2022, 10, 1), to: new Date() },
enableSelect: false,
};
export const UncontrolledWithMinMax = UncontrolledTemplate.bind({});
UncontrolledWithMinMax.args = {
defaultValue: { from: new Date(2022, 10, 1), to: new Date() },
minDate: new Date(2023, 4, 1),
maxDate: new Date(2023, 4, 15),
};
export const UncontrolledWithDropdownOptions = UncontrolledWithChildrenTemplate.bind({});
UncontrolledWithDropdownOptions.args = {
defaultValue: { from: new Date(2022, 10, 1), to: new Date(), selectValue: "one" },
};
export const UncontrolledWithDisabled = UncontrolledTemplate.bind({});
UncontrolledWithDisabled.args = {
defaultValue: { from: new Date(2022, 10, 1), to: new Date(), selectValue: "tdy" },
disabled: true,
};
export const UncontrolledDefaultWithYearNavigation = UncontrolledTemplate.bind({});
UncontrolledDefaultWithYearNavigation.args = {
enableYearNavigation: true,
};
export const ControlledDefault = ControlledTemplate.bind({});
export const ControlledWithDefaultDateRange = ControlledTemplate.bind({});
ControlledWithDefaultDateRange.args = {
value: { from: new Date(2022, 10, 1), to: new Date() },
};
export const ControlledWithDefaultSelectOption = ControlledTemplate.bind({});
ControlledWithDefaultSelectOption.args = {
value: { from: undefined, to: undefined, selectValue: "t" },
};
export const ControlledWithDefaultValue = ControlledTemplate.bind({});
ControlledWithDefaultValue.args = {
value: { from: new Date(2022, 10, 1), to: new Date(), selectValue: "t" },
};
export const UncontrolledWithoutAllowClear = UncontrolledTemplate.bind({});
UncontrolledWithoutAllowClear.args = {
defaultValue: { from: new Date(2022, 10, 1), to: new Date() },
enableClear: false,
};
export const UncontrolledWithWeekStartsOnTuesday = UncontrolledTemplate.bind({});
UncontrolledWithWeekStartsOnTuesday.args = {
defaultValue: { from: new Date(2022, 10, 1), to: new Date() },
weekStartsOn: 2,
};