wave-ui 3.16.3 → 3.17.1

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,241 +0,0 @@
1
- <template lang="pug">
2
- .w-accordion(:class="accordionClasses")
3
- .w-accordion__item(
4
- v-for="(item, i) in accordionItems"
5
- :key="i"
6
- :class="itemClasses(item)"
7
- :aria-expanded="item._expanded ? 'true' : 'false'")
8
- .w-accordion__item-title(
9
- @click="!item._disabled && toggleItem(item, $event)"
10
- @focus="$emit('focus', getOriginalItem(item))"
11
- @keypress.enter="!item._disabled && toggleItem(item, $event)"
12
- :tabindex="!item._disabled && 0"
13
- :class="titleClasses")
14
- //- Expand icon on left.
15
- w-button.w-accordion__expand-icon(
16
- v-if="expandIcon && !expandIconRight"
17
- :icon="(item._expanded && collapseIcon) || expandIcon"
18
- :icon-props="expandIconProps"
19
- :disabled="item._disabled || null"
20
- :tabindex="-1"
21
- text
22
- @keypress.stop
23
- @click.stop="!item._disabled && toggleItem(item, $event)"
24
- :class="{ 'w-accordion__expand-icon--expanded': item._expanded, 'w-accordion__expand-icon--rotate90': expandIconRotate90 }")
25
- //- Title.
26
- slot(
27
- v-if="$slots[`item-title.${item.id || i + 1}`]"
28
- :name="`item-title.${item.id || i + 1}`"
29
- :item="getOriginalItem(item)"
30
- :expanded="item._expanded" :index="i + 1")
31
- slot(v-else name="item-title" :item="getOriginalItem(item)" :expanded="item._expanded" :index="i + 1")
32
- div.grow(v-html="item[itemTitleKey]")
33
- //- Expand icon on right.
34
- w-button.w-accordion__expand-icon(
35
- v-if="expandIcon && expandIconRight"
36
- :icon="(item._expanded && collapseIcon) || expandIcon"
37
- text
38
- @keypress.stop
39
- @click.stop="!item._disabled && toggleItem(item, $event)"
40
- :class="{ 'w-accordion__expand-icon--expanded': item._expanded, 'w-accordion__expand-icon--rotate90': expandIconRotate90 }")
41
- //- Content.
42
- w-transition-expand(
43
- y
44
- @after-leave="onEndOfCollapse(item)"
45
- :duration="duration")
46
- .w-accordion__item-content(
47
- v-if="item._expanded"
48
- :class="contentClasses")
49
- slot(
50
- v-if="$slots[`item-content.${item.id || i + 1}`]"
51
- :name="`item-content.${item.id || i + 1}`"
52
- :item="getOriginalItem(item)"
53
- :expanded="item._expanded"
54
- :index="i + 1")
55
- slot(
56
- v-else
57
- name="item-content"
58
- :item="getOriginalItem(item)"
59
- :expanded="item._expanded"
60
- :index="i + 1")
61
- div(v-html="item[itemContentKey]")
62
- </template>
63
-
64
- <script>
65
- import { objectifyClasses } from '../utils/index'
66
-
67
- export default {
68
- name: 'w-accordion',
69
-
70
- props: {
71
- modelValue: { type: Array },
72
- color: { type: String },
73
- bgColor: { type: String },
74
- items: { type: [Array, Number], required: true },
75
- itemColorKey: { type: String, default: 'color' }, // Support a different color per item.
76
- itemTitleKey: { type: String, default: 'title' },
77
- itemContentKey: { type: String, default: 'content' },
78
- itemClass: { type: [String, Array, Object] },
79
- titleClass: { type: [String, Array, Object] },
80
- contentClass: { type: [String, Array, Object] },
81
- expandIcon: { type: [String, Boolean], default: 'wi-triangle-down' },
82
- expandIconRight: { type: Boolean },
83
- expandIconRotate90: { type: Boolean },
84
- expandIconProps: { type: Object, default: () => ({}) },
85
- expandSingle: { type: Boolean },
86
- collapseIcon: { type: String },
87
- shadow: { type: Boolean },
88
- duration: { type: Number, default: 250 },
89
- dark: { type: Boolean },
90
- light: { type: Boolean }
91
- },
92
-
93
- emits: ['input', 'update:modelValue', 'focus', 'item-expand', 'item-collapsed'],
94
-
95
- data: () => ({
96
- accordionItems: []
97
- }),
98
-
99
- computed: {
100
- accordionClasses () {
101
- return {
102
- [this.color]: this.color,
103
- [`${this.bgColor}--bg`]: this.bgColor,
104
- 'w-accordion--dark': this.dark,
105
- 'w-accordion--light': this.light,
106
- 'w-accordion--shadow': this.shadow,
107
- 'w-accordion--no-icon': !this.expandIcon && !this.collapseIcon,
108
- 'w-accordion--icon-right': this.expandIcon && this.expandIconRight,
109
- 'w-accordion--rotate-icon': this.expandIcon && !this.collapseIcon
110
- }
111
- },
112
-
113
- titleClasses () {
114
- return objectifyClasses(this.titleClass)
115
- },
116
-
117
- contentClasses () {
118
- return objectifyClasses(this.contentClass)
119
- }
120
- },
121
-
122
- methods: {
123
- toggleItem (item, e) {
124
- item._expanded = !item._expanded
125
- if (this.expandSingle) this.accordionItems.forEach(obj => obj._index !== item._index && (obj._expanded = false))
126
- const expandedItems = this.accordionItems.map(item => item._expanded || false)
127
- this.$emit('update:modelValue', expandedItems)
128
- this.$emit('input', expandedItems)
129
- this.$emit('item-expand', { item, expanded: item._expanded })
130
-
131
- // When a focused item moves in the page, the scrollTop is naturally updated by the browser.
132
- // So if expandSingle is set to true, clicking on the next title of an open pane would shift the
133
- // scrollTop unless unfocused while transitioning. #3.
134
- e.target.blur()
135
- setTimeout(() => e.target.focus(), 300)
136
- },
137
- onEndOfCollapse (item) {
138
- this.$emit('item-collapsed', { item, expanded: item._expanded })
139
- },
140
- // Return the original accordion item (so there is no `_index`, etc.).
141
- getOriginalItem (item) {
142
- return this.items[item._index]
143
- },
144
- itemClasses (item) {
145
- return {
146
- 'w-accordion__item--expanded': item._expanded,
147
- 'w-accordion__item--disabled': item._disabled,
148
- [item[this.itemColorKey]]: item[this.itemColorKey],
149
- ...objectifyClasses(this.itemClass)
150
- }
151
- },
152
- updateItems () {
153
- const items = typeof this.items === 'number' ? Array(this.items).fill({}) : this.items || []
154
- this.accordionItems = items.map((item, _index) => ({
155
- ...item,
156
- _index,
157
- _expanded: this.modelValue && this.modelValue[_index],
158
- _disabled: !!item.disabled
159
- }))
160
- }
161
- },
162
-
163
- created () {
164
- this.updateItems()
165
- },
166
-
167
- watch: {
168
- modelValue () {
169
- this.updateItems()
170
- },
171
- items: {
172
- handler () {
173
- this.updateItems()
174
- },
175
- deep: true
176
- }
177
- }
178
- }
179
- </script>
180
-
181
- <style lang="scss">
182
- .w-accordion {
183
- z-index: 1;
184
-
185
- @include themeable;
186
-
187
- &--shadow {box-shadow: $box-shadow;}
188
-
189
- &__item {position: relative;}
190
-
191
- button.w-accordion__expand-icon {color: rgba(var(--w-base-color-rgb), 0.4);}
192
- &__expand-icon {
193
- margin-right: $base-increment;
194
-
195
- .w-accordion--rotate-icon & {@include default-transition;}
196
- &--rotate90 {transform: rotate(-90deg);}
197
- &--expanded {transform: rotate(-180deg);}
198
- &--expanded.w-accordion__expand-icon--rotate90 {transform: rotate(0deg);}
199
-
200
- .w-icon:before {font-size: 1.1em;}
201
- }
202
-
203
- &__item-title {
204
- position: relative;
205
- display: flex;
206
- align-items: center;
207
- font-size: round(1.2 * $base-font-size);
208
- padding: 1 * $base-increment;
209
- user-select: none;
210
- cursor: pointer;
211
- border-top: $border;
212
- -webkit-tap-highlight-color: transparent;
213
-
214
- .w-accordion__item--disabled & {
215
- cursor: not-allowed;
216
- opacity: 0.6;
217
- -webkit-tap-highlight-color: transparent;
218
- }
219
- .w-accordion--no-icon &, .w-accordion--icon-right & {padding-left: 3 * $base-increment;}
220
-
221
- .w-accordion__item:first-child & {border-top-color: transparent;}
222
-
223
- &:before {
224
- content: '';
225
- position: absolute;
226
- inset: 0;
227
- background-color: currentColor;
228
- opacity: 0;
229
- transition: $fast-transition-duration;
230
- }
231
-
232
- &:focus:before, &:hover:before {opacity: 0.03;}
233
- &:active:before {opacity: 0.05;}
234
- .w-accordion__item--disabled &:before {display: none;}
235
- }
236
-
237
- &__item-content {
238
- padding: (2 * $base-increment) (3 * $base-increment);
239
- }
240
- }
241
- </style>