@mozaic-ds/vue 0.23.0-beta.1 → 1.0.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.
@@ -13,18 +13,8 @@
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>
25
16
  <component
26
17
  :is="tab.href ? (tab.disabled ? 'span' : 'a') : 'button'"
27
- v-else
28
18
  :id="tab.id"
29
19
  ref="tab"
30
20
  :href="tab.href ? (!tab.disabled ? tab.href : null) : null"
@@ -33,9 +23,14 @@
33
23
  class="mc-tabs__link"
34
24
  role="tab"
35
25
  :aria-selected="tab.active ? 'true' : 'false'"
36
- :class="setLinkClass(tab)"
37
- v-bind="tab.attrs"
38
- @click="onTabClicked($event, tab, index)"
26
+ :class="setActiveClass(tab)"
27
+ @click="
28
+ manageTabs(
29
+ $event.target,
30
+ $event,
31
+ Object.assign({ index: index }, tab)
32
+ )
33
+ "
39
34
  >
40
35
  {{ tab.text }}
41
36
  </component>
@@ -87,41 +82,38 @@ export default {
87
82
  },
88
83
  activeIndex: {
89
84
  type: Number,
90
- default: null,
85
+ default: 0,
91
86
  },
92
87
  },
93
88
 
94
89
  data() {
95
90
  return {
96
91
  tablist: null,
97
- localActiveIndex: null,
98
92
  };
99
93
  },
100
94
 
101
95
  computed: {
102
96
  setClasses() {
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
- };
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;
109
107
  },
110
108
  },
111
109
 
112
110
  watch: {
113
111
  activeIndex(newValue) {
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
- },
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
+ }
125
117
  },
126
118
 
127
119
  mounted: function () {
@@ -130,16 +122,17 @@ export default {
130
122
  this.tablist = this.$refs.tablist;
131
123
 
132
124
  if (this.activeIndex) {
133
- this.localActiveIndex = this.activeIndex;
125
+ const tab = this.getTabFromIndex(this.activeIndex);
126
+ if (tab) {
127
+ this.manageTabs(tab);
128
+ }
134
129
  } else {
135
- const isActive = this.tabs.some(
136
- (tab) =>
137
- Object.prototype.hasOwnProperty.call(tab, 'active') &&
138
- tab.active === true
130
+ const isActive = this.tabs.some((tab) =>
131
+ Object.prototype.hasOwnProperty.call(tab, 'active')
139
132
  );
140
-
141
133
  if (!isActive) {
142
- this.localActiveIndex = 0;
134
+ const firstTab = this.tablist.querySelector('.mc-tabs__link');
135
+ this.manageTabs(firstTab);
143
136
  }
144
137
  }
145
138
  }
@@ -147,50 +140,40 @@ export default {
147
140
  },
148
141
 
149
142
  methods: {
150
- setLinkClass: function (tab) {
151
- return {
152
- 'mc-tabs__link--selected': tab.active,
153
- 'mc-tabs__link--disabled': tab.disabled,
154
- };
155
- },
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
- });
143
+ setActiveClass: function (tab) {
144
+ const tabClasses = [];
161
145
 
162
- tab.classList.add('mc-tabs__link--selected');
163
- tab.setAttribute('aria-selected', 'true');
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;
164
155
  },
165
- setTabState(tab) {
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
+ }
163
+
166
164
  this.tablist.querySelectorAll('.mc-tabs__link').forEach((el) => {
167
165
  el.classList.remove('mc-tabs__link--selected');
168
166
  el.setAttribute('aria-selected', 'false');
169
167
  });
170
168
 
171
- tab.classList.add('mc-tabs__link--selected');
172
- tab.setAttribute('aria-selected', 'true');
169
+ el.classList.add('mc-tabs__link--selected');
170
+ el.setAttribute('aria-selected', 'true');
173
171
  },
174
172
  getTabFromIndex: function (index) {
175
- if (
176
- this.tablist &&
177
- this.tablist.children[index] &&
178
- this.tablist.children[index].children[0]
179
- ) {
173
+ if (this.tablist && this.tablist.children[index] && this.tablist.children[index].children[0]) {
180
174
  return this.tablist.children[index].children[0];
181
175
  }
182
176
  },
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
- },
194
177
  },
