-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
56 lines (51 loc) · 1.19 KB
/
index.js
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
'use strict';
var React = require('react');
var defaults = require('lodash.defaults');
var MultiStep = React.createFactory(require('react-multistep').Multistep);
var PropTypes = React.PropTypes;
module.exports = React.createClass({
displayName: 'Gandalf',
propTypes: {
allowBack: PropTypes.bool,
steps: PropTypes.arrayOf(
PropTypes.shape({
name: PropTypes.string,
skippable: PropTypes.bool,
component: PropTypes.func
})
).isRequired
},
getDefaultProps: function(){
return {
allowBack: true
};
},
previousStep: function(){
this.refs.stepper.previous();
},
nextStep: function(){
this.refs.stepper.next();
},
getSteps: function(){
return this.props.steps.map(transformStep, this);
},
render: function(){
var props = defaults({
ref: 'stepper',
steps: this.getSteps()
}, this.props);
return MultiStep(props);
}
});
function transformStep(cfg){
var goBack = this.props.allowBack ? this.previousStep : null;
var next = this.nextStep;
return {
name: cfg.name,
component: cfg.component({
skippable: cfg.skippable,
nextStep: next,
previousStep: goBack
})
};
}