Skip to content

Commit 1c75ad3

Browse files
committed
Added content tab card
1 parent c1596fa commit 1c75ad3

File tree

4 files changed

+164
-5
lines changed

4 files changed

+164
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sparc-design-system-components-2",
3-
"version": "0.0.19",
3+
"version": "0.0.20",
44
"private": false,
55
"scripts": {
66
"dev": "vite",

src/App.vue

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,27 @@
239239
:selected="selectedPage"
240240
@select-page="onPaginationChange"
241241
/>
242-
<pagination-menu
242+
<pagination-menu
243+
class="mb-24"
243244
:page-size="pageSize"
244245
@update-page-size="updatePageSize"
245246
/>
247+
<content-tab-card
248+
:tabs="contentTabCard.tabs"
249+
:active-tab-id="contentTabCard.activeTabId"
250+
@tab-changed="tabChanged"
251+
>
252+
<div
253+
v-for="tab in contentTabCard.tabs"
254+
:key="tab.id"
255+
>
256+
<div
257+
v-show="contentTabCard.activeTabId === tab.id"
258+
>
259+
Content for {{tab.label}} goes here!
260+
</div>
261+
</div>
262+
</content-tab-card>
246263
</main>
247264
</template>
248265

@@ -257,6 +274,7 @@
257274
import PaginationMenu from './components/PaginationMenu.vue'
258275
import BreadcrumbTrail from './components/BreadcrumbTrail.vue'
259276
import IconCard from './components/IconCard.vue'
277+
import ContentTabCard from './components/ContentTabCard.vue'
260278
import { ref } from 'vue'
261279
import { successMessage, infoMessage, failMessage, informationNotification, iconInformationNotification } from "../utils/notificationMessages"
262280
@@ -826,7 +844,24 @@
826844
}, {
827845
label: "Level 2",
828846
to: "/#"
829-
}]
847+
}
848+
]
849+
const contentTabCard = {
850+
tabs: [{
851+
label: 'Team Information',
852+
id: 'Team Information'
853+
},
854+
{
855+
label: 'Diseases',
856+
id: 'Diseases'
857+
},
858+
{
859+
label: 'Datasets',
860+
id: 'Datasets',
861+
href: '/#'
862+
}],
863+
activeTabId: "Team Information"
864+
}
830865
export default {
831866
components: {
832867
HelloWorld,
@@ -838,7 +873,8 @@
838873
Pagination,
839874
PaginationMenu,
840875
BreadcrumbTrail,
841-
IconCard
876+
IconCard,
877+
ContentTabCard
842878
},
843879
name: 'App',
844880
setup() {
@@ -882,6 +918,7 @@
882918
const pageSize= ref(10)
883919
const pageCount= ref(100)
884920
const selectedPage = ref(3)
921+
const tabCard = ref(contentTabCard)
885922
886923
return {
887924
dropdownMultiselectTooltip,
@@ -905,7 +942,8 @@
905942
pageCount,
906943
selectedPage,
907944
breadcrumbs,
908-
iconCardData
945+
iconCardData,
946+
contentTabCard: tabCard
909947
}
910948
},
911949
methods: {
@@ -934,6 +972,9 @@
934972
this.pageSize = limit === 'View All' ? 100 : limit
935973
this.pageCount = limit === 'View All' ? 100 : limit
936974
},
975+
tabChanged(newTab) {
976+
this.contentTabCard.activeTabId = newTab.id
977+
},
937978
}
938979
}
939980
</script>

src/components/ContentTabCard.vue

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<template>
2+
<div class="card-container">
3+
<span :class="[tabStyle, 'link-container']" v-for="tab in tabs" :key="tab.label">
4+
<!-- Expect this to be either nuxt-link or router-link -->
5+
<component v-if="linkComponent"
6+
:is="linkComponent"
7+
:to="{ query: queryParams(tab.id) }"
8+
v-on:click="$emit('tab-changed', tab)"
9+
:class="[{ active: tab.id === activeTabId }, tabStyle, tabClass, 'tab-link p-16']"
10+
>
11+
{{ tab.label }}
12+
</component>
13+
<a v-else-if="tab.href"
14+
:class="[{ active: tab.id === activeTabId }, tabStyle, tabClass, 'tab-link p-16']"
15+
:href="tab.href"
16+
target="_blank"
17+
>
18+
{{ tab.label }}
19+
</a>
20+
<a
21+
v-else
22+
:class="[{ active: tab.id === activeTabId }, tabStyle, tabClass, 'tab-link p-16']"
23+
@click.prevent="$emit('tab-changed', tab)"
24+
>
25+
{{ tab.label }}
26+
</a>
27+
</span>
28+
<div class="content mt-16 p-16">
29+
<slot />
30+
</div>
31+
</div>
32+
</template>
33+
34+
<script>
35+
36+
export default {
37+
name: 'ContentTabCard',
38+
props: {
39+
tabs: {
40+
type: Array,
41+
required: true
42+
},
43+
linkComponent: {
44+
type: String
45+
},
46+
activeTabId: {
47+
type: String,
48+
required: true
49+
},
50+
routeName: {
51+
type: String,
52+
default: 'tab'
53+
},
54+
tabStyle: {
55+
type: String,
56+
default: 'style1'
57+
}
58+
},
59+
computed: {
60+
tabClass: function() {
61+
switch(this.tabStyle) {
62+
case 'style1':
63+
return 'tab2'
64+
case 'style2':
65+
return 'tab4'
66+
case 'style3':
67+
return 'body1'
68+
default:
69+
return ''
70+
}
71+
}
72+
},
73+
methods: {
74+
queryParams(tabId) {
75+
return { ...this.$route.query, [this.routeName]: tabId }
76+
}
77+
},
78+
}
79+
</script>
80+
81+
<style lang="scss" scoped>
82+
@import '../assets/_variables.scss';
83+
.style1 {
84+
line-height: normal;
85+
}
86+
.tab-link {
87+
text-decoration: none;
88+
flex-wrap: nowrap;
89+
border: 1px solid $lineColor1;
90+
cursor: pointer;
91+
&:hover, &.active {
92+
&.style1, &.style3 {
93+
border: 1px solid $purple;
94+
border-bottom: .125em solid $purple;
95+
color: $purple;
96+
background-color: #f9f2fc;
97+
font-weight: 500;
98+
}
99+
&.style2 {
100+
border-bottom: .125em solid white;
101+
font-weight: 500;
102+
}
103+
}
104+
}
105+
.content {
106+
border: 1px solid $lineColor1;
107+
background-color: white;
108+
overflow: auto;
109+
}
110+
.tab-link {
111+
background-color: white;
112+
}
113+
.card-container {
114+
line-height: normal;
115+
}
116+
</style>

src/components/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Pagination from './Pagination.vue'
1111
import PaginationMenu from './PaginationMenu.vue'
1212
import Breadcrumb from './BreadcrumbTrail.vue'
1313
import IconCard from './IconCard.vue'
14+
import ContentTabCard from './ContentTabCard.vue'
1415

1516
export default {
1617
install(app) {
@@ -24,5 +25,6 @@ export default {
2425
app.component('PaginationMenu', PaginationMenu);
2526
app.component('Breadcrumb', Breadcrumb);
2627
app.component('IconCard', IconCard)
28+
app.component('ContentTabCard', ContentTabCard)
2729
},
2830
};

0 commit comments

Comments
 (0)