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

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.23.0-beta.0",
4
4
  "description": "Vue.js implementation of Mozaic Design System",
5
5
  "author": "Adeo - Mozaic Design System",
6
6
  "scripts": {
@@ -13,8 +13,18 @@
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
+ active-class="mc-tabs__link--selected"
22
+ >
23
+ {{ tab.text }}
24
+ </component>
16
25
  <component
17
26
  :is="tab.href ? (tab.disabled ? 'span' : 'a') : 'button'"
27
+ v-else
18
28
  :id="tab.id"
19
29
  ref="tab"
20
30
  :href="tab.href ? (!tab.disabled ? tab.href : null) : null"
@@ -24,6 +34,7 @@
24
34
  role="tab"
25
35
  :aria-selected="tab.active ? 'true' : 'false'"
26
36
  :class="setLinkClass(tab)"
37
+ v-bind="tab.attrs"
27
38
  @click="onTabClicked($event, tab, index)"
28
39
  >
29
40
  {{ tab.text }}
@@ -83,31 +94,34 @@ export default {
83
94
  data() {
84
95
  return {
85
96
  tablist: null,
97
+ localActiveIndex: null,
86
98
  };
87
99
  },
88
100
 
89
101
  computed: {
90
102
  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;
103
+ return {
104
+ 'mc-tabs--full': this.align === 'full',
105
+ 'mc-tabs--full-centered': this.align === 'centered',
106
+ 'mc-tabs--dropdown': this.type === 'dropdown',
107
+ 'mc-tabs--no-shadow': !this.shadow,
108
+ };
101
109
  },
102
110
  },
103
111
 
104
112
  watch: {
105
113
  activeIndex(newValue) {
106
- const tab = this.getTabFromIndex(newValue);
107
- if (tab && this.tabs[newValue]) {
108
- this.setTabState(tab);
109
- }
110
- }
114
+ this.localActiveIndex = newValue;
115
+ },
116
+ localActiveIndex: {
117
+ handler: function (newValue) {
118
+ const selectedTab = this.getTabFromIndex(newValue);
119
+ if (selectedTab) {
120
+ this.setTabState(selectedTab);
121
+ }
122
+ },
123
+ immediate: true,
124
+ },
111
125
  },
112
126
 
113
127
  mounted: function () {
@@ -116,17 +130,16 @@ export default {
116
130
  this.tablist = this.$refs.tablist;
117
131
 
118
132
  if (this.activeIndex) {
119
- const tab = this.getTabFromIndex(this.activeIndex);
120
- if (tab) {
121
- this.setTabState(tab);
122
- }
133
+ this.localActiveIndex = this.activeIndex;
123
134
  } else {
124
- const isActive = this.tabs.some((tab) =>
125
- Object.prototype.hasOwnProperty.call(tab, 'active')
135
+ const isActive = this.tabs.some(
136
+ (tab) =>
137
+ Object.prototype.hasOwnProperty.call(tab, 'active') &&
138
+ tab.active === true
126
139
  );
140
+
127
141
  if (!isActive) {
128
- const firstTab = this.tablist.querySelector('.mc-tabs__link');
129
- this.setTabState(firstTab);
142
+ this.localActiveIndex = 0;
130
143
  }
131
144
  }
132
145
  }
@@ -140,35 +153,14 @@ export default {
140
153
  'mc-tabs__link--disabled': tab.disabled,
141
154
  };
142
155
  },
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
-
156
+ setTabState(tab) {
165
157
  this.tablist.querySelectorAll('.mc-tabs__link').forEach((el) => {
166
158
  el.classList.remove('mc-tabs__link--selected');
167
159
  el.setAttribute('aria-selected', 'false');
168
160
  });
169
161
 
170
- el.classList.add('mc-tabs__link--selected');
171
- el.setAttribute('aria-selected', 'true');
162
+ tab.classList.add('mc-tabs__link--selected');
163
+ tab.setAttribute('aria-selected', 'true');
172
164
  },
173
165
  setTabState(tab) {
174
166
  this.tablist.querySelectorAll('.mc-tabs__link').forEach((el) => {
@@ -180,10 +172,25 @@ export default {
180
172
  tab.setAttribute('aria-selected', 'true');
181
173
  },
182
174
  getTabFromIndex: function (index) {
183
- if (this.tablist && this.tablist.children[index] && this.tablist.children[index].children[0]) {
175
+ if (
176
+ this.tablist &&
177
+ this.tablist.children[index] &&
178
+ this.tablist.children[index].children[0]
179
+ ) {
184
180
  return this.tablist.children[index].children[0];
185
181
  }
186
182
  },
183
+ onTabClicked(e, tab, index) {
184
+ if (tab && tab.disabled) {
185
+ return;
186
+ }
187
+
188
+ if (!this.activeIndex) {
189
+ this.localActiveIndex = index;
190
+ }
191
+
192
+ this.$emit('tab-clicked', e.target, Object.assign({ index: index }, tab));
193
+ },
187
194
  },
188
195
  };
189
196
  </script>