@mozaic-ds/vue 0.22.0 → 0.23.0-beta.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.0",
3
+ "version": "0.23.0-beta.1",
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"
@@ -23,14 +33,9 @@
23
33
  class="mc-tabs__link"
24
34
  role="tab"
25
35
  :aria-selected="tab.active ? 'true' : 'false'"
26
- :class="setActiveClass(tab)"
27
- @click="
28
- manageTabs(
29
- $event.target,
30
- $event,
31
- Object.assign({ index: index }, tab)
32
- )
33
- "
36
+ :class="setLinkClass(tab)"
37
+ v-bind="tab.attrs"
38
+ @click="onTabClicked($event, tab, index)"
34
39
  >
35
40
  {{ tab.text }}
36
41
  </component>
@@ -82,38 +87,41 @@ export default {
82
87
  },
83
88
  activeIndex: {
84
89
  type: Number,
85
- default: 0,
90
+ default: null,
86
91
  },
87
92
  },
88
93
 
89
94
  data() {
90
95
  return {
91
96
  tablist: null,
97
+ localActiveIndex: null,
92
98
  };
93
99
  },
94
100
 
95
101
  computed: {
96
102
  setClasses() {
97
- const classes = [
98
- {
99
- 'mc-tabs--full': this.align === 'full',
100
- 'mc-tabs--full-centered': this.align === 'centered',
101
- 'mc-tabs--dropdown': this.type === 'dropdown',
102
- 'mc-tabs--no-shadow': !this.shadow,
103
- },
104
- ];
105
-
106
- 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
+ };
107
109
  },
108
110
  },
109
111
 
110
112
  watch: {
111
113
  activeIndex(newValue) {
112
- const tab = this.getTabFromIndex(newValue);
113
- if (tab && this.tabs[newValue]) {
114
- this.manageTabs(tab, null, Object.assign({index: newValue}, this.tabs[newValue]));
115
- }
116
- }
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
+ },
117
125
  },
118
126
 
119
127
  mounted: function () {
@@ -122,17 +130,16 @@ export default {
122
130
  this.tablist = this.$refs.tablist;
123
131
 
124
132
  if (this.activeIndex) {
125
- const tab = this.getTabFromIndex(this.activeIndex);
126
- if (tab) {
127
- this.manageTabs(tab);
128
- }
133
+ this.localActiveIndex = this.activeIndex;
129
134
  } else {
130
- const isActive = this.tabs.some((tab) =>
131
- 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
132
139
  );
140
+
133
141
  if (!isActive) {
134
- const firstTab = this.tablist.querySelector('.mc-tabs__link');
135
- this.manageTabs(firstTab);
142
+ this.localActiveIndex = 0;
136
143
  }
137
144
  }
138
145
  }
@@ -140,40 +147,50 @@ export default {
140
147
  },
141
148
 
142
149
  methods: {
143
- setActiveClass: function (tab) {
144
- const tabClasses = [];
145
-
146
- if (tab.active) {
147
- tabClasses.push('mc-tabs__link--selected');
148
- }
149
-
150
- if (tab.disabled) {
151
- tabClasses.push('mc-tabs__link--disabled');
152
- }
153
-
154
- return tabClasses;
150
+ setLinkClass: function (tab) {
151
+ return {
152
+ 'mc-tabs__link--selected': tab.active,
153
+ 'mc-tabs__link--disabled': tab.disabled,
154
+ };
155
155
  },
156
- manageTabs: function (el, e, tab) {
157
- if (tab && tab.disabled) {
158
- return;
159
- }
160
- if (e) {
161
- this.$emit('tab-clicked', e.target, tab);
162
- }
156
+ setTabState(tab) {
157
+ this.tablist.querySelectorAll('.mc-tabs__link').forEach((el) => {
158
+ el.classList.remove('mc-tabs__link--selected');
159
+ el.setAttribute('aria-selected', 'false');
160
+ });
163
161
 
162
+ tab.classList.add('mc-tabs__link--selected');
163
+ tab.setAttribute('aria-selected', 'true');
164
+ },
165
+ setTabState(tab) {
164
166
  this.tablist.querySelectorAll('.mc-tabs__link').forEach((el) => {
165
167
  el.classList.remove('mc-tabs__link--selected');
166
168
  el.setAttribute('aria-selected', 'false');
167
169
  });
168
170
 
169
- el.classList.add('mc-tabs__link--selected');
170
- el.setAttribute('aria-selected', 'true');
171
+ tab.classList.add('mc-tabs__link--selected');
172
+ tab.setAttribute('aria-selected', 'true');
171
173
  },
172
174
  getTabFromIndex: function (index) {
173
- 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
+ ) {
174
180
  return this.tablist.children[index].children[0];
175
181
  }
176
182
  },
183
+ onTabClicked(e, tab, index) {
184
+ if (tab && tab.disabled) {
185
+ return;
186
+ }
187
+
188
+ if (typeof this.activeIndex !== 'number') {
189
+ this.localActiveIndex = index;
190
+ }
191
+
192
+ this.$emit('tab-clicked', e.target, Object.assign({ index: index }, tab));
193
+ },
177
194
  },
178
195
  };
179
196
  </script>