-
Notifications
You must be signed in to change notification settings - Fork 14
/
TextInput.stories.tsx
608 lines (595 loc) · 21.5 KB
/
TextInput.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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
import React from "react";
import { userEvent, within } from "@storybook/testing-library";
import { BackgroundColorProvider } from "../BackgroundColorContext";
import Title from "../../.storybook/components/Title";
import ExampleContainer from "../../.storybook/components/ExampleContainer";
import DarkContainer from "../../.storybook/components/DarkSection";
import DxcTextInput from "./TextInput";
import DxcButton from "../button/Button";
import DxcCheckbox from "../checkbox/Checkbox";
import DxcFlex from "../flex/Flex";
import Suggestions from "./Suggestions";
import { ThemeProvider } from "styled-components";
import useTheme from "../useTheme";
import { HalstackProvider } from "../HalstackContext";
export default {
title: "Text input",
component: DxcTextInput,
};
const action = {
onClick: () => {},
icon: (
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
<path d="M0 0h24v24H0V0z" fill="none" />
<path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z" />
</svg>
),
};
const actionLargeIconSVG = {
onClick: () => {},
icon: (
<svg xmlns="http://www.w3.org/2000/svg" height="48px" viewBox="0 0 24 24" width="48px" fill="currentColor">
<path d="M0 0h24v24H0V0z" fill="none" />
<path d="M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm.5-13H11v6l5.25 3.15.75-1.23-4.5-2.67z" />
</svg>
),
};
const actionLargeIconURL = {
onClick: () => {},
icon: "https://iconape.com/wp-content/files/yd/367773/svg/logo-linkedin-logo-icon-png-svg.png",
};
const country = ["Afghanistan"];
const countries = [
"Afghanistan",
"Albania",
"Algeria",
"Andorra Andorra Andorra Andorra Andorra Andorra Andorra Andorra",
"Angola",
"Antigua and Barbuda Antigua and Barbuda Antigua and Barbuda",
"Bahamas",
"Bahrain",
"Bangladesh",
"Barbados",
"Cabo Verde",
"Cambodia",
"Cameroon",
"Canada",
"Cayman Islands, The",
"Central African Republic",
"Chad",
"Democratic Republic of the Congo",
"Dominican Republic",
"Dominica",
"Denmark",
"Djibouti",
"*",
];
const opinionatedTheme = {
textInput: {
fontColor: "#000000",
hoverBorderColor: "#a46ede",
},
};
export const Chromatic = () => (
<>
<ExampleContainer pseudoState="pseudo-hover">
<Title title="Hovered input" theme="light" level={4} />
<DxcTextInput label="Text input" />
</ExampleContainer>
<ExampleContainer pseudoState="pseudo-focus-within">
<Title title="Focused input" theme="light" level={4} />
<DxcTextInput label="Text input" />
</ExampleContainer>
<ExampleContainer pseudoState="pseudo-hover">
<Title title="Hovered action" theme="light" level={4} />
<DxcTextInput label="Text input" defaultValue="Text" clearable />
</ExampleContainer>
<ExampleContainer pseudoState="pseudo-active">
<Title title="Actived action" theme="light" level={4} />
<DxcTextInput label="Text input" action={action} clearable />
</ExampleContainer>
<ExampleContainer pseudoState="pseudo-focus">
<Title title="Focused action" theme="light" level={4} />
<DxcTextInput label="Text input" action={action} clearable />
</ExampleContainer>
<ExampleContainer>
<Title title="Without label" theme="light" level={4} />
<DxcTextInput />
</ExampleContainer>
<ExampleContainer>
<Title title="With label and placeholder" theme="light" level={4} />
<DxcTextInput label="Text input" placeholder="Placeholder" />
</ExampleContainer>
<ExampleContainer>
<Title title="Helper text, optional, and clearable" theme="light" level={4} />
<DxcTextInput label="Text input" clearable defaultValue="Text" helperText="Help message" optional />
</ExampleContainer>
<ExampleContainer>
<Title title="Clearable and large icon action (SVG)" theme="light" level={4} />
<DxcTextInput
label="Text input"
defaultValue="Text text text text text text text text text text"
clearable
action={actionLargeIconSVG}
/>
</ExampleContainer>
<ExampleContainer>
<Title title="Clearable and large icon action (URL)" theme="light" level={4} />
<DxcTextInput
label="Text input"
defaultValue="Text text text text text text text text text text"
clearable
action={actionLargeIconURL}
/>
</ExampleContainer>
<ExampleContainer>
<Title title="Prefix" theme="light" level={4} />
<DxcTextInput label="With prefix" prefix="+34" />
</ExampleContainer>
<ExampleContainer>
<Title title="Suffix and action" theme="light" level={4} />
<DxcTextInput label="With suffix" suffix="USD" action={action} />
</ExampleContainer>
<ExampleContainer>
<Title title="Invalid" theme="light" level={4} />
<DxcTextInput
label="Error text input"
helperText="Help message"
error="Error message."
defaultValue="Text"
clearable
optional
action={action}
/>
</ExampleContainer>
<ExampleContainer pseudoState="pseudo-hover">
<Title title="Invalid and hovered" theme="light" level={4} />
<DxcTextInput
label="Error text input"
helperText="Help message"
placeholder="Placeholder"
error="Error message."
/>
</ExampleContainer>
<ExampleContainer>
<Title title="Disabled and placeholder" theme="light" level={4} />
<DxcTextInput label="Disabled text input" disabled placeholder="Placeholder" />
</ExampleContainer>
<ExampleContainer>
<Title title="Disabled, helper text, optional, value and action" theme="light" level={4} />
<DxcTextInput
label="Disabled text input"
helperText="Help message"
disabled
optional
defaultValue="Text"
action={action}
/>
</ExampleContainer>
<ExampleContainer>
<Title title="Disabled with prefix and suffix" theme="light" level={4} />
<DxcTextInput
label="Disabled text input"
helperText="Help message"
disabled
optional
prefix="+34"
suffix="USD"
defaultValue="Text"
action={action}
/>
</ExampleContainer>
<ExampleContainer>
<Title title="Read only" theme="light" level={4} />
<DxcTextInput
label="Example label"
helperText="Help message"
clearable
readOnly
optional
prefix="+34"
defaultValue="Text"
action={action}
/>
</ExampleContainer>
<ExampleContainer pseudoState="pseudo-hover">
<Title title="Hovered read only" theme="light" level={4} />
<DxcTextInput
label="Example label"
helperText="Help message"
clearable
readOnly
optional
prefix="+34"
defaultValue="Text"
action={action}
/>
</ExampleContainer>
<ExampleContainer pseudoState="pseudo-active">
<Title title="Active read only" theme="light" level={4} />
<DxcTextInput
label="Example label"
helperText="Help message"
clearable
readOnly
optional
prefix="+34"
defaultValue="Text"
action={action}
/>
</ExampleContainer>
<BackgroundColorProvider color="#333333">
<DarkContainer>
<Title title="Dark theme" theme="dark" level={2} />
<ExampleContainer pseudoState="pseudo-hover">
<Title title="Hovered" theme="dark" level={4} />
<DxcTextInput label="Text input" />
</ExampleContainer>
<ExampleContainer pseudoState="pseudo-focus-within">
<Title title="Focused" theme="dark" level={4} />
<DxcTextInput label="Text input" />
</ExampleContainer>
<ExampleContainer pseudoState="pseudo-hover">
<Title title="Hovered action" theme="dark" level={4} />
<DxcTextInput label="Text input" defaultValue="Text" clearable />
</ExampleContainer>
<ExampleContainer pseudoState="pseudo-active">
<Title title="Actived action" theme="dark" level={4} />
<DxcTextInput label="Text input" action={action} clearable />
</ExampleContainer>
<ExampleContainer pseudoState="pseudo-focus">
<Title title="Focused action" theme="dark" level={4} />
<DxcTextInput label="Text input" action={action} clearable />
</ExampleContainer>
<ExampleContainer>
<Title title="Helper text, placeholder, optional and action" theme="dark" level={4} />
<DxcTextInput
label="Text input"
helperText="Help message"
placeholder="Placeholder"
clearable
optional
action={action}
/>
</ExampleContainer>
<ExampleContainer>
<Title title="Invalid" theme="dark" level={4} />
<DxcTextInput
label="Error text input"
helperText="Help message"
error="Error message."
defaultValue="Text"
clearable
action={action}
/>
</ExampleContainer>
<ExampleContainer pseudoState="pseudo-hover">
<Title title="Invalid and hovered" theme="dark" level={4} />
<DxcTextInput
label="Error text input"
helperText="Help message"
placeholder="Placeholder"
error="Error message."
/>
</ExampleContainer>
<ExampleContainer>
<Title title="Prefix and suffix" theme="dark" level={4} />
<DxcTextInput label="With prefix and suffix" prefix="+34" suffix="USD" />
</ExampleContainer>
<ExampleContainer>
<Title title="Disabled and placeholder" theme="dark" level={4} />
<DxcTextInput label="Disabled text input" disabled placeholder="Placeholder" />
</ExampleContainer>
<ExampleContainer>
<Title title="Disabled, helper text, optional, value and action" theme="dark" level={4} />
<DxcTextInput
label="Disabled text input"
helperText="Help message"
disabled
optional
defaultValue="Text"
action={action}
/>
</ExampleContainer>
<ExampleContainer>
<Title title="Disabled with prefix and suffix" theme="dark" level={4} />
<DxcTextInput
label="Disabled text input"
helperText="Help message"
disabled
optional
prefix="+34"
suffix="USD"
defaultValue="Text"
action={action}
/>
</ExampleContainer>
</DarkContainer>
</BackgroundColorProvider>
<Title title="Margins" theme="light" level={2} />
<ExampleContainer>
<Title title="Xxsmall margin" theme="light" level={4} />
<DxcTextInput label="Xxsmall" margin="xxsmall" />
</ExampleContainer>
<ExampleContainer>
<Title title="Xsmall margin" theme="light" level={4} />
<DxcTextInput label="Xsmall" margin="xsmall" />
</ExampleContainer>
<ExampleContainer>
<Title title="Small margin" theme="light" level={4} />
<DxcTextInput label="Small" margin="small" />
</ExampleContainer>
<ExampleContainer>
<Title title="Medium margin" theme="light" level={4} />
<DxcTextInput label="Medium" margin="medium" />
</ExampleContainer>
<ExampleContainer>
<Title title="Large margin" theme="light" level={4} />
<DxcTextInput label="Large" margin="large" />
</ExampleContainer>
<ExampleContainer>
<Title title="Xlarge margin" theme="light" level={4} />
<DxcTextInput label="Xlarge" margin="xlarge" />
</ExampleContainer>
<ExampleContainer>
<Title title="Xxlarge margin" theme="light" level={4} />
<DxcTextInput label="Xxlarge" margin="xxlarge" />
</ExampleContainer>
<Title title="Sizes" theme="light" level={2} />
<ExampleContainer>
<Title title="Small size" theme="light" level={4} />
<DxcTextInput label="Small" size="small" />
</ExampleContainer>
<ExampleContainer>
<Title title="Medium size" theme="light" level={4} />
<DxcTextInput label="Medium" size="medium" />
</ExampleContainer>
<ExampleContainer>
<Title title="Large size" theme="light" level={4} />
<DxcTextInput label="Large" size="large" />
</ExampleContainer>
<ExampleContainer>
<Title title="FillParent size" theme="light" level={4} />
<DxcTextInput label="FillParent" size="fillParent" />
</ExampleContainer>
<Title title="Opinionated theme" theme="light" level={2} />
<ExampleContainer>
<HalstackProvider theme={opinionatedTheme}>
<ExampleContainer pseudoState="pseudo-hover">
<Title title="Hovered input" theme="light" level={4} />
<DxcTextInput label="Text input" helperText="Help message" />
</ExampleContainer>
<ExampleContainer pseudoState="pseudo-focus-within">
<Title title="Focused input" theme="light" level={4} />
<DxcTextInput label="Text input" helperText="Help message" />
</ExampleContainer>
<ExampleContainer pseudoState="pseudo-hover">
<Title title="Hovered action" theme="light" level={4} />
<DxcTextInput label="Text input" helperText="Help message" defaultValue="Text" clearable />
</ExampleContainer>
<ExampleContainer pseudoState="pseudo-active">
<Title title="Actived action" theme="light" level={4} />
<DxcTextInput label="Text input" helperText="Help message" action={action} clearable />
</ExampleContainer>
<ExampleContainer pseudoState="pseudo-focus">
<Title title="Focused action" theme="light" level={4} />
<DxcTextInput label="Text input" helperText="Help message" action={action} clearable />
</ExampleContainer>
<ExampleContainer>
<Title title="Prefix" theme="light" level={4} />
<DxcTextInput label="With prefix" prefix="+34" helperText="Help message" />
</ExampleContainer>
<ExampleContainer>
<Title title="Suffix and action" theme="light" level={4} />
<DxcTextInput label="With suffix" helperText="Help message" suffix="USD" action={action} />
</ExampleContainer>
<ExampleContainer>
<Title title="Invalid" theme="light" level={4} />
<DxcTextInput
label="Error text input"
helperText="Help message"
error="Error message."
defaultValue="Text"
clearable
optional
action={action}
/>
</ExampleContainer>
<ExampleContainer>
<Title title="Disabled and placeholder" theme="light" level={4} />
<DxcTextInput label="Disabled text input" disabled placeholder="Placeholder" prefix="+34" suffix="USD" />
</ExampleContainer>
<ExampleContainer>
<Title title="Disabled, helper text, optional, value and action" theme="light" level={4} />
<DxcTextInput
label="Disabled text input"
helperText="Help message"
disabled
optional
defaultValue="Text"
action={action}
/>
</ExampleContainer>
</HalstackProvider>
</ExampleContainer>
</>
);
const AutosuggestListbox = () => {
const colorsTheme: any = useTheme();
return (
<ThemeProvider theme={colorsTheme.textInput}>
<ExampleContainer>
<Title title="Autosuggest listbox" theme="light" level={2} />
<ExampleContainer>
<Title
title="List dialog uses a Radix Popover to appear over elements with a certain z-index"
theme="light"
level={3}
/>
<div
style={{
display: "flex",
flexDirection: "column",
gap: "20px",
height: "150px",
width: "500px",
marginBottom: "250px",
padding: "20px",
border: "1px solid black",
borderRadius: "4px",
overflow: "auto",
zIndex: "1300",
position: "relative",
}}
>
<DxcTextInput
label="Label"
suggestions={countries}
optional
placeholder="Choose an option"
size="fillParent"
/>
<button style={{ zIndex: "1", width: "100px" }}>Submit</button>
</div>
</ExampleContainer>
<Title title="Listbox suggestion states" theme="light" level={3} />
<ExampleContainer pseudoState="pseudo-hover">
<Title title="Hovered suggestion" theme="light" level={4} />
<Suggestions
id="x"
value=""
suggestions={country}
visualFocusIndex={-1}
highlightedSuggestions={false}
searchHasErrors={false}
isSearching={false}
suggestionOnClick={() => {}}
getTextInputWidth={() => 350}
/>
</ExampleContainer>
<ExampleContainer pseudoState="pseudo-active">
<Title title="Active suggestion" theme="light" level={4} />
<Suggestions
id="x"
value=""
suggestions={country}
visualFocusIndex={-1}
highlightedSuggestions={false}
searchHasErrors={false}
isSearching={false}
suggestionOnClick={(suggestion) => {}}
getTextInputWidth={() => 350}
/>
</ExampleContainer>
<ExampleContainer>
<Title title="Focused suggestion" theme="light" level={4} />
<Suggestions
id="x"
value=""
suggestions={country}
visualFocusIndex={0}
highlightedSuggestions={false}
searchHasErrors={false}
isSearching={false}
suggestionOnClick={(suggestion) => {}}
getTextInputWidth={() => 350}
/>
</ExampleContainer>
<ExampleContainer>
<Title title="Highlighted suggestion" theme="light" level={4} />
<Suggestions
id="x"
value="Afgh"
suggestions={country}
visualFocusIndex={-1}
highlightedSuggestions={true}
searchHasErrors={false}
isSearching={false}
suggestionOnClick={(suggestion) => {}}
getTextInputWidth={() => 350}
/>
</ExampleContainer>
</ExampleContainer>
<ExampleContainer>
<Title title="Autosuggest Error" theme="light" level={3} />
<Suggestions
id="x"
value=""
suggestions={country}
visualFocusIndex={-1}
highlightedSuggestions={false}
searchHasErrors={true}
isSearching={false}
suggestionOnClick={(suggestion) => {}}
getTextInputWidth={() => 350}
/>
</ExampleContainer>
<ExampleContainer>
<Title title="Autosuggest Searching message" theme="light" level={3} />
<Suggestions
id="x"
value=""
suggestions={country}
visualFocusIndex={-1}
highlightedSuggestions={false}
searchHasErrors={false}
isSearching={true}
suggestionOnClick={(suggestion) => {}}
getTextInputWidth={() => 350}
/>
</ExampleContainer>
</ThemeProvider>
);
};
const DarkAutosuggestListbox = () => {
const colorsTheme: any = useTheme();
return (
<ThemeProvider theme={colorsTheme.textInput}>
<BackgroundColorProvider color="#333333">
<DarkContainer>
<Title title="Dark theme" theme="dark" level={2} />
<ExampleContainer>
<Title title="Default with opened suggestions" theme="dark" level={3} />
<DxcFlex direction="column" gap="5rem">
<DxcTextInput label="Label" suggestions={countries} optional placeholder="Choose an option" />
<DxcCheckbox
label="You understand the selection and give your consent"
onChange={() => {}}
labelPosition="after"
/>
<DxcButton label="Submit" onClick={() => {}} size="medium" margin={{ bottom: "xxlarge" }} />
</DxcFlex>
</ExampleContainer>
<ExampleContainer>
<Title title="Autosuggest Error" theme="dark" level={3} />
<div style={{ height: "100px" }}>
<Suggestions
id="x"
value=""
suggestions={country}
visualFocusIndex={-1}
highlightedSuggestions={false}
searchHasErrors={true}
isSearching={false}
suggestionOnClick={(suggestion) => {}}
getTextInputWidth={() => 350}
/>
</div>
</ExampleContainer>
</DarkContainer>
</BackgroundColorProvider>
</ThemeProvider>
);
};
export const AutosuggestListboxStates = AutosuggestListbox.bind({});
AutosuggestListboxStates.play = async ({ canvasElement }) => {
const canvas = within(canvasElement);
const select = canvas.getByRole("combobox");
await userEvent.click(select);
};
export const AutosuggestListboxOnDark = DarkAutosuggestListbox.bind({});
AutosuggestListboxOnDark.play = async ({ canvasElement }) => {
const canvas = within(canvasElement);
const select = canvas.getByRole("combobox");
await userEvent.click(select);
};