wave-ui 3.17.0 → 3.17.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wave-ui",
3
- "version": "3.17.0",
3
+ "version": "3.17.2",
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",
@@ -6,7 +6,7 @@
6
6
  //- Else, when providing the items array or number through the items prop.
7
7
  template(v-else-if="!isNaN(items) || (items || []).length")
8
8
  w-accordion-item(
9
- v-for="(accordionItem, i) in accordionItems"
9
+ v-for="(accordionItem, i) in state.accordionItems"
10
10
  :key="i"
11
11
  :class="itemClass"
12
12
  :item="accordionItem"
@@ -81,17 +81,19 @@ export default {
81
81
  itemClasses: objectifyClasses(this.itemClasses),
82
82
  titleClasses: this.titleClasses,
83
83
  contentClasses: this.contentClasses,
84
- toggleItem: this.toggleItem,
84
+ onItemToggle: this.onItemToggle,
85
85
  onEndOfCollapse: this.onEndOfCollapse,
86
86
  getOriginalItem: this.getOriginalItem,
87
87
  options: this.$props,
88
- registerItem: this.registerItem
88
+ registerItem: this.registerItem,
89
+ state: this.state
89
90
  }
90
91
  },
91
92
 
92
93
  data: () => ({
93
- accordionItems: [],
94
- registeredAccordionItems: [] // When using w-accordion-item component and not items prop.
94
+ state: {
95
+ accordionItems: []
96
+ }
95
97
  }),
96
98
 
