Last active
July 1, 2018 21:35
-
-
Save nodox/5cbe8daeaab816442bb3edf473ea0fc1 to your computer and use it in GitHub Desktop.
Buidling a stepper - step.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
class Step extends React.Component { | |
render() { | |
const { | |
isActive, | |
displayPrevious, | |
displayNext, | |
displaySubmit, | |
component, | |
children, | |
} = this.props; | |
if(isActive === false) return null; | |
return ( | |
<React.Fragment> | |
{component ? React.createElement(component) : children} | |
<Previous | |
isActive={displayPrevious} | |
goToPreviousStep={() => this.props.goToPreviousStep()} | |
/> | |
<Next | |
isActive={displayNext} | |
goToNextStep={() => this.props.goToNextStep()} | |
/> | |
<Submit isActive={displaySubmit} /> | |
</React.Fragment> | |
); | |
} | |
} | |
class Next extends React.Component { | |
render() { | |
const { isActive } = this.props; | |
if (isActive === false) return null; | |
return ( | |
<button onClick={() => this.props.goToNextStep()}> | |
Next | |
</button> | |
); | |
} | |
} | |
class Previous extends React.Component { | |
render() { | |
const { isActive } = this.props; | |
if (isActive === false) return null; | |
return ( | |
<button onClick={() => this.props.goToPreviousStep()}> | |
Previous | |
</button> | |
); | |
} | |
} | |
class Submit extends React.Component { | |
render() { | |
const { isActive } = this.props; | |
if (isActive === false) return null; | |
return ( | |
<button type="submit"> | |
Submit | |
</button> | |
); | |
} | |
} | |
export { Step }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment