UNPKG

765 BJavaScriptView Raw
1import React from 'react'
2import PropTypes from 'prop-types'
3import styled, { keyframes } from 'styled-components'
4
5const animation = keyframes `
6 0% {
7 opacity: 0;
8 }
9 10% {
10 opacity: 1;
11 }
12 90% {
13 opacity 1;
14 }
15 100% {
16 opacity 0;
17 }
18`
19
20const FadeInOut = styled(({ className, children, ...props}) => {
21 return React.cloneElement(children, {
22 className: `${children.props.className ? `${children.props.className} ` : ``}${className}`
23 })
24})`
25 animation: ${animation} ${props => props.duration}s ease-in-out ${props => props.iteration};
26`
27
28FadeInOut.propTypes = {
29 duration: PropTypes.number,
30 iteration: PropTypes.string
31}
32
33FadeInOut.defaultProps = {
34 duration: 5,
35 iteration: 'infinite'
36}
37
38/** @component */
39export default FadeInOut