-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBreadcrumbs.js
39 lines (32 loc) · 917 Bytes
/
Breadcrumbs.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
import React from 'react'
import Link from 'next/link'
export class Breadcrumbs extends React.Component {
/**
* Verify that breadcrumb has valid attributes.
* @param crumb
* @returns {boolean}
*/
crumbIsValid (crumb) {
let hasUrl = typeof crumb.url !== 'undefined'
let hasName = typeof crumb.name !== 'undefined'
if (crumb.active) {
return hasName
}
return (hasUrl && hasName)
}
crumb (c) {
if (!this.crumbIsValid(c)) {
return ``
}
if (c.active) {
return <li className='is-active' key={c.name}><a href='#' aria-current='page'>{c.name}</a></li>
}
return <li key={c.name}><Link href={c.url}><a>{c.name}</a></Link></li>
}
render () {
let crumbs = this.props.crumbs
return <nav className='breadcrumb has-succeeds-separator' aria-label='breadcrumbs'><ul>{crumbs.map(c => {
return this.crumb(c)
})}</ul></nav>
}
}