Last active
April 5, 2017 10:18
-
-
Save RyanCCollins/2a450da6b4038edace28b143ac31d173 to your computer and use it in GitHub Desktop.
Styled Components, easy animation. See here: https://github.com/RyanCCollins/the-agency/blob/master/src/client/containers/NavigationMenu/heading.ts
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 styled, { css } from 'styled-components'; | |
import { StateProps } from './types'; | |
import { Heading } from 'ui'; | |
function styles({ isVisible }: StateProps) { | |
const opacity = isVisible | |
? 1.0 | |
: 0.0; | |
const translate = isVisible | |
? 0 | |
: 100; | |
return css` | |
transform: translateY(${translate}%); | |
opacity: ${opacity}; | |
`; | |
} | |
function transition(props: StateProps) { | |
const duration = 600; | |
return css` | |
transition: transform ${duration}ms ease, opacity ${duration}ms ease; | |
`; | |
} | |
export default styled(Heading)` | |
${(props: StateProps) => styles(props)} | |
${(props: StateProps) => transition(props)} | |
will-change: transform, opacity; | |
`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment