@mozaic-ds/vue 0.23.0-beta.0 → 1.0.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.
@@ -7,48 +7,35 @@
7
7
  aria-labelledby="listbox"
8
8
  :class="{ 'is-open': open, 'mc-listbox--multi': multiple }"
9
9
  >
10
- <li v-for="item in localItems" :key="item.id" class="mc-listbox__item">
11
- <m-icon
12
- v-if="item.icon"
13
- :name="item.icon"
14
- class="mc-listbox__icon"
15
- color="#666666"
16
- />
17
- <label
18
- :for="`listboxItem-${item[dataKeyExpr]}-${uuid}`"
19
- class="mc-listbox__label"
20
- >
21
- {{ item[dataTextExpr] }}
22
- </label>
23
- <input
24
- :id="`listboxItem-${item[dataKeyExpr]}-${uuid}`"
25
- ref="input"
26
- v-model="localValue"
27
- class="mc-checkbox__input mc-listbox__input"
28
- type="checkbox"
29
- :value="item[dataValueExpr]"
30
- @change="onChange"
10
+ <li
11
+ v-for="item in selectableItems"
12
+ :key="item.id"
13
+ class="mc-listbox__item"
14
+ @change="$emit('update:itemSelected', item)"
15
+ @click.self="updateList(item.id, item.text, !item.selected, true)"
16
+ >
17
+ <slot name="item" :item="item">
18
+ <span class="mc-listbox__text">{{ item.text }} </span>
19
+ </slot>
20
+ <m-checkbox
21
+ v-if="multiple"
22
+ :id="`checkbox-dropdown-${item.id}`"
23
+ v-model="selectableItems.find((elem) => elem.id === item.id).selected"
24
+ class="mc-listbox__input"
25
+ @change="updateList(item.id, item.text, !item.selected, $e)"
31
26
  />
32
27
  </li>
33
28
  </ul>
34
- <div v-else class="mc-listbox__empty">
29
+ <div v-else class="mc-list-box__empty">
35
30
  {{ emptySearchLabel }}
36
31
  </div>
37
32
  </template>
38
-
39
33
  <script>
40
- import MIcon from '../icon/MIcon.vue';
41
-
34
+ import MCheckbox from '../checkbox/MCheckbox.vue';
42
35
  export default {
43
36
  name: 'MListbox',
44
37
 
45
- components: {
46
- MIcon,
47
- },
48
-
49
- model: {
50
- event: 'change',
51
- },
38
+ components: { MCheckbox },
52
39
 
53
40
  props: {
54
41
  open: {
@@ -71,208 +58,49 @@ export default {
71
58
  type: Boolean,
72
59
  default: false,
73
60
  },
74
- dataKeyExpr: {
75
- type: String,
76
- default: 'id',
77
- },
78
- dataTextExpr: {
79
- type: String,
80
- default: 'text',
81
- },
82
- dataValueExpr: {
83
- type: String,
84
- default: 'text',
85
- },
86
- value: {
87
- type: [Array, String],
88
- default: undefined,
89
- },
90
61
  },
91
-
92
62
  data() {
93
63
  return {
94
- localItems: null,
95
- localValue: [],
64
+ selectableItems: null,
96
65
  selected: [],
97
- uuid: null,
98
- inputBaseId: 'listboxInput',
99
66
  };
100
67
  },
101
-
102
68
  watch: {
103
69
  items: {
104
70
  handler: function (val) {
105
- this.localItems = val;
106
- },
107
- immediate: true,
108
- },
109
- value: {
110
- handler: function (value) {
111
- this.localValue = value;
112
- },
113
- immediate: true,
114
- },
115
- localValue: {
116
- handler: function (localValue) {
117
- const inputs = this.$refs.input;
118
- if (!this.multiple && inputs) {
119
- const selectedValue = Array.from(localValue);
120
-
121
- inputs.forEach(function (input) {
122
- const listItem = input.closest('.mc-listbox__item');
123
-
124
- if (input.value == selectedValue[0]) {
125
- listItem.classList.add('is-checked');
126
- } else {
127
- listItem.classList.remove('is-checked');
128
- }
129
- });
130
- }
71
+ this.selectableItems = val;
131
72
  },
132
73
  immediate: true,
133
74
  },
134
75
  },
135
-
136
- mounted() {
137
- this.uuid = Math.random();
138
- },
139
-
140
76
  methods: {
141
- onChange() {
77
+ updateList(id, text, value, isCheckboxUpdate) {
142
78
  if (!this.multiple) {
143
- const currentValue = this.localValue;
144
- this.localValue = [];
145
- this.localValue = currentValue.slice(-1);
79
+ this.$emit('update:itemSelected', [{ id, selected: value, text }]);
80
+
81
+ this.$emit('close-list-box');
82
+ return;
83
+ }
84
+
85
+ if (
86
+ isCheckboxUpdate &&
87
+ this.selectableItems.find((item) => item.id === id)
88
+ ) {
89
+ this.selectableItems.find((item) => item.id === id).selected = value;
146
90
  }
147
91
 
148
- this.$emit('change', this.localValue);
92
+ if (value) {
93
+ this.selected = [...this.selected, { id, selected: value, text }];
94
+ } else {
95
+ this.selected = this.selected.filter((item) => item.id !== id);
96
+ }
97
+ this.$emit('update:itemSelected', this.selectableItems);
149
98
  },
150
99
  },
151
100
  };
152
101
  </script>
153
102
 
154
103
  <style lang="scss">
155
- @import 'settings-tools/all-settings';
156
-
157
- .mc-listbox {
158
- $parent: get-parent-selector(&);
159
-
160
- @include unstyle-list();
161
-
162
- background-color: $color-grey-000;
163
- border: 1px solid $color-grey-600;
164
- border-radius: 3px;
165
- position: absolute;
166
- overflow-y: auto;
167
- margin-top: 5px;
168
- margin-bottom: 0;
169
- max-height: 13.8125rem; // =221px
170
- min-width: 17.875rem; // =286px
171
- opacity: 0;
172
- visibility: hidden;
173
- width: 100%;
174
-
175
- &.is-open {
176
- opacity: 1;
177
- visibility: visible;
178
- z-index: 11;
179
- }
180
-
181
- &::-webkit-scrollbar {
182
- background-color: $color-grey-100;
183
- width: $mu025;
184
-
185
- &-thumb {
186
- background: $color-grey-600;
187
- }
188
- }
189
-
190
- &__item {
191
- align-items: center;
192
- display: flex;
193
- gap: $mu050;
194
- min-height: $mu300;
195
- padding-left: $mu075;
196
- padding-right: $mu075;
197
- position: relative;
198
- justify-content: space-between;
199
-
200
- &:not(:last-child) {
201
- border-bottom: 1px solid $color-grey-300;
202
- }
203
-
204
- &:hover {
205
- background-color: $color-grey-100;
206
- box-shadow: inset 9px 0 0 -7px $color-grey-900;
207
- }
208
- }
209
-
210
- &__flag,
211
- &__icon {
212
- width: $mu200;
213
- height: $mu200;
214
- }
215
-
216
- &__flag {
217
- @include set-font-scale('07', 'm');
218
-
219
- text-align: center;
220
- }
221
-
222
- &__empty {
223
- @include set-font-scale('04', 'm');
224
-
225
- color: $color-fields-error;
226
- display: inline-block;
227
- margin-top: $mu025;
228
- }
229
-
230
- &__label {
231
- cursor: pointer;
232
- margin-right: auto;
233
-
234
- &::after {
235
- content: '';
236
- position: absolute;
237
- inset: 0;
238
- z-index: 2;
239
- }
240
- }
241
-
242
- .is-focus {
243
- background-color: $color-grey-100;
244
- box-shadow: inset 9px 0 0 -7px $color-grey-900;
245
- }
246
-
247
- .is-disabled {
248
- cursor: not-allowed;
249
- box-shadow: none;
250
- background-color: $color-grey-200;
251
- color: $color-grey-600;
252
- pointer-events: none;
253
- }
254
-
255
- &--left {
256
- right: 0;
257
- transform: translateX(-100%);
258
- }
259
-
260
- &:not(.mc-listbox--multi) {
261
- .is-checked {
262
- background-size: $mu150;
263
- background-image: url(inline-icons(
264
- 'notification-available-24',
265
- $color-grey-900
266
- ));
267
- background-repeat: no-repeat;
268
- background-position: right $mu075 center;
269
- }
270
-
271
- #{$parent} {
272
- &__input {
273
- @include visually-hidden();
274
- }
275
- }
276
- }
277
- }
104
+ @import 'settings-tools/_all-settings';
105
+ @import 'components/_c.listbox';
278
106
  </style>
@@ -1,12 +1,7 @@
1
1
  import MListBox from './MListBox.vue';
2
- import MListBoxActions from './MListBoxActions.vue';
3
2
 
4
3
  MListBox.install = function (Vue) {
5
4
  Vue.component(MListBox.name, MListBox);
6
5
  };
7
6
 
8
- MListBoxActions.install = function (Vue) {
9
- Vue.component(MListBoxActions.name, MListBoxActions);
10
- };
11
-
12
- export { MListBox, MListBoxActions };
7
+ export { MListBox };
@@ -80,7 +80,6 @@
80
80
  @keydown.backspace="
81
81
  (event) => (formatOnBlur ? null : backspaceFunction(event))
82
82
  "
83
- v-on="$listeners"
84
83
  />
85
84
  </div>
86
85
  </template>
@@ -7,10 +7,9 @@
7
7
  icon-position="left"
8
8
  :aria-label="decrementAriaLabel"
9
9
  :aria-controls="id"
10
- :disabled="disabled ? disabled : currentValue === valuemin"
10
+ :disabled="currentValue === valuemin"
11
11
  :size="small ? 's' : null"
12
12
  tabindex="-1"
13
- type="button"
14
13
  @click="decrement()"
15
14
  />
16
15
 
@@ -26,11 +25,9 @@
26
25
  :aria-valuemax="valuemax"
27
26
  :placeholder="placeholder"
28
27
  :size="small ? 's' : null"
29
- :disabled="disabled"
30
28
  role="spinbutton"
31
29
  @input="handle"
32
30
  @keypress="integerOnly && formatValue($event)"
33
- v-on="$listeners"
34
31
  />
35
32
 
36
33
  <m-button
@@ -40,10 +37,9 @@
40
37
  icon-position="right"
41
38
  :aria-label="incrementAriaLabel"
42
39
  :aria-controls="id"
43
- :disabled="disabled ? disabled : currentValue === valuemax"
40
+ :disabled="currentValue === valuemax"
44
41
  :size="small ? 's' : null"
45
42
  tabindex="-1"
46
- type="button"
47
43
  @click="increment()"
48
44
  />
49
45
  </div>
@@ -106,10 +102,6 @@ export default {
106
102
  type: Boolean,
107
103
  default: false,
108
104
  },
109
- disabled: {
110
- type: Boolean,
111
- default: false,
112
- },
113
105
  },
114
106
 
115
107
  data() {
@@ -19,7 +19,6 @@
19
19
  :value="rateId"
20
20
  class="mc-stars-input__radio"
21
21
  :required="required"
22
- @click="$emit('star-clicked', index + 1)"
23
22
  />
24
23
 
25
24
  <label
@@ -1,58 +1,28 @@
1
1
  <template>
2
- <nav
3
- class="mc-stepper"
4
- :class="{
5
- 'mc-stepper--compact': compact,
6
- 'mc-stepper--shrinked': steps.length > 3,
7
- }"
8
- :aria-label="accessibilityLabels.stepperDescription"
9
- >
10
- <ol class="mc-stepper__list">
2
+ <nav class='mc-stepper' :class="{ 'mc-stepper--compact': compact, 'mc-stepper--shrinked': steps.length > 3}"
3
+ :aria-label='accessibilityLabels.stepperDescription'>
4
+ <ol class='mc-stepper__list'>
11
5
  <li
12
- v-for="(step, idx) in steps"
13
- :key="`mc-stepper__item-${idx}`"
14
- class="mc-stepper__item"
6
+ v-for='(step, idx) in steps'
7
+ :key='`mc-stepper__item-${idx}`'
8
+ class='mc-stepper__item'
15
9
  :class="{
16
10
  'mc-stepper__item--validated': isStepValidated(idx),
17
11
  'mc-stepper__item--current': step.isCurrent,
18
12
  }"
19
13
  :aria-current="step.isCurrent ? 'step' : false"
20
- :aria-label="stepDescription(step, idx)"
21
- :style="`--steps: ${steps.length}; --current: ${idx + 1};`"
14
+ :aria-label='stepDescription(step,idx)'
15
+ :style='`--steps: ${ steps.length }; --current: ${ idx +1 };`'
22
16
  @click="isStepValidated(idx) && $emit('step-changed', step)"
23
17
  >
24
- <a v-if="step.href" :href="step.href" class="mc-stepper__link">
25
- <div class="mc-stepper__indicator" aria-hidden="true">
26
- <m-icon
27
- v-if="isStepValidated(idx)"
28
- name="NotificationAvailable16"
29
- class="mc-stepper__icon"
30
- />
31
- <span v-else-if="step.isCurrent">{{ idx + 1 }}</span>
32
- </div>
33
- <div class="mc-stepper__detail">
34
- <span class="mc-stepper__title"
35
- >{{ idx + 1 }} / {{ steps.length }}</span
36
- >
37
- <span class="mc-stepper__label">{{ step.label }}</span>
38
- </div>
39
- </a>
40
- <template v-else>
41
- <div class="mc-stepper__indicator" aria-hidden="true">
42
- <m-icon
43
- v-if="isStepValidated(idx)"
44
- name="NotificationAvailable16"
45
- class="mc-stepper__icon"
46
- />
47
- <span v-else-if="step.isCurrent">{{ idx + 1 }}</span>
48
- </div>
49
- <div class="mc-stepper__detail">
50
- <span class="mc-stepper__title"
51
- >{{ idx + 1 }} / {{ steps.length }}</span
52
- >
53
- <span class="mc-stepper__label">{{ step.label }}</span>
54
- </div>
55
- </template>
18
+ <div class='mc-stepper__indicator' aria-hidden='true'>
19
+ <m-icon v-if='isStepValidated(idx)' name='NotificationAvailable16' class='mc-stepper__icon' />
20
+ <span v-else-if='step.isCurrent'>{{ idx + 1 }}</span>
21
+ </div>
22
+ <div class='mc-stepper__detail'>
23
+ <span class='mc-stepper__title'>{{ idx + 1 }} / {{ steps.length }}</span>
24
+ <span class='mc-stepper__label'>{{ step.label }}</span>
25
+ </div>
56
26
  </li>
57
27
  </ol>
58
28
  </nav>
@@ -64,48 +34,37 @@ import MIcon from '../icon/MIcon.vue';
64
34
  export default {
65
35
  name: 'MStepper',
66
36
  components: {
67
- MIcon,
37
+ MIcon
68
38
  },
69
39
  props: {
70
40
  steps: {
71
41
  type: Array,
72
- required: true,
42
+ required: true
73
43
  },
74
44
  compact: {
75
45
  type: Boolean,
76
- default: false,
46
+ default: false
77
47
  },
78
48
  accessibilityLabels: {
79
49
  type: Object,
80
- required: true,
81
- },
50
+ required: true
51
+ }
82
52
  },
83
53
  methods: {
84
54
  isStepValidated(index) {
85
- return index < this.steps.findIndex((step) => step.isCurrent);
55
+ return index < this.steps.findIndex(step => step.isCurrent);
86
56
  },
87
57
  stepDescription(step, index) {
88
- return (
89
- '#' +
90
- (index + 1) +
91
- ' ' +
92
- step.label +
93
- ', ' +
94
- this.stepStateLabel(step, index)
95
- );
58
+ return '#' + (index + 1) + ' ' + step.label + ', ' + this.stepStateLabel(step,index);
96
59
  },
97
60
  stepStateLabel(step, index) {
98
- return this.isStepValidated(index)
99
- ? this.accessibilityLabels.validatedLabel
100
- : step.isCurrent
101
- ? this.accessibilityLabels.currentLabel
102
- : this.accessibilityLabels.disabledLabel;
103
- },
104
- },
61
+ return this.isStepValidated(index) ? this.accessibilityLabels.validatedLabel : step.isCurrent ? this.accessibilityLabels.currentLabel : this.accessibilityLabels.disabledLabel;
62
+ }
63
+ }
105
64
  };
106
65
  </script>
107
66
 
108
- <style lang="scss" scoped>
67
+ <style lang='scss' scoped>
109
68
  @import 'settings-tools/_all-settings';
110
69
  @import 'components/_c.stepper';
111
70
  </style>
@@ -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>
@@ -94,34 +89,31 @@ export default {
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 (!this.activeIndex) {
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>