195
178
  };
196
179
  </script>
@@ -6,6 +6,7 @@
6
6
  :class="setClasses"
7
7
  :aria-invalid="isInvalid"
8
8
  :value="value"
9
+ @input="$emit('input', $event.target.value)"
9
10
  v-on="inputListeners"
10
11
  />
11
12
  </template>
package/src/index.js CHANGED
@@ -37,7 +37,7 @@ export { MHero } from './components/hero';
37
37
  export { MIcon } from './components/icon';
38
38
  export { MLayer } from './components/layer';
39
39
  export { MLink } from './components/link';
40
- export { MListBox, MListBoxActions } from './components/listbox';
40
+ export { MListBox } from './components/listbox';
41
41
  export { MLoader } from './components/loader';
42
42
  export { MModal } from './components/modal';
43
43
  export { MNotification } from './components/notification';
package/types/index.d.ts CHANGED
@@ -24,7 +24,6 @@ declare module '@mozaic-ds/vue' {
24
24
  const MLayer: VueConstructor;
25
25
  const MLink: VueConstructor;
26
26
  const MListBox: VueConstructor;
27
- const MListBoxActions: VueConstructor;
28
27
  const MLoader: VueConstructor;
29
28
  const MModal: VueConstructor;
30
29
  const MNotification: VueConstructor;
@@ -72,7 +71,6 @@ declare module '@mozaic-ds/vue' {
72
71
  MLayer,
73
72
  MLink,
74
73
  MListBox,
75
- MListBoxActions,
76
74
  MLoader,
77
75
  MModal,
78
76
  MNotification,
@@ -1,251 +0,0 @@
1
- <template>
2
- <div v-click-outside="onClickOutside" class="mc-listbox-options">
3
- <button
4
- type="button"
5
- class="mc-listbox-options__trigger"
6
- @click="isOpen = !isOpen"
7
- >
8
- <m-icon name="DisplayOptions24" />
9
- <span class="mc-listbox-options__trigger-label">{{ triggerLabel }}</span>
10
- </button>
11
- <div
12
- ref="listbox"
13
- class="mc-listbox-options__container"
14
- :class="{ 'is-open': isOpen, 'align-right': position == 'right' }"
15
- role="listbox"
16
- aria-labelledby="listbox"
17
- >
18
- <ul
19
- v-for="(list, i) in listItems"
20
- :key="`list${i}`"
21
- class="mc-listbox-options__list"
22
- >
23
- <li
24
- v-for="(item, j) in list"
25
- :key="`item${j}`"
26
- class="mc-listbox-options__tile"
27
- :class="{ 'is-disabled': item.disabled }"
28
- >
29
- <m-icon
30
- v-if="item.icon"
31
- :name="item.icon"
32
- class="mc-listbox-options__icon"
33
- :color="item.danger ? '#C61112' : '#71706B'"
34
- />
35
- <component
36
- :is="item.href ? 'a' : 'button'"
37
- :href="item.href ? item.href : null"
38
- :type="item.href ? null : 'button'"
39
- :disabled="item.disabled ? true : null"
40
- class="mc-listbox-options__item"
41
- :class="{ 'is-danger': item.danger, 'is-disabled': item.disabled }"
42
- @click.self="onClickItem(item, i, j)"
43
- >
44
- {{ item.text }}
45
- </component>
46
- </li>
47
- </ul>
48
- </div>
49
- </div>
50
- </template>
51
-
52
- <script>
53
- import MIcon from '../icon/MIcon.vue';
54
-
55
- export default {
56
- name: 'MListBoxActions',
57
-
58
- components: {
59
- MIcon,
60
- },
61
-
62
- directives: {
63
- 'click-outside': {
64
- bind(el, binding, vnode) {
65
- el.clickOutsideEvent = (event) => {
66
- if (!(el === event.target || el.contains(event.target))) {
67
- vnode.context[binding.expression](event);
68
- }
69
- };
70
- document.body.addEventListener('click', el.clickOutsideEvent);
71
- },
72
- unbind(el) {
73
- document.body.removeEventListener('click', el.clickOutsideEvent);
74
- },
75
- },
76
- },
77
-
78
- props: {
79
- open: {
80
- type: Boolean,
81
- default: false,
82
- },
83
- position: {
84
- type: String,
85
- default: 'left',
86
- },
87
- items: {
88
- type: Array,
89
- default: () => [],
90
- },
91
- triggerLabel: {
92
- type: String,
93
- default: 'Display options',
94
- },
95
- },
96
-
97
- data() {
98
- return {
99
- isOpen: this.open,
100
- };
101
- },
102
-
103
- computed: {
104
- listItems: function () {
105
- const hasNestedArray = this.items.filter(Array.isArray).length;
106
-
107
- if (hasNestedArray === 0) {
108
- const listItems = [];
109
- listItems.push(this.items);
110
- return [this.items];
111
- }
112
-
113
- return this.items;
114
- },
115
- },
116
-
117
- methods: {
118
- onClickOutside() {
119
- this.isOpen = false;
120
- },
121
- onClickItem(item, listIndex, itemIndex) {
122
- const valToEmit = Object.assign(
123
- { listIndex: listIndex, itemIndex: itemIndex },
124
- item
125
- );
126
- this.$emit('update:itemSelected', valToEmit);
127
- },
128
- },
129
- };
130
- </script>
131
-
132
- <style lang="scss">
133
- @import 'settings-tools/all-settings';
134
-
135
- .mc-listbox-options {
136
- display: inline-block;
137
- position: relative;
138
-
139
- &__trigger {
140
- align-items: center;
141
- background: none;
142
- border: none;
143
- cursor: pointer;
144
- display: flex;
145
- height: $mu150;
146
- justify-content: center;
147
- padding: 0;
148
- width: $mu150;
149
-
150
- &-label {
151
- @include visually-hidden();
152
- }
153
- }
154
-
155
- &__container {
156
- position: absolute;
157
- overflow-y: auto;
158
- opacity: 0;
159
- visibility: hidden;
160
- min-width: $mu800;
161
- background-color: $color-grey-000;
162
- border: 1px solid $color-grey-600;
163
- border-radius: 3px;
164
-
165
- &.is-open {
166
- opacity: 1;
167
- visibility: visible;
168
- z-index: 11;
169
- }
170
-
171
- &.align-right {
172
- transform: translateX(calc(-100% + #{$mu150}));
173
- }
174
- }
175
-
176
- &__list {
177
- $parent: get-parent-selector(&);
178
- @include unstyle-list();
179
- margin: 0 auto;
180
- padding: 8px 0;
181
-
182
- &::-webkit-scrollbar {
183
- background-color: $color-grey-100;
184
- width: $mu025;
185
-
186
- &-thumb {
187
- background: $color-grey-600;
188
- }
189
- }
190
-
191
- &:not(:last-child) {
192
- border-bottom: 1px solid #bab6bc;
193
- }
194
- }
195
-
196
- &__tile {
197
- align-items: center;
198
- color: #1e1e1c;
199
- display: flex;
200
- gap: $mu050;
201
- min-height: $mu250;
202
- padding-left: $mu075;
203
- padding-right: $mu075;
204
- position: relative;
205
-
206
- &:hover {
207
- background-color: #eeedea;
208
- }
209
-
210
- &.is-disabled {
211
- background-color: $color-grey-200;
212
-
213
- &,
214
- .mc-listbox-options__item {
215
- color: $color-grey-600;
216
- cursor: not-allowed;
217
- pointer-events: none;
218
- }
219
- }
220
- }
221
-
222
- &__item {
223
- @include set-font-scale('05', 'm');
224
-
225
- background: none;
226
- border: none;
227
- color: currentColor;
228
- cursor: pointer;
229
- padding: 0;
230
- white-space: nowrap;
231
-
232
- &::after {
233
- content: '';
234
- position: absolute;
235
- inset: 0;
236
- z-index: 2;
237
- }
238
-
239
- &,
240
- &:active,
241
- &:hover,
242
- &:focus {
243
- text-decoration: none;
244
- }
245
-
246
- &.is-danger {
247
- color: #c61112;
248
- }
249
- }
250
- }
251
- </style>