Skip to content

Instantly share code, notes, and snippets.

@tuor4eg
Last active September 17, 2018 10:58
Show Gist options
  • Save tuor4eg/85f7ac45cb6367a88bd4575ce8539385 to your computer and use it in GitHub Desktop.
Save tuor4eg/85f7ac45cb6367a88bd4575ce8539385 to your computer and use it in GitHub Desktop.
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