|
1 | 1 | <template> |
2 | | - <div v-if="isExternalLink"> |
3 | | - <a :href="url" :class="classList"> |
4 | | - <i :class="classIcon"></i> {{name}} |
5 | | - <c-badge v-if="badge && badge.text" :variant="badge.variant">{{badge.text}}</c-badge> |
6 | | - </a> |
7 | | - </div> |
8 | | - <div v-else> |
9 | | - <router-link :to="url" :class="classList"> |
10 | | - <i :class="classIcon"></i> {{name}} |
11 | | - <c-badge v-if="badge && badge.text" :variant="badge.variant">{{badge.text}}</c-badge> |
12 | | - </router-link> |
13 | | - </div> |
| 2 | + <CLink |
| 3 | + v-bind="computedProps" |
| 4 | + :exact="true" |
| 5 | + class="nav-link" |
| 6 | + > |
| 7 | + <i :class="['nav-icon', icon]"></i> {{name}} |
| 8 | + <CBadge |
| 9 | + v-if="badge && badge.text" |
| 10 | + :variant="badge.variant" |
| 11 | + > |
| 12 | + {{badge.text}} |
| 13 | + </CBadge> |
| 14 | + </CLink> |
14 | 15 | </template> |
15 | 16 |
|
16 | | - |
17 | 17 | <script> |
18 | | -export default { |
19 | | - name: 'CSidebarNavLink', |
20 | | - props: { |
21 | | - name: { |
22 | | - type: String, |
23 | | - default: '' |
24 | | - }, |
25 | | - url: { |
26 | | - type: String, |
27 | | - default: '' |
28 | | - }, |
29 | | - icon: { |
30 | | - type: String, |
31 | | - default: '' |
32 | | - }, |
| 18 | +import CLink, { propsFactory as linkPropsFactory} from '../Link/CLink' |
| 19 | +
|
| 20 | +const props = Object.assign(linkPropsFactory(), { |
| 21 | + name: String, |
| 22 | + icon: [String, Array, Object], |
33 | 23 | badge: { |
34 | 24 | type: Object, |
35 | 25 | default: () => {} |
36 | 26 | }, |
37 | | - variant: { |
38 | | - type: String, |
39 | | - default: '' |
40 | | - }, |
41 | | - classes: { |
42 | | - type: String, |
43 | | - default: '' |
44 | | - } |
45 | | - }, |
| 27 | + variant: String, |
| 28 | + url: String |
| 29 | + } |
| 30 | +) |
| 31 | +export default { |
| 32 | + name: 'CSidebarNavLink', |
| 33 | + props, |
46 | 34 | computed: { |
47 | | - classList () { |
48 | | - return [ |
49 | | - 'nav-link', |
50 | | - this.linkVariant, |
51 | | - ...this.itemClasses |
52 | | - ] |
53 | | - }, |
54 | | - classIcon () { |
55 | | - return [ |
56 | | - 'nav-icon', |
57 | | - this.icon |
58 | | - ] |
59 | | - }, |
60 | | - linkVariant () { |
61 | | - return this.variant ? `nav-link-${this.variant}` : '' |
62 | | - }, |
63 | | - itemClasses () { |
64 | | - return this.classes ? this.classes.split(' ') : [] |
| 35 | + linkGeneratedFromUrlProp () { |
| 36 | + if (!this.url) return {} |
| 37 | + return this.url && this.url.substring(0,4) === 'http' ? |
| 38 | + { href: this.url } : { to: this.url } |
65 | 39 | }, |
66 | | - isExternalLink () { |
67 | | - if (this.url.substring(0, 4) === 'http') { |
68 | | - return true |
69 | | - } else { |
70 | | - return false |
71 | | - } |
| 40 | + computedProps () { |
| 41 | + return Object.assign({}, this.$props, this.linkGeneratedFromUrlProp) |
72 | 42 | } |
73 | 43 | } |
74 | 44 | } |
|
0 commit comments