@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.
@@ -1,17 +1,13 @@
1
1
  <template>
2
2
  <ul
3
- v-if="state.selectableItems.length > 0"
3
+ v-if="items.length > 0"
4
4
  ref="listbox"
5
5
  role="listbox"
6
- class="mc-listbox mc-listbox--multi"
6
+ class="mc-listbox"
7
7
  aria-labelledby="listbox"
8
- :class="{ 'is-open': open }"
8
+ :class="{ 'is-open': open, 'mc-listbox--multi': multiple }"
9
9
  >
10
- <li
11
- v-for="item in state.selectableItems"
12
- :key="item[dataKeyExpr]"
13
- class="mc-listbox__item"
14
- >
10
+ <li v-for="item in selectableItems" :key="item.id" class="mc-listbox__item">
15
11
  <slot name="item" :item="item">
16
12
  <label
17
13
  :for="`checkbox-dropdown-${item[dataKeyExpr]}-${uuid}`"
@@ -19,32 +15,36 @@
19
15
  >{{ item[dataTextExpr] }}
20
16
  </label>
21
17
  </slot>
22
- <m-checkbox
18
+ <!-- <m-checkbox
19
+ v-if="multiple"
20
+ :id="`checkbox-dropdown-${item.id}`"
21
+ v-model="selectableItems.find((elem) => elem.id === item.id).selected"
22
+ class="mc-listbox__input"
23
+ @change="updateList(item.id, item.text, !item.selected, $e)"
24
+ /> -->
25
+ <input
23
26
  :id="`checkbox-dropdown-${item[dataKeyExpr]}-${uuid}`"
27
+ ref="input"
28
+ v-model="localValue"
29
+ class="mc-checkbox__input mc-listbox__input"
24
30
  :class="{ hideCheckbox: !multiple }"
25
- class="mc-listbox__input"
26
- :checked="updateModelValue(true, item)"
27
- @update:modelValue="(v) => updateList(v, item[dataValueExpr])"
31
+ type="checkbox"
32
+ :value="item.value"
33
+ @change="onChange"
28
34
  />
29
35
  </li>
30
36
  </ul>
31
- <div v-else class="mc-listbox__empty">
37
+ <div v-else class="mc-list-box__empty">
32
38
  {{ emptySearchLabel }}
33
39
  </div>
34
40
  </template>
35
41
 
36
42
  <script>
