forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubNav.js
More file actions
60 lines (58 loc) · 1.81 KB
/
SubNav.js
File metadata and controls
60 lines (58 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import React, { useState } from 'react';
import { motion } from 'framer-motion';
import { SubNav } from './elements';
export default ({ components, name, openedNav, hasOpened }) => {
const [hovered, setHovered] = useState(null);
const variants = {
normal: { scale: 1 },
hover: { scale: 1.2 },
};
return (
openedNav === name && (
<SubNav>
<nav>
<ul>
{components.map((Component, i) => {
const { Icon, Label } = Component;
return (
// eslint-disable-next-line react/no-array-index-key
<li key={i}>
<motion.div
initial={{
opacity: 0,
scale: hasOpened ? 1 : 0,
}}
animate={{ opacity: 1, scale: 1 }}
transition={{
delay: hasOpened ? 0 : (i + 1) * 0.05,
duration: 0.25,
type: 'spring',
}}
>
<motion.div
animate={hovered === i ? 'hover' : 'normal'}
variants={variants}
>
<div
onMouseEnter={() => setHovered(i)}
onMouseLeave={() => setHovered(null)}
>
<Icon />
</div>
</motion.div>
<div
onMouseEnter={() => setHovered(i)}
onMouseLeave={() => setHovered(null)}
>
<Label />
</div>
</motion.div>
</li>
);
})}
</ul>
</nav>
</SubNav>
)
);
};