@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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mozaic-ds/vue",
3
- "version": "0.23.0-beta.1",
3
+ "version": "1.0.0-beta.1",
4
4
  "description": "Vue.js implementation of Mozaic Design System",
5
5
  "author": "Adeo - Mozaic Design System",
6
6
  "scripts": {
@@ -23,9 +23,9 @@
23
23
  "postinstall.js"
24
24
  ],
25
25
  "dependencies": {
26
- "@mozaic-ds/css-dev-tools": "^1.38.0",
27
- "@mozaic-ds/icons": "1.40.0",
28
- "@mozaic-ds/styles": "^1.39.1",
26
+ "@mozaic-ds/css-dev-tools": "2.0.0-rc.1",
27
+ "@mozaic-ds/icons": "1.34.0",
28
+ "@mozaic-ds/styles": "2.0.0-rc.4",
29
29
  "@mozaic-ds/web-fonts": "1.22.0",
30
30
  "core-js": "^3.18.3",
31
31
  "libphonenumber-js": "1.9.50",
@@ -1,103 +1,70 @@
1
1
  <template>
2
2
  <div
3
3
  ref="autocomplete"
4
- v-click-outside="onClickOutside"
5
4
  class="mc-autocomplete"
6
5
  :class="{ 'mc-autocomplete--multi': multiple }"
7
6
  :style="tagStyle"
7
+ @keyup.esc="isOpen = true"
8
8
  >
9
9
  <m-tag
10
- v-if="multiple && tagValue.length > 1"
10
+ v-if="multiple && selectedItems().length > 0"
11
+ id="tag"
11
12
  type="removable"
12
- :label="tagValue.length.toString() + ' ' + tagLabel"
13
+ :label="selectedItems().length.toString() + ' ' + labelTag"
13
14
  class="mc-autocomplete__tag"
14
15
  size="s"
15
- @remove-tag="clearAutocomplete()"
16
+ @remove-tag="removeElementsFromList()"
16
17
  />
17
18
  <m-text-input
18
- v-model="inputValue"
19
+ v-model="itemDisplayed"
19
20
  :placeholder="placeholder"
20
- :is-invalid="itemListForDropdown.length === 0"
21
21
  text-input-field-class="mc-autocomplete__trigger"
22
22
  icon-position="left"
23
23
  icon="DisplaySearch48"
24
24
  autocomplete="off"
25
- @input="filterList"
25
+ :style="{ width: boxWidth + 'px' }"
26
+ @input="filerList"
26
27
  @click="isOpen = true"
27
28
  />
28
29
  <m-list-box
29
- v-model="listboxValue"
30
30
  :open="isOpen"
31
- :items="itemListForDropdown"
31
+ :items="sort ? orderedItems() : itemListForDropdown"
32
32
  :multiple="multiple"
33
33
  :empty-search-label="emptySearchLabel"
34
- :data-key-expr="dataKeyExpr"
35
- :data-text-expr="dataTextExpr"
36
- :data-value-expr="dataValueExpr"
37
- @change="onChange"
34
+ :style="{ width: boxWidth + 'px' }"
35
+ @update:itemSelected="updateList"
36
+ @close-list-box="isOpen = false"
38
37
  >
39
38
  <template #item="{ item }">
40
- <slot name="item" :item="item" />
39
+ <slot name="item" :item="item"> </slot>
41
40
  </template>
42
41
  </m-list-box>
43
42
  </div>
44
43
  </template>
45
44
 
46
45
  <script>
47
- import MListBox from '../listbox/MListBox.vue';
48
- import MTag from '../tags/MTag.vue';
49
46
  import MTextInput from '../textinput/MTextInput.vue';
47
+ import MTag from '../tags/MTag.vue';
48
+ import MListBox from '../listbox/MListBox.vue';
50
49
 
51
50
  export default {
52
51
  name: 'MAutocomplete',
53
52
 
54
- components: {
55
- MListBox,
56
- MTag,
57
- MTextInput,
58
- },
59
-
60
- directives: {
61
- 'click-outside': {
62
- bind(el, binding, vnode) {
63
- el.clickOutsideEvent = (event) => {
64
- if (!(el === event.target || el.contains(event.target))) {
65
- vnode.context[binding.expression](event);
66
- }
67
- };
68
- document.body.addEventListener('click', el.clickOutsideEvent);
69
- },
70
- unbind(el) {
71
- document.body.removeEventListener('click', el.clickOutsideEvent);
72
- },
73
- },
74
- },
75
-
76
- model: {
77
- event: 'change',
78
- },
53
+ components: { MListBox, MTag, MTextInput },
79
54
 
80
55
  props: {
81
- open: {
56
+ multiple: {
82
57
  type: Boolean,
83
58
  default: false,
84
59
  },
85
- tagLabel: {
86
- type: String,
87
- default: '',
88
- },
89
60
  placeholder: {
90
61
  type: String,
91
62
  default: '',
92
63
  },
93
64
  items: {
94
65
  type: Array,
95
- default: () => [],
96
66
  required: true,
97
- },
98
- multiple: {
99
- type: Boolean,
100
- default: false,
67
+ default: () => [],
101
68
  },
102
69
  filter: {
103
70
  type: Function,
@@ -107,85 +74,48 @@ export default {
107
74
  type: String,
108
75
  default: 'No item matching your criteria found',
109
76
  },
110
- dataKeyExpr: {
111
- type: String,
112
- default: 'id',
113
- },
114
- dataTextExpr: {
115
- type: String,
116
- default: 'label',
77
+ sort: {
78
+ type: Boolean,
79
+ default: false,
117
80
  },
118
- dataValueExpr: {
81
+ labelTag: {
119
82
  type: String,
120
- default: 'value',
83
+ default: '',
121
84
  },
122
- value: {
123
- type: Array,
124
- default: () => [],
85
+ open: {
86
+ type: Boolean,
87
+ default: false,
125
88
  },
126
89
  },
127
-
128
90
  data() {
129
91
  return {
130
- itemListForDropdown: this.items,
131
- selected: this.items,
92
+ itemListForDropdown: this.$props.items,
93
+ selected: this.$props.items,
132
94
  itemDisplayed: '',
133
- isOpen: this.open,
95
+ isOpen: this.$props.open,
134
96
  tagWidth: '0px',
135
- maxWidth: '17.875rem',
136
- uuid: undefined,
137
- tagValue: '',
138
- inputValue: '',
139
- listboxValue: [],
97
+ boxWidth: '288px',
140
98
  };
141
99
  },
142
-
143
100
  computed: {
144
101
  tagStyle() {
145
102
  return {
146
103
  '--tag-width': this.tagWidth,
147
- '--max-width': this.maxWidth,
148
104
  };
149
105
  },
150
- },
151
-
152
- watch: {
153
- listboxValue: function (newValue) {
154
- const valueExpr = this.dataValueExpr;
155
- const textExpr = this.dataTextExpr;
156
-
157
- if (newValue.length === 1) {
158
- const valueToDisplay = this.items.find(
159
- (item) => item[valueExpr] == newValue
160
- );
161
- this.inputValue = valueToDisplay[textExpr];
162
- } else {
163
- this.inputValue = '';
164
- this.tagValue = newValue;
165
- }
166
- },
167
-
168
- tagValue: {
169
- handler: function () {
170
- this.setTagWidth();
171
- },
172
- immediate: true,
173
- },
174
-
175
- value: {
176
- handler: function (value) {
177
- this.listboxValue = value;
178
- },
179
- immediate: true,
106
+ boxStyle() {
107
+ return {
108
+ '--box-width': this.boxWidth,
109
+ };
180
110
  },
181
111
  },
182
-
183
112
  mounted() {
184
- this.uuid = this._uid;
113
+ this.selectedItems();
114
+ this.tagWidthCalcul();
115
+ this.boxWidthCalcul();
185
116
  },
186
-
187
117
  methods: {
188
- setTagWidth() {
118
+ tagWidthCalcul() {
189
119
  this.$nextTick(() => {
190
120
  this.tagWidth =
191
121
  document && document.querySelector('.mc-autocomplete__tag')
@@ -193,45 +123,74 @@ export default {
193
123
  : '0px';
194
124
  });
195
125
  },
196
-
197
- clearAutocomplete() {
198
- this.listboxValue = [];
199
- this.onChange();
200
- this.$emit('clear');
126
+ selectedItems() {
127
+ return this.selected.filter((item) => {
128
+ return item.selected;
129
+ });
201
130
  },
202
-
203
- filterList(value) {
204
- if (value.length && this.filter) {
205
- this.filter(value);
131
+ orderedItems() {
132
+ this.itemListForDropdown.sort((a, b) => {
133
+ if (a.selected === b.selected) {
134
+ return a.id - b.id;
135
+ } else if (a.selected < b.selected) {
136
+ return 1;
137
+ } else {
138
+ return -1;
139
+ }
140
+ });
141
+ },
142
+ updateList(list) {
143
+ if (!this.$props.multiple && list) {
144
+ this.itemDisplayed = list[0].text;
145
+ } else {
146
+ this.isOpen = true;
147
+ this.selectedItems();
148
+ }
149
+ this.itemListForDropdown.forEach((elem) => {
150
+ if (elem.id === list.id) {
151
+ elem.selected = false;
152
+ }
153
+ });
154
+ this.tagWidthCalcul();
155
+ this.$emit(
156
+ 'update:modelValue',
157
+ this.$props.multiple ? this.selectedItems().value : list
158
+ );
159
+ },
160
+ removeElementsFromList() {
161
+ this.itemListForDropdown.forEach((elem) => {
162
+ elem.selected = false;
163
+ });
164
+ this.selectedItems();
165
+ this.tagWidthCalcul();
166
+ this.$emit('list-removed');
167
+ },
168
+ filerList(value) {
169
+ if (value.length && this.$props.filter) {
170
+ this.$props.filter(value);
206
171
  } else if (value.length) {
207
172
  this.itemListForDropdown = this.itemListForDropdown.filter((item) =>
208
- item[this.dataTextExpr].toUpperCase().includes(value.toUpperCase())
173
+ item.text.toUpperCase().includes(value.toUpperCase())
209
174
  );
210
175
  } else {
211
- this.itemListForDropdown = this.items;
176
+ this.itemListForDropdown = this.$props.items;
212
177
  }
213
178
  this.$emit('list-filtered', this.itemListForDropdown);
214
179
  },
215
-
216
- onClickOutside() {
217
- this.isOpen = false;
218
- },
219
-
220
- onChange() {
221
- this.$emit('change', this.listboxValue);
180
+ boxWidthCalcul() {
181
+ this.$nextTick(() => {
182
+ this.boxWidth = document.querySelector('.mc-autocomplete').clientWidth;
183
+ console.log(this.boxWidth);
184
+ });
185
+ return;
222
186
  },
223
187
  },
224
188
  };
225
189
  </script>
226
190
 
227
191
  <style lang="scss">
228
- @import 'settings-tools/all-settings';
229
- @import 'components/c.checkbox';
230
- @import 'components/c.autocomplete';
231
-
232
- .mc-autocomplete {
233
- max-width: var(--max-width);
234
- }
192
+ @import 'settings-tools/_all-settings';
193
+ @import 'components/_c.autocomplete';
235
194
 
236
195
  .mc-autocomplete--multi .mc-autocomplete__trigger {
237
196
  padding-left: calc(2.9375rem + var(--tag-width));
@@ -22,7 +22,6 @@
22
22
  v-bind="option"
23
23
  :key="option.id ? option.id : option.value"
24
24
  class="mc-field__item"
25
- :disabled="disabled"
26
25
  :checked="value ? value.includes(option.value) : undefined"
27
26
  @change="(v) => onChange(v, option.value)"
28
27
  >
@@ -125,13 +124,6 @@ export default {
125
124
  type: Boolean,
126
125
  default: false,
127
126
  },
128
- /**
129
- * Disabled
130
- */
131
- disabled: {
132
- type: Boolean,
133
- default: false,
134
- },
135
127
  },
136
128
 
137
129
  data() {