vueless 0.0.199 → 0.0.201

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,8 +1,9 @@
1
- import { getArgTypes, getSlotNames } from "../service.storybook";
1
+ import { getArgTypes, getSlotNames, allSlotsFragment } from "../service.storybook";
2
2
 
3
3
  import USelect from "../ui.form-select";
4
4
  import URow from "../ui.container-row";
5
5
  import UBadge from "../ui.text-badge";
6
+ import UIcon from "../ui.image-icon";
6
7
 
7
8
  /**
8
9
  * The `USelect` component. | [View on GitHub](https://github.com/vuelessjs/vueless/tree/main/src/ui.form-select)
@@ -43,9 +44,7 @@ const DefaultTemplate = (args) => ({
43
44
  },
44
45
  template: `
45
46
  <USelect v-bind="args" v-model="args.modelValue">
46
- <template v-for="(slot, index) of slots" :key="index" v-slot:[slot]>
47
- <template v-if="args[slot]">{{ args[slot] }}</template>
48
- </template>
47
+ ${allSlotsFragment}
49
48
  </USelect>
50
49
  `,
51
50
  });
@@ -170,7 +169,7 @@ const SizesTemplate = (args, { argTypes } = {}) => ({
170
169
  });
171
170
 
172
171
  const SlotTemplate = (args) => ({
173
- components: { USelect },
172
+ components: { USelect, UIcon },
174
173
  setup() {
175
174
  return { args };
176
175
  },
@@ -323,6 +322,43 @@ slotBeforeCaret.args = {
323
322
  `,
324
323
  };
325
324
 
325
+ export const slotBeforeOption = SlotTemplate.bind({});
326
+ slotBeforeOption.args = {
327
+ slotTemplate: `
328
+ <template #before-option>
329
+ 🤘
330
+ </template>
331
+ `,
332
+ };
333
+
334
+ export const iconLeft = DefaultTemplate.bind({});
335
+ iconLeft.args = {
336
+ iconLeft: "star",
337
+ };
338
+
339
+ export const iconRight = DefaultTemplate.bind({});
340
+ iconRight.args = {
341
+ iconRight: "star",
342
+ };
343
+
344
+ export const iconLeftSlot = SlotTemplate.bind({});
345
+ iconLeftSlot.args = {
346
+ slotTemplate: `
347
+ <template #icon-left>
348
+ <UIcon name="star" color="green" />
349
+ </template>
350
+ `,
351
+ };
352
+
353
+ export const iconRightSlot = SlotTemplate.bind({});
354
+ iconRightSlot.args = {
355
+ slotTemplate: `
356
+ <template #icon-right>
357
+ <UIcon name="star" color="green" />
358
+ </template>
359
+ `,
360
+ };
361
+
326
362
  export const slotLeft = SlotTemplate.bind({});
327
363
  slotLeft.args = {
328
364
  slotTemplate: `
@@ -332,10 +368,10 @@ slotLeft.args = {
332
368
  `,
333
369
  };
334
370
 
335
- export const slotBeforeOption = SlotTemplate.bind({});
336
- slotBeforeOption.args = {
371
+ export const slotRight = SlotTemplate.bind({});
372
+ slotRight.args = {
337
373
  slotTemplate: `
338
- <template #before-option>
374
+ <template #right>
339
375
  🤘
340
376
  </template>
341
377
  `,
@@ -28,7 +28,10 @@
28
28
  v-if="hasSlotContent($slots['after-caret']) && !(multiple && localValue.length)"
29
29
  v-bind="afterCaretSlotAttrs"
30
30
  >
31
- <!-- @slot Use it to add something after caret. -->
31
+ <!--
32
+ @slot Use it to add something after caret.
33
+ @binding {object} scope-props
34
+ -->
32
35
  <slot :scope-props="props" name="after-caret" />
33
36
  </div>
34
37
 
@@ -51,7 +54,10 @@
51
54
  v-if="hasSlotContent($slots['before-caret']) && !(multiple && localValue.length)"
52
55
  v-bind="beforeCaretSlotAttrs"
53
56
  >
54
- <!-- @slot Use it to add something after caret. -->
57
+ <!--
58
+ @slot Use it to add something before caret.
59
+ @binding {object} scope-props
60
+ -->
55
61
  <slot :scope-props="props" name="before-caret" />
56
62
  </div>
57
63
 
@@ -68,9 +74,32 @@
68
74
  </div>
69
75
 
70
76
  <div ref="innerWrapperRef" v-bind="innerWrapperAttrs">
77
+ <span
78
+ v-if="hasSlotContent($slots['icon-left']) || iconLeft"
79
+ ref="leftSlotWrapperRef"
80
+ v-bind="leftIconSlotAttrs"
81
+ >
82
+ <!--
83
+ @slot Use it to add icon before option.
84
+ @binding {string} icon-name
85
+ @binding {string} icon-size
86
+ -->
87
+ <slot name="icon-left" :icon-name="iconLeft" :icon-size="iconSize">
88
+ <UIcon v-if="iconLeft" :name="iconLeft" :size="iconSize" />
89
+ </slot>
90
+ </span>
91
+
92
+ <span v-if="hasSlotContent($slots['left'])" ref="leftSlotWrapperRef">
93
+ <!-- @slot Use it to add something before input. -->
94
+ <slot name="left" />
95
+ </span>
96
+
71
97
  <div v-if="multiple && localValue.length" v-bind="selectedLabelsAttrs">
72
98
  <span v-for="item in localValue" :key="item[valueKey]" v-bind="selectedLabelAttrs">
73
- <!-- @slot Use it to add selected value label. -->
99
+ <!--
100
+ @slot Use it to add selected value label.
101
+ @binding {string} selected-label
102
+ -->
74
103
  <slot
75
104
  name="selected-label"
76
105
  :selected-label="getOptionLabel(item)"
@@ -80,7 +109,10 @@
80
109
  {{ getOptionLabel(item) }}
81
110
  </slot>
82
111
 
83
- <!-- @slot Use it to add selected value label. -->
112
+ <!--
113
+ @slot Use it to add something after selected value label.
114
+ @binding {object} scope-props
115
+ -->
84
116
  <slot :scope-props="props" name="selected-label-after" />
85
117
 
86
118
  <div
@@ -103,15 +135,6 @@
103
135
  </div>
104
136
 
105
137
  <div v-bind="searchAttrs">
106
- <span
107
- v-if="hasSlotContent($slots['left'])"
108
- ref="leftSlotWrapperRef"
109
- v-bind="leftSlotAttrs"
110
- >
111
- <!-- @slot Use it to add some component before text. -->
112
- <slot name="left" />
113
- </span>
114
-
115
138
  <input
116
139
  v-show="searchable || !localValue || multiple || !isOpen"
117
140
  :id="id"
@@ -139,12 +162,19 @@
139
162
  v-bind="selectedLabelAttrs"
140
163
  @mousedown.prevent="toggle"
141
164
  >
142
- <!-- @slot Use it to add selected value label. -->
165
+ <!--
166
+ @slot Use it to add selected value label.
167
+ @binding {string} selected-label
168
+ @binding {string} value
169
+ -->
143
170
  <slot name="selected-label" :selected-label="selectedLabel" :value="localValue[valueKey]">
144
171
  {{ selectedLabel }}
145
172
  </slot>
146
173
 
147
- <!-- @slot Use it to add selected value label. -->
174
+ <!--
175
+ @slot Use it to add something after selected value label.
176
+ @binding {object} scope-props
177
+ -->
148
178
  <slot :scope-props="props" name="selected-label-after" />
149
179
  </span>
150
180
 
@@ -155,6 +185,20 @@
155
185
  @click.prevent.capture
156
186
  v-text="currentLocale.clear"
157
187
  />
188
+
189
+ <!-- @slot Use it to add something after input. -->
190
+ <slot name="right" />
191
+
192
+ <span v-if="hasSlotContent($slots['icon-right']) || iconRight" v-bind="rightIconSlotAttrs">
193
+ <!--
194
+ @slot Use it to add icon after option.
195
+ @binding {string} icon-name
196
+ @binding {string} icon-size
197
+ -->
198
+ <slot name="icon-right" :icon-name="iconRight" :icon-size="iconSize">
199
+ <UIcon v-if="iconRight" :name="iconRight" :size="iconSize" />
200
+ </slot>
201
+ </span>
158
202
  </div>
159
203
 
160
204
  <UDropdownList
@@ -176,16 +220,27 @@
176
220
  @click.prevent.capture
177
221
  >
178
222
  <template #before-option="{ option }">
179
- <!-- @slot Use it to add something before option. -->
223
+ <!--
224
+ @slot Use it to add something before option.
225
+ @binding {other} option
226
+ -->
180
227
  <slot :option="option" name="before-option" />
181
228
  </template>
182
229
 
183
230
  <template #option="{ option, index }">
231
+ <!--
232
+ @slot Use it to add something instead of option.
233
+ @binding {other} option
234
+ @binding {number} index
235
+ -->
184
236
  <slot name="option" :option="option" :index="index" />
185
237
  </template>
186
238
 
187
239
  <template #after-option="{ option }">
188
- <!-- @slot Use it to add something after option. -->
240
+ <!--
241
+ @slot Use it to add something after option.
242
+ @binding {other} option
243
+ -->
189
244
  <slot :option="option" name="after-option" />
190
245
  </template>
191
246
 
@@ -288,6 +343,22 @@ const props = defineProps({
288
343
  default: UIService.get(defaultConfig, USelect).default.size,
289
344
  },
290
345
 
346
+ /**
347
+ * Left side icon name.
348
+ */
349
+ iconLeft: {
350
+ type: String,
351
+ default: "",
352
+ },
353
+
354
+ /**
355
+ * Right side icon name.
356
+ */
357
+ iconRight: {
358
+ type: String,
359
+ default: "",
360
+ },
361
+
291
362
  /**
292
363
  * Select open direction.
293
364
  * @values auto, top, bottom
@@ -412,13 +483,44 @@ const props = defineProps({
412
483
  });
413
484
 
414
485
  const emit = defineEmits([
486
+ /**
487
+ * Triggers when dropdown list is opened.
488
+ * @property {string} propsId
489
+ */
415
490
  "open",
491
+
492
+ /**
493
+ * Triggers when dropdown list is closed.
494
+ * @property {string} propsId
495
+ */
416
496
  "close",
497
+
498
+ /**
499
+ * Triggers when the input value is changed.
500
+ */
417
501
  "searchChange",
502
+
503
+ /**
504
+ * Triggers when option is removed.
505
+ * @property {string} option
506
+ * @property {string} propsId
507
+ */
418
508
  "remove",
509
+
510
+ /**
511
+ * Triggers when option is selected.
512
+ * @property {number} value
513
+ */
419
514
  "update:modelValue",
420
- "select",
515
+
516
+ /**
517
+ * Triggers when dropdown options list is updated.
518
+ */
421
519
  "addOption",
520
+
521
+ /**
522
+ * Triggers when label position is changed.
523
+ */
422
524
  "change",
423
525
  ]);
424
526
 
@@ -462,7 +564,8 @@ const {
462
564
  labelAttrs,
463
565
  wrapperAttrs,
464
566
  innerWrapperAttrs,
465
- leftSlotAttrs,
567
+ leftIconSlotAttrs,
568
+ rightIconSlotAttrs,
466
569
  beforeCaretSlotAttrs,
467
570
  afterCaretSlotAttrs,
468
571
  caretToggleAttrs,
@@ -699,7 +802,13 @@ function removeElement(option, shouldClose = true) {
699
802
  }
700
803
 
701
804
  function setLabelPosition() {
702
- if (props.labelAlign === "top" || !hasSlotContent(slots["left"])) return;
805
+ if (
806
+ props.labelAlign === "top" ||
807
+ !hasSlotContent(slots["left"]) ||
808
+ (!hasSlotContent(slots["icon-left"]) && !props.iconLeft)
809
+ ) {
810
+ return;
811
+ }
703
812
 
704
813
  const leftSlotWidth = leftSlotWrapperRef.value.getBoundingClientRect().width;
705
814
  const innerWrapperPaddingLeft = parseInt(