-
Notifications
You must be signed in to change notification settings - Fork 27
/
RadioGroupExamples.tsx
197 lines (181 loc) · 4.97 KB
/
RadioGroupExamples.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
import Formsy from 'formsy-react';
import * as React from 'react';
import {
Container,
Button,
Label,
Segment,
Radio,
Checkbox,
Message,
} from 'semantic-ui-react';
import { RadioGroup, Form } from '../src';
const styles = {
root: {
marginTop: 18,
},
radioGroup: {
display: 'flex',
marginBottom: 18,
},
};
export default class RadioGroupExamples extends React.Component {
public state = {
result: null,
};
private formRef = React.createRef<Formsy>();
onValidSubmit = (formData) =>
this.setState({ result: JSON.stringify(formData, null, 2) });
render() {
const errorLabel = <Label color="red" pointing="left" />;
const radioGroup = (
<RadioGroup
name="radioGroup"
required
label="Label"
validationErrors={{
isDefaultRequiredValue: 'Please select one of these',
}}
errorLabel={errorLabel}
style={styles.radioGroup}
>
<Radio label="one" value="one" />
<Radio label="two" value="two" />
<Radio label="three" value="three" />
</RadioGroup>
);
const disabledRadioGroup = (
<RadioGroup
name="radioGroup"
required
validationErrors={{
isDefaultRequiredValue: 'Please select one of these',
}}
errorLabel={errorLabel}
style={styles.radioGroup}
>
<Radio label="one" value="one" />
<Radio label="two" value="two" />
<Radio label="three" value="three" />
</RadioGroup>
);
const checkboxes = (
<RadioGroup
name="checkboxes"
required
validationErrors={{
isDefaultRequiredValue: 'Please select one of these',
}}
errorLabel={errorLabel}
style={styles.radioGroup}
>
<Checkbox label="one" value="one" />
<Checkbox label="two" value="two" />
<Checkbox label="three" value="three" />
</RadioGroup>
);
// Use All variations
const allVariations = (
<RadioGroup
name="allVariations"
required
validationErrors={{
isDefaultRequiredValue: 'Please select one of these',
}}
errorLabel={errorLabel}
style={styles.radioGroup}
>
<Checkbox label="one" value="one" />
<Radio toggle label="two" value="two" />
<Radio slider label="three" value="three" />
<Radio label="four" value="four" />
</RadioGroup>
);
const defaultSelected = (
<RadioGroup
name="defaultSelected"
required
defaultSelected="two"
validationErrors={{
isDefaultRequiredValue: 'Please select one of these',
}}
errorLabel={errorLabel}
style={styles.radioGroup}
>
<Checkbox label="one" value="one" />
<Checkbox label="two" value="two" />
<Checkbox label="three" value="three" />
</RadioGroup>
);
return (
<Container style={styles.root}>
<Form onValidSubmit={this.onValidSubmit} ref={this.formRef}>
<Segment>
<h5> RadioGroup </h5>
{radioGroup}
<h5>Grouped</h5>
<RadioGroup
name="radioGroup"
required
inline={false}
label="Label"
validationErrors={{
isDefaultRequiredValue: 'Please select one of these',
}}
errorLabel={errorLabel}
style={styles.radioGroup}
>
<Radio label="one" value="one" />
<Radio label="two" value="two" />
<Radio label="three" value="three" />
</RadioGroup>
<h5>Disabled</h5>
<RadioGroup
name="radioGroup"
required
disabled={true}
label="Label"
validationErrors={{
isDefaultRequiredValue: 'Please select one of these',
}}
errorLabel={errorLabel}
style={styles.radioGroup}
>
<Radio label="one" value="one" />
<Radio label="two" value="two" />
<Radio label="three" value="three" />
</RadioGroup>
</Segment>
<Segment>
<h5> Checkboxes </h5>
{checkboxes}
</Segment>
<Segment>
<h5> All Variations </h5>
{allVariations}
</Segment>
<Segment>
<h5> Default Selected </h5>
{defaultSelected}
</Segment>
<Button content="Submit" color="orange" />
<Button
type="button"
onClick={() =>
this.formRef.current?.reset({
defaultSelected: 'two',
})
}
content="Reset"
color="black"
/>
</Form>
{!!this.state.result && (
<Message>
<pre>{this.state.result}</pre>
</Message>
)}
</Container>
);
}
}