wave-ui 3.8.0 → 3.9.0

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": "wave-ui",
3
- "version": "3.8.0",
3
+ "version": "3.9.0",
4
4
  "description": "An emerging UI framework for Vue.js (2 & 3) with only the bright side. :sunny:",
5
5
  "author": "Antoni Andre <antoniandre.web@gmail.com>",
6
6
  "homepage": "https://antoniandre.github.io/wave-ui",
@@ -213,10 +213,7 @@ export default {
213
213
  &:before {
214
214
  content: '';
215
215
  position: absolute;
216
- top: 0;
217
- left: 0;
218
- right: 0;
219
- bottom: 0;
216
+ inset: 0;
220
217
  background-color: currentColor;
221
218
  opacity: 0;
222
219
  transition: $fast-transition-duration;
@@ -162,10 +162,7 @@ export default {
162
162
  // ------------------------------------------------------
163
163
  &:before, &:after {
164
164
  position: absolute;
165
- top: 0;
166
- bottom: 0;
167
- left: 0;
168
- right: 0;
165
+ inset: 0;
169
166
  background-color: currentColor;
170
167
  pointer-events: none;
171
168
  }
@@ -2,31 +2,41 @@
2
2
  .w-autocomplete(:class="classes" @click="onClick")
3
3
  template(v-if="selection.length")
4
4
  .w-autocomplete__selection(v-for="(item, i) in selection")
5
- span(v-html="item[itemLabelKey]")
6
- w-button(@click.stop="unselectItem(i)" icon="i-cross" xs text color="currentColor")
7
- .w-autocomplete__placeholder(v-if="!selection.length && !keywords && placeholder" v-html="placeholder")
5
+ slot(name="selection" :item="item" :unselect="i => unselectItem(i)")
6
+ span(v-html="item[itemLabelKey]")
7
+ w-button(@click.stop="unselectItem(i)" icon="wi-cross" xs text color="currentColor")
8
+ .w-autocomplete__placeholder(
9
+ v-if="!selection.length && !keywords && placeholder"
10
+ v-html="placeholder")
8
11
  input.w-autocomplete__input(
9
12
  ref="input"
10
- v-model="keywords"
11
- @focus="onFocus"
12
- @keydown="onKeydown"
13
- @drop="onDrop"
14
- @compositionstart="onCompositionStart"
15
- @compositionupdate="onCompositionUpdate"
16
- v-on="$listeners")
17
- w-transition-slide-fade(y)
18
- ul.w-autocomplete__menu(v-if="menuOpen" ref="menu")
13
+ :value="keywords"
14
+ v-on="inputEventListeners")
15
+ w-transition-slide-fade
16
+ ul.w-autocomplete__menu(
17
+ v-if="menuOpen"
18
+ ref="menu"
19
+ @mousedown="menuIsBeingClicked = true"
20
+ @mouseup="setEndOfMenuClick"
21
+ @touchstart="menuIsBeingClicked = true"
22
+ @touchend="setEndOfMenuClick")
19
23
  li(
20
24
  v-for="(item, i) in filteredItems"
21
25
  :key="i"
22
- @click.stop="selectItem(item)"
26
+ @click.stop="selectItem(item), $emit('item-click', item)"
23
27
  :class="{ highlighted: highlightedItem === item.uid }")
24
- span(v-html="item[itemLabelKey]")
28
+ slot(name="item" :item="item" :highlighted="highlightedItem === item.uid")
29
+ span(v-html="item[itemLabelKey]")
25
30
  li.w-autocomplete__no-match(
26
31
  v-if="!filteredItems.length"
27
32
  :class="{ 'w-autocomplete__no-match--default': !$slots.noMatch }")
28
33
  slot(name="no-match")
29
34
  .caption(v-html="noMatch ?? 'No match.'")
35
+ li.w-autocomplete__extra-item(
36
+ v-if="$slots['extra-item']"
37
+ @click="selectExtraItem"
38
+ :class="{ highlighted: highlightedItem === 'extra-item' }")
39
+ slot(name="extra-item")
30
40
  </template>
31
41
 
32
42
  <script>
@@ -52,13 +62,17 @@ export default {
52
62
  itemSearchableKey: { type: String, default: 'searchable' }
53
63
  },
54
64
 
55
- emits: ['input'],
65
+ // item-select is also from keyboard, 'item-click' may be useful for mouseenter mouseleave events.
66
+ emits: ['update:modelValue', 'input', 'focus', 'blur', 'keydown', 'item-click', 'item-select', 'extra-item-select'],
56
67
 
57
68
  data: () => ({
58
69
  keywords: '',
59
70
  selection: [],
60
71
  menuOpen: false,
61
- highlightedItem: null
72
+ highlightedItem: null,
73
+ // The focus-blur events occur more times than it should emit to the outside due to the menu
74
+ // item clicking. So keep the focus on as long as the user is interacting with the autocomplete.
75
+ menuIsBeingClicked: false
62
76
  }),
63
77
 
64
78
  computed: {
@@ -102,12 +116,40 @@ export default {
102
116
 
103
117
  highlightedItemIndex () {
104
118
  if (this.highlightedItem === null) return -1
119
+ else if (this.highlightedItem === 'extra-item') return this.filteredItems.length
105
120
  return this.filteredItems.findIndex(item => item.uid === this.highlightedItem)
106
121
  },
107
122
 
123
+ inputEventListeners () {
124
+ return {
125
+ ...this.$attrs,
126
+ input: e => {
127
+ this.keywords = e.target.value
128
+ },
129
+ focus: e => {
130
+ if (this.menuIsBeingClicked) return
131
+ this.onFocus(e)
132
+ this.$emit('focus', e)
133
+ },
134
+ blur: e => {
135
+ if (!this.menuIsBeingClicked) this.$emit('blur', e)
136
+ },
137
+ keydown: e => {
138
+ this.onKeydown(e)
139
+ this.$emit('keydown', e)
140
+ },
141
+ drop: this.onDrop,
142
+ compositionstart: this.onCompositionStart,
143
+ compositionupdate: this.onCompositionUpdate
144
+ }
145
+ },
146
+
108
147
  classes () {
109
148
  return {
110
- 'w-autocomplete--open': this.menuOpen
149
+ 'w-autocomplete--open': this.menuOpen,
150
+ 'w-autocomplete--filled': this.selection.length,
151
+ 'w-autocomplete--has-keywords': this.keywords,
152
+ 'w-autocomplete--empty': !this.selection.length && !this.keywords
111
153
  }
112
154
  }
113
155
  },
@@ -124,7 +166,11 @@ export default {
124
166
  this.selection.push(item)
125
167
  this.highlightedItem = item.uid
126
168
  this.keywords = ''
127
- this.$emit('input', this.multiple ? this.selection.map(item => item[this.itemValueKey]) : item[this.itemValueKey])
169
+ const emitPayload = this.multiple ? this.selection.map(item => item[this.itemValueKey]) : item[this.itemValueKey]
170
+ // Unlike input, item-select is only emitted when selecting (not unselecting).
171
+ this.$emit('item-select', item)
172
+ this.$emit('update:modelValue', emitPayload)
173
+ this.$emit('input', emitPayload)
128
174
  this.$refs.input.focus()
129
175
  if (!this.multiple) this.closeMenu()
130
176
  },
@@ -132,10 +178,21 @@ export default {
132
178
  unselectItem (i) {
133
179
  this.selection.splice(i ?? this.selection.length - 1, 1)
134
180
  this.highlightedItem = null
181
+ this.$emit('update:modelValue', null)
135
182
  this.$emit('input', null)
136
183
  this.$refs.input.focus()
137
184
  },
138
185
 
186
+ selectExtraItem () {
187
+ this.keywords = ''
188
+ this.$emit('extra-item-select')
189
+ this.closeMenu()
190
+ },
191
+
192
+ setEndOfMenuClick () {
193
+ setTimeout(() => (this.menuIsBeingClicked = false), 100)
194
+ },
195
+
139
196
  onClick () {
140
197
  if (!this.openOnKeydown) this.openMenu()
141
198
  this.$refs.input.focus()
@@ -145,20 +202,31 @@ export default {
145
202
  if (!this.openOnKeydown) this.openMenu()
146
203
  },
147
204
 
205
+ // Can be triggered by a click outside the autocomplete, or by a tab key.
206
+ // It should not be simply triggered by input blur, because when we click a menu item it will
207
+ // blur the input for a few ms before we refocus it.
208
+ // onBlur () {
209
+ // this.closeMenu()
210
+ // },
211
+
148
212
  onKeydown (e) {
149
- const itemsCount = this.filteredItems.length
213
+ const itemsCount = this.filteredItems.length + (this.$slots['extra-item'] ? 1 : 0)
150
214
  // `e.key.length === 1`: is all the keyboard keys that generate a character.
151
215
  if (!this.openOnKeydown || ((this.keywords || e.key.length === 1) && !this.menuOpen)) this.openMenu()
152
216
 
217
+ // Tab key.
218
+ if (e.keyCode === 9) this.closeMenu()
219
+
153
220
  // Delete key.
154
- if (e.keyCode === 8 && (!this.keywords || (!e.target.selectionStart && !e.target.selectionEnd))) {
221
+ else if (e.keyCode === 8 && (!this.keywords || (!e.target.selectionStart && !e.target.selectionEnd))) {
155
222
  this.unselectItem()
156
223
  }
157
224
 
158
225
  // Enter key.
159
226
  else if (e.keyCode === 13) {
160
227
  e.preventDefault() // Prevent form submissions.
161
- if (this.highlightedItemIndex >= 0) this.selectItem(this.filteredItems[this.highlightedItemIndex])
228
+ if (this.highlightedItem === 'extra-item') this.selectExtraItem()
229
+ else if (this.highlightedItemIndex >= 0) this.selectItem(this.filteredItems[this.highlightedItemIndex])
162
230
  }
163
231
 
164
232
  // Up & down arrow keys.
@@ -168,16 +236,20 @@ export default {
168
236
  if (index === -1) index = e.keyCode === 38 ? itemsCount - 1 : 0
169
237
  else index = (index + (e.keyCode === 38 ? -1 : 1) + itemsCount) % itemsCount // Never out of range.
170
238
 
171
- this.highlightedItem = this.filteredItems[index]?.uid || 0
239
+ if (this.$slots['extra-item'] && index === itemsCount - 1) this.highlightedItem = 'extra-item'
240
+ else this.highlightedItem = this.filteredItems[index]?.uid || 0
172
241
 
173
242
  // Scroll the container if highlighted item is not in view.
174
243
  const menuEl = this.$refs.menu
175
244
  if (menuEl) {
176
- const { offsetHeight: itemElHeight, offsetTop: itemElTop } = menuEl.childNodes[index] || {}
177
- if (menuEl.scrollTop + menuEl.offsetHeight - itemElHeight < itemElTop) {
178
- menuEl.scrollTop = itemElTop - menuEl.offsetHeight + itemElHeight
245
+ if (this.$slots['extra-item'] && index === itemsCount - 1) menuEl.scrollTop = menuEl.scrollHeight
246
+ else {
247
+ const { offsetHeight: itemElHeight, offsetTop: itemElTop } = menuEl.childNodes[index] || {}
248
+ if (menuEl.scrollTop + menuEl.offsetHeight - itemElHeight < itemElTop) {
249
+ menuEl.scrollTop = itemElTop - menuEl.offsetHeight + itemElHeight
250
+ }
251
+ else if (menuEl.scrollTop > itemElTop) menuEl.scrollTop = itemElTop
179
252
  }
180
- else if (menuEl.scrollTop > itemElTop) menuEl.scrollTop = itemElTop
181
253
  }
182
254
  }
183
255
 
@@ -226,6 +298,18 @@ export default {
226
298
 
227
299
  beforeUnmount () {
228
300
  document.removeEventListener('click', this.onDocumentClick)
301
+ },
302
+
303
+ watch: {
304
+ modelValue (value) {
305
+ this.selection = []
306
+ if (value) {
307
+ const arrayOfValues = Array.isArray(value) ? value : [value]
308
+ arrayOfValues.forEach(value => {
309
+ this.selection.push(this.optimizedItemsForSearch.find(item => item[this.itemValueKey] === +value))
310
+ })
311
+ }
312
+ }
229
313
  }
230
314
  }
231
315
  </script>
@@ -236,8 +320,8 @@ export default {
236
320
  flex-wrap: wrap;
237
321
  gap: 4px;
238
322
  position: relative;
239
- border-radius: 4px;
240
- border: 1px solid rgba(#000, 0.2);
323
+ border-radius: $border-radius;
324
+ border: $border;
241
325
  padding: 2px 4px;
242
326
  user-select: none;
243
327
 
@@ -249,9 +333,9 @@ export default {
249
333
  &__selection {
250
334
  display: flex;
251
335
  align-items: center;
252
- background: rgba(#000, 0.035);
253
- border: 1px solid rgba(#000, 0.05);
254
- border-radius: 4px;
336
+ background: rgba(var(--w-contrast-bg-color-rgb), 0.035);
337
+ border: 1px solid rgba(var(--w-contrast-bg-color-rgb), 0.05);
338
+ border-radius: $border-radius;
255
339
  padding: 0 2px 0 4px;
256
340
  flex-shrink: 0;
257
341
 
@@ -269,8 +353,7 @@ export default {
269
353
  }
270
354
 
271
355
  &__placeholder {
272
- position: absolute;
273
- color: #ccc;
356
+ color: rgba(var(--w-base-color-rgb), 0.5);
274
357
  pointer-events: none;
275
358
  line-height: 18px;
276
359
  }
@@ -281,25 +364,37 @@ export default {
281
364
  max-height: clamp(20px, 400px, 80vh);
282
365
  margin-top: -1px;
283
366
  margin-left: 0;
284
- background-color: #fff;
285
- border: 1px solid rgba(#000, 0.2);
367
+ background-color: $base-bg-color;
368
+ border: 1px solid rgba(var(--w-contrast-bg-color-rgb), 0.2);
286
369
  border-top: none;
287
- border-bottom-left-radius: inherit;
288
- border-bottom-right-radius: inherit;
370
+ border-bottom-left-radius: $border-radius;
371
+ border-bottom-right-radius: $border-radius;
289
372
  overflow: auto;
290
373
  z-index: 10;
291
374
 
292
375
  li {
376
+ position: relative;
293
377
  list-style-type: none;
294
378
  margin: 0;
295
379
  padding: 4px 8px;
296
- border-left: 2px solid transparent;
297
380
 
298
381
  &:hover {background-color: rgba($primary, 0.1);}
299
382
 
300
- &.highlighted {
301
- background-color: rgba($primary, 0.15);
302
- border-left-color: rgba($primary, 0.75);
383
+ &:before, &:after {
384
+ content: '';
385
+ position: absolute;
386
+ inset: 0;
387
+ }
388
+
389
+ &.highlighted:before {
390
+ border-left: 2px solid transparent;
391
+ border-left-color: $primary;
392
+ opacity: 0.3;
393
+ }
394
+
395
+ &.highlighted:after {
396
+ background-color: $primary;
397
+ opacity: 0.1;
303
398
  }
304
399
  }
305
400
  }
@@ -236,10 +236,7 @@ $spinner-size: 40;
236
236
  &:before {
237
237
  content: '';
238
238
  position: absolute;
239
- top: 0;
240
- left: 0;
241
- right: 0;
242
- bottom: 0;
239
+ inset: 0;
243
240
  opacity: 0;
244
241
  background-color: #000;
245
242
  border-radius: inherit;
@@ -302,10 +299,7 @@ $spinner-size: 40;
302
299
 
303
300
  &__loader {
304
301
  position: absolute;
305
- top: 0;
306
- bottom: 0;
307
- left: 0;
308
- right: 0;
302
+ inset: 0;
309
303
  display: flex;
310
304
  align-items: center;
311
305
  justify-content: center;
@@ -204,10 +204,7 @@ export default {
204
204
 
205
205
  &--absolute {
206
206
  position: absolute;
207
- top: 0;
208
- left: 0;
209
- bottom: 0;
210
- right: 0;
207
+ inset: 0;
211
208
  overflow: hidden;
212
209
  }
213
210
 
@@ -223,10 +220,7 @@ export default {
223
220
 
224
221
  .w-overlay {
225
222
  position: absolute;
226
- top: 0;
227
- bottom: 0;
228
- left: 0;
229
- right: 0;
223
+ inset: 0;
230
224
  z-index: 2;
231
225
  }
232
226
  .w-drawer {position: absolute;}
@@ -196,19 +196,13 @@ export default {
196
196
  background-repeat: no-repeat;
197
197
  background-size: cover;
198
198
  position: absolute;
199
- top: 0;
200
- left: 0;
201
- right: 0;
202
- bottom: 0;
199
+ inset: 0;
203
200
 
204
201
  &--contain {background-size: contain;}
205
202
 
206
203
  &__loader, &__content {
207
204
  position: absolute;
208
- top: 0;
209
- left: 0;
210
- right: 0;
211
- bottom: 0;
205
+ inset: 0;
212
206
  display: flex;
213
207
  justify-content: center;
214
208
  align-items: center;
@@ -449,10 +449,7 @@ export default {
449
449
  &:before {
450
450
  content: '';
451
451
  position: absolute;
452
- top: 0;
453
- left: 0;
454
- bottom: 0;
455
- right: 0;
452
+ inset: 0;
456
453
  background-color: currentColor;
457
454
  opacity: 0;
458
455
  transition: 0.2s;
@@ -50,9 +50,7 @@ export default {
50
50
  <style lang="scss">
51
51
  .w-notification-manager {
52
52
  position: fixed;
53
- top: 0;
54
- bottom: 0;
55
- right: 0;
53
+ inset: 0 0 0 auto;
56
54
  z-index: 1000;
57
55
  pointer-events: none;
58
56
  width: 280px;
@@ -154,10 +154,7 @@ $circle-size: 40;
154
154
  &.w-progress--default-bg:after {
155
155
  content: '';
156
156
  position: absolute;
157
- top: 0;
158
- bottom: 0;
159
- left: 0;
160
- right: 0;
157
+ inset: 0;
161
158
  border-radius: inherit;
162
159
  background-color: currentColor;
163
160
  opacity: 0.15;
@@ -188,10 +185,7 @@ $circle-size: 40;
188
185
  &:before, &:after {
189
186
  content: '';
190
187
  position: absolute;
191
- top: 0;
192
- bottom: 0;
193
- left: 0;
194
- right: -5%;
188
+ inset: 0 -5% 0 0;
195
189
  background: currentColor;
196
190
  z-index: 1;
197
191
  will-change: transform;
@@ -238,10 +238,7 @@ export default {
238
238
  &__button:after {
239
239
  content: "";
240
240
  position: absolute;
241
- top: 0;
242
- left: 0;
243
- right: 0;
244
- bottom: 0;
241
+ inset: 0;
245
242
  background-color: currentColor;
246
243
  border-radius: 100%;
247
244
  transform: translateX(100%) scale(0);
@@ -395,10 +395,7 @@ export default {
395
395
  }
396
396
  // Colored border on thumb when hover and active - but with a transparency.
397
397
  &:before {
398
- left: 0;
399
- right: 0;
400
- top: 0;
401
- bottom: 0;
398
+ inset: 0;
402
399
  opacity: 0.5;
403
400
  border: 1px solid currentColor;
404
401
  }
@@ -764,10 +764,7 @@ $tr-border-top: 1px;
764
764
  &:before {
765
765
  content: '';
766
766
  position: absolute;
767
- top: 0;
768
- left: 0;
769
- right: 0;
770
- bottom: 0;
767
+ inset: 0;
771
768
  z-index: -1;
772
769
  background-color: $base-bg-color;
773
770
  }
@@ -848,10 +845,7 @@ $tr-border-top: 1px;
848
845
  &__row--selected td:before {
849
846
  content: '';
850
847
  position: absolute;
851
- top: 0;
852
- left: 0;
853
- right: 0;
854
- bottom: 0;
848
+ inset: 0;
855
849
  background-color: var(--w-primary-color);
856
850
  opacity: 0.2;
857
851
  pointer-events: none;
@@ -403,10 +403,7 @@ export default {
403
403
  &:before {
404
404
  content: '';
405
405
  position: absolute;
406
- top: 0;
407
- left: 0;
408
- right: 0;
409
- bottom: 0;
406
+ inset: 0;
410
407
  background-color: currentColor;
411
408
  opacity: 0;
412
409
  transition: $fast-transition-duration;
@@ -162,10 +162,7 @@ export default {
162
162
  &:before {
163
163
  content: '';
164
164
  position: absolute;
165
- top: 0;
166
- left: 0;
167
- right: 0;
168
- bottom: 0;
165
+ inset: 0;
169
166
  opacity: 0;
170
167
  background-color: transparent;
171
168
  // As this overlay is a smaller rectangle, the radius must be smaller to cover perfectly.
@@ -42,7 +42,7 @@ a {text-decoration: none;}
42
42
  position: relative; // Make the .w-app a referential for tooltips / menus.
43
43
  display: flex;
44
44
  flex-direction: column;
45
- min-height: 100vh;
45
+ min-height: 100dvh;
46
46
 
47
47
  &, *, :before, :after {box-sizing: border-box;}
48
48
 
@@ -47,7 +47,7 @@ $use-layout-classes: true !default;
47
47
  $base-font-size: 14px !default; // Must be a px unit.
48
48
  $base-increment: round(divide($base-font-size, 4)) !default;
49
49
  $layout-padding: $base-increment * 4 !default; // Applied on the .content-wrap tag.
50
- $border-radius: 3px !default;
50
+ $border-radius: 4px !default;
51
51
  $border-color: rgba(var(--w-contrast-bg-color-rgb), 0.12) !default;
52
52
  $border: 1px solid $border-color !default;
53
53
  $transition-duration: 0.25s !default;