@mozaic-ds/vue 0.20.0-beta.2 → 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,14 +1,14 @@
1
1
  {
2
2
  "name": "@mozaic-ds/vue",
3
- "version": "0.20.0-beta.2",
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": {
7
7
  "serve": "vue-cli-service serve",
8
8
  "build": "vue-cli-service build ./src/index.js",
9
9
  "lint": "vue-cli-service lint",
10
- "build:bundle": "vue-cli-service build --target lib --inline-vue --name mozaic-vue ./src/index.js",
11
- "build:bundleAdeo": "vue-cli-service build --mode adeo --target lib --formats umd --inline-vue --filename mozaic-vue.adeo ./src/index.js --no-clean",
10
+ "build:bundle": "vue-cli-service build --target lib --name mozaic-vue ./src/index.js",
11
+ "build:bundleAdeo": "vue-cli-service build --target lib --formats umd --mode adeo --filename mozaic-vue.adeo ./src/index.js --no-clean",
12
12
  "postinstall": "node postinstall.js",
13
13
  "prepublishOnly": "npm run-script build:bundle && npm run-script build:bundleAdeo",
14
14
  "publish:beta": "npm publish --access public --tag alpha",
@@ -27,8 +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/core": "^8.6.0",
32
30
  "core-js": "^3.18.3",
33
31
  "libphonenumber-js": "1.9.50",
34
32
  "postcss-scss": "^4.0.1",
@@ -1,60 +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 {
51
- ref,
52
- reactive,
53
- onMounted,
54
- computed,
55
- nextTick,
56
- } from '@vue/composition-api';
57
- import { onClickOutside } from '@vueuse/core';
58
48
  import MListBox from '../listbox/MListBox.vue';
59
49
  import MTag from '../tags/MTag.vue';
60
50
  import MTextInput from '../textinput/MTextInput.vue';
@@ -68,19 +58,43 @@ export default {
68
58
  MTextInput,
69
59
  },
70
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
+
71
77
  props: {
72
- multiple: {
78
+ open: {
73
79
  type: Boolean,
74
80
  default: false,
75
81
  },
82
+ tagLabel: {
83
+ type: String,
84
+ default: 'voitures',
85
+ },
76
86
  placeholder: {
77
87
  type: String,
78
88
  default: '',
79
89
  },
80
90
  items: {
81
91
  type: Array,
82
- required: true,
83
92
  default: () => [],
93
+ required: true,
94
+ },
95
+ multiple: {
96
+ type: Boolean,
97
+ default: false,
84
98
  },
85
99
  filter: {
86
100
  type: Function,
@@ -90,18 +104,6 @@ export default {
90
104
  type: String,
91
105
  default: 'No item matching your criteria found',
92
106
  },
93
- sort: {
94
- type: Boolean,
95
- default: false,
96
- },
97
- labelTag: {
98
- type: String,
99
- default: '',
100
- },
101
- modelValue: {
102
- type: Array,
103
- default: () => [],
104
- },
105
107
  dataKeyExpr: {
106
108
  type: String,
107
109
  default: 'id',
@@ -110,119 +112,105 @@ export default {
110
112
  type: String,
111
113
  default: 'text',
112
114
  },
113
- dataSelectedExpr: {
114
- type: String,
115
- default: 'selected',
116
- },
117
115
  dataValueExpr: {
118
116
  type: String,
119
117
  default: 'text',
120
118
  },
119
+ // value: {
120
+ // type: Array,
121
+ // default: () => [],
122
+ // },
121
123
  },
122
124
 
123
- emits: ['update:modelValue', 'list-removed', 'list-filtered', 'input-change'],
124
-
125
- setup(props, { emit }) {
126
- const autocomplete = ref(null);
127
- const listbox = ref(null);
128
-
129
- const state = reactive({
130
- open: false,
131
- itemListForDropdown: props.items,
132
- selected: [],
125
+ data() {
126
+ return {
127
+ itemListForDropdown: this.items,
128
+ selected: this.items,
133
129
  itemDisplayed: '',
130
+ isOpen: this.open,
134
131
  tagWidth: '0px',
135
- });
136
-
137
- onMounted(() => {
138
- manageTag();
139
- });
140
-
141
- const selectedItems = computed(() =>
142
- state.selected.filter((item) => {
143
- return item[props.dataValueExpr];
144
- })
145
- );
146
-
147
- const orderedItems = () => {
148
- // Order by selected then by id
149
- return Array.from(state.itemListForDropdown).sort((a, b) => {
150
- if (a.selected === b.selected) {
151
- return a.id - b.id;
152
- } else if (a.selected < b.selected) {
153
- return 1;
154
- } else {
155
- return -1;
156
- }
157
- });
132
+ uuid: undefined,
133
+ tagValue: '',
134
+ inputValue: '',
135
+ listboxValue: [],
158
136
  };
137
+ },
159
138
 
160
- const boxWidth = computed(() =>
161
- autocomplete.value ? autocomplete.value.clientWidth : ''
162
- );
163
-
164
- onClickOutside(listbox, () => (state.open = false));
139
+ computed: {
140
+ tagStyle() {
141
+ return {
142
+ '--tag-width': this.tagWidth,
143
+ };
144
+ },
145
+ },
165
146
 
166
- const updateList = (list) => {
167
- if (!props.multiple && list) {
168
- 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;
169
154
  } else {
170
- state.open = true;
171
- manageTag();
155
+ this.inputValue = '';
156
+ this.tagValue = newValue;
172
157
  }
173
- state.selected = list;
174
- emit('update:modelValue', list);
175
- };
158
+ },
176
159
 
177
- const removeElementsFromList = () => {
178
- state.selected = [];
179
- manageTag();
180
- emit('update:modelValue', state.selected);
181
- emit('list-removed');
182
- };
160
+ tagValue: {
161
+ handler: function () {
162
+ this.setTagWidth();
163
+ },
164
+ immediate: true,
165
+ },
166
+ },
183
167
 
184
- const updateDropdown = (value) => {
185
- if (value.length && props.filter) {
186
- props.filter(value);
187
- } else if (value.length) {
188
- state.itemListForDropdown = props.items.filter((item) =>
189
- item[props.dataTextExpr].toUpperCase().includes(value.toUpperCase())
190
- );
191
- } else {
192
- state.itemListForDropdown = props.items;
193
- }
194
- emit('update:modelValue', state.selected);
195
- emit('list-filtered', state.itemListForDropdown);
196
- };
168
+ mounted() {
169
+ this.uuid = this._uid;
170
+ },
197
171
 
198
- const manageTag = () => {
199
- nextTick(() => {
200
- state.tagWidth =
172
+ methods: {
173
+ setTagWidth() {
174
+ this.$nextTick(() => {
175
+ this.tagWidth =
201
176
  document && document.querySelector('.mc-autocomplete__tag')
202
177
  ? document.querySelector('.mc-autocomplete__tag').clientWidth + 'px'
203
178
  : '0px';
204
179
  });
205
- };
180
+ },
206
181
 
207
- return {
208
- autocomplete,
209
- listbox,
210
- state,
211
- selectedItems,
212
- orderedItems,
213
- boxWidth,
214
- updateList,
215
- removeElementsFromList,
216
- updateDropdown,
217
- manageTag,
218
- };
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
+ },
219
203
  },
220
204
  };
205
+
206
+ // TODO:
207
+ // - boxWidth ?
208
+ // - dataSelectedExpr ?
221
209
  </script>
222
210
 
223
211
  <style lang="scss">
224
- @import 'settings-tools/_all-settings';
225
- @import 'components/_c.autocomplete';
212
+ @import 'settings-tools/all-settings';
213
+ @import 'components/c.autocomplete';
226
214
 
227
215
  .mc-autocomplete--multi .mc-autocomplete__trigger {
228
216
  padding-left: calc(2.9375rem + var(--tag-width));