Last active
November 14, 2021 16:23
-
-
Save tchardin/ed551c191c5869092128b93fa8705b98 to your computer and use it in GitHub Desktop.
Play/Pause toggle SVG button in React
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
import React from 'react' | |
const Pause = ({onPlayerClick}) => { | |
return ( | |
<svg className="button" viewBox="0 0 60 60" onClick={onPlayerClick}> | |
<polygon points="0,0 15,0 15,60 0,60" /> | |
<polygon points="25,0 40,0 40,60 25,60" /> | |
</svg> | |
) | |
} | |
export default Pause |
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
import React from 'react' | |
const Play = ({onPlayerClick}) => { | |
return ( | |
<svg className="button" viewBox="0 0 60 60" onClick={onPlayerClick}> | |
<polygon points="0,0 50,30 0,60" /> | |
</svg> | |
) | |
} | |
export default Play |
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
import React, { Component } from 'react' | |
class Player extends Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
playing: false | |
} | |
} | |
handlePlayerClick = () => { | |
if (!this.state.playing) { | |
this.setState({playing: true}) | |
} else { | |
this.setState({playing: false}) | |
} | |
} | |
render() { | |
return ( | |
<div className="player" > | |
{this.state.playing? <Pause onPlayerClick={this.handlePlayerClick} /> : <Play onPlayerClick={this.handlePlayerClick} />} | |
</div> | |
) | |
} | |
} | |
export default Player |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment