Skip to content

Instantly share code, notes, and snippets.

@kvasdopil
Forked from tuor4eg/reactHuyakt.js
Last active September 17, 2018 11:01
Show Gist options
  • Save kvasdopil/97e05305b0e0e79bc37284c2fd2a0dfe to your computer and use it in GitHub Desktop.
Save kvasdopil/97e05305b0e0e79bc37284c2fd2a0dfe to your computer and use it in GitHub Desktop.
export default class BtnGroup extends React.Component {
state = {
active: null
};
onClick = (id) => {
this.setState({ active: id });
}
render() {
const { active } = this.state;
const getClass = (cls, id) => [
cls
'btn',
'btn-secondary',
active === id ? 'active' : '',
].join(' ');
return <div className="btn-group" role="group">
<button onClick={() => this.onClick(0)} type="button" className={getClass('left', 0)}>Left</button>
<button onClick={() => this.onClick(1)} type="button" className={getClass('right', 1)}>Right</button>
</div>;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment