I am looking to update the appearance of buttons when they are clicked.
Here is a preview of my files:
MainApp.js:
class ChangeButton extends Component {
constructor(){
super();
this.state = {
black: true
}
}
changeColor(){
this.setState({black: !this.state.black})
}
render(){
let btn_class1 = this.state.black ? "blackButton" : "whiteButton";
let btn_class2 = this.state.black ? "whiteButton" : "blackButton";
let btn_class3 = this.state.black ? "whiteButton" : "blackButton";
return (
<div>
<button className={btn_class1}
onClick={this.changeColor.bind(this)}>
Button1
</button>
<button className={btn_class2}
onClick={this.changeColor.bind(this)}>
Button2
</button>
<button className={btn_class3}
onClick={this.changeColor.bind(this)}>
Button3
</button>
</div>
)
}
}
export default MainApp;
design.css:
button{
width: 80px;
height: 40px;
margin: 15px;
}
.blackButton{
background-color: black;
color: white;
}
.whiteButton{
background-color: white;
color: black;
}
Initially, I want button1 to have a black background while button2 and button3 should have a white background.
Upon clicking button2, it should switch to a black background, with button1 and button3 changing to a white background.
Similarly, when pressing button3, it should turn to a black background, shifting button1 and button2 to have a white background.