@volverjs/ui-vue 0.0.10-beta.24 → 0.0.10-beta.25

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.
@@ -16,6 +16,7 @@
16
16
 
17
17
  // props and emit
18
18
  const props = defineProps(VvAccordionGroupProps)
19
+ // eslint-disable-next-line
19
20
  const emit = defineEmits(VvAccordionGroupEvents)
20
21
 
21
22
  // data
@@ -30,7 +31,7 @@
30
31
  })
31
32
 
32
33
  const accordionNames = reactive(new Set<string>())
33
- let modelValue = ref(new Set<string>())
34
+ let storeModelValue: Ref<string | string[] | undefined> = ref()
34
35
  watch(
35
36
  () => props.storeKey,
36
37
  (newKey, oldKey) => {
@@ -38,73 +39,86 @@
38
39
  localStorage.removeItem(oldKey)
39
40
  }
40
41
  if (newKey) {
41
- modelValue = useLocalStorage(newKey, modelValue.value)
42
+ storeModelValue = useLocalStorage(newKey, storeModelValue.value)
42
43
  return
43
44
  }
44
- modelValue = ref(new Set<string>(modelValue.value))
45
- },
46
- { immediate: true },
47
- )
48
- watch(
49
- [modelValue, accordionNames, () => props.not, () => props.collapse],
50
- () => {
51
- if (props.not) {
52
- emit(
53
- 'update:modelValue',
54
- [...accordionNames].filter(
55
- (name) => !modelValue.value.has(name),
56
- ),
57
- )
58
- return
59
- }
60
- if (props.collapse) {
61
- emit('update:modelValue', [...modelValue.value])
62
- return
63
- }
64
- emit('update:modelValue', modelValue.value.values().next().value)
45
+ storeModelValue = ref(storeModelValue.value)
65
46
  },
66
47
  {
67
- deep: true,
68
48
  immediate: true,
69
49
  },
70
50
  )
