@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.
- package/dist/components/VvAccordionGroup/VvAccordionGroup.es.js +87 -60
- package/dist/components/VvAccordionGroup/VvAccordionGroup.umd.js +1 -1
- package/dist/components/VvAccordionGroup/VvAccordionGroup.vue.d.ts +18 -3
- package/dist/components/VvAccordionGroup/index.d.ts +1 -0
- package/dist/components/index.es.js +87 -60
- package/dist/components/index.umd.js +1 -1
- package/dist/icons.es.js +3 -3
- package/dist/icons.umd.js +1 -1
- package/dist/stories/AccordionGroup/AccordionGroup.stories.d.ts +24 -5
- package/dist/stories/AccordionGroup/AccordionGroupSlots.stories.d.ts +152 -36
- package/package.json +1 -1
- package/src/assets/icons/detailed.json +1 -1
- package/src/assets/icons/normal.json +1 -1
- package/src/assets/icons/simple.json +1 -1
- package/src/components/VvAccordionGroup/VvAccordionGroup.vue +81 -58
- package/src/components/VvAccordionGroup/index.ts +1 -0
- package/src/stories/AccordionGroup/AccordionGroup.settings.ts +2 -2
- package/src/stories/AccordionGroup/AccordionGroup.test.ts +5 -5
|
@@ -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
|
|
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
|
-
|
|
42
|
+
storeModelValue = useLocalStorage(newKey, storeModelValue.value)
|
|
42
43
|
return
|
|
43
44
|
}
|
|
44
|
-
|
|
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
|
-
|
|
72
|
-
() =>
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
|
70
|
+
if (typeof localModelValue.value === 'string') {
|
|
84
71
|
toReturn = new Set<string>(
|
|
85
|
-
[...accordionNames].filter(
|
|
72
|
+
[...accordionNames].filter(
|
|
73
|
+
(name) => name !== localModelValue.value,
|
|
74
|
+
),
|
|
86
75
|
)
|
|
87
|
-
} else if (Array.isArray(
|
|
76
|
+
} else if (Array.isArray(localModelValue.value)) {
|
|
88
77
|
toReturn = new Set<string>(
|
|
89
78
|
[...accordionNames].filter(
|
|
90
|
-
(name) =>
|
|
79
|
+
(name) =>
|
|
80
|
+
!(localModelValue.value as string[]).includes(
|
|
81
|
+
name,
|
|
82
|
+
),
|
|
91
83
|
),
|
|
92
84
|
)
|
|
93
85
|
}
|
|
94
|
-
} else if (typeof
|
|
95
|
-
toReturn = new Set<string>([
|
|
96
|
-
} else if (Array.isArray(
|
|
97
|
-
toReturn = new Set<string>(
|
|
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
|
-
|
|
100
|
-
bus.emit('toggle', { name, value: toReturn.has(name) })
|
|
101
|
-
}
|
|
102
|
-
modelValue.value = toReturn
|
|
91
|
+
return toReturn
|
|
103
92
|
},
|
|
104
|
-
{
|
|
105
|
-
|
|
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
|
|
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
|
-
|
|
145
|
+
newValue.clear()
|
|
131
146
|
}
|
|
132
|
-
|
|
147
|
+
newValue.add(name)
|
|
148
|
+
expandedAccordions.value = newValue
|
|
133
149
|
return
|
|
134
150
|
}
|
|
135
|
-
|
|
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({
|
|
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
|
-
|
|
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
|
|
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="`
|
|
225
|
+
<slot v-bind="data" :name="`summary::${item.name}`" />
|
|
206
226
|
</template>
|
|
207
|
-
<template
|
|
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="`
|
|
232
|
+
<slot v-bind="data" :name="`content::${item.name}`" />
|
|
210
233
|
</template>
|
|
211
234
|
</VvAccordion>
|
|
212
235
|
</slot>
|
|
@@ -65,12 +65,12 @@ export const argTypes = {
|
|
|
65
65
|
},
|
|
66
66
|
modifiers: {
|
|
67
67
|
...ModifiersArgTypes.modifiers,
|
|
68
|
-
options: ['
|
|
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(
|
|
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
|