@volverjs/ui-vue 0.0.5-beta.3 → 0.0.5-beta.5

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.
Files changed (29) hide show
  1. package/dist/components/VvCheckbox/VvCheckbox.es.js +1 -1
  2. package/dist/components/VvCheckbox/VvCheckbox.umd.js +1 -1
  3. package/dist/components/VvCheckboxGroup/VvCheckboxGroup.es.js +2 -2
  4. package/dist/components/VvCheckboxGroup/VvCheckboxGroup.umd.js +1 -1
  5. package/dist/components/VvCombobox/VvCombobox.es.js +21 -10
  6. package/dist/components/VvCombobox/VvCombobox.umd.js +1 -1
  7. package/dist/components/VvRadio/VvRadio.es.js +1 -1
  8. package/dist/components/VvRadio/VvRadio.umd.js +1 -1
  9. package/dist/components/VvRadioGroup/VvRadioGroup.es.js +2 -2
  10. package/dist/components/VvRadioGroup/VvRadioGroup.umd.js +1 -1
  11. package/dist/components/VvSelect/VvSelect.es.js +1 -1
  12. package/dist/components/VvSelect/VvSelect.umd.js +1 -1
  13. package/dist/components/index.es.js +23 -12
  14. package/dist/components/index.umd.js +1 -1
  15. package/dist/composables/useOptions.d.ts +1 -1
  16. package/dist/icons.es.js +3 -3
  17. package/dist/icons.umd.js +1 -1
  18. package/package.json +8 -7
  19. package/src/assets/icons/detailed.json +1 -1
  20. package/src/assets/icons/normal.json +1 -1
  21. package/src/assets/icons/simple.json +1 -1
  22. package/src/components/VvCheckbox/index.ts +1 -1
  23. package/src/components/VvCombobox/VvCombobox.vue +23 -11
  24. package/src/components/VvRadio/index.ts +1 -1
  25. package/src/composables/useOptions.ts +1 -1
  26. package/src/stories/Combobox/Combobox.test.ts +14 -6
  27. package/src/stories/Combobox/ComboboxOptions.stories.mdx +35 -0
  28. package/src/stories/Select/Select.test.ts +4 -1
  29. package/src/stories/Select/SelectOptions.stories.mdx +35 -0
@@ -42,7 +42,7 @@ export function useGroupProps(
42
42
  const valid = getGroupOrLocalRef('valid', props) as Ref<boolean>
43
43
  const invalid = getGroupOrLocalRef('invalid', props) as Ref<boolean>
44
44
  const readonly = computed(() =>
45
- Boolean(props.readonly || group?.value?.disabled.value),
45
+ Boolean(props.readonly || group?.value?.readonly.value),
46
46
  )
47
47
  const disabled = computed(() =>
48
48
  Boolean(props.disabled || group?.value?.disabled.value),
@@ -30,6 +30,14 @@
30
30
  props,
31
31
  )
32
32
 
33
+ // Grouped options
34
+ const isGroup = (option: string | Option) => {
35
+ if (typeof option === 'string') {
36
+ return false
37
+ }
38
+ return option.options && option.options.length > 0
39
+ }
40
+
33
41
  // hint slot
34
42
  const { HintSlot } = HintSlotFactory(props, slots)
35
43
 
@@ -202,9 +210,21 @@
202
210
  } else if (props.modelValue) {
203
211
  selectedValues = [props.modelValue]
204
212
  }
205
- return props.options.filter((option) =>
206
- selectedValues.includes(getOptionValue(option)),
207
- )
213
+ const options = props.options.reduce((acc, value) => {
214
+ if (isGroup(value)) {
215
+ return [...acc, ...getOptionGrouped(value)]
216
+ }
217
+ return [...acc, value]
218
+ }, [] as Array<Option | string>)
219
+
220
+ return options.filter((option) => {
221
+ if (isGroup(option)) {
222
+ return getOptionGrouped(option).some((item) =>
223
+ selectedValues.includes(getOptionValue(item)),
224
+ )
225
+ }
226
+ return selectedValues.includes(getOptionValue(option))
227
+ })
208
228
  })
209
229
 
210
230
  const hasValue = computed(() => {
@@ -332,14 +352,6 @@
332
352
  toggleExpanded()
333
353
  }
334
354
  })
335
-
336
- // Grouped options
337
- const isGroup = (option: string | Option) => {
338
- if (typeof option === 'string') {
339
- return false
340
- }
341
- return option.options && option.options.length > 0
342
- }
343
355
  </script>
344
356
 
345
357
  <template>
