Skip to content

Commit 77c7aac

Browse files
committed
refactor: removed current option from CBreadcrumb, add props allowing class manipulation, enable HTML text.
1 parent 0454c63 commit 77c7aac

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/components/Breadcrumb/CBreadcrumb.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,26 @@ export default {
66
name: 'CBreadcrumb',
77
props: {
88
items: Array,
9+
addLinkClasses: [String, Array],
10+
lastItemClasses: [String, Array],
911
},
1012
render (h, { props, data }) {
1113
if(!Array.isArray(props.items)){ return }
1214
let childNodes = props.items.map((item, index, items) => {
13-
const active = items.length === index + 1 && item.current === undefined || item.current
14-
const tag = active ? 'span' : CLink
15-
const itemProps = active ? { class: { active: true } } : { props: item }
15+
if(typeof item !== 'object'){ return }
16+
const isLast = items.length === index + 1
17+
const tag = isLast ? 'span' : CLink
18+
const itemProps = isLast ?
19+
{ class: props.lastItemClasses, domProps: { innerHTML: item.text} } :
20+
{ class: [props.addLinkClasses, item.addLinkClasses],
21+
domProps: { innerHTML: item.text}, props: item }
1622
return h('li',
1723
{
1824
staticClass: 'breadcrumb-item',
19-
class: { active: active },
25+
class: { active: isLast },
2026
attrs: { role: 'presentation' }
2127
},
22-
[h(tag, itemProps, item.text)])
28+
[h(tag, itemProps)])
2329
})
2430
return h('ol', mergeData(data, { staticClass: 'breadcrumb' }), childNodes)
2531
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import CBreadcrumb from './CBreadcrumb'
22

3-
export default{
3+
export default {
44
name: 'CBreadcrumbRouter',
55
computed: {
66
items () {
7-
const routes = this.$route.matched.filter((route) => route.name || route.meta.label)
8-
return routes.map((route) => {
7+
const routes = this.$route.matched.filter(route => route.name || route.meta.label)
8+
return routes.map(route => {
99
const item = {
1010
to: route,
1111
text: route.meta && route.meta.label ? route.meta.label : route.name || null
@@ -15,6 +15,6 @@ export default{
1515
}
1616
},
1717
render (h){
18-
return h(CBreadcrumb, { props: {items: this.items} })
18+
return h(CBreadcrumb, { props: { items: this.items }})
1919
}
2020
}

0 commit comments

Comments
 (0)