-
-
Save kvasdopil/97e05305b0e0e79bc37284c2fd2a0dfe 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 = (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