Wizard.js
8.47 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
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
import React from 'react';
import {
Row,
Col,
Button,
FormGroup,
Label,
Nav,
NavLink,
NavItem,
Progress,
} from 'reactstrap';
import Formsy from 'formsy-react';
import Select2 from 'react-select2-wrapper';
import MaskedInput from 'react-maskedinput';
import Datetime from 'react-datetime';
import { select2CountriesData, select2ShipmentData, cardTypesData } from './data';
import InputValidation from '../../../../components/InputValidation/InputValidation';
import Widget from '../../../../components/Widget';
import s from './Wizard.module.scss';
const count = 4;
const StepsComponents = {
Step1: function Step1() {
return (<fieldset>
<FormGroup>
<Label for="username">Username</Label>
<InputValidation
type="text"
id="username"
name="username"
validations={{ isAlphanumeric: true }}
trigger="change"
required
validationError={{ isAlphanumeric: 'Username can contain any letters or numbers, without spaces' }}
/>
<p className="help-block">Username can contain any letters or numbers, without spaces</p>
</FormGroup>
<FormGroup>
<Label for="email">Email</Label>
<InputValidation
type="text"
id="email"
name="email"
validations={{ isEmail: true }}
required
validationError={{ isEmail: 'Please provide your E-mail' }}
/>
<p className="help-block">Please provide your E-mail</p>
</FormGroup>
<FormGroup>
<Label for="address">Address</Label>
<InputValidation
type="text"
id="address"
name="address"
validations={{ isAlpha: true }}
required
validationError={{ isAlpha: 'Please provide your address' }}
/>
<p className="help-block">Please provide your address</p>
</FormGroup>
</fieldset>);
},
Step2: function Step2() {
return (
<fieldset>
<FormGroup>
<Label for="country-select">Destination Country</Label>
<Select2
style={{ width: '100%' }}
id="country-selec"
data={select2CountriesData}
/>
<p className="help-block">Please choose your country destination</p>
</FormGroup>
<FormGroup>
<Label for="courier">Choose shipping option</Label>
<Select2
style={{ width: '100%' }}
id="courier"
data={select2ShipmentData}
/>
<p className="help-block">Please choose your shipping option</p>
</FormGroup>
<FormGroup>
<Label for="destination">Destination Zip Code</Label>
<MaskedInput
className="form-control" id="destination" mask="111111"
size="6"
/>
<p className="help-block">Please provide your Destination Zip Code</p>
</FormGroup>
<FormGroup>
<Label for="dest-address">Destination Address</Label>
<InputValidation type="text" id="dest-address" name="dest-address" />
<p className="help-block">Please provide the destination address</p>
</FormGroup>
</fieldset>
);
},
Step3: function Step3(props) {
return (
<fieldset>
<FormGroup>
<Label for="name">Name on the Card</Label>
<InputValidation type="text" id="name" name="name" />
</FormGroup>
<FormGroup>
<Label for="credit-card-type">Choose shipping option</Label>
<Select2
style={{ width: '100%' }}
id="credit-card-type"
data={cardTypesData}
/>
</FormGroup>
<FormGroup>
<Label for="credit">Credit Card Number</Label>
<InputValidation type="text" id="credit" name="credit" />
</FormGroup>
<FormGroup>
<Label for="expiration-data">Expiration Date</Label>
<div className="datepicker">
<Datetime
id="datepicker"
open={props.isDatePickerOpen} //eslint-disable-line
viewMode="days"
/>
</div>
</FormGroup>
</fieldset>
);
},
Step4: function Step4() {
return (
<fieldset>
<h2>Thank you!</h2>
<p>Your submission has been received.</p>
</fieldset>
);
},
};
class Wizard extends React.Component {
constructor(prop) {
super(prop);
this.state = {
currentStep: 1,
progress: 25,
isDatePickerOpen: false,
};
this.nextStep = this.nextStep.bind(this);
this.previousStep = this.previousStep.bind(this);
}
nextStep() {
let currentStep = this.state.currentStep;
if (currentStep >= count) {
currentStep = count;
} else {
currentStep += 1;
}
this.setState({
currentStep,
progress: (100 / count) * currentStep,
});
}
previousStep() {
let currentStep = this.state.currentStep;
if (currentStep <= 1) {
currentStep = 1;
} else {
currentStep -= 1;
}
this.setState({
currentStep,
progress: (100 / count) * currentStep,
});
}
render() {
const currentStep = this.state.currentStep;
return (
<div className={s.root}>
<ol className="breadcrumb">
<li className="breadcrumb-item">YOU ARE HERE</li>
<li className="breadcrumb-item active">Form Wizard</li>
</ol>
<h1 className="page-title">Form - <span className="fw-semi-bold">Wizard</span>
</h1>
<Row>
<Col xl={8} lg={12}>
<Widget
close collapse
className={s.formWizard}
title={<div>
<h4>
Wizard
<small>Tunable widget</small>
</h4>
<p className="text-muted">An example of complete wizard form in widget.</p></div>}
>
<Nav pills justified className={s.wizardNavigation}>
<NavItem>
<NavLink active={currentStep === 1}>
<small>1.</small>
Your Details
</NavLink>
</NavItem>
<NavItem>
<NavLink active={currentStep === 2}>
<small>2.</small>
Shipping
</NavLink>
</NavItem>
<NavItem>
<NavLink active={currentStep === 3}>
<small>3.</small>
Pay
</NavLink>
</NavItem>
<NavItem>
<NavLink active={currentStep === 4}>
<small>4.</small>
Thank you!
</NavLink>
</NavItem>
</Nav>
<Progress value={this.state.progress} color="gray-light" className="progress-xs" />
<div className="tab-content">
<div className={s.stepBody}>
<Formsy.Form>
{currentStep === 1 && <StepsComponents.Step1 />}
{currentStep === 2 && <StepsComponents.Step2 />}
{currentStep === 3 && <StepsComponents.Step3 />}
{currentStep === 4 &&
<StepsComponents.Step4 isDatePickerOpen={this.state.isDatePickerOpen} />}
</Formsy.Form>
</div>
<div className="description">
<ul className="pager wizard">
<li className="previous">
<Button disabled={currentStep === 1} color="primary" onClick={this.previousStep}><i
className="fa fa-caret-left"
/>
Previous</Button>
</li>
{currentStep < count &&
<li className="next">
<Button color="primary" onClick={this.nextStep}>Next <i className="fa fa-caret-right" /></Button>
</li>
}
{currentStep === count &&
<li className="finish">
<Button color="success">Finish <i className="fa fa-check" /></Button>
</li>
}
</ul>
</div>
</div>
</Widget>
</Col>
</Row>
</div>
);
}
}
export default Wizard;