-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNav0.jsx
99 lines (93 loc) · 2.52 KB
/
Nav0.jsx
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
import React from 'react';
import TweenOne from 'rc-tween-one';
import { Menu } from 'antd';
const Item = Menu.Item;
class Header extends React.Component {
constructor(props) {
super(props);
this.state = {
phoneOpen: false,
menuHeight: 0,
};
this.menu = React.createRef();
}
/*
componentDidMount() {
// 如果是 react 16.3 以下版本请使用 findDOMNode;
this.menuDom = findDOMNode(this.menu);
}
*/
phoneClick = () => {
const phoneOpen = !this.state.phoneOpen;
this.setState({
phoneOpen,
menuHeight: phoneOpen ? this.menu.current.dom.scrollHeight : 0,
});
};
render() {
const { ...props } = this.props;
const { dataSource, isMobile } = props;
delete props.dataSource;
delete props.isMobile;
const { menuHeight, phoneOpen } = this.state;
const navData = dataSource.Menu.children;
const navChildren = Object.keys(navData).map((key, i) => (
<Item key={i.toString()} {...navData[key]}>
<a
{...navData[key].a}
href={navData[key].a.href}
target={navData[key].a.target}
>
{navData[key].a.children}
</a>
</Item>
));
return (
<TweenOne
component="header"
animation={{ opacity: 0, type: 'from' }}
{...dataSource.wrapper}
{...props}
>
<div
{...dataSource.page}
className={`${dataSource.page.className}${phoneOpen ? ' open' : ''}`}
>
<TweenOne
animation={{ x: -30, type: 'from', ease: 'easeOutQuad' }}
{...dataSource.logo}
>
<img width="100%" src={dataSource.logo.children} alt="img" />
</TweenOne>
{isMobile && (
<div
{...dataSource.mobileMenu}
onClick={() => {
this.phoneClick();
}}
>
<em />
<em />
<em />
</div>
)}
<TweenOne
{...dataSource.Menu}
animation={{ x: 30, type: 'from', ease: 'easeOutQuad' }}
ref={this.menu} // {(c) => { this.menu = c; }}
style={isMobile ? { height: menuHeight } : null}
>
<Menu
mode={isMobile ? 'inline' : 'horizontal'}
defaultSelectedKeys={['0']}
theme={isMobile ? 'dark' : 'default'}
>
{navChildren}
</Menu>
</TweenOne>
</div>
</TweenOne>
);
}
}
export default Header;