@@ -25,7 +25,7 @@ export function useGroupProps(
25
25
  const valid = getGroupOrLocalRef('valid', props) as Ref<boolean>
26
26
  const invalid = getGroupOrLocalRef('invalid', props) as Ref<boolean>
27
27
  const readonly = computed(() =>
28
- Boolean(props.readonly || group?.value?.disabled.value),
28
+ Boolean(props.readonly || group?.value?.readonly.value),
29
29
  )
30
30
  const disabled = computed(() =>
31
31
  Boolean(props.disabled || group?.value?.disabled.value),
@@ -31,7 +31,7 @@ export function useOptions(props: any) {
31
31
 
32
32
  const getOptionGrouped = (option: string | Option) => {
33
33
  if (typeof option !== 'object' && option !== null) return []
34
- return option.options
34
+ return option.options || []
35
35
  }
36
36
 
37
37
  return {
@@ -21,11 +21,11 @@ export async function defaultTest({ canvasElement, args }: PlayAttributes) {
21
21
  const dropdown = element.getElementsByClassName(
22
22
  'vv-dropdown',
23
23
  )[0] as HTMLElement
24
- const dropdownFirstItem = dropdown.getElementsByTagName(
25
- 'li',
24
+ const dropdownFirstItem = dropdown.querySelectorAll(
25
+ 'li[role="option"]',
26
26
  )[0] as HTMLElement
27
- const dropdownSecondItem = dropdown.getElementsByTagName(
28
- 'li',
27
+ const dropdownSecondItem = dropdown.querySelectorAll(
28
+ 'li[role="option"]',
29
29
  )[1] as HTMLElement
30
30
  const hint = element.getElementsByClassName('vv-select__hint')[0]
31
31
 
@@ -49,7 +49,12 @@ export async function defaultTest({ canvasElement, args }: PlayAttributes) {
49
49
  // select first value
50
50
  await expect(dropdownFirstItem).toBeClicked()
51
51
  await sleep()
52
- const firstValue = getOptionValue(args, 0)
52
+ const firstValue = getOptionValue(
53
+ args.options[0].options ? args.options[0] : args,
54
+ 0,
55
+ )
56
+
57
+ // in grouped options the first element is not selectable
53
58
  if (args.multiple) {
54
59
  await expect(JSON.parse(value.innerHTML)).toEqual([firstValue])
55
60
  } else {
@@ -60,7 +65,10 @@ export async function defaultTest({ canvasElement, args }: PlayAttributes) {
60
65
  if (args.options.length > 1) {
61
66
  await expect(dropdownSecondItem).toBeClicked()
62
67
  await sleep()
63
- const secondValue = getOptionValue(args, 1)
68
+ const secondValue = getOptionValue(
69
+ args.options[0].options ? args.options[0] : args,
70
+ 1,
71
+ )
64
72
  if (args.multiple) {
65
73
  await expect(JSON.parse(value.innerHTML)).toEqual([
66
74
  firstValue,
@@ -98,3 +98,38 @@ import { defaultTest } from './Combobox.test'
98
98
  {Template.bind()}
99
99
  </Story>
100
100
  </Canvas>
101
+
102
+ <Canvas>
103
+ <Story
104
+ name="Grouped options"
105
+ play={defaultTest}
106
+ argTypes={{
107
+ options: {
108
+ ...argTypes.options,
109
+ control: {
110
+ disable: true,
111
+ },
112
+ },
113
+ }}
114
+ args={{
115
+ options: [
116
+ {
117
+ label: 'Group 1',
118
+ options: [
119
+ { value: 'first', label: 'First' },
120
+ { value: 'second', label: 'Second' },
121
+ ],
122
+ },
123
+ {
124
+ label: 'Group 2',
125
+ options: [
126
+ { value: 'third', label: 'Third' },
127
+ { value: 'fourth', label: 'Fourth' },
128
+ ],
129
+ },
130
+ ],
131
+ }}
132
+ >
133
+ {Template.bind()}
134
+ </Story>
135
+ </Canvas>
@@ -24,7 +24,10 @@ export async function defaultTest({ canvasElement, args }: PlayAttributes) {
24
24
  args.options.length > 0
25
25
  ) {
26
26
  // select first value
27
- const firstValue = getOptionValue(args, 0)
27
+ const firstValue = getOptionValue(
28
+ args.options[0].options ? args.options[0] : args,
29
+ 0,
30
+ )
28
31
  select.value = firstValue
29
32
  select.dispatchEvent(new Event('change'))
30
33
  await sleep()
@@ -98,3 +98,38 @@ import { defaultTest } from './Select.test'
98
98
  {Template.bind()}
99
99
  </Story>
100
100
  </Canvas>
101
+
102
+ <Canvas>
103
+ <Story
104
+ name="Grouped options"
105
+ play={defaultTest}
106
+ argTypes={{
107
+ options: {
108
+ ...argTypes.options,
109
+ control: {
110
+ disable: true,
111
+ },
112
+ },
113
+ }}
114
+ args={{
115
+ options: [
116
+ {
117
+ label: 'Group 1',
118
+ options: [
119
+ { value: 'first', label: 'First' },
120
+ { value: 'second', label: 'Second' },
121
+ ]
122
+ },
123
+ {
124
+ label: 'Group 2',
125
+ options: [
126
+ { value: 'third', label: 'Third' },
127
+ { value: 'fourth', label: 'Fourth' },
128
+ ]
129
+ },
130
+ ],
131
+ }}
132
+ >
133
+ {Template.bind()}
134
+ </Story>
135
+ </Canvas>