1 | import React from 'react'
|
2 | import PropTypes from 'prop-types'
|
3 | import styled, { keyframes } from 'styled-components'
|
4 |
|
5 | const 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 |
|
20 | const 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 |
|
28 | FadeInOut.propTypes = {
|
29 | duration: PropTypes.number,
|
30 | iteration: PropTypes.string
|
31 | }
|
32 |
|
33 | FadeInOut.defaultProps = {
|
34 | duration: 5,
|
35 | iteration: 'infinite'
|
36 | }
|
37 |
|
38 |
|
39 | export default FadeInOut
|