Skip to content

Commit 0f1b988

Browse files
committed
Feat: Added CTab and CTabs components
1 parent e952614 commit 0f1b988

File tree

3 files changed

+155
-0
lines changed

3 files changed

+155
-0
lines changed

src/components/Tabs/CTab.vue

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<script>
2+
import CLink, { propsFactory as linkPropsFactory } from '../Link/CLink'
3+
4+
export default {
5+
name: 'CTab',
6+
props: Object.assign(linkPropsFactory(), {
7+
title: String
8+
}),
9+
data () {
10+
return {
11+
isActive: this.disabled ? null : this.active
12+
}
13+
},
14+
computed: {
15+
computedProps () {
16+
return Object.assign({}, this.$props, { active: this.isActive } )
17+
},
18+
},
19+
render (h) {
20+
return h(
21+
'li',
22+
{
23+
staticClass: 'nav-item',
24+
},
25+
[
26+
h(
27+
CLink,
28+
{
29+
staticClass: 'nav-link',
30+
props: this.computedProps,
31+
domProps: this.title ? { innerHTML: this.title } : null
32+
},
33+
this.$slots.title
34+
)
35+
]
36+
)
37+
}
38+
}
39+
40+
</script>

src/components/Tabs/CTabs.vue

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<script>
2+
import CNav from '../Nav/CNav'
3+
export default {
4+
name: 'CTabs',
5+
extends: CNav,
6+
props: {
7+
tabs: {
8+
type: Boolean,
9+
default: true
10+
},
11+
noFade: Boolean,
12+
vertical: [Boolean, Number, String],
13+
card: Boolean,
14+
addNavWrapperClasses: [String, Array],
15+
addNavClasses: [String, Array],
16+
addTabsWrapperClasses: [String, Array],
17+
addTabsClasses: [String, Array],
18+
addTabClasses: [String, Array]
19+
},
20+
data () {
21+
return {
22+
children: [],
23+
}
24+
},
25+
computed: {
26+
verticalTabsClass() {
27+
return !this.vertical ? '' :
28+
this.vertical === true ? 'col-sm-6' : `col-sm-${this.vertical}`
29+
},
30+
verticalContentClass() {
31+
return !this.vertical ? '' :
32+
this.vertical === true ? 'col-sm-6' : `col-sm-${12 - this.vertical}`
33+
}
34+
},
35+
//make children reactive
36+
mounted () {
37+
this.children = this.$children
38+
},
39+
updated () {
40+
//hacky solution to enable fading
41+
if (!this.noFade) {
42+
setTimeout(() => {
43+
return this.$el.getElementsByClassName('active fade')[0]
44+
.classList.add('show')
45+
}, 0)
46+
}
47+
},
48+
render (h) {
49+
const nav = h(
50+
'ul',
51+
{
52+
class: [ this.navClasses, this.addNavClasses, {'h-100':this.vertical }],
53+
on: {
54+
click: this.onClick
55+
}
56+
},
57+
this.$slots.default
58+
)
59+
const navWrapper = h(
60+
'div',
61+
{ class: [
62+
this.addNavWrapperClasses,
63+
this.verticalTabsClass,
64+
{ 'card-header': this.card }
65+
]},
66+
[nav]
67+
)
68+
69+
const tab = this.children.map((tab, index) => {
70+
return h(
71+
'div',
72+
{
73+
staticClass: 'tab-pane',
74+
class: [
75+
this.addTabClasses,
76+
{
77+
active: tab.isActive,
78+
fade: !this.noFade
79+
}
80+
]
81+
},
82+
tab.$slots ? tab.$slots.default : ''
83+
)
84+
})
85+
86+
const tabs = h(
87+
'div',
88+
{
89+
staticClass: 'tab-content',
90+
class: this.addTabsClasses
91+
},
92+
tab
93+
)
94+
const tabsWrapper = h(
95+
'div',
96+
{ class: [this.addTabsWrapperClasses, this.verticalContentClass]},
97+
[tabs]
98+
)
99+
100+
const wrapper = h(
101+
'div',
102+
{ class: this.vertical ? 'row no-gutters': '' },
103+
[navWrapper, tabsWrapper]
104+
)
105+
return wrapper
106+
}
107+
}
108+
</script>

src/components/Tabs/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import CTab from './CTab'
2+
import CTabs from './CTabs'
3+
4+
export {
5+
CTab,
6+
CTabs
7+
}

0 commit comments

Comments
 (0)