-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathSelect.stories.tsx
More file actions
84 lines (76 loc) · 2.64 KB
/
Select.stories.tsx
File metadata and controls
84 lines (76 loc) · 2.64 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import React, { MouseEvent } from 'react';
import { Select, Button, Input } from '../../src';
import { Meta, StoryObj } from '@storybook/react';
const meta: Meta<typeof Select> = {
title: 'Components/Select',
component: Select,
};
export default meta;
type Story = StoryObj<typeof Select>;
Select.Option.displayName = 'Select.Option';
export const Standard: Story = {
render: (args) => (
<Select id="select-1" label="Label text goes here">
<Select.Option value="1">NHS.UK frontend option 1</Select.Option>
<Select.Option value="2" selected>
NHS.UK frontend option 2
</Select.Option>
<Select.Option value="3" disabled>
NHS.UK frontend option 3
</Select.Option>
</Select>
),
};
export const SelectWithHintText: Story = {
render: (args) => (
<Select label="Label text goes here" hint="Hint text goes here" id="with-hint-text">
<Select.Option value="1">NHS.UK frontend option 1</Select.Option>
<Select.Option value="2">NHS.UK frontend option 2</Select.Option>
<Select.Option value="3">NHS.UK frontend option 3</Select.Option>
</Select>
),
};
export const SelectWithErrorBoolean: Story = {
render: function SelectWithErrorBooleanRender() {
const [error, setError] = React.useState<boolean>(true);
return (
<>
<Select error={error} label="Label text goes here" id="error-boolean">
<Select.Option value="1">NHS.UK frontend option 1</Select.Option>
<Select.Option value="2">NHS.UK frontend option 2</Select.Option>
<Select.Option value="3">NHS.UK frontend option 3</Select.Option>
</Select>
<Button
onClick={(e: MouseEvent<HTMLButtonElement>) => {
e.preventDefault();
setError(!error);
}}
>
Toggle Error
</Button>
</>
);
},
name: 'Select With Error (Boolean)',
};
export const SelectWithErrorString: Story = {
render: function SelectWithErrorStringRender() {
const [error, setError] = React.useState<string>('Error message goes here');
return (
<>
<Select error={error} label="Label text goes here" id="error-string">
<Select.Option value="1">NHS.UK frontend option 1</Select.Option>
<Select.Option value="2">NHS.UK frontend option 2</Select.Option>
<Select.Option value="3">NHS.UK frontend option 3</Select.Option>
</Select>
<Input
id="error-string-input"
label="Use this input to change the error message"
onChange={(e) => setError(e.currentTarget.value)}
value={error}
/>
</>
);
},
name: 'Select With Error (String)',
};