-
-
Notifications
You must be signed in to change notification settings - Fork 921
/
DocHeader.js
91 lines (82 loc) · 2.4 KB
/
DocHeader.js
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
import React from 'react';
import classNames from 'classnames';
import { scrollTop, on} from 'dom-lib';
import { Router, Route, Link } from 'react-router';
import { Header, Navbar, Nav } from '../../src/index';
const NAV_LINKS = [
{
link: '/getting-started',
title: '开始使用'
}, {
link: '/components',
title: '组件'
}, {
link: '/examples',
title: '实例'
}];
const DocHeader = React.createClass({
propTypes: {
activePage: React.PropTypes.string
},
contextTypes: {
router: React.PropTypes.object.isRequired
},
getInitialState: function () {
return {
overflow: false
};
},
componentDidMount() {
this._onWindowScrollListener = on(window, 'scroll', this.handleWindowScroll);
},
componentWillUnmount() {
if (this._onWindowScrollListener) {
this._onWindowScrollListener.off();
}
},
handleWindowScroll() {
if (scrollTop(window) > 30) {
this.setState({
overflow: true
});
return;
}
this.setState({
overflow: false
});
},
render() {
let links = NAV_LINKS.map((nav, index) => {
return (
<li className={this.context.router.isActive(nav.link) ? 'active' : null} key={index} >
<Link to={nav.link}>{nav.title}</Link>
</li>
);
});
let classes = classNames({
'doc-header': true,
'overflow': this.state.overflow
});
return (
<Header className={classes} inverse>
<div className="container">
<Navbar.Header>
<Navbar.Brand>
<a href="#"><span className="prefix">R</span>Suite</a>
</Navbar.Brand>
<Navbar.Toggle />
</Navbar.Header>
<Navbar.Collapse>
<Nav>
{links}
</Nav>
<Nav pullRight>
<Nav.Item href="https://github.com/rsuite/rsuite">GitHub</Nav.Item>
</Nav>
</Navbar.Collapse>
</div>
</Header>
);
}
});
export default DocHeader;