97
99
  computed: {
@@ -127,21 +129,12 @@ export default {
127
129
  },
128
130
 
129
131
  methods: {
130
- toggleItem (item, e) {
131
- item._expanded = !item._expanded
132
-
133
- const items = this.registeredAccordionItems.length ? this.registeredAccordionItems : this.accordionItems
134
- if (this.expandSingle) items.forEach(obj => obj._index !== item._index && (obj._expanded = false))
135
- const expandedItems = items.map(item => item._expanded || false)
132
+ onItemToggle (item) {
133
+ if (this.expandSingle) this.state.accordionItems.forEach(obj => obj._index !== item._index && (obj._expanded = false))
134
+ const expandedItems = this.state.accordionItems.map(item => item._expanded || false)
136
135
  this.$emit('update:modelValue', expandedItems)
137
136
  this.$emit('input', expandedItems)
138
137
  this.$emit('item-expand', { item, expanded: item._expanded })
139
-
140
- // When a focused item moves in the page, the scrollTop is naturally updated by the browser.
141
- // So if expandSingle is set to true, clicking on the next title of an open pane would shift the
142
- // scrollTop unless unfocused while transitioning. #3.
143
- e.target.blur()
144
- setTimeout(() => e.target.focus(), 300)
145
138
  },
146
139
 
147
140
  onEndOfCollapse (item) {
@@ -150,18 +143,19 @@ export default {
150
143
 
151
144
  // Return the original accordion item (so there is no `_index`, etc.).
152
145
  getOriginalItem (item) {
153
- return (this.registeredAccordionItems.length ? this.registeredAccordionItems : this.items)[item._index]
146
+ return this.items[item._index]
154
147
  },
155
148
 
156
149
  updateItems () {
157
- let items = []
158
- if (this.registeredAccordionItems.length) items = this.registeredAccordionItems
159
- else items = (typeof this.items === 'number' ? Array(this.items).fill({}) : this.items) || []
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
+ }
160
154
 
161
- this.accordionItems = items.map((item, _index) => ({
155
+ this.state.accordionItems = items.map((item, _index) => ({
162
156
  ...item,
163
157
  _index,
164
- _expanded: this.modelValue && this.modelValue[_index],
158
+ _expanded: this.modelValue?.[_index] ?? false,
165
159
  _disabled: !!item.disabled
166
160
  }))
167
161
  },
@@ -169,18 +163,20 @@ export default {
169
163
  // Provide-injected in and used from w-accordion-item.
170
164
  // Only when w-accordion-item is directly used outside of Wave UI.
171
165
  registerItem (item) {
172
- if (!this.items) {
173
- item._index = this.registeredAccordionItems.length
174
- item._expanded = this.modelValue?.[item._index] || false
166
+ if (this.accordionItemsProvided) {
167
+ item._index = this.state.accordionItems.length
168
+ item._expanded = this.modelValue?.[item._index] ?? false
169
+ item._disabled = !!item.disabled
175
170
 
176
- this.registeredAccordionItems.push(item)
177
- this.updateItems()
171
+ this.state.accordionItems.push(item)
178
172
  }
173
+
174
+ return item._index
179
175
  }
180
176
  },
181
177
 
182
178
  created () {
183
- this.updateItems()
179
+ if (!this.accordionItemsProvided && this.items) this.updateItems()
184
180
  },
185
181
 
186
182
  watch: {
@@ -188,7 +184,7 @@ export default {
188
184
  this.updateItems()
189
185
  },
190
186
  items () {
191
- this.updateItems()
187
+ // this.updateItems()
192
188
  }
193
189
  }
194
190
  }
@@ -2,7 +2,7 @@
2
2
  .w-accordion__item(:class="itemClasses" :aria-expanded="accordionItem._expanded ? 'true' : 'false'")
3
3
  .w-accordion__item-title(
4
4
  @click="!accordionItem._disabled && toggleItem(accordionItem, $event)"
5
- @focus="$emit('focus', getOriginalItem(accordionItem))"
5
+ @focus="$emit('focus', (accordionItem))"
6
6
  @keypress.enter="!accordionItem._disabled && toggleItem(accordionItem, $event)"
7
7
  :tabindex="!accordionItem._disabled && 0"
8
8
  :class="titleClasses")
@@ -20,7 +20,7 @@
20
20
  //- Title.
21
21
  slot(
22
22
  name="title"
23
- :item="getOriginalItem(accordionItem)"
23
+ :item="(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="getOriginalItem(accordionItem)"
40
+ :item="(accordionItem)"
41
41
  :expanded="accordionItem._expanded"
42
42
  :index="accordionItem._index + 1")
43
43
  div(v-html="accordionItem[options.itemContentKey]")
@@ -56,26 +56,30 @@ export default {
56
56
  'itemClasses',
57
57
  'titleClasses',
58
58
  'contentClasses',
59
- 'toggleItem',
59
+ 'onItemToggle',
60
60
  'onEndOfCollapse',
61
61
  'getOriginalItem',
62
- 'registerItem'
62
+ 'registerItem',
63
+ 'state'
63
64
  ],
64
65
 
65
66
  emits: ['focus'],
66
67
 
67
68
  data () {
68
69
  return {
69
- accordionItem: {
70
- ...(this.item || {}),
71
- _index: this.item?._index ?? 0,
72
- _expanded: this.item?._expanded || false,
73
- _disabled: this.item?._disabled || false
74
- }
70
+ accordionItemIndex: this.item?._index
75
71
  }
76
72
  },
77
73
 
78
74
  computed: {
75
+ accordionItem: {
76
+ get () {
77
+ return this.state.accordionItems[this.accordionItemIndex] || {}
78
+ },
79
+ set () {
80
+
81
+ }
82
+ },
79
83
  itemClass () {
80
84
  return {
81
85
  'w-accordion__item--expanded': this.accordionItem._expanded,
@@ -86,27 +90,46 @@ export default {
86
90
  }
87
91
  },
88
92
 
93
+ methods: {
94
+ toggleItem (item, e) {
95
+ item._expanded = !item._expanded
96
+
97
+ this.onItemToggle(item)
98
+
99
+ // When a focused item moves in the page, the scrollTop is naturally updated by the browser.
100
+ // So if expandSingle is set to true, clicking on the next title of an open pane would shift the
101
+ // scrollTop unless unfocused while transitioning. Issue #3.
102
+ e.target.blur()
103
+ setTimeout(() => e.target.focus(), 300)
104
+ }
105
+ },
106
+
89
107
  created () {
90
108
  // Register this item to the w-accordion component.
91
- this.registerItem(this.accordionItem)
109
+ this.accordionItemIndex = this.registerItem({
110
+ _index: 0,
111
+ _expanded: false,
112
+ _disabled: false,
113
+ ...(this.item || {})
114
+ })
92
115
  }
93
116
  }
94
117
  </script>
95
118
 
96
119
  <style lang="scss">
97
- .w-accordion__item {position: relative;}
120
+ .w-accordion__item {position: relative;}
98
121
 
99
- button.w-accordion__expand-icon {color: rgba(var(--w-base-color-rgb), 0.4);}
100
- .w-accordion__expand-icon {
101
- margin-right: $base-increment;
122
+ button.w-accordion__expand-icon {color: rgba(var(--w-base-color-rgb), 0.4);}
123
+ .w-accordion__expand-icon {
124
+ margin-right: $base-increment;
102
125
 
103
- .w-accordion--rotate-icon & {@include default-transition;}
104
- &--rotate90 {transform: rotate(-90deg);}
105
- &--expanded {transform: rotate(-180deg);}
106
- &--expanded.w-accordion__expand-icon--rotate90 {transform: rotate(0deg);}
126
+ .w-accordion--rotate-icon & {@include default-transition;}
127
+ &--rotate90 {transform: rotate(-90deg);}
128
+ &--expanded {transform: rotate(-180deg);}
129
+ &--expanded.w-accordion__expand-icon--rotate90 {transform: rotate(0deg);}
107
130
 
108
- .w-icon:before {font-size: 1.1em;}
109
- }
131
+ .w-icon:before {font-size: 1.1em;}
132
+ }
110
133
 
111
134
  .w-accordion__item-title {
112
135
  position: relative;
@@ -145,5 +168,4 @@ export default {
145
168
  .w-accordion__item-content {
146
169
  padding: (2 * $base-increment) (3 * $base-increment);
147
170
  }
148
-
149
171
  </style>