@mozaic-ds/vue 0.35.1-beta.1 → 0.36.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.35.1-beta.1",
3
+ "version": "0.36.0",
4
4
  "description": "Vue.js implementation of Mozaic Design System",
5
5
  "author": "Adeo - Mozaic Design System",
6
6
  "scripts": {
@@ -28,8 +28,8 @@
28
28
  "@mozaic-ds/icons": "1.52.0",
29
29
  "@mozaic-ds/styles": "1.52.0",
30
30
  "@mozaic-ds/web-fonts": "1.22.0",
31
- "core-js": "^3.27.1",
32
- "libphonenumber-js": "^1.10.15",
31
+ "core-js": "^3.27.2",
32
+ "libphonenumber-js": "^1.10.18",
33
33
  "vue": "^2.6.14",
34
34
  "vue-country-flag": "2.3.2"
35
35
  },
@@ -42,13 +42,13 @@
42
42
  "@vue/compiler-sfc": "^3.2.45",
43
43
  "@vue/eslint-config-prettier": "^7.0.0",
44
44
  "babel-eslint": "^10.1.0",
45
- "eslint": "^8.31.0",
45
+ "eslint": "^8.32.0",
46
46
  "eslint-config-prettier": "^8.6.0",
47
- "eslint-plugin-vue": "^9.8.0",
48
- "postcss": "^8.4.20",
47
+ "eslint-plugin-vue": "^9.9.0",
48
+ "postcss": "^8.4.21",
49
49
  "postcss-loader": "^7.0.2",
50
50
  "postcss-scss": "^4.0.6",
51
- "prettier": "^2.8.1",
51
+ "prettier": "^2.8.3",
52
52
  "sass": "^1.57.1",
53
53
  "sass-loader": "^13.2.0",
54
54
  "vue-template-compiler": "^2.7.14"
@@ -1,31 +1,42 @@
1
1
  <template>
2
2
  <div
3
3
  ref="dropdown"
4
- v-click-outside="onClickOutside"
4
+ v-click-outside="closeListBox"
5
5
  class="mc-dropdown"
6
- :class="{ 'mc-dropdown--multi': multiple }"
6
+ :class="classObject"
7
7
  :style="setStyles"
8
8
  >
9
- <MTag
10
- v-if="multiple && listboxValue.length > 0"
11
- :id="tagId ? tagId : `autoCompleteTag-${uuid}`"
12
- ref="tag"
13
- :label="setTagLabel"
14
- :disabled="disabled"
15
- type="removable"
16
- class="mc-dropdown__tag"
17
- size="s"
18
- @remove-tag="clearAutocomplete()"
19
- />
20
- <button
21
- type="button"
22
- class="mc-select mc-dropdown__trigger"
23
- :class="{ 'is-open': openState, 'mc-select--s': size === 's' }"
24
- :disabled="disabled"
25
- @click="openState = !openState"
26
- >
27
- {{ buttonValue }}
28
- </button>
9
+ <div class="mc-dropdown__main">
10
+ <MTag
11
+ v-if="multiple && listboxValue.length > 0"
12
+ :id="tagId ? tagId : `dropdownTag-${uuid}`"
13
+ ref="tag"
14
+ :label="setTagLabel"
15
+ :disabled="disabled"
16
+ type="removable"
17
+ class="mc-dropdown__tag"
18
+ size="s"
19
+ @remove-tag="clearListbox()"
20
+ />
21
+ <button
22
+ type="button"
23
+ class="mc-select mc-dropdown__trigger"
24
+ :class="classObjectTrigger"
25
+ :disabled="disabled"
26
+ @click="openState = !openState"
27
+ >
28
+ {{ buttonValue }}
29
+ </button>
30
+ <button
31
+ v-if="isClearable"
32
+ class="mc-dropdown__clear"
33
+ type="button"
34
+ @click="clearListbox"
35
+ >
36
+ <MIcon name="ControlTagCross24" class="mc-dropdown__clear-icon" />
37
+ <span class="mc-dropdown__clear-text">{{ labelClearButton }}</span>
38
+ </button>
39
+ </div>
29
40
  <MListBox
30
41
  v-model="listboxValue"
31
42
  :open="openState"
@@ -36,16 +47,17 @@
36
47
  :data-text-expr="dataTextExpr"
37
48
  :data-value-expr="dataValueExpr"
38
49
  :max-width="maxWidth"
39
- @change="onChange"
50
+ @change="onChangeListbox"
40
51
  >
41
52
  <template #item="{ item }">
42
- <slot name="item" :item="item"></slot>
53
+ <slot name="item" :item="item" />
43
54
  </template>
44
55
  </MListBox>
45
56
  </div>
46
57
  </template>
47
58
 
48
59
  <script>
60
+ import MIcon from '../icon/MIcon.vue';
49
61
  import MTag from '../tags/MTag.vue';
50
62
  import MListBox from '../listbox/MListBox.vue';
51
63
 
@@ -53,6 +65,7 @@ export default {
53
65
  name: 'MDropdown',
54
66
 
55
67
  components: {
68
+ MIcon,
56
69
  MTag,
57
70
  MListBox,
58
71
  },
@@ -92,10 +105,6 @@ export default {
92
105
  type: String,
93
106
  default: '-- Placeholder --',
94
107
  },
95
- filter: {
96
- type: Function,
97
- default: null,
98
- },
99
108
  size: {
100
109
  type: String,
101
110
  default: 'm',
@@ -142,6 +151,15 @@ export default {
142
151
  type: Boolean,
143
152
  default: true,
144
153
  },
154
+ // Clear Button
155
+ clearable: {
156
+ type: Boolean,
157
+ default: true,
158
+ },
159
+ labelClearButton: {
160
+ type: String,
161
+ default: 'Clear',
162
+ },
145
163
  // Global
146
164
  maxWidth: {
147
165
  type: String,
@@ -163,8 +181,11 @@ export default {
163
181
  },
164
182
 
165
183
  computed: {
166
- setTagLabel() {
167
- return this.listboxValue.length.toString() + ' ' + this.tagLabel;
184
+ classObject() {
185
+ return {
186
+ 'mc-dropdown--multi': this.multiple,
187
+ 'mc-dropdown--clearable': this.isClearable,
188
+ };
168
189
  },
169
190
  setStyles() {
170
191
  return {
@@ -172,9 +193,32 @@ export default {
172
193
  '--dropdown-tag-width': this.tagWidth,
173
194
  };
174
195
  },
196
+ setTagLabel() {
197
+ return this.listboxValue.length.toString() + ' ' + this.tagLabel;
198
+ },
199
+ getListboxValue() {
200
+ return this.multiple
201
+ ? this.listboxValue.length
202
+ : this.listboxValue !== undefined;
203
+ },
204
+ isClearable() {
205
+ return this.clearable && this.getListboxValue && !this.disabled;
206
+ },
207
+ classObjectTrigger() {
208
+ return {
209
+ 'is-open': this.openState,
210
+ 'mc-select--s': this.size === 's',
211
+ };
212
+ },
175
213
  },
176
214
 
177
215
  watch: {
216
+ items: {
217
+ handler: function (val) {
218
+ this.localItems = val;
219
+ },
220
+ immediate: true,
221
+ },
178
222
  value: {
179
223
  handler: function (val) {
180
224
  if (!val && this.multiple) {
@@ -185,15 +229,6 @@ export default {
185
229
  },
186
230
  immediate: true,
187
231
  },
188
-
189
- items: {
190
- handler: function (val) {
191
- this.localItems = val;
192
- // this.clearAutocomplete();
193
- },
194
- immediate: true,
195
- },
196
-
197
232
  listboxValue: function (val) {
198
233
  const selectedItems = this.getSelectedItems(val);
199
234
  const seletedLabels = selectedItems.map(
@@ -201,17 +236,16 @@ export default {
201
236
  );
202
237
 
203
238
  this.buttonValue =
204
- val.length === 0 ? this.placeholder : seletedLabels.join(', ');
239
+ ((!val || val.length === 0) && this.placeholder) ||
240
+ seletedLabels.join(', ');
205
241
 
206
242
  if (this.multiple) {
207
243
  this.tagValue = val;
208
244
  }
209
245
  },
210
-
211
246
  tagValue: function () {
212
247
  this.setTagWidth();
213
248
  },
214
-
215
249
  openState: function (val) {
216
250
  const eventName = val ? 'open' : 'close';
217
251
  this.$emit(eventName);
@@ -229,14 +263,12 @@ export default {
229
263
  }
230
264
  });
231
265
  },
232
-
233
- clearAutocomplete() {
266
+ clearListbox() {
234
267
  this.listboxValue = this.multiple ? [] : undefined;
235
- this.onChange();
268
+ this.onChangeListbox();
236
269
  this.$emit('clear');
237
270
  },
238
-
239
- onClickOutside() {
271
+ closeListBox() {
240
272
  this.openState = false;
241
273
 
242
274
  if (this.multiple && this.sort) {
@@ -245,15 +277,13 @@ export default {
245
277
  this.localItems = this.items;
246
278
  }
247
279
  },
248
-
249
- onChange() {
280
+ onChangeListbox() {
250
281
  this.$emit('change', this.listboxValue);
251
282
 
252
283
  if (!this.multiple) {
253
- this.onClickOutside();
284
+ this.closeListBox();
254
285
  }
255
286
  },
256
-
257
287
  getSelectedItems(val) {
258
288
  const value = val ? val : this.listboxValue;
259
289
 
@@ -265,7 +295,6 @@ export default {
265
295
 
266
296
  return selectedItems;
267
297
  },
268
-
269
298
  sortItems() {
270
299
  this.sortedListItems = this.items;
271
300
  const selectedItems = this.getSelectedItems();
@@ -282,6 +311,8 @@ export default {
282
311
  return -1;
283
312
  }
284
313
  });
314
+
315
+ this.localItems = this.sortedListItems;
285
316
  },
286
317
  },
287
318
  };