Skip to content

Commit ee3cb91

Browse files
authored
Merge pull request #3 from nih-sparc/Breadcrumb
Breadcrumb
2 parents 5ff16fd + 63b4259 commit ee3cb91

File tree

6 files changed

+845
-767
lines changed

6 files changed

+845
-767
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"@carbon/grid": "^11.20.0",
2323
"element-plus": "^2.4.2",
2424
"ramda": "^0.29.1",
25-
"vue": "^3.3.4"
25+
"vue": "^3.3.4",
26+
"vue-router":"^4.2.5"
2627
},
2728
"devDependencies": {
2829
"@storybook/addon-essentials": "7.5.1",

src/App.vue

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
<main>
1111
<SparcLogo></SparcLogo>
12+
<breadcrumb-trail
13+
:breadcrumb="breadcrumbs"
14+
link-component="router-link"
15+
title="Level 3 this should be truncated "
16+
/>
1217
<div class="tooltip">
1318
<sparc-tooltip v-for="dir in tooltipDirs" :key="dir" :placement="dir">
1419
<template v-slot:data>
@@ -243,6 +248,7 @@
243248
import DropdownMultiselect from './components/DropdownMultiselect/DropdownMultiselect.vue'
244249
import Pagination from './components/Pagination.vue'
245250
import PaginationMenu from './components/PaginationMenu.vue'
251+
import BreadcrumbTrail from './components/BreadcrumbTrail.vue'
246252
import { ref } from 'vue'
247253
import { successMessage, infoMessage, failMessage, informationNotification, iconInformationNotification } from "../utils/notificationMessages"
248254
@@ -729,7 +735,13 @@
729735
value: 'Option5',
730736
label: 'Option5'
731737
}]
732-
738+
const breadcrumbs= [{
739+
label: "Home",
740+
to: "/home"
741+
}, {
742+
label: "Level 2",
743+
to: "/#"
744+
}]
733745
export default {
734746
components: {
735747
HelloWorld,
@@ -739,7 +751,8 @@
739751
SparcRadio,
740752
DropdownMultiselect,
741753
Pagination,
742-
PaginationMenu
754+
PaginationMenu,
755+
BreadcrumbTrail
743756
},
744757
name: 'App',
745758
setup() {
@@ -804,7 +817,8 @@
804817
options,
805818
pageSize,
806819
pageCount,
807-
selectedPage
820+
selectedPage,
821+
breadcrumbs
808822
}
809823
},
810824
methods: {
@@ -838,13 +852,16 @@
838852
</script>
839853

840854
<style scoped lang="scss">
855+
841856
header {
842857
line-height: 1.5;
843858
}
844859
845860
.logo {
846861
display: block;
847862
margin: 0 auto 2rem;
863+
height: 100px;
864+
width:100px;
848865
}
849866
850867
.tooltip {

src/components/BreadcrumbTrail.vue

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<template>
2+
<div class="design-system-component-breadcrumb">
3+
<div v-for="item in breadcrumb" :key="item.label" class="breadcrumb-link">
4+
<template v-if="linkComponent === 'nuxt-link' || linkComponent === 'router-link'">
5+
<component :is="linkComponent" :to="item.to">
6+
{{ item.label }}
7+
</component>
8+
</template>
9+
<template v-else>
10+
<component :is="linkComponent" :href="item.to">
11+
{{ item.label }}
12+
</component>
13+
</template>
14+
<span class="arrow">
15+
&gt;
16+
</span>
17+
</div>
18+
<span class="title">{{ formatTitle(title) }}</span>
19+
</div>
20+
</template>
21+
22+
<script>
23+
export default {
24+
name: 'BreadcrumbTrail',
25+
26+
props: {
27+
breadcrumb: {
28+
type: Array,
29+
default: () => []
30+
},
31+
title: {
32+
type: String,
33+
default: ''
34+
},
35+
linkComponent: {
36+
type: String,
37+
default: 'nuxt-link'
38+
}
39+
},
40+
41+
methods: {
42+
/**
43+
* Formats breadcrumb length
44+
* 32 characters max
45+
* Truncation should occur at the end of a
46+
* word and not part way through a word.
47+
* @param {String} breadcrumb
48+
*/
49+
formatTitle: function(title) {
50+
const truncated = title.replace(/^(.{32}[^\s]*).*/, '$1')
51+
return truncated.length === title.length
52+
? title
53+
: `${truncated}...`
54+
}
55+
}
56+
}
57+
</script>
58+
59+
<style lang="scss">
60+
@import '../assets/_variables.scss';
61+
.design-system-component-breadcrumb {
62+
align-items: flex-start;
63+
background: $lineColor2;
64+
color: $darkBlue;
65+
display: flex;
66+
font-size: 0.875rem;
67+
margin-top: 0;
68+
padding: 0.5rem 2.5rem;
69+
.breadcrumb-link {
70+
align-items: center;
71+
display: flex;
72+
flex-shrink: 0;
73+
}
74+
a {
75+
font-weight: 500;
76+
text-decoration: none;
77+
color: $darkBlue;
78+
}
79+
.arrow {
80+
margin: 0 0.5rem;
81+
transform: translateY(-1px);
82+
}
83+
}
84+
</style>

src/components/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import SparcRadio from './SparcRadio.vue';
99
import DropdownMultiselect from './DropdownMultiselect/DropdownMultiselect.vue'
1010
import Pagination from './Pagination.vue'
1111
import PaginationMenu from './PaginationMenu.vue'
12+
import BreadCrumbTrail from './BreadcrumbTrail.vue'
1213

1314
export default {
1415
install(app) {
@@ -20,5 +21,6 @@ export default {
2021
app.component('DropdownMultiselect', DropdownMultiselect);
2122
app.component('Pagination', Pagination);
2223
app.component('PaginationMenu', PaginationMenu);
24+
app.component('BreadCrumbTrail', BreadCrumbTrail);
2325
},
2426
};

src/main.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ import './assets/styles.scss'
22

33
import { createApp } from 'vue'
44
import ElementPlus from 'element-plus'
5+
import {createRouter, createWebHashHistory} from 'vue-router'
56
import App from './App.vue'
67

78
const app = createApp(App)
9+
const routes = []
10+
const router = createRouter({history:createWebHashHistory(), routes})
11+
12+
app.use(router)
813
app.use(ElementPlus)
914
app.mount('#app')

0 commit comments

Comments
 (0)