@volverjs/ui-vue 0.0.9 → 0.0.10-beta.1

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.
@@ -182,8 +182,8 @@
182
182
  const {
183
183
  getOptionLabel,
184
184
  getOptionValue,
185
- getOptionDisabled,
186
185
  getOptionGrouped,
186
+ isOptionDisabled,
187
187
  } = useOptions(props)
188
188
 
189
189
  // options filtered by search text
@@ -210,7 +210,7 @@
210
210
  * Check if an option exist into modelValue array (multiple) or is equal to modelValue (single)
211
211
  * @param {String | Option} option
212
212
  */
213
- function getOptionSelected(option: string | Option) {
213
+ function isOptionSelected(option: string | Option) {
214
214
  if (Array.isArray(props.modelValue)) {
215
215
  // check if contain whole option or option value
216
216
  return (
@@ -230,29 +230,17 @@
230
230
  * Check if is multiple mode, object mode or "string" mode
231
231
  */
232
232
  const selectedOptions = computed(() => {
233
- let selectedValues: Array<typeof props.modelValue> = []
234
- if (Array.isArray(props.modelValue)) {
235
- selectedValues = props.modelValue as Array<typeof props.modelValue>
236
- } else if (props.modelValue) {
237
- selectedValues = [props.modelValue]
238
- }
239
- const options = props.options.reduce(
233
+ const options = props.options.reduce<Array<Option | string>>(
240
234
  (acc, value) => {
241
235
  if (isGroup(value)) {
242
236
  return [...acc, ...getOptionGrouped(value)]
243
237
  }
244
238
  return [...acc, value]
245
239
  },
246
- [] as Array<Option | string>,
240
+ [],
247
241
  )
248
-
249
242
  return options.filter((option) => {
250
- if (isGroup(option)) {
251
- return getOptionGrouped(option).some((item) =>
252
- selectedValues.includes(getOptionValue(item)),
253
- )
254
- }
255
- return selectedValues.includes(getOptionValue(option))
243
+ return isOptionSelected(option)
256
244
  })
257
245
  })
258
246
 
@@ -518,8 +506,8 @@
518
506
  option,
519
507
  )"
520
508
  v-bind="{
521
- disabled: getOptionDisabled(item),
522
- selected: getOptionSelected(item),
509
+ selected: isOptionSelected(item),
510
+ disabled: isOptionDisabled(item),
523
511
  unselectable,
524
512
  deselectHintLabel:
525
513
  propsDefaults.deselectHintLabel,
@@ -538,8 +526,8 @@
538
526
  v-bind="{
539
527
  option,
540
528
  selectedOptions,
541
- selected: getOptionSelected(item),
542
- disabled: getOptionDisabled(item),
529
+ selected: isOptionSelected(item),
530
+ disabled: isOptionDisabled(item),
543
531
  }"
544
532
  >
545
533
  {{ getOptionLabel(item) }}
@@ -549,8 +537,8 @@
549
537
  <VvDropdownOption
550
538
  v-else
551
539
  v-bind="{
552
- disabled: getOptionDisabled(option),
553
- selected: getOptionSelected(option),
540
+ selected: isOptionSelected(option),
541
+ disabled: isOptionDisabled(option),
554
542
  unselectable,
555
543
  deselectHintLabel:
556
544
  propsDefaults.deselectHintLabel,
@@ -568,8 +556,8 @@
568
556
  v-bind="{
569
557
  option,
570
558
  selectedOptions,
571
- selected: getOptionSelected(option),
572
- disabled: getOptionDisabled(option),
559
+ selected: isOptionSelected(option),
560
+ disabled: isOptionDisabled(option),
573
561
  }"
574
562
  >
575
563
  {{ getOptionLabel(option) }}
@@ -139,7 +139,7 @@
139
139
  const {
140
140
  getOptionLabel,
141
141
  getOptionValue,
142
- getOptionDisabled,
142
+ isOptionDisabled,
143
143
  getOptionGrouped,
144
144
  } = useOptions(props)
145
145
 
@@ -195,7 +195,7 @@
195
195
  <option
196
196
  v-if="!isGroup(option)"
197
197
  :key="index"
198
- :disabled="getOptionDisabled(option)"
198
+ :disabled="isOptionDisabled(option)"
199
199
  :value="getOptionValue(option)"
200
200
  >
201
201
  {{ getOptionLabel(option) }}
@@ -203,13 +203,13 @@
203
203
  <optgroup
204
204
  v-else
205
205
  :key="`group-${index}`"
206
- :disabled="getOptionDisabled(option)"
206
+ :disabled="isOptionDisabled(option)"
207
207
  :label="getOptionLabel(option)"
208
208
  >
209
209
  <option
210
210
  v-for="(item, i) in getOptionGrouped(option)"
211
211
  :key="`group-${index}-item-${i}`"
212
- :disabled="getOptionDisabled(item)"
212
+ :disabled="isOptionDisabled(item)"
213
213
  :value="getOptionValue(item)"
214
214
  >
215
215
  {{ getOptionLabel(item) }}
@@ -24,7 +24,7 @@ export function useOptions(props: any) {
24
24
  : get(option, valueKey.value)
25
25
  }
26
26
 
27
- const getOptionDisabled = (option: string | Option): boolean => {
27
+ const isOptionDisabled = (option: string | Option): boolean => {
28
28
  if (typeof option !== 'object' && option !== null) return false
29
29
 
30
30
  return typeof disabledKey.value === 'function'
@@ -41,7 +41,7 @@ export function useOptions(props: any) {
41
41
  options,
42
42
  getOptionLabel,
43
43
  getOptionValue,
44
- getOptionDisabled,
44
+ isOptionDisabled,
45
45
  getOptionGrouped,
46
46
  }
47
47
  }
@@ -94,3 +94,21 @@ export const DotPathOptions: Story = {
94
94
  ],
95
95
  },
96
96
  }
97
+
98
+ export const ObjectValue: Story = {
99
+ ...Default,
100
+ args: {
101
+ ...Default.args,
102
+ multiple: true,
103
+ options: [
104
+ {
105
+ value: { name: 'John Doe', email: 'john.doe@test.com' },
106
+ label: 'John Doe',
107
+ },
108
+ {
109
+ value: { name: 'Jane Doe', email: 'jane.doe@test.com' },
110
+ label: 'Jane Doe',
111
+ },
112
+ ],
113
+ },
114
+ }
@@ -14,7 +14,7 @@ export default meta
14
14
 
15
15
  type Story = StoryObj<typeof VvInputText>
16
16
 
17
- export const RegExp: Story = {
17
+ export const Regex: Story = {
18
18
  ...Default,
19
19
  args: {
20
20
  ...defaultArgs,
@@ -9,9 +9,10 @@ import type { Ref } from 'vue'
9
9
  */
10
10
  // eslint-disable-next-line
11
11
  export function equals(obj1: any, obj2: any, field?: string) {
12
- if (field)
12
+ if (field) {
13
13
  return resolveFieldData(obj1, field) === resolveFieldData(obj2, field)
14
- else return deepEquals(obj1, obj2)
14
+ }
15
+ return deepEquals(obj1, obj2)
15
16
  }
16
17
 
17
18
  /**