|
| 1 | +import React from 'react' |
| 2 | +import ReactDOM from 'react-dom' |
| 3 | +import styled, { keyframes } from 'styled-components' |
| 4 | +import spring from 'css-spring' |
| 5 | + |
| 6 | +const start = `transform: translateX(0px);` |
| 7 | +const end = `transform: translateX(100px);` |
| 8 | + |
| 9 | +const AnimateWrapper = styled.div` |
| 10 | + height: 60px; |
| 11 | + width: 60px; |
| 12 | + background: #ddd; |
| 13 | + display: flex; |
| 14 | + flex-direction: column; |
| 15 | + justify-content: center; |
| 16 | + align-items: center; |
| 17 | + color: #999; |
| 18 | + margin: 5px; |
| 19 | + font-weight: bold; |
| 20 | + border: 1px solid #ccc; |
| 21 | + animation: ${({ tension, wobble }) => |
| 22 | + keyframes`${spring(start, end, { tension, wobble })}`} |
| 23 | + 2s linear infinite; |
| 24 | +` |
| 25 | + |
| 26 | +const AnimateRowWrapper = styled.div` |
| 27 | + display: flex; |
| 28 | + justify-content: space-between; |
| 29 | + padding-right: 175px; |
| 30 | +` |
| 31 | + |
| 32 | +const AnimateRow = ({ wobble }) => |
| 33 | + <AnimateRowWrapper> |
| 34 | + {[...new Array(11)].map((v, i) => |
| 35 | + <Animate tension={i / 10} wobble={wobble} /> |
| 36 | + )} |
| 37 | + </AnimateRowWrapper> |
| 38 | + |
| 39 | +const Animate = ({ tension, wobble }) => |
| 40 | + <AnimateWrapper tension={tension} wobble={wobble}> |
| 41 | + <div> |
| 42 | + t {tension} |
| 43 | + </div> |
| 44 | + <div> |
| 45 | + w {wobble} |
| 46 | + </div> |
| 47 | + </AnimateWrapper> |
| 48 | + |
| 49 | +const Matrix = () => |
| 50 | + React.Children.toArray([ |
| 51 | + <AnimateRow wobble={0} />, |
| 52 | + <AnimateRow wobble={0.1} />, |
| 53 | + <AnimateRow wobble={0.2} />, |
| 54 | + <AnimateRow wobble={0.3} />, |
| 55 | + <AnimateRow wobble={0.4} />, |
| 56 | + <AnimateRow wobble={0.5} />, |
| 57 | + <AnimateRow wobble={0.6} />, |
| 58 | + <AnimateRow wobble={0.7} />, |
| 59 | + <AnimateRow wobble={0.8} />, |
| 60 | + <AnimateRow wobble={0.9} />, |
| 61 | + <AnimateRow wobble={1} />, |
| 62 | + ]) |
| 63 | + |
| 64 | +ReactDOM.render(<Matrix />, document.querySelector('#app')) |
0 commit comments