Last active
September 17, 2018 10:58
-
-
Save tuor4eg/85f7ac45cb6367a88bd4575ce8539385 to your computer and use it in GitHub Desktop.
This file contains 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
export default class BtnGroup extends React.Component { | |
state = { | |
active: null | |
}; | |
onClick = ({ target }) => { | |
const getSide = target.classList[2]; | |
this.setState({ active: getSide }); | |
} | |
render() { | |
const defaultBtnClass = 'btn btn-secondary'; | |
const isLeftActive = this.state.active === 'left' ? ' active' : ''; | |
const isRightActive = this.state.active === 'right' ? ' active' : ''; | |
const leftBtnClass = `${defaultBtnClass} left${isLeftActive}`; | |
const rightBtnClass = `${defaultBtnClass} right${isRightActive}`; | |
return <div className="btn-group" role="group"> | |
<button onClick={this.onClick} type="button" className={leftBtnClass}>Left</button> | |
<button onClick={this.onClick} type="button" className={rightBtnClass}>Right</button> | |
</div>; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment