-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnav-list.jsx
More file actions
74 lines (63 loc) · 1.85 KB
/
Copy pathnav-list.jsx
File metadata and controls
74 lines (63 loc) · 1.85 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"use strict"
import React from 'react'
import classnames from 'classnames'
import menulist from './menulist'
const { Icon } = global.uiRequire()
export default class NavList extends React.Component {
static displayName = 'NavList'
static propTypes = {
onToggle: React.PropTypes.func
}
static contextTypes = {
history: React.PropTypes.object.isRequired
}
state = {
active: true
}
getClasses (name, path) {
return classnames(name, {
active: this.context.history.isActive(path)
})
}
pathChange (path) {
if (!this.context.history.isActive(path)) {
this.context.history.pushState(null, path)
}
}
getRoutesList (paths, index) {
let list = paths.map(function (r, i) {
if (r.path) {
return (
<li key={i} className="pure-menu-item">
<a onClick={this.pathChange.bind(this, r.path)} className={this.getClasses("pure-menu-link", r.path)}>{r.text}</a>
</li>
)
} else if (r.hr) {
return (<hr key={i} />)
} else if (r.text) {
return (
<li key={i} className="pure-menu-item">
<span className="pure-menu-link">{r.text}</span>
</li>
)
}
}, this)
return <ul key={index} className="pure-menu-list">{list}</ul>
}
render () {
let list = menulist.map(function (paths, index) {
return this.getRoutesList(paths, index)
}, this)
return (
<div className={classnames("nav", {active: this.state.active})}>
<a className="pure-menu-heading" onClick={this.pathChange.bind(this, '/home')}>React UI</a>
<a className="link-github" href="https://github.com/Lobos/react-ui"><Icon size={2} icon="github" /></a>
<div className="nav-inner">
<div ref="list" className="nav-list">
{list}
</div>
</div>
</div>
)
}
}