Skip to content

Instantly share code, notes, and snippets.

@pauloremoli
Last active February 23, 2022 07:37
Show Gist options
  • Save pauloremoli/39638f55c5e0f384a4ec7f07895de430 to your computer and use it in GitHub Desktop.
Save pauloremoli/39638f55c5e0f384a4ec7f07895de430 to your computer and use it in GitHub Desktop.
FadeIn component
// 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