-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathslds-scoped-tabs.vue
90 lines (70 loc) · 2.35 KB
/
slds-scoped-tabs.vue
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<template>
<div :class="tabsClassNames">
<!-- Tabs -->
<ul class="slds-tabs_scoped__nav" role="tablist">
<slot name="scoped-tabs">
<!-- Automatically generated tabs -->
<slds-scoped-tab
v-for="scopedTab in scopedTabs"
:key="scopedTab.id"
:is-active="active === scopedTab.name"
:label="scopedTab.label"
:name="scopedTab.name"
@click.stop.prevent="handleClickTab(scopedTab.name)"
/>
<!-- Overflow -->
<!-- TODO: Implement overflow -->
</slot>
</ul>
<!-- Content -->
<template v-if="!noContent">
<slot name="content">
<slds-scoped-tab-content
v-for="scopedTab in scopedTabs"
:key="scopedTab.id"
:is-active="active === scopedTab.name"
:name="scopedTab.name"
>
<slot :name="scopedTab.name"/>
</slds-scoped-tab-content>
</slot>
</template>
</div>
</template>
<script lang="ts">
import { defineComponent, type PropType } from "vue"
import SldsScopedTab from "../slds-scoped-tabs/slds-scoped-tab.vue"
import SldsScopedTabContent from "../slds-scoped-tabs/slds-scoped-tab-content.vue"
import type { ScopedTab } from "../slds-scoped-tabs/scoped-tab"
import { EVENTS } from "../../constants"
export default defineComponent({
name: "SldsScopedTabs",
components: {
SldsScopedTab,
SldsScopedTabContent,
},
props: {
active: String,
large: Boolean,
medium: Boolean,
noContent: Boolean,
scopedTabs: { type: Array as PropType<ScopedTab[]>, default: () => [] as ScopedTab[] },
},
computed: {
/**
* The CSS class names for the tabs.
*/
tabsClassNames(): string {
let classNames = "slds-tabs_scoped"
if (this.large) classNames += " slds-tabs_large"
else if (this.medium) classNames += " slds-tabs_medium"
return classNames
},
},
methods: {
handleClickTab(scopedTabName: string): void {
this.$emit(EVENTS.CLICK_TAB, scopedTabName)
},
},
})
</script>