Last active
February 23, 2022 07:37
-
-
Save pauloremoli/39638f55c5e0f384a4ec7f07895de430 to your computer and use it in GitHub Desktop.
FadeIn component
This file contains hidden or 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://www.joshwcomeau.com/snippets/react-components/fade-in/ | |
// FadeIn.js | |
import React from 'react'; | |
import styled, { keyframes } from 'styled-components'; | |
const fadeIn = keyframes` | |
from { | |
opacity: 0; | |
} | |
to { | |
opacity: 1; | |
} | |
`; | |
const FadeIn = ({ | |
duration = 300, | |
delay = 0, | |
children, | |
...delegated | |
}) => { | |
return ( | |
<Wrapper | |
{...delegated} | |
style={{ | |
...(delegated.style || {}), | |
animationDuration: duration + 'ms', | |
animationDelay: delay + 'ms', | |
}} | |
> | |
{children} | |
</Wrapper> | |
); | |
}; | |
const Wrapper = styled.div` | |
@media (prefers-reduced-motion: no-preference) { | |
animation-name: ${fadeIn}; | |
animation-fill-mode: backwards; | |
} | |
`; | |
export default FadeIn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment