|
1 | 1 | <template>
|
2 |
| - <div class="tabs" > |
3 |
| - <ul :class="['nav','nav-' + navStyle]"> |
4 |
| - <li class="nav-item" v-for="(item,index) in items" @click="setActive(index)"> |
| 2 | + <div class="tabs"> |
| 3 | + <ul :class="['nav','nav-' + navStyle]"> |
| 4 | + <li class="nav-item" v-for="(item,index) in items" @click="setActive(index)"> |
5 | 5 | <span :class="['nav-link','btn',btnSize,item.active ? 'active' : '',item.disabled ? 'disabled' : '']">
|
6 | 6 | {{item.title}}
|
7 | 7 | </span>
|
8 |
| - </li> |
9 |
| - </ul> |
10 |
| - <div class="tab-content"> |
11 |
| - <slot></slot> |
| 8 | + </li> |
| 9 | + </ul> |
| 10 | + <div class="tab-content"> |
| 11 | + <slot></slot> |
| 12 | + </div> |
12 | 13 | </div>
|
13 |
| - </div> |
14 | 14 | </template>
|
15 | 15 |
|
16 | 16 | <script>
|
17 |
| - import {csstransitions} from '../utils/helpers'; |
| 17 | + import {csstransitions} from '../utils/helpers'; |
18 | 18 |
|
19 |
| - // this is directly linked to the bootstrap animation timing in _tabs.scss |
20 |
| - // for browsers that do not support transitions like IE9 just change slide immediately |
21 |
| - const TRANSITION_DURATION = csstransitions() ? 150 : 0; |
| 19 | + // this is directly linked to the bootstrap animation timing in _tabs.scss |
| 20 | + // for browsers that do not support transitions like IE9 just change slide immediately |
| 21 | + const TRANSITION_DURATION = csstransitions() ? 150 : 0; |
22 | 22 |
|
23 |
| - // export component object |
24 |
| - export default { |
25 |
| - replace: true, |
26 |
| - data() { |
27 |
| - let currentTab = this.value || 0 |
28 |
| - return { |
29 |
| - currentTab, |
30 |
| - items: [] |
31 |
| - }; |
32 |
| - }, |
33 |
| - computed: { |
34 |
| - btnSize() { |
35 |
| - return !this.size || this.size === 'default' ? '' : `btn-${this.size}`; |
36 |
| - } |
37 |
| - }, |
38 |
| - props: { |
39 |
| - fade: { |
40 |
| - type: Boolean, |
41 |
| - default: true |
42 |
| - }, |
43 |
| - size: { |
44 |
| - type: String, |
45 |
| - default: 'md' |
46 |
| - }, |
47 |
| - value: { |
48 |
| - type: Number, |
49 |
| - default: 0 |
50 |
| - }, |
51 |
| - navStyle: { |
52 |
| - type: String, |
53 |
| - default: 'tabs' |
54 |
| - } |
55 |
| - }, |
56 |
| - watch: { |
57 |
| - currentTab (val) { |
58 |
| - this.$emit('input', val) |
59 |
| - }, |
60 |
| - value (val) { |
61 |
| - this.setActive(val); |
62 |
| - } |
63 |
| - }, |
64 |
| - methods: { |
| 23 | + // export component object |
| 24 | + export default { |
| 25 | + replace: true, |
| 26 | + data() { |
| 27 | + const currentTab = this.value || 0; |
| 28 | + return { |
| 29 | + currentTab, |
| 30 | + items: [] |
| 31 | + }; |
| 32 | + }, |
| 33 | + computed: { |
| 34 | + btnSize() { |
| 35 | + return !this.size || this.size === 'default' ? '' : `btn-${this.size}`; |
| 36 | + } |
| 37 | + }, |
| 38 | + props: { |
| 39 | + fade: { |
| 40 | + type: Boolean, |
| 41 | + default: true |
| 42 | + }, |
| 43 | + size: { |
| 44 | + type: String, |
| 45 | + default: 'md' |
| 46 | + }, |
| 47 | + value: { |
| 48 | + type: Number, |
| 49 | + default: 0 |
| 50 | + }, |
| 51 | + navStyle: { |
| 52 | + type: String, |
| 53 | + default: 'tabs' |
| 54 | + } |
| 55 | + }, |
| 56 | + watch: { |
| 57 | + currentTab(val) { |
| 58 | + this.$emit('input', val); |
| 59 | + }, |
| 60 | + value(val) { |
| 61 | + this.setActive(val); |
| 62 | + } |
| 63 | + }, |
| 64 | + methods: { |
65 | 65 |
|
66 |
| - /** |
67 |
| - * get an index of an active tab |
68 |
| - * @return {Number} |
69 |
| - */ |
70 |
| - getActive() { |
71 |
| - let active = -1; |
72 |
| - this.items.forEach((item, index) => { |
73 |
| - if (item.active) { |
74 |
| - active = index; |
75 |
| - } |
76 |
| - }); |
77 |
| - return active; |
78 |
| - }, |
| 66 | + /** |
| 67 | + * get an index of an active tab |
| 68 | + * @return {Number} |
| 69 | + */ |
| 70 | + getActive() { |
| 71 | + let active = -1; |
| 72 | + this.items.forEach((item, index) => { |
| 73 | + if (item.active) { |
| 74 | + active = index; |
| 75 | + } |
| 76 | + }); |
| 77 | + return active; |
| 78 | + }, |
79 | 79 |
|
80 |
| - /** |
81 |
| - * set active tab on the items collection and the child 'tab' component |
82 |
| - */ |
83 |
| - setActive(index) { |
84 |
| - // ignore disabled |
85 |
| - if (this.items[index].disabled) { |
86 |
| - return; |
87 |
| - } |
| 80 | + /** |
| 81 | + * set active tab on the items collection and the child 'tab' component |
| 82 | + */ |
| 83 | + setActive(index) { |
| 84 | + // ignore disabled |
| 85 | + if (this.items[index].disabled) { |
| 86 | + return; |
| 87 | + } |
88 | 88 |
|
89 |
| - // deactivate previous active tab |
90 |
| - const activeTab = this.getActive(); |
91 |
| - if (activeTab !== -1) { |
92 |
| - // setting animate to false will trigger fade out effect |
93 |
| - this.items[activeTab].active = false; |
94 |
| - this.$set(this.$children[activeTab], 'animate', false); |
95 |
| - this.$set(this.$children[activeTab], 'active', false); |
96 |
| - } |
| 89 | + // deactivate previous active tab |
| 90 | + const activeTab = this.getActive(); |
| 91 | + if (activeTab !== -1) { |
| 92 | + // setting animate to false will trigger fade out effect |
| 93 | + this.items[activeTab].active = false; |
| 94 | + this.$set(this.$children[activeTab], 'animate', false); |
| 95 | + this.$set(this.$children[activeTab], 'active', false); |
| 96 | + } |
97 | 97 |
|
98 |
| - // set new active tab and animate (if fade flag is set to true) |
99 |
| - this.$set(this.$children[index], 'active', true); |
100 |
| - this._tabAnimation = setTimeout(() => { |
101 |
| - // setting animate to true will trigger fade in effect |
102 |
| - this.items[index].active = true; |
103 |
| - this.$set(this.$children[index], 'animate', true); |
104 |
| - this.$root.$emit('changed::tab', this.items[index].id); |
105 |
| - }, this.fade ? TRANSITION_DURATION : 0); |
| 98 | + // set new active tab and animate (if fade flag is set to true) |
| 99 | + this.$set(this.$children[index], 'active', true); |
| 100 | + this._tabAnimation = setTimeout(() => { |
| 101 | + // setting animate to true will trigger fade in effect |
| 102 | + this.items[index].active = true; |
| 103 | + this.$set(this.$children[index], 'animate', true); |
| 104 | + this.$root.$emit('changed::tab', this.items[index].id); |
| 105 | + }, this.fade ? TRANSITION_DURATION : 0); |
106 | 106 |
|
107 |
| - // store currentActive |
108 |
| - this.currentTab = index |
109 |
| - } |
110 |
| - }, |
111 |
| - mounted() { |
112 |
| - // if no active tab, set the first one by default |
113 |
| - if (this.getActive() === -1) { |
114 |
| - this.setActive(this.currentTab); |
115 |
| - } |
116 |
| - }, |
117 |
| - destroyed() { |
118 |
| - clearTimeout(this._tabAnimation); |
119 |
| - } |
120 |
| - }; |
| 107 | + // store currentActive |
| 108 | + this.currentTab = index; |
| 109 | + } |
| 110 | + }, |
| 111 | + mounted() { |
| 112 | + // if no active tab, set the first one by default |
| 113 | + if (this.getActive() === -1) { |
| 114 | + this.setActive(this.currentTab); |
| 115 | + } |
| 116 | + }, |
| 117 | + destroyed() { |
| 118 | + clearTimeout(this._tabAnimation); |
| 119 | + } |
| 120 | + }; |
121 | 121 |
|
122 | 122 | </script>
|
0 commit comments