-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNav.tsx
102 lines (94 loc) · 2.54 KB
/
Nav.tsx
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { useState } from 'react';
import TweenOne from 'rc-tween-one';
import { Menu } from 'antd';
import { getChildrenToRender, getSelectedKeys, onComplete } from './utils';
import { IObject } from 'rc-queue-anim';
import { BannerProps } from '../types';
const { Item } = Menu;
const Nav = ({ dataSource, isMobile, ...props }: BannerProps) => {
const [phoneOpen, setPhoneOpen] = useState(false);
const navData = dataSource.Menu.children;
const navChildren = navData.map((item: any) => {
const { children, ...itemProps } = item;
return (
<Item key={item.name} {...itemProps}>
<a {...children} className={`header3-item-block ${children.className}`.trim()}>
{children.children.map(getChildrenToRender)}
</a>
</Item>
);
});
const moment = phoneOpen === undefined ? 300 : null;
return (
<TweenOne
component="header"
animation={[
{
x: 0,
y: 0,
duration: 200,
type: 'from',
opacity: 0,
},
{ x: 0, y: 0, opacity: 1 },
]}
{...dataSource.wrapper}
{...props}
>
<div
{...dataSource.page}
className={`${dataSource.page.className}${phoneOpen ? ' open' : ''}`}
>
<TweenOne
animation={{ x: -30, type: 'from', ease: 'easeOutQuad' }}
{...dataSource.logo}
>
<a href={dataSource.logo.children.href}>
<img
width="100%"
src={dataSource.logo.children.logo}
alt="img"
/>
</a>
</TweenOne>
{isMobile && (
<div
{...dataSource.mobileMenu}
onClick={() => setPhoneOpen(!phoneOpen)}
>
<em />
<em />
<em />
</div>
)}
<TweenOne
id='animationNav'
{...dataSource.Menu}
animation={
isMobile
? {
x: 0,
height: 0,
duration: 300,
onComplete: (e: IObject) => onComplete(e, phoneOpen),
ease: 'easeInOutQuad',
}
: null
}
moment={moment}
reverse={!!phoneOpen}
>
<Menu
style={{ borderRadius: 20 }}
mode={isMobile ? 'inline' : 'horizontal'}
defaultSelectedKeys={getSelectedKeys()}
theme="light"
>
{navChildren}
</Menu>
</TweenOne>
</div>
</TweenOne >
);
};
export default Nav;