-
Notifications
You must be signed in to change notification settings - Fork 14
/
DateInput.stories.tsx
314 lines (302 loc) · 11.5 KB
/
DateInput.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
import React from "react";
import { userEvent, within, fireEvent, screen } from "@storybook/testing-library";
import DxcDateInput from "./DateInput";
import DxcDatePicker from "./DatePicker";
import YearPicker from "./YearPicker";
import Calendar from "./Calendar";
import Title from "../../.storybook/components/Title";
import ExampleContainer from "../../.storybook/components/ExampleContainer";
import { BackgroundColorProvider } from "../BackgroundColorContext";
import DarkContainer from "../../.storybook/components/DarkSection";
import dayjs from "dayjs";
import useTheme from "../useTheme";
import { ThemeProvider } from "styled-components";
import { HalstackProvider } from "../HalstackContext";
export default {
title: "Date input",
component: DxcDateInput,
};
const opinionatedTheme = {
dateInput: {
baseColor: "#5f249f",
selectedFontColor: "#ffffff",
},
};
const DateInputChromatic = () => (
<>
<ExampleContainer>
<Title title="Complete date input" theme="light" level={4} />
<DxcDateInput label="Date input" helperText="Help message" format="dd/mm/yy" placeholder optional />
</ExampleContainer>
<ExampleContainer>
<Title title="Disabled" theme="light" level={4} />
<DxcDateInput
label="Disabled date input"
helperText="Help message"
defaultValue="06-04-2007"
clearable
disabled
/>
</ExampleContainer>
<ExampleContainer>
<Title title="Read only" theme="light" level={4} />
<DxcDateInput
label="Example label"
helperText="Help message"
defaultValue="06-04-2007"
clearable
readOnly
/>
</ExampleContainer>
<ExampleContainer>
<Title title="Invalid" theme="light" level={4} />
<DxcDateInput label="Error date input" error="Error message." placeholder />
</ExampleContainer>
<ExampleContainer>
<Title title="Relation between icons" theme="light" level={4} />
<DxcDateInput label="Error date input" error="Error message." defaultValue="06-04-2007" clearable />
</ExampleContainer>
<BackgroundColorProvider color="#333333">
<DarkContainer>
<Title title="Dark" theme="dark" level={2} />
<ExampleContainer>
<Title title="Complete date input" theme="dark" level={4} />
<DxcDateInput label="Date input" helperText="Help message" format="yyyy/dd/mm" placeholder optional />
</ExampleContainer>
<ExampleContainer>
<Title title="Disabled" theme="dark" level={4} />
<DxcDateInput
label="Disabled Date input"
helperText="Help message"
defaultValue="06-04-2027"
clearable
disabled
/>
</ExampleContainer>
<ExampleContainer>
<Title title="Invalid" theme="dark" level={4} />
<DxcDateInput label="Error date input" error="Error message." placeholder />
</ExampleContainer>
<ExampleContainer>
<Title title="Relation between icons" theme="dark" level={4} />
<DxcDateInput label="Error date input" defaultValue="06-04-2007" error="Error message." clearable />
</ExampleContainer>
</DarkContainer>
</BackgroundColorProvider>
<Title title="Margins" theme="light" level={2} />
<ExampleContainer>
<Title title="Xxsmall" theme="light" level={4} />
<DxcDateInput label="Xxsmall" margin="xxsmall" />
</ExampleContainer>
<ExampleContainer>
<Title title="Xsmall" theme="light" level={4} />
<DxcDateInput label="Xsmall" margin="xsmall" />
</ExampleContainer>
<ExampleContainer>
<Title title="Small" theme="light" level={4} />
<DxcDateInput label="Small" margin="small" />
</ExampleContainer>
<ExampleContainer>
<Title title="Medium" theme="light" level={4} />
<DxcDateInput label="Medium" margin="medium" />
</ExampleContainer>
<ExampleContainer>
<Title title="Large" theme="light" level={4} />
<DxcDateInput label="Large" margin="large" />
</ExampleContainer>
<ExampleContainer>
<Title title="Xlarge" theme="light" level={4} />
<DxcDateInput label="Xlarge" margin="xlarge" />
</ExampleContainer>
<ExampleContainer>
<Title title="Xxlarge" theme="light" level={4} />
<DxcDateInput label="Xxlarge" margin="xxlarge" />
</ExampleContainer>
<Title title="Sizes" theme="light" level={2} />
<ExampleContainer>
<Title title="Medium size" theme="light" level={4} />
<DxcDateInput label="Medium" size="medium" />
</ExampleContainer>
<ExampleContainer>
<Title title="Large size" theme="light" level={4} />
<DxcDateInput label="Large" size="large" />
</ExampleContainer>
<ExampleContainer>
<Title title="FillParent size" theme="light" level={4} />
<DxcDateInput label="FillParent" size="fillParent" />
</ExampleContainer>
<ExampleContainer expanded>
<Title title="Year picker" theme="light" level={4} />
<DxcDateInput label="Date input" defaultValue="06-04-1905" />
</ExampleContainer>
</>
);
export const Chromatic = DateInputChromatic.bind({});
Chromatic.play = async ({ canvasElement }) => {
const canvas = within(canvasElement);
await userEvent.click(canvas.getAllByRole("combobox")[canvas.getAllByRole("combobox").length - 1]);
await fireEvent.click(screen.getByText("April 1905"));
};
const DateInputOpinionatedTheme = () => (
<>
<Title title="Opinionated theme" theme="light" level={2} />
<ExampleContainer>
<Title title="Enabled" theme="light" level={4} />
<HalstackProvider theme={opinionatedTheme}>
<DxcDateInput
label="Date input"
helperText="Help message"
format="dd/mm/yy"
placeholder
optional
defaultValue="10-10-2022"
/>
</HalstackProvider>
</ExampleContainer>
<ExampleContainer>
<Title title="Disabled" theme="light" level={4} />
<HalstackProvider theme={opinionatedTheme}>
<DxcDateInput label="Date input" helperText="Help message" format="dd/mm/yy" placeholder optional />
</HalstackProvider>
</ExampleContainer>
<ExampleContainer>
<Title title="Invalid" theme="light" level={4} />
<HalstackProvider theme={opinionatedTheme}>
<DxcDateInput label="Error date input" error="Error message." placeholder />
</HalstackProvider>
</ExampleContainer>
<ExampleContainer expanded>
<Title title="Date picker" theme="light" level={4} />
<HalstackProvider theme={opinionatedTheme}>
<DxcDateInput label="Date input" defaultValue="06-04-1905" />
</HalstackProvider>
</ExampleContainer>
</>
);
export const DateInputOpinionated = DateInputOpinionatedTheme.bind({});
DateInputOpinionated.play = async ({ canvasElement }) => {
const canvas = within(canvasElement);
await userEvent.click(canvas.getAllByRole("combobox")[canvas.getAllByRole("combobox").length - 1]);
};
const YearPickerOpinionatedTheme = () => (
<ExampleContainer expanded>
<Title title="Year picker" theme="light" level={4} />
<HalstackProvider theme={opinionatedTheme}>
<DxcDateInput label="Date input" defaultValue="06-04-1905" />
</HalstackProvider>
</ExampleContainer>
);
export const YearPickerOpinionated = YearPickerOpinionatedTheme.bind({});
YearPickerOpinionated.play = async ({ canvasElement }) => {
const canvas = within(canvasElement);
await userEvent.click(canvas.getByRole("combobox"));
await fireEvent.click(screen.getByText("April 1905"));
};
const DatePickerButtonStates = () => {
const colorsTheme: any = useTheme();
return (
<>
<ExampleContainer>
<Title title="Show date picker over another element with z-index 0" theme="light" level={4} />
<div
style={{
display: "flex",
flexDirection: "column",
gap: "20px",
height: "200px",
width: "500px",
marginBottom: "250px",
padding: "20px",
border: "1px solid black",
borderRadius: "4px",
overflow: "auto",
zIndex: "1300",
position: "relative",
}}
>
<DxcDateInput label="From" defaultValue="01-12-1995" />
<DxcDateInput label="To" />
<button style={{ zIndex: "1", width: "100px" }}>Submit</button>
</div>
</ExampleContainer>
<ThemeProvider theme={colorsTheme}>
<ExampleContainer pseudoState="pseudo-focus">
<Title title="Isolated calendar focused" theme="light" level={4} />
<DxcDatePicker date={dayjs("06-04-1950", "DD-MM-YYYY")} onDateSelect={() => {}} id="test-calendar" />
</ExampleContainer>
<ExampleContainer pseudoState="pseudo-hover">
<Title title="Isolated calendar hovered" theme="light" level={4} />
<DxcDatePicker date={dayjs("06-04-1950", "DD-MM-YYYY")} onDateSelect={() => {}} id="test-calendar" />
</ExampleContainer>
<ExampleContainer pseudoState="pseudo-active">
<Title title="Isolated calendar actived" theme="light" level={4} />
<DxcDatePicker date={dayjs("06-04-1950", "DD-MM-YYYY")} onDateSelect={() => {}} id="test-calendar" />
</ExampleContainer>
</ThemeProvider>
</>
);
};
export const DatePickerStates = DatePickerButtonStates.bind({});
DatePickerStates.play = async ({ canvasElement }) => {
const canvas = within(canvasElement);
const dateBtn = canvas.getAllByTitle("Open calendar")[0];
await userEvent.click(dateBtn);
};
export const YearPickerStates = () => {
const colorsTheme: any = useTheme();
return (
<>
<ThemeProvider theme={colorsTheme}>
<ExampleContainer pseudoState="pseudo-focus">
<Title title="Isolated year picker focused" theme="light" level={4} />
<YearPicker
selectedDate={dayjs("06-04-1905", "DD-MM-YYYY")}
onYearSelect={() => {}}
today={dayjs("1904-04-03", "YYYY-MM-DD")}
/>
</ExampleContainer>
<ExampleContainer pseudoState="pseudo-hover">
<Title title="Isolated year picker hovered" theme="light" level={4} />
<YearPicker
selectedDate={dayjs("06-04-1905", "DD-MM-YYYY")}
onYearSelect={() => {}}
today={dayjs("1904-04-03", "YYYY-MM-DD")}
/>
</ExampleContainer>
<ExampleContainer pseudoState="pseudo-active">
<Title title="Isolated year picker actived" theme="light" level={4} />
<YearPicker
selectedDate={dayjs("06-04-1905", "DD-MM-YYYY")}
onYearSelect={() => {}}
today={dayjs("1904-04-03", "YYYY-MM-DD")}
/>
</ExampleContainer>
</ThemeProvider>
</>
);
};
export const DatePickerWithToday = () => {
const colorsTheme: any = useTheme();
return (
<ThemeProvider theme={colorsTheme}>
<ExampleContainer>
<Title title="Isolated calendar with today" theme="light" level={4} />
<Calendar
selectedDate={dayjs("06-04-1904", "DD-MM-YYYY")}
today={dayjs("1904-04-03", "YYYY-MM-DD")}
onInnerDateChange={() => {}}
onDaySelect={() => {}}
innerDate={dayjs("06-04-1904", "DD-MM-YYYY")}
/>
</ExampleContainer>
<ExampleContainer>
<Title title="Isolated year picker with today" theme="light" level={4} />
<YearPicker
selectedDate={dayjs("06-04-1905", "DD-MM-YYYY")}
onYearSelect={() => {}}
today={dayjs("1904-04-03", "YYYY-MM-DD")}
/>
</ExampleContainer>
</ThemeProvider>
);
};