Skip to content

Commit 6541c0d

Browse files
committed
Step components added and changing between them
1 parent b766153 commit 6541c0d

File tree

9 files changed

+367
-68
lines changed

9 files changed

+367
-68
lines changed

.idea/workspace.xml

+187-56
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"prop-types": "^15.6.0",
99
"react": "^16.0.0",
1010
"react-dom": "^16.0.0",
11-
"react-scripts": "1.0.17"
11+
"react-scripts": "1.0.17",
12+
"react-transition-group": "^2.2.1"
1213
},
1314
"scripts": {
1415
"build-css": "node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/",

src/demo/App.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'bootstrap/dist/css/bootstrap.css';
55

66
import '../publish_component/Stepper'
77
import Stepper from '../publish_component/Stepper';
8-
import DummyData from '../publish_component/DummyData'
8+
import DummyData from './DummyData'
99

1010
class App extends Component {
1111
constructor(props) {
@@ -19,8 +19,8 @@ class App extends Component {
1919
render() {
2020
return (
2121
<div className="container-fluid App no-gutters">
22-
<div className="row" style={{marginBottom: '2rem'}}>
23-
<div className="col no-gutters">
22+
<div className="row no-gutters" style={{marginBottom: '2rem'}}>
23+
<div className="col">
2424
<header className="App-header">
2525
<img src={logo} className="App-logo" alt="logo"/>
2626
<h1 className="App-title">Welcome to React</h1>
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
2-
1+
import StepOne from './StepOne'
2+
import StepTwo from './StepTwo'
33

44
export default [
55
{
66
icon: 'mail',
77
name: 'first',
88
title: 'Sample title 1',
9-
subtitle: 'Subtitle sample'
9+
subtitle: 'Subtitle sample',
10+
component: StepOne
1011

1112
},
1213
{
1314
icon: 'report_problem',
1415
name: 'second',
1516
title: 'Sample title 2',
16-
subtitle: 'Subtitle sample'
17+
subtitle: 'Subtitle sample',
18+
component: StepTwo
1719
}
1820
]

src/demo/StepOne.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React, {Component} from 'react'
2+
import PropTypes from 'prop-types'
3+
4+
class StepOne extends Component {
5+
render() {
6+
return (
7+
<div style={{padding: '2rem 3rem', textAlign: 'left'}}>
8+
<div className="form-group">
9+
<label>Email address</label>
10+
<input type="email" className="form-control" placeholder="Enter email"/>
11+
<small className="form-text text-muted">We'll never share your email with anyone else.</small>
12+
</div>
13+
<div className="form-group">
14+
<label>Password</label>
15+
<input type="password" className="form-control" placeholder="Password"/>
16+
</div>
17+
<div className="form-check">
18+
<label className="form-check-label">
19+
<input type="checkbox" className="form-check-input"/>
20+
Check me out
21+
</label>
22+
</div>
23+
</div>
24+
)
25+
}
26+
}
27+
28+
export default StepOne

src/demo/StepTwo.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React, {Component} from 'react'
2+
import PropTypes from 'prop-types'
3+
4+
class StepTwo extends Component {
5+
render() {
6+
return (
7+
<div style={{padding: '2rem 3rem', textAlign: 'left'}}>
8+
TEST
9+
</div>
10+
)
11+
}
12+
}
13+
14+
export default StepTwo

src/publish_component/Stepper.js

+90-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, {Component} from 'react';
22
import PropTypes from 'prop-types';
3+
import { CSSTransition } from 'react-transition-group'
34

45
//Styles
56
import './Stepper.css'
@@ -18,11 +19,79 @@ class Stepper extends Component {
1819
previousStep: {},
1920
nextButton: {},
2021
canContinue: false,
21-
finalStep: false
22+
finalStep: false,
23+
transition: false
24+
};
25+
26+
// Binding Methods
27+
this.activateStep = this.activateStep.bind(this);
28+
this.nextStep = this.nextStep.bind(this);
29+
this.backStep = this.backStep.bind(this);
30+
}
31+
32+
activateStep(index, back = false) {
33+
if (this.props.steps[index]) {
34+
// Setting states
35+
this.setState((prevState, props) => ({
36+
previousStep: prevState.currentStep,
37+
currentStep: {
38+
name: props.steps[index].name,
39+
index: index
40+
}
41+
}));
42+
43+
if (index + 1 === this.props.steps.length) {
44+
this.setState({finalStep: true})
45+
} else {
46+
this.setState({finalStep: false})
47+
}
48+
49+
if (!back) {
50+
// this.$emit('completed-step', this.previousStep);
51+
}
2252
}
53+
// this.$emit('active-step', this.currentStep);
54+
}
55+
56+
nextStep() {
57+
if (this.state.canContinue) {
58+
if (this.state.finalStep) {
59+
// this.$emit('stepper-finished', this.currentStep);
60+
}
61+
let currentIndex = this.state.currentStep.index + 1;
62+
this.activateStep(currentIndex);
63+
64+
}
65+
this.setState((prevState) => ({
66+
nextButton: {[prevState.currentStep.name]: true},
67+
canContinue: false
68+
}));
69+
this.forceUpdate();
70+
}
71+
72+
backStep() {
73+
// this.$emit('clicking-back');
74+
let currentIndex = this.state.currentStep.index - 1;
75+
if (currentIndex >= 0) {
76+
this.activateStep(currentIndex, true);
77+
}
78+
}
79+
80+
componentWillMount() {
81+
// Initiate stepper
82+
this.activateStep(0);
83+
this.props.steps.forEach((step) => {
84+
this.setState({
85+
nextButton: {[step.name]: false}
86+
})
87+
});
2388
}
2489

2590
render() {
91+
92+
// Store component in variable
93+
const StepComponent = this.props.steps[this.state.currentStep.index].component;
94+
2695
return (
2796
<div className="stepper-box">
2897
<div className="top">
@@ -34,9 +103,9 @@ class Stepper extends Component {
34103
currentIndex={this.state.currentStep.index}/>
35104

36105
{/*Loops through indicator to show based on step amount*/}
37-
{this.props.steps.map( (step, index, array) =>
106+
{this.props.steps.map((step, index, array) =>
38107
<StepIndicator step={step} index={index} stepsLength={array.length}
39-
currentStep={this.state.currentStep}/>
108+
currentStep={this.state.currentStep} key={step.name}/>
40109
)}
41110

42111
<TopButtons show={this.props.topButtons} previous={false}
@@ -45,7 +114,25 @@ class Stepper extends Component {
45114
</div>
46115

47116
<div className="content">
117+
<CSSTransition in={this.state.transition}>
118+
<StepComponent/>
119+
</CSSTransition>
120+
</div>
48121

122+
123+
<div className={['bottom', (this.state.currentStep.index > 0) ? '' : 'only-next'].join(' ')}>
124+
{this.state.currentStep.index > 0 && (
125+
<div className="stepper-button previous" onClick={this.backStep}>
126+
<i className="material-icons">keyboard_arrow_left</i>
127+
<span>Back</span>
128+
</div>
129+
)}
130+
<div className={['stepper-button next', !this.state.canContinue ? 'deactivated' : ''].join(' ')}
131+
onClick={this.nextStep}
132+
>
133+
<span>Next</span>
134+
<i className="material-icons">keyboard_arrow_right</i>
135+
</div>
49136
</div>
50137
</div>
51138
)

src/publish_component/TopButtons.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class TopButtons extends Component {
66
// Render if current step index > 0
77
let topButton = null;
88
if (this.props.show) {
9-
if(this.props.previous) {
9+
if (this.props.previous) {
1010
if (this.props.currentIndex > 0) {
1111
topButton =
1212
<div className={['stepper-button-top', this.props.previous ? 'previous' : 'next'].join(' ')}>

0 commit comments

Comments
 (0)