71
- watch(
72
- () => props.modelValue,
73
- (newValue, oldValue) => {
74
- if (
75
- newValue === undefined ||
76
- newValue === null ||
77
- JSON.stringify(newValue) === JSON.stringify(oldValue)
78
- ) {
79
- return
51
+ const localModelValue = computed({
52
+ get: () => {
53
+ if (props.modelValue !== null && props.modelValue !== undefined) {
54
+ return props.modelValue
55
+ }
56
+ return storeModelValue.value
57
+ },
58
+ set: (newValue) => {
59
+ emit('update:modelValue', newValue)
60
+ storeModelValue.value = newValue
61
+ },
62
+ })
63
+ const expandedAccordions = computed<Set<string>>({
64
+ get: () => {
65
+ if (localModelValue.value === undefined) {
66
+ return new Set<string>()
80
67
  }
81
68
  let toReturn = new Set<string>()
82
69
  if (props.not) {
83
- if (typeof newValue === 'string') {
70
+ if (typeof localModelValue.value === 'string') {
84
71
  toReturn = new Set<string>(
85
- [...accordionNames].filter((name) => name !== newValue),
72
+ [...accordionNames].filter(
73
+ (name) => name !== localModelValue.value,
74
+ ),
86
75
  )
87
- } else if (Array.isArray(newValue)) {
76
+ } else if (Array.isArray(localModelValue.value)) {
88
77
  toReturn = new Set<string>(
89
78
  [...accordionNames].filter(
90
- (name) => !newValue.includes(name),
79
+ (name) =>
80
+ !(localModelValue.value as string[]).includes(
81
+ name,
82
+ ),
91
83
  ),
92
84
  )
93
85
  }
94
- } else if (typeof newValue === 'string') {
95
- toReturn = new Set<string>([newValue])
96
- } else if (Array.isArray(newValue)) {
97
- toReturn = new Set<string>(newValue)
86
+ } else if (typeof localModelValue.value === 'string') {
87
+ toReturn = new Set<string>([localModelValue.value])
88
+ } else if (Array.isArray(localModelValue.value)) {
89
+ toReturn = new Set<string>(localModelValue.value)
98
90
  }
99
- for (const name of accordionNames) {
100
- bus.emit('toggle', { name, value: toReturn.has(name) })
101
- }
102
- modelValue.value = toReturn
91
+ return toReturn
103
92
  },
104
- {
105
- immediate: true,
93
+ set: (newValue) => {
94
+ if (props.not) {
95
+ localModelValue.value = [...accordionNames].filter(
96
+ (name) => !newValue.has(name),
97
+ )
98
+ return
99
+ }
100
+ if (props.collapse) {
101
+ localModelValue.value = [...newValue]
102
+ return
103
+ }
104
+ localModelValue.value = newValue.values().next().value
106
105
  },
107
- )
106
+ })
107
+ onMounted(() => {
108
+ if (props.not && localModelValue.value === undefined) {
109
+ localModelValue.value = props.collapse
110
+ ? []
111
+ : [...accordionNames.values()].splice(1, accordionNames.size)
112
+ }
113
+ nextTick(() => {
114
+ for (const name of accordionNames) {
115
+ bus.emit('toggle', {
116
+ name,
117
+ value: expandedAccordions.value.has(name),
118
+ })
119
+ }
120
+ })
121
+ })
108
122
 
109
123
  // provide
110
124
  const bus = mitt<AccordionGroupBusEvents>()
@@ -120,19 +134,22 @@
120
134
  accordionNames.delete(name)
121
135
  })
122
136
  bus.on('toggle', ({ name, value }) => {
137
+ const newValue = new Set<string>(expandedAccordions.value)
123
138
  if (value) {
124
139
  if (!props.collapse) {
125
- for (const item of modelValue.value) {
140
+ for (const item of newValue) {
126
141
  if (item !== name) {
127
142
  bus.emit('toggle', { name: item, value: false })
128
143
  }
129
144
  }
130
- modelValue.value.clear()
145
+ newValue.clear()
131
146
  }
132
- modelValue.value.add(name)
147
+ newValue.add(name)
148
+ expandedAccordions.value = newValue
133
149
  return
134
150
  }
135
- modelValue.value.delete(name)
151
+ newValue.delete(name)
152
+ expandedAccordions.value = newValue
136
153
  })
137
154
  const expand = (name?: string | string[]) => {
138
155
  if (typeof name === 'string') {
@@ -169,7 +186,7 @@
169
186
  bus.on('collapse', ({ name }) => collapse(name))
170
187
 
171
188
  // expose
172
- defineExpose({ modelValue, expand, collapse })
189
+ defineExpose({ expandedAccordions, expand, collapse })
173
190
 
174
191
  // styles
175
192
  const bemCssClasses = useModifiers(
@@ -186,7 +203,7 @@
186
203
  <!-- @slot Default slot -->
187
204
  <slot
188
205
  v-bind="{
189
- modelValue,
206
+ expandedAccordions,
190
207
  expand,
191
208
  collapse,
192
209
  }"
@@ -200,13 +217,19 @@
200
217
  content: item.content,
201
218
  }"
202
219
  >
203
- <template #header="data">
220
+ <template
221
+ v-if="$slots[`summary::${item.name}`]"
222
+ #summary="data"
223
+ >
204
224
  <!-- @slot Slot for accordion header -->
205
- <slot v-bind="data" :name="`header::${item.name}`" />
225
+ <slot v-bind="data" :name="`summary::${item.name}`" />
206
226
  </template>
207
- <template #details="data">
227
+ <template
228
+ v-if="$slots[`content::${item.name}`]"
229
+ #default="data"
230
+ >
208
231
  <!-- @slot Slot for accordion details -->
209
- <slot v-bind="data" :name="`details::${item.name}`" />
232
+ <slot v-bind="data" :name="`content::${item.name}`" />
210
233
  </template>
211
234
  </VvAccordion>
212
235
  </slot>
@@ -15,6 +15,7 @@ export const VvAccordionGroupProps = {
15
15
  */
16
16
  modelValue: {
17
17
  type: [String, Array] as PropType<string | string[] | undefined>,
18
+ default: undefined,
18
19
  },
19
20
  /**
20
21
  * Accordion items
@@ -65,12 +65,12 @@ export const argTypes = {
65
65
  },
66
66
  modifiers: {
67
67
  ...ModifiersArgTypes.modifiers,
68
- options: ['compact', 'bordered'],
68
+ options: ['condensed'],
69
69
  },
70
70
  itemModifiers: {
71
71
  description: 'Accordion items BEM modifiers',
72
72
  control: 'check',
73
- options: ['marker-right', 'bordered'],
73
+ options: ['marker-right', 'bordered', 'square'],
74
74
  },
75
75
  ...DisabledArgTypes,
76
76
  ...DefaultSlotArgTypes,
@@ -29,10 +29,10 @@ export async function defaultTest({ canvasElement, args }: PlayAttributes) {
29
29
 
30
30
  // open
31
31
  if (!args.disabled && args.items && args.items.length > 0) {
32
- expect(firstChild.open).toBe(false)
32
+ expect(firstChild.open).toBe(args.not ?? false)
33
33
  expect(firstChildSummary).toBeClicked()
34
34
  await sleep()
35
- expect(firstChild.open).toBe(true)
35
+ expect(firstChild.open).toBe(!args.not)
36
36
  if (firstChild.open) {
37
37
  if (args.not) {
38
38
  expect(JSON.stringify(JSON.parse(value.innerText))).toBe(
@@ -51,10 +51,10 @@ export async function defaultTest({ canvasElement, args }: PlayAttributes) {
51
51
  } else {
52
52
  expect(value.innerText).toBe(args.items[0].name)
53
53
  }
54
+ expect(firstChildSummary.getAttribute('aria-expanded')).toBe('true')
55
+ const content = firstChild.lastChild as HTMLElement
56
+ expect(content.getAttribute('aria-hidden')).toBe('false')
54
57
  }
55
- expect(firstChildSummary.getAttribute('aria-expanded')).toBe('true')
56
- const content = firstChild.lastChild as HTMLElement
57
- expect(content.getAttribute('aria-hidden')).toBe('false')
58
58
  }
59
59
 
60
60
  // accessibility