()
| 12 | import styles from './styles.module.css' |
| 13 | |
| 14 | export default function App() { |
| 15 | const [open, set] = useState(false) |
| 16 | |
| 17 | const springApi = useSpringRef() |
| 18 | const { size, ...rest } = useSpring({ |
| 19 | ref: springApi, |
| 20 | config: config.stiff, |
| 21 | from: { size: '20%', background: 'hotpink' }, |
| 22 | to: { |
| 23 | size: open ? '100%' : '20%', |
| 24 | background: open ? 'white' : 'hotpink', |
| 25 | }, |
| 26 | }) |
| 27 | |
| 28 | const transApi = useSpringRef() |
| 29 | const transition = useTransition(open ? data : [], { |
| 30 | ref: transApi, |
| 31 | trail: 400 / data.length, |
| 32 | from: { opacity: 0, scale: 0 }, |
| 33 | enter: { opacity: 1, scale: 1 }, |
| 34 | leave: { opacity: 0, scale: 0 }, |
| 35 | }) |
| 36 | |
| 37 | // This will orchestrate the two animations above, comment the last arg and it creates a sequence |
| 38 | useChain(open ? [springApi, transApi] : [transApi, springApi], [ |
| 39 | 0, |
| 40 | open ? 0.1 : 0.6, |
| 41 | ]) |
| 42 | |
| 43 | return ( |
| 44 | <div className={styles.wrapper}> |
| 45 | <animated.div |
| 46 | style={{ ...rest, width: size, height: size }} |
| 47 | className={styles.container} |
| 48 | onClick={() => set(open => !open)} |
| 49 | > |
| 50 | {transition((style, item) => ( |
| 51 | <animated.div |
| 52 | className={styles.item} |
| 53 | style={{ ...style, background: item.css }} |
| 54 | /> |
| 55 | ))} |
| 56 | </animated.div> |
| 57 | </div> |
| 58 | ) |
| 59 | } |
nothing calls this directly
no test coverage detected