Skip to content

Commit 0ed7244

Browse files
committed
Split Nav
1 parent 71879ac commit 0ed7244

File tree

3 files changed

+99
-50
lines changed

3 files changed

+99
-50
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from 'react';
2+
import { Router, Link } from 'react-router'
3+
4+
class LinksApp extends React.Component
5+
{
6+
constructor(props, context) {
7+
super(props, context);
8+
this.generate = this.generate.bind(this);
9+
this.state = {
10+
links: [
11+
[ '/', 'Home'],
12+
['/client', 'Client'],
13+
['/area', 'Area']
14+
]
15+
};
16+
}
17+
18+
generate() {
19+
return this.state.links.map((link, index) => (
20+
<Link to={link[0]}
21+
key={index}
22+
className="nav-item is-tab"
23+
onlyActiveOnIndex={true}
24+
activeClassName="is-active"
25+
onClick={this.props.hide}>{link[1]}
26+
</Link>
27+
));
28+
}
29+
30+
render() {
31+
return (
32+
<span className="nav-right nav-menu is-active">
33+
{this.generate()}
34+
</span>
35+
);
36+
}
37+
}
38+
39+
LinksApp.propTypes = {
40+
hide: React.PropTypes.func.isRequired,
41+
};
42+
43+
export default LinksApp;
44+

app/components/Menu/Menu.js

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,27 @@
11
import React from 'react';
22
import { Router, Link } from 'react-router'
33

4+
import Nav from 'components/Nav/Nav'
5+
46
class Menu extends React.Component{
57
constructor(props, context) {
68
super(props, context);
79
this.handleLogout = this.handleLogout.bind(this);
810
this.handleView = this.handleView.bind(this);
9-
this.toggleNav = this.toggleNav.bind(this);
10-
this.handleLink = this.handleLink.bind(this);
11-
this.createLink = this.createLink.bind(this);
12-
this.state = {
13-
toggleNav: '',
14-
links: [
15-
[ '/', 'Home'],
16-
['/client', 'Client'],
17-
['/area', 'Area']
18-
]
19-
};
2011
}
2112

2213
handleLogout() {
2314
delete localStorage.token;
2415
this.context.router.push("/");
2516
}
2617

27-
toggleNav() {
28-
let isActive = this.state.toggleNav ? '' : 'is-active';
29-
this.setState({toggleNav: isActive});
30-
}
31-
32-
handleLink(e) {
33-
this.setState({toggleNav: ''});
34-
}
35-
36-
createLink() {
37-
return this.state.links.map((link, index) => (
38-
<Link to={link[0]}
39-
key={index}
40-
className="nav-item is-tab"
41-
onlyActiveOnIndex={true}
42-
activeClassName="is-active"
43-
onClick={this.handleLink}>{link[1]}
44-
</Link>
45-
));
46-
}
47-
4818
handleView() {
4919
return (
50-
<nav className="nav has-shadow" id="top">
51-
<div className="container">
52-
<div className="nav-left">
53-
<a className="nav-item" href="../index.html">IClient</a>
54-
</div>
55-
<span className={ `nav-toggle ${this.state.toggleNav}` } onClick={this.toggleNav}>
56-
<span></span>
57-
<span></span>
58-
<span></span>
59-
</span>
60-
<div className={ `nav-right nav-menu ${this.state.toggleNav}` }>
61-
{this.createLink()}
62-
<span className="nav-item">
63-
<a className="button" onClick={this.handleLogout}>Logout</a>
64-
</span>
65-
</div>
66-
</div>
67-
</nav>
20+
<Nav>
21+
<span className="nav-item">
22+
<a className="button" onClick={this.handleLogout}>Logout</a>
23+
</span>
24+
</Nav>
6825
);
6926
}
7027

app/components/Nav/Nav.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React from 'react';
2+
3+
import LinksApp from 'components/LinksApp/LinksApp'
4+
5+
class Nav extends React.Component
6+
{
7+
constructor(props, context) {
8+
super(props, context);
9+
this.toggleNav = this.toggleNav.bind(this);
10+
this.hide = this.hide.bind(this);
11+
this.state = {
12+
toggleNav: ''
13+
};
14+
}
15+
16+
hide(e) {
17+
this.setState({toggleNav: ''});
18+
}
19+
20+
toggleNav() {
21+
let isActive = this.state.toggleNav ? '' : 'is-active';
22+
this.setState({toggleNav: isActive});
23+
}
24+
25+
render() {
26+
return (
27+
<nav className="nav has-shadow" id="top">
28+
<div className="container">
29+
<div className="nav-left">
30+
<a className="nav-item" href="../index.html">IClient</a>
31+
</div>
32+
<span className={ `nav-toggle ${this.state.toggleNav}` } onClick={this.toggleNav}>
33+
<span></span>
34+
<span></span>
35+
<span></span>
36+
</span>
37+
<div className={ `nav-right nav-menu ${this.state.toggleNav}` }>
38+
<LinksApp hide={this.hide} />
39+
{this.props.children}
40+
</div>
41+
</div>
42+
</nav>
43+
);
44+
}
45+
}
46+
47+
export default Nav;
48+

0 commit comments

Comments
 (0)