@mozaic-ds/vue 0.20.0-beta.0 → 0.20.0-beta.3

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