wave-ui 3.17.2 → 3.17.3
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/types/components/WAccordion.d.ts +2 -6
- package/dist/wave-ui.cjs.js +1 -1
- package/dist/wave-ui.es.js +80 -69
- package/dist/wave-ui.umd.js +1 -1
- package/package.json +1 -1
- package/src/wave-ui/components/w-accordion/index.vue +60 -45
- package/src/wave-ui/components/w-accordion/item.vue +22 -22
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wave-ui",
|
|
3
|
-
"version": "3.17.
|
|
3
|
+
"version": "3.17.3",
|
|
4
4
|
"description": "A UI framework for Vue.js 3 (and 2) with only the bright side. :sunny:",
|
|
5
5
|
"author": "Antoni Andre <antoniandre.web@gmail.com>",
|
|
6
6
|
"homepage": "https://antoniandre.github.io/wave-ui",
|
|
@@ -4,18 +4,21 @@
|
|
|
4
4
|
slot(v-if="accordionItemsProvided")
|
|
5
5
|
|
|
6
6
|
//- Else, when providing the items array or number through the items prop.
|
|
7
|
-
template(v-else-if="
|
|
7
|
+
template(v-else-if="(items || []).length")
|
|
8
8
|
w-accordion-item(
|
|
9
|
-
v-for="(
|
|
9
|
+
v-for="(item, i) in (items.length ? items : accordionItems)"
|
|
10
10
|
:key="i"
|
|
11
|
-
:class="
|
|
12
|
-
:
|
|
11
|
+
:class="itemClasses"
|
|
12
|
+
:title="item.title"
|
|
13
|
+
:content="item.content"
|
|
14
|
+
:expanded="item.expanded || item._expanded"
|
|
15
|
+
:disabled="item.disabled || item._disabled"
|
|
13
16
|
@focus="$emit('focus', $event)")
|
|
14
17
|
//- Title.
|
|
15
18
|
template(#title="{ item, expanded, index }")
|
|
16
19
|
slot(
|
|
17
|
-
v-if="$slots[`item-title.${
|
|
18
|
-
:name="`item-title.${
|
|
20
|
+
v-if="$slots[`item-title.${item.id || index}`]"
|
|
21
|
+
:name="`item-title.${item.id || index}`"
|
|
19
22
|
:item="item"
|
|
20
23
|
:expanded="expanded"
|
|
21
24
|
:index="index")
|
|
@@ -28,8 +31,8 @@
|
|
|
28
31
|
//- Content.
|
|
29
32
|
template(#content="{ item, expanded, index }")
|
|
30
33
|
slot(
|
|
31
|
-
v-if="$slots[`item-content.${
|
|
32
|
-
:name="`item-content.${
|
|
34
|
+
v-if="$slots[`item-content.${item.id || index}`]"
|
|
35
|
+
:name="`item-content.${item.id || index}`"
|
|
33
36
|
:item="item"
|
|
34
37
|
:expanded="expanded"
|
|
35
38
|
:index="index")
|
|
@@ -43,6 +46,7 @@
|
|
|
43
46
|
|
|
44
47
|
<script>
|
|
45
48
|
import { objectifyClasses } from '../../utils/index'
|
|
49
|
+
import { consoleError } from '../../utils/console'
|
|
46
50
|
import WAccordionItem from './item.vue'
|
|
47
51
|
|
|
48
52
|
export default {
|
|
@@ -52,7 +56,9 @@ export default {
|
|
|
52
56
|
modelValue: { type: Array },
|
|
53
57
|
color: { type: String },
|
|
54
58
|
bgColor: { type: String },
|
|
55
|
-
|
|
59
|
+
// Required unless externally using WAccordionItem.
|
|
60
|
+
// Number deprecated: use WAccordionItem.
|
|
61
|
+
items: { type: [Array, Number] },
|
|
56
62
|
itemColorKey: { type: String, default: 'color' }, // Support a different color per item.
|
|
57
63
|
itemTitleKey: { type: String, default: 'title' },
|
|
58
64
|
itemContentKey: { type: String, default: 'content' },
|
|
@@ -78,7 +84,6 @@ export default {
|
|
|
78
84
|
// All provided to the WAccordionItem, not passed as prop since it could be used externally.
|
|
79
85
|
provide () {
|
|
80
86
|
return {
|
|
81
|
-
itemClasses: objectifyClasses(this.itemClasses),
|
|
82
87
|
titleClasses: this.titleClasses,
|
|
83
88
|
contentClasses: this.contentClasses,
|
|
84
89
|
onItemToggle: this.onItemToggle,
|
|
@@ -86,17 +91,23 @@ export default {
|
|
|
86
91
|
getOriginalItem: this.getOriginalItem,
|
|
87
92
|
options: this.$props,
|
|
88
93
|
registerItem: this.registerItem,
|
|
89
|
-
|
|
94
|
+
unregisterItem: this.unregisterItem,
|
|
95
|
+
getAccordionItem: this.getAccordionItem
|
|
90
96
|
}
|
|
91
97
|
},
|
|
92
98
|
|
|
93
99
|
data: () => ({
|
|
94
|
-
|
|
95
|
-
accordionItems: []
|
|
96
|
-
}
|
|
100
|
+
accordionItems: []
|
|
97
101
|
}),
|
|
98
102
|
|
|
99
103
|
computed: {
|
|
104
|
+
accordionItemsById () {
|
|
105
|
+
return this.accordionItems.reduce((obj, item) => {
|
|
106
|
+
obj[item._cuid] = item
|
|
107
|
+
return obj
|
|
108
|
+
}, {})
|
|
109
|
+
},
|
|
110
|
+
|
|
100
111
|
// Detect if the accordion items are directly provided through slot using WAccordionItem.
|
|
101
112
|
accordionItemsProvided () {
|
|
102
113
|
return this.$slots.default?.()?.some(item => item?.type?.name)
|
|
@@ -129,9 +140,13 @@ export default {
|
|
|
129
140
|
},
|
|
130
141
|
|
|
131
142
|
methods: {
|
|
143
|
+
getAccordionItem (cuid) {
|
|
144
|
+
return this.accordionItemsById[cuid]
|
|
145
|
+
},
|
|
146
|
+
|
|
132
147
|
onItemToggle (item) {
|
|
133
|
-
if (this.expandSingle) this.
|
|
134
|
-
const expandedItems = this.
|
|
148
|
+
if (this.expandSingle) this.accordionItems.forEach(obj => obj._index !== item._index && (obj._expanded = false))
|
|
149
|
+
const expandedItems = this.accordionItems.map(item => item._expanded || false)
|
|
135
150
|
this.$emit('update:modelValue', expandedItems)
|
|
136
151
|
this.$emit('input', expandedItems)
|
|
137
152
|
this.$emit('item-expand', { item, expanded: item._expanded })
|
|
@@ -143,48 +158,48 @@ export default {
|
|
|
143
158
|
|
|
144
159
|
// Return the original accordion item (so there is no `_index`, etc.).
|
|
145
160
|
getOriginalItem (item) {
|
|
146
|
-
return this.items[item._index]
|
|
147
|
-
},
|
|
148
|
-
|
|
149
|
-
updateItems () {
|
|
150
|
-
let items = this.state.accordionItems
|
|
151
|
-
if (!this.accordionItemsProvided && this.items) {
|
|
152
|
-
items = (typeof this.items === 'number' ? Array(this.items).fill({}) : this.items) || []
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
this.state.accordionItems = items.map((item, _index) => ({
|
|
156
|
-
...item,
|
|
157
|
-
_index,
|
|
158
|
-
_expanded: this.modelValue?.[_index] ?? false,
|
|
159
|
-
_disabled: !!item.disabled
|
|
160
|
-
}))
|
|
161
|
+
return this.items?.[item._index] || item
|
|
161
162
|
},
|
|
162
163
|
|
|
163
|
-
// Provide-injected
|
|
164
|
+
// Provide-injected and used from w-accordion-item.
|
|
164
165
|
// Only when w-accordion-item is directly used outside of Wave UI.
|
|
165
166
|
registerItem (item) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
167
|
+
item._index = this.accordionItems.length
|
|
168
|
+
item = Object.assign(item, this.items?.[item._index])
|
|
169
|
+
item._expanded = this.modelValue?.[item._index] ?? false
|
|
170
|
+
item._disabled = !!item._disabled
|
|
170
171
|
|
|
171
|
-
|
|
172
|
-
|
|
172
|
+
this.accordionItems.push(item)
|
|
173
|
+
},
|
|
173
174
|
|
|
174
|
-
|
|
175
|
+
// Provide-injected and used from w-accordion-item.
|
|
176
|
+
unregisterItem (cuid) {
|
|
177
|
+
const index = this.getAccordionItem(cuid)?._index
|
|
178
|
+
if (index !== undefined) this.accordionItems.splice(index, 1)
|
|
175
179
|
}
|
|
176
180
|
},
|
|
177
181
|
|
|
178
182
|
created () {
|
|
179
|
-
if (!this.
|
|
183
|
+
if (!isNaN(this.items)) {
|
|
184
|
+
consoleError(
|
|
185
|
+
`Since version 3.17.3, the w-accordion \`items\` prop can no longer be a Number.
|
|
186
|
+
Please use the w-accordion-item component instead for advanced custom rendering.
|
|
187
|
+
https://antoniandre.github.io/wave-ui/w-accordion#w-accordion-item`
|
|
188
|
+
)
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
|
|
192
|
+
unmounted () {
|
|
193
|
+
this.accordionItems = []
|
|
180
194
|
},
|
|
181
195
|
|
|
182
196
|
watch: {
|
|
183
|
-
modelValue () {
|
|
184
|
-
this.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
197
|
+
modelValue (array) {
|
|
198
|
+
if (this.expandSingle) {
|
|
199
|
+
const firstExpandedIndex = array.findIndex(bool => !!bool)
|
|
200
|
+
if (firstExpandedIndex > -1) array = array.fill(false, firstExpandedIndex + 1)
|
|
201
|
+
}
|
|
202
|
+
array.forEach((bool, i) => ((this.accordionItems[i] || {})._expanded = bool))
|
|
188
203
|
}
|
|
189
204
|
}
|
|
190
205
|
}
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
//- Title.
|
|
21
21
|
slot(
|
|
22
22
|
name="title"
|
|
23
|
-
:item="(accordionItem)"
|
|
23
|
+
:item="getOriginalItem(accordionItem)"
|
|
24
24
|
:expanded="accordionItem._expanded"
|
|
25
25
|
:index="accordionItem._index + 1")
|
|
26
26
|
.grow(v-html="accordionItem[options.itemTitleKey]")
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
.w-accordion__item-content(v-if="accordionItem._expanded" :class="contentClasses")
|
|
38
38
|
slot(
|
|
39
39
|
name="content"
|
|
40
|
-
:item="(accordionItem)"
|
|
40
|
+
:item="getOriginalItem(accordionItem)"
|
|
41
41
|
:expanded="accordionItem._expanded"
|
|
42
42
|
:index="accordionItem._index + 1")
|
|
43
43
|
div(v-html="accordionItem[options.itemContentKey]")
|
|
@@ -48,44 +48,38 @@ export default {
|
|
|
48
48
|
name: 'w-accordion-item',
|
|
49
49
|
|
|
50
50
|
props: {
|
|
51
|
-
|
|
51
|
+
title: { type: String },
|
|
52
|
+
content: { type: String },
|
|
53
|
+
expanded: { type: Boolean },
|
|
54
|
+
disabled: { type: Boolean }
|
|
52
55
|
},
|
|
53
56
|
|
|
54
57
|
inject: [
|
|
55
58
|
'options',
|
|
56
|
-
'itemClasses',
|
|
57
59
|
'titleClasses',
|
|
58
60
|
'contentClasses',
|
|
59
61
|
'onItemToggle',
|
|
60
62
|
'onEndOfCollapse',
|
|
61
63
|
'getOriginalItem',
|
|
64
|
+
'getAccordionItem',
|
|
62
65
|
'registerItem',
|
|
63
|
-
'
|
|
66
|
+
'unregisterItem'
|
|
64
67
|
],
|
|
65
68
|
|
|
66
69
|
emits: ['focus'],
|
|
67
70
|
|
|
68
|
-
data () {
|
|
69
|
-
return {
|
|
70
|
-
accordionItemIndex: this.item?._index
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
|
|
74
71
|
computed: {
|
|
75
72
|
accordionItem: {
|
|
76
73
|
get () {
|
|
77
|
-
return this.
|
|
74
|
+
return this.getAccordionItem(this._.uid)
|
|
78
75
|
},
|
|
79
|
-
set () {
|
|
80
|
-
|
|
81
|
-
}
|
|
76
|
+
set () {}
|
|
82
77
|
},
|
|
83
|
-
|
|
78
|
+
itemClasses () {
|
|
84
79
|
return {
|
|
85
80
|
'w-accordion__item--expanded': this.accordionItem._expanded,
|
|
86
81
|
'w-accordion__item--disabled': this.accordionItem._disabled,
|
|
87
|
-
[this.accordionItem[this.options.itemColorKey]]: this.accordionItem[this.options.itemColorKey]
|
|
88
|
-
...this.accordionItemClasses
|
|
82
|
+
[this.accordionItem[this.options.itemColorKey]]: this.accordionItem[this.options.itemColorKey]
|
|
89
83
|
}
|
|
90
84
|
}
|
|
91
85
|
},
|
|
@@ -106,12 +100,18 @@ export default {
|
|
|
106
100
|
|
|
107
101
|
created () {
|
|
108
102
|
// Register this item to the w-accordion component.
|
|
109
|
-
this.
|
|
103
|
+
this.registerItem({
|
|
104
|
+
_cuid: this._.uid,
|
|
110
105
|
_index: 0,
|
|
111
|
-
_expanded:
|
|
112
|
-
_disabled:
|
|
113
|
-
|
|
106
|
+
_expanded: this.expanded,
|
|
107
|
+
_disabled: this.disabled,
|
|
108
|
+
title: this.title,
|
|
109
|
+
content: this.content
|
|
114
110
|
})
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
beforeUnmount () {
|
|
114
|
+
this.unregisterItem(this._.uid)
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
</script>
|