site/components/fade-in.js
2021-03-22 14:11:08 +08:00

26 lines
609 B
JavaScript

import React from 'react'
import { Box } from 'theme-ui'
import styled from '@emotion/styled'
import { keyframes } from '@emotion/react'
const fadeIn = keyframes({ from: { opacity: 0 }, to: { opacity: 1 } })
const Wrapper = styled(Box)`
@media (prefers-reduced-motion: no-preference) {
animation-name: ${fadeIn};
animation-fill-mode: backwards;
}
`
const FadeIn = ({ duration = 300, delay = 0, ...props }) => (
<Wrapper
{...props}
style={{
...(props.style || {}),
animationDuration: duration + 'ms',
animationDelay: delay + 'ms'
}}
/>
)
export default FadeIn