Skip to content

Instantly share code, notes, and snippets.

@bhavaniravi
Created May 19, 2019 09:07
Show Gist options
  • Save bhavaniravi/216cbefebec4e6d3c37ae5baced536ab to your computer and use it in GitHub Desktop.
Save bhavaniravi/216cbefebec4e6d3c37ae5baced536ab to your computer and use it in GitHub Desktop.
CheatSheet to create a Button Component in React
import React from 'react'
import styled, { css } from 'styled-components'
const Button = styled.button`
position: absolute;
height: 10%;
width: 10%;
top: 50%;
left:50%;
font-size: 2.6vmin;
cursor: pointer;
box-shadow: rgba(255, 255, 255, 0.05) 0px 3px 20px;
border-width: initial;
background-color: grey;
color: white;
border-style: none;
border-color: initial;
border-image: initial;
outline: none;
&:hover {
background-color: #445b65;
color: white;
}
`
export default class UpgradedButton extends React.Component{
constructor(props){
super(props)
this.state = {
buttonText: "Start"
}
}
handleClick = () => {
console.log("Button clicked...")
let buttonText = this.state.buttonText == "Start" ? "Stop" : "Start"
this.setState({buttonText: buttonText})
}
render(){
return (
<Button onClick={this.handleClick}>{this.state.buttonText}</Button>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment