@mozaic-ds/vue 0.22.1-beta.0 → 0.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mozaic-ds/vue",
3
- "version": "0.22.1-beta.0",
3
+ "version": "0.22.1",
4
4
  "description": "Vue.js implementation of Mozaic Design System",
5
5
  "author": "Adeo - Mozaic Design System",
6
6
  "scripts": {
@@ -13,8 +13,20 @@
13
13
  class="mc-tabs__item"
14
14
  role="presentation"
15
15
  >
16
+ <component
17
+ :is="`${tab.router}`"
18
+ v-if="tab.router"
19
+ v-bind="tab.attrs"
20
+ :to="tab.to"
21
+ class="mc-tabs__link"
22
+ :class="setLinkClass(tab)"
23
+ active-class="mc-tabs__link--selected"
24
+ >
25
+ {{ tab.text }}
26
+ </component>
16
27
  <component
17
28
  :is="tab.href ? (tab.disabled ? 'span' : 'a') : 'button'"
29
+ v-else
18
30
  :id="tab.id"
19
31
  ref="tab"
20
32
  :href="tab.href ? (!tab.disabled ? tab.href : null) : null"
@@ -24,6 +36,7 @@
24
36
  role="tab"
25
37
  :aria-selected="tab.active ? 'true' : 'false'"
26
38
  :class="setLinkClass(tab)"
39
+ v-bind="tab.attrs"
27
40
  @click="onTabClicked($event, tab, index)"
28
41
  >
29
42
  {{ tab.text }}
@@ -76,38 +89,41 @@ export default {
76
89
  },
77
90
  activeIndex: {
78
91
  type: Number,
79
- default: 0,
92
+ default: null,
80
93
  },
81
94
  },
82
95
 
83
96
  data() {
84
97
  return {
85
98
  tablist: null,
99
+ localActiveIndex: null,
86
100
  };
87
101
  },
88
102
 
89
103
  computed: {
90
104
  setClasses() {
91
- const classes = [
92
- {
93
- 'mc-tabs--full': this.align === 'full',
94
- 'mc-tabs--full-centered': this.align === 'centered',
95
- 'mc-tabs--dropdown': this.type === 'dropdown',
96
- 'mc-tabs--no-shadow': !this.shadow,
97
- },
98
- ];
99
-
100
- return classes;
105
+ return {
106
+ 'mc-tabs--full': this.align === 'full',
107
+ 'mc-tabs--full-centered': this.align === 'centered',
108
+ 'mc-tabs--dropdown': this.type === 'dropdown',
109
+ 'mc-tabs--no-shadow': !this.shadow,
110
+ };
101
111
  },
102
112
  },
103
113
 
104
114
  watch: {
105
115
  activeIndex(newValue) {
106
- const tab = this.getTabFromIndex(newValue);
107
- if (tab && this.tabs[newValue]) {
108
- this.setTabState(tab);
109
- }
110
- }
116
+ this.localActiveIndex = newValue;
117
+ },
118
+ localActiveIndex: {
119
+ handler: function (newValue) {
120
+ const selectedTab = this.getTabFromIndex(newValue);
121
+ if (selectedTab) {
122
+ this.setTabState(selectedTab);
123
+ }
124
+ },
125
+ immediate: true,
126
+ },
111
127
  },
112
128
 
113
129
  mounted: function () {
@@ -116,17 +132,16 @@ export default {
116
132
  this.tablist = this.$refs.tablist;
117
133
 
118
134
  if (this.activeIndex) {
119
- const tab = this.getTabFromIndex(this.activeIndex);
120
- if (tab) {
121
- this.setTabState(tab);
122
- }
135
+ this.localActiveIndex = this.activeIndex;
123
136
  } else {
124
- const isActive = this.tabs.some((tab) =>
125
- Object.prototype.hasOwnProperty.call(tab, 'active')
137
+ const isActive = this.tabs.some(
138
+ (tab) =>
139
+ Object.prototype.hasOwnProperty.call(tab, 'active') &&
140
+ tab.active === true
126
141
  );
142
+
127
143
  if (!isActive) {
128
- const firstTab = this.tablist.querySelector('.mc-tabs__link');
129
- this.setTabState(firstTab);
144
+ this.localActiveIndex = 0;
130
145
  }
131
146
  }
132
147
  }
@@ -140,36 +155,6 @@ export default {
140
155
  'mc-tabs__link--disabled': tab.disabled,
141
156
  };
142
157
  },
143
- onTabClicked(e, tab, index) {
144
- if (tab && tab.disabled) {
145
- return;
146
- }
147
-
148
- let selectedTab = this.getTabFromIndex(index);
149
-
150
- if (this.activeIndex) {
151
- selectedTab = this.getTabFromIndex(this.activeIndex);
152
- }
153
-
154
- this.setTabState(selectedTab);
155
- this.$emit('tab-clicked', e.target, Object.assign({ index: index }, tab));
156
- },
157
- manageTabs: function (el, e, tab) {
158
- if (tab && tab.disabled) {
159
- return;
160
- }
161
- if (e) {
162
- this.$emit('tab-clicked', e.target, tab);
163
- }
164
-
165
- this.tablist.querySelectorAll('.mc-tabs__link').forEach((el) => {
166
- el.classList.remove('mc-tabs__link--selected');
167
- el.setAttribute('aria-selected', 'false');
168
- });
169
-
170
- el.classList.add('mc-tabs__link--selected');
171
- el.setAttribute('aria-selected', 'true');
172
- },
173
158
  setTabState(tab) {
174
159
  this.tablist.querySelectorAll('.mc-tabs__link').forEach((el) => {
175
160
  el.classList.remove('mc-tabs__link--selected');
@@ -180,10 +165,25 @@ export default {
180
165
  tab.setAttribute('aria-selected', 'true');
181
166
  },
182
167
  getTabFromIndex: function (index) {
183
- if (this.tablist && this.tablist.children[index] && this.tablist.children[index].children[0]) {
168
+ if (
169
+ this.tablist &&
170
+ this.tablist.children[index] &&
171
+ this.tablist.children[index].children[0]
172
+ ) {
184
173
  return this.tablist.children[index].children[0];
185
174
  }
186
175
  },
176
+ onTabClicked(e, tab, index) {
177
+ if (tab && tab.disabled) {
178
+ return;
179
+ }
180
+
181
+ if (typeof this.activeIndex !== 'number') {
182
+ this.localActiveIndex = index;
183
+ }
184
+
185
+ this.$emit('tab-clicked', e.target, Object.assign({ index: index }, tab));
186
+ },
187
187
  },
188
188
  };
189
189
  </script>