37
- import Vue from 'vue';
38
- import VueCompositionAPI from '@vue/composition-api';
39
- Vue.use(VueCompositionAPI);
40
- import { reactive, watch, ref } from '@vue/composition-api';
41
- import MCheckbox from '../checkbox/MCheckbox.vue';
42
-
43
43
  export default {
44
44
  name: 'MListbox',
45
45
 
46
- components: {
47
- MCheckbox,
46
+ model: {
47
+ event: 'change',
48
48
  },
49
49
 
50
50
  props: {
@@ -80,73 +80,203 @@ export default {
80
80
  type: String,
81
81
  default: 'text',
82
82
  },
83
- modelValue: {
84
- type: Array,
85
- default: () => [],
83
+ value: {
84
+ type: [Array, String],
85
+ default: undefined,
86
86
  },
87
87
  },
88
88
 
89
- emits: ['update:itemSelected', 'close-list-box', 'update:modelValue'],
90
-
91
- setup(props, { emit }) {
92
- const listbox = ref(null);
93
-
94
- let uuid = Math.random();
95
-
96
- const state = reactive({
97
- selectableItems: props.items,
89
+ data() {
90
+ return {
91
+ selectableItems: null,
92
+ localValue: [],
98
93
  selected: [],
99
- });
94
+ uuid: null,
95
+ inputBaseId: 'listboxInput',
96
+ };
97
+ },
100
98
 
101
- const updateList = (checked, value) => {
102
- if (!props.multiple) {
103
- emit('update:modelValue', [{ value }]);
104
- emit('close-list-box');
105
- return;
106
- }
99
+ watch: {
100
+ items: {
101
+ handler: function (val) {
102
+ this.selectableItems = val;
103
+ },
104
+ immediate: true,
105
+ },
106
+ value: {
107
+ handler: function (value) {
108
+ this.localValue = value;
109
+ },
110
+ immediate: true,
111
+ },
112
+ localValue: {
113
+ handler: function (localValue) {
114
+ const inputs = this.$refs.input;
115
+ if (!this.multiple && inputs) {
116
+ const selectedValue = Array.from(localValue);
107
117
 
108
- if (checked) {
109
- state.selected = [...state.selected, { [props.dataValueExpr]: value }];
110
- } else {
111
- state.selected = state.selected.filter(
112
- (item) => item[props.dataValueExpr] !== value
113
- );
114
- }
115
- emit('update:modelValue', state.selected);
116
- };
118
+ inputs.forEach(function (input) {
119
+ const listItem = input.closest('.mc-listbox__item');
117
120
 
118
- const updateModelValue = (checked, value) => {
119
- state.selected = props.modelValue;
120
- if (state.selected) {
121
- return (
122
- state.selected.filter(
123
- (item) => item[props.dataValueExpr] === value[props.dataValueExpr]
124
- ).length > 0
125
- );
126
- } else {
127
- return undefined;
128
- }
129
- };
121
+ if (input.value == selectedValue[0]) {
122
+ listItem.classList.add('is-checked');
123
+ } else {
124
+ listItem.classList.remove('is-checked');
125
+ }
126
+ });
127
+ }
128
+ },
129
+ immediate: true,
130
+ },
131
+ },
132
+
133
+ mounted() {
134
+ this.uuid = Math.random();
135
+ },
130
136
 
131
- watch(
132
- () => props.items,
133
- (nextItems) => {
134
- state.selectableItems = nextItems;
137
+ methods: {
138
+ onChange() {
139
+ if (!this.multiple) {
140
+ const currentValue = this.localValue;
141
+ this.localValue = [];
142
+ this.localValue = currentValue.slice(-1);
135
143
  }
136
- );
137
144
 
138
- return {
139
- listbox,
140
- uuid,
141
- state,
142
- updateList,
143
- updateModelValue,
144
- };
145
+ this.$emit('change', this.localValue);
146
+ },
145
147
  },
146
148
  };
147
149
  </script>
148
150
 
149
151
  <style lang="scss">
150
- @import 'settings-tools/_all-settings';
151
- @import 'components/_c.listbox';
152
+ @import 'settings-tools/all-settings';
153
+
154
+ .mc-listbox {
155
+ $parent: get-parent-selector(&);
156
+
157
+ @include unstyle-list();
158
+
159
+ background-color: $color-grey-000;
160
+ border: 1px solid $color-grey-600;
161
+ border-radius: 3px;
162
+ position: absolute;
163
+ overflow-y: auto;
164
+ margin-top: 5px;
165
+ margin-bottom: 0;
166
+ // max-height: 13.5rem;
167
+ // min-width: 18rem;
168
+ opacity: 0;
169
+ visibility: hidden;
170
+ width: 100%;
171
+
172
+ &.is-open {
173
+ opacity: 1;
174
+ visibility: visible;
175
+ z-index: 11;
176
+ }
177
+
178
+ &::-webkit-scrollbar {
179
+ background-color: $color-grey-100;
180
+ width: $mu025;
181
+
182
+ &-thumb {
183
+ background: $color-grey-600;
184
+ }
185
+ }
186
+
187
+ &__item {
188
+ align-items: center;
189
+ display: flex;
190
+ gap: $mu050;
191
+ min-height: $mu300;
192
+ padding-left: $mu075;
193
+ padding-right: $mu075;
194
+ position: relative;
195
+ justify-content: space-between;
196
+
197
+ &:not(:last-child) {
198
+ border-bottom: 1px solid $color-grey-300;
199
+ }
200
+
201
+ &:hover {
202
+ background-color: $color-grey-100;
203
+ box-shadow: inset 9px 0 0 -7px $color-grey-900;
204
+ }
205
+ }
206
+
207
+ &__flag,
208
+ &__icon {
209
+ width: $mu200;
210
+ height: $mu200;
211
+ }
212
+
213
+ &__flag {
214
+ @include set-font-scale('07', 'm');
215
+
216
+ text-align: center;
217
+ }
218
+
219
+ &__empty {
220
+ align-items: center;
221
+ border: 1px solid $color-grey-600;
222
+ border-radius: get-border-radius('m');
223
+ padding: $mu100 $mu050;
224
+ }
225
+
226
+ &__label {
227
+ cursor: pointer;
228
+
229
+ &::after {
230
+ content: '';
231
+ position: absolute;
232
+ inset: 0;
233
+ z-index: 2;
234
+ }
235
+ }
236
+
237
+ &__input {
238
+ position: absolute;
239
+ right: $mu075;
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
+ }
278
+
279
+ .hideCheckbox {
280
+ opacity: 0;
281
+ }
152
282
  </style>
@@ -19,6 +19,7 @@
19
19
  :value="rateId"
20
20
  class="mc-stars-input__radio"
21
21
  :required="required"
22
+ @click="$emit('star-clicked', index + 1)"
22
23
  />
23
24
 
24
25
  <label