@volverjs/ui-vue 0.0.8-beta.3 → 0.0.8-beta.4

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,4 +1,5 @@
1
1
  import type { Option } from '../types/generic'
2
+ import { get } from 'ts-dot-prop'
2
3
 
3
4
  // eslint-disable-next-line
4
5
  export function useOptions(props: any) {
@@ -11,7 +12,7 @@ export function useOptions(props: any) {
11
12
  return String(
12
13
  typeof labelKey.value === 'function'
13
14
  ? labelKey.value(option)
14
- : option[labelKey.value],
15
+ : get(option, labelKey.value),
15
16
  )
16
17
  }
17
18
 
@@ -20,7 +21,7 @@ export function useOptions(props: any) {
20
21
 
21
22
  return typeof valueKey.value === 'function'
22
23
  ? valueKey.value(option)
23
- : option[valueKey.value]
24
+ : get(option, valueKey.value)
24
25
  }
25
26
 
26
27
  const getOptionDisabled = (option: string | Option): boolean => {
@@ -28,7 +29,7 @@ export function useOptions(props: any) {
28
29
 
29
30
  return typeof disabledKey.value === 'function'
30
31
  ? disabledKey.value(option)
31
- : option[disabledKey.value]
32
+ : get(option, disabledKey.value)
32
33
  }
33
34
 
34
35
  const getOptionGrouped = (option: string | Option) => {
@@ -2,7 +2,6 @@ import type { PlayAttributes } from '@/test/types'
2
2
  import { expect } from '@/test/expect'
3
3
  import { within } from '@storybook/testing-library'
4
4
  import { sleep } from '@/test/sleep'
5
- import { getOptionValue } from '@/test/options'
6
5
  import { defaultTest as selectDefaultTest } from '@/stories/Select/Select.test'
7
6
 
8
7
  export async function defaultTest({ canvasElement, args }: PlayAttributes) {
@@ -49,11 +48,12 @@ export async function defaultTest({ canvasElement, args }: PlayAttributes) {
49
48
  // select first value
50
49
  await expect(dropdownFirstItem).toBeClicked()
51
50
  await sleep()
51
+
52
+ const { getOptionValue } = useOptions(args)
53
+
52
54
  const firstValue = getOptionValue(
53
- args.options[0].options ? args.options[0] : args,
54
- 0,
55
+ args.options[0].options?.[0] ?? args.options[0],
55
56
  )
56
-
57
57
  // in grouped options the first element is not selectable
58
58
  if (args.multiple) {
59
59
  await expect(JSON.parse(value.innerHTML)).toEqual([firstValue])
@@ -66,8 +66,7 @@ export async function defaultTest({ canvasElement, args }: PlayAttributes) {
66
66
  await expect(dropdownSecondItem).toBeClicked()
67
67
  await sleep()
68
68
  const secondValue = getOptionValue(
69
- args.options[0].options ? args.options[0] : args,
70
- 1,
69
+ args.options[0].options?.[1] ?? args.options[1],
71
70
  )
72
71
  if (args.multiple) {
73
72
  await expect(JSON.parse(value.innerHTML)).toEqual([
@@ -76,3 +76,21 @@ export const GroupedOptions: Story = {
76
76
  ],
77
77
  },
78
78
  }
79
+
80
+ export const DotPathOptions: Story = {
81
+ ...Default,
82
+ args: {
83
+ ...Default.args,
84
+ valueKey: 'value.val',
85
+ labelKey: 'label.en',
86
+ options: [
87
+ { value: { val: 'first' }, label: { it: 'Primo', en: 'First' } },
88
+ {
89
+ value: { val: 'second' },
90
+ label: { it: 'Secondo', en: 'Second' },
91
+ },
92
+ { value: { val: 'third' }, label: { it: 'Terzo', en: 'Third' } },
93
+ { value: { val: 'fourth' }, label: { it: 'Quarto', en: 'Fourth' } },
94
+ ],
95
+ },
96
+ }
@@ -2,7 +2,6 @@ import type { PlayAttributes } from '@/test/types'
2
2
  import { within } from '@storybook/testing-library'
3
3
  import { expect } from '@/test/expect'
4
4
  import { sleep } from '@/test/sleep'
5
- import { getOptionValue } from '@/test/options'
6
5
 
7
6
  export async function defaultTest({ canvasElement, args }: PlayAttributes) {
8
7
  const element = (await within(canvasElement).findByTestId(
@@ -16,6 +15,8 @@ export async function defaultTest({ canvasElement, args }: PlayAttributes) {
16
15
  )[0] as HTMLSelectElement
17
16
  const hint = element.getElementsByClassName('vv-select__hint')[0]
18
17
 
18
+ const { getOptionValue } = useOptions(args)
19
+
19
20
  if (
20
21
  !args.invalid &&
21
22
  !args.disabled &&
@@ -25,8 +26,7 @@ export async function defaultTest({ canvasElement, args }: PlayAttributes) {
25
26
  ) {
26
27
  // select first value
27
28
  const firstValue = getOptionValue(
28
- args.options[0].options ? args.options[0] : args,
29
- 0,
29
+ args.options[0].options?.[0] ?? args.options[0],
30
30
  )
31
31
  select.value = firstValue
32
32
  select.dispatchEvent(new Event('change'))