-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathRadios.stories.tsx
More file actions
221 lines (207 loc) · 6.79 KB
/
Radios.stories.tsx
File metadata and controls
221 lines (207 loc) · 6.79 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
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
import React, { MouseEvent } from 'react';
import { Radios, Fieldset, Button, Input, Checkboxes } from '../../src';
import { Meta, StoryObj } from '@storybook/react';
const meta: Meta<typeof Radios> = {
title: 'Components/Radios',
component: Radios,
};
export default meta;
type Story = StoryObj<typeof Radios>;
Radios.Radio.displayName = 'Radios.Radio';
Radios.Divider.displayName = 'Radios.Divider';
export const StandardRadios: Story = {
render: (args) => (
<Fieldset>
<Fieldset.Legend>Have you changed your name?</Fieldset.Legend>
<Radios
name="example"
id="standard-example"
hint="This includes changing your last name or spelling your name differently."
>
<Radios.Radio value="yes">Yes</Radios.Radio>
<Radios.Radio value="no" checked>
No
</Radios.Radio>
</Radios>
</Fieldset>
),
};
export const InlineRadios: Story = {
render: (args) => (
<Fieldset>
<Fieldset.Legend>Have you changed your name?</Fieldset.Legend>
<Radios
name="example"
inline
id="inline-example"
hint="This includes changing your last name or spelling your name differently."
>
<Radios.Radio value="yes">Yes</Radios.Radio>
<Radios.Radio value="no" checked>
No
</Radios.Radio>
</Radios>
</Fieldset>
),
};
export const DisabledRadios: Story = {
render: (args) => (
<Fieldset>
<Fieldset.Legend>Have you changed your name?</Fieldset.Legend>
<Radios
name="example"
id="disabled-example"
hint="This includes changing your last name or spelling your name differently."
>
<Radios.Radio disabled value="yes">
Yes
</Radios.Radio>
<Radios.Radio disabled value="no">
No
</Radios.Radio>
</Radios>
</Fieldset>
),
};
export const RadiosWithConditionalContent: Story = {
render: (args) => {
const impairmentsForm = (
<Checkboxes name="impairments" id="impairments">
<Checkboxes.Box value="autism">Autism</Checkboxes.Box>
<Checkboxes.Box value="developmental-conditions">
Developmental conditions (excluding autism)
</Checkboxes.Box>
<Checkboxes.Box value="dementia">Dementia</Checkboxes.Box>
<Checkboxes.Box value="learning-disability">Learning disability</Checkboxes.Box>
<Checkboxes.Box value="mental-health-condition">Mental Health Condition</Checkboxes.Box>
<Checkboxes.Box value="physical-disability">Physical disability</Checkboxes.Box>
<Checkboxes.Box value="sensory-disability">
Sensory disability - such as sight, hearing or verbal
</Checkboxes.Box>
<Checkboxes.Box value="long-term-condition">Long-term condition</Checkboxes.Box>
</Checkboxes>
);
return (
<Fieldset>
<Fieldset.Legend>Impairment requirement</Fieldset.Legend>
<Radios name="example" id="example-conditional" hint="Select relevant options.">
<Radios.Radio id="hello1" value="yes" conditional={impairmentsForm}>
Patient requires an impairment to be added
</Radios.Radio>
<Radios.Radio id="hello2" value="no">
Patient would prefer not to say
</Radios.Radio>
</Radios>
</Fieldset>
);
},
};
export const RadiosWithADivider: Story = {
render: (args) => (
<Fieldset>
<Fieldset.Legend>How do you want to sign in?</Fieldset.Legend>
<Radios name="example" id="example-divider">
<Radios.Radio value="government-gateway">Use Government Gateway</Radios.Radio>
<Radios.Radio value="nhsuk-login">Use NHS.UK login</Radios.Radio>
<Radios.Divider>or</Radios.Divider>
<Radios.Radio value="create-account">Create an account</Radios.Radio>
</Radios>
</Fieldset>
),
};
export const RadiosWithHintsOnItems: Story = {
render: (args) => (
<Fieldset>
<Fieldset.Legend>How do you want to sign in?</Fieldset.Legend>
<Radios name="example" id="example-divider">
<Radios.Radio
value="government-gateway"
hint="You'll have a user ID if you've registered for self-assessment or filed a tax return online before."
>
Use Government Gateway
</Radios.Radio>
<Radios.Radio
value="nhsuk-login"
hint="You’ll have an account if you’ve already proved your identity with either Barclays, CitizenSafe, Digidentity, Experian, Post Office, Royal Mail or SecureIdentity."
>
Use NHS.UK login
</Radios.Radio>
</Radios>
</Fieldset>
),
};
export const RadiosWithoutFieldset: Story = {
render: (args) => (
<Radios name="colours" id="colours">
<Radios.Radio value="red">Red</Radios.Radio>
<Radios.Radio value="green">Green</Radios.Radio>
<Radios.Radio value="blue">Blue</Radios.Radio>
</Radios>
),
};
export const RadiosWithErrorBoolean: Story = {
render: function RadiosWithErrorBooleanRender() {
const [error, setError] = React.useState<boolean>(true);
return (
<>
<Fieldset>
<Fieldset.Legend>Have you changed your name?</Fieldset.Legend>
<Radios
id="example"
name="example"
error={error}
hint="This includes changing your last name or spelling your name differently."
>
<Radios.Radio id="example-1" value="yes">
Yes
</Radios.Radio>
<Radios.Radio id="example-2" value="no" checked>
No
</Radios.Radio>
</Radios>
</Fieldset>
<Button
onClick={(e: MouseEvent<HTMLButtonElement>) => {
e.preventDefault();
setError(!error);
}}
>
Toggle Error
</Button>
</>
);
},
name: 'Radios With Error (Boolean)',
};
export const RadiosWithErrorString: Story = {
render: function RadiosWithErrorStringRender() {
const [error, setError] = React.useState('Please select an option');
return (
<>
<Fieldset>
<Fieldset.Legend>Have you changed your name?</Fieldset.Legend>
<Radios
id="example"
name="example"
error={error}
hint="This includes changing your last name or spelling your name differently."
>
<Radios.Radio id="example-1" value="yes">
Yes
</Radios.Radio>
<Radios.Radio id="example-2" value="no" checked>
No
</Radios.Radio>
</Radios>
</Fieldset>
<Input
id="error-input"
value={error}
onChange={(e) => setError(e.currentTarget.value)}
label="Use this input to set the error message"
/>
</>
);
},
name: 'Radios With Error (String)',
};