@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.
@@ -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,29 +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 { reactive, watch, ref } from '@vue/composition-api';
38
- import MCheckbox from '../checkbox/MCheckbox.vue';
39
-
40
43
  export default {
41
44
  name: 'MListbox',
42
45
 
43
- components: {
44
- MCheckbox,
46
+ model: {
47
+ event: 'change',
45
48
  },
46
49
 
47
50
  props: {
@@ -77,73 +80,203 @@ export default {
77
80
  type: String,
78
81
  default: 'text',
79
82
  },
80
- modelValue: {
81
- type: Array,
82
- default: () => [],
83
+ value: {
84
+ type: [Array, String],
85
+ default: undefined,
83
86
  },
84
87
  },
85
88
 
86
- emits: ['update:itemSelected', 'close-list-box', 'update:modelValue'],
87
-
88
- setup(props, { emit }) {
89
- const listbox = ref(null);
90
-
91
- let uuid = Math.random();
92
-
93
- const state = reactive({
94
- selectableItems: props.items,
89
+ data() {
90
+ return {
91
+ selectableItems: null,
92
+ localValue: [],
95
93
  selected: [],
96
- });
94
+ uuid: null,
95
+ inputBaseId: 'listboxInput',
96
+ };
97
+ },
97
98
 
98
- const updateList = (checked, value) => {
99
- if (!props.multiple) {
100
- emit('update:modelValue', [{ value }]);
101
- emit('close-list-box');
102
- return;
103
- }
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);
104
117
 
105
- if (checked) {
106
- state.selected = [...state.selected, { [props.dataValueExpr]: value }];
107
- } else {
108
- state.selected = state.selected.filter(
109
- (item) => item[props.dataValueExpr] !== value
110
- );
111
- }
112
- emit('update:modelValue', state.selected);
113
- };
118
+ inputs.forEach(function (input) {
119
+ const listItem = input.closest('.mc-listbox__item');
114
120
 
115
- const updateModelValue = (checked, value) => {
116
- state.selected = props.modelValue;
117
- if (state.selected) {
118
- return (
119
- state.selected.filter(
120
- (item) => item[props.dataValueExpr] === value[props.dataValueExpr]
121
- ).length > 0
122
- );
123
- } else {
124
- return undefined;
125
- }
126
- };
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
+ },
127
136
 
128
- watch(
129
- () => props.items,
130
- (nextItems) => {
131
- 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);
132
143
  }
133
- );
134
144
 
135
- return {
136
- listbox,
137
- uuid,
138
- state,
139
- updateList,
140
- updateModelValue,
141
- };
145
+ this.$emit('change', this.localValue);
146
+ },
142
147
  },
143
148
  };
144
149
  </script>
145
150
 
146
151
  <style lang="scss">
147
- @import 'settings-tools/_all-settings';
148
- @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
+ }
149
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