Last active
September 11, 2019 19:30
-
-
Save felipegenuino/bd8777cbd826b4bd6b863b4e188106ba to your computer and use it in GitHub Desktop.
Usando props no styled-components
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
//https://codesandbox.io/s/propsstyled-components-rph5f | |
import React, { useState, Fragment } from "react"; | |
import styled from "styled-components"; | |
const MyComponent = props => { | |
const [expanded, setExpanded] = useState(false); | |
function handleExpandClick(event) { | |
setExpanded(!expanded); | |
} | |
return ( | |
<Fragment> | |
<button onClick={event => handleExpandClick(event)}>CallToAction</button> | |
<Icone expanded={expanded}> > </Icone> | |
</Fragment> | |
); | |
}; | |
export default MyComponent; | |
const Icone = styled.div` | |
transition: all 0.2s linear; | |
color: #fff; | |
width: 100px; | |
height: 100px; | |
border-radius: 100%; | |
background: ${props => (props.expanded ? "red" : "blue")}; | |
transform: ${props => | |
props.expanded ? " rotate(180deg) scale(1)" : "rotate(0deg) scale(0.9)"}; | |
`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment