@kiva/kv-components 3.0.2 → 3.0.5

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/CHANGELOG.md CHANGED
@@ -3,6 +3,37 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [3.0.5](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@3.0.4...@kiva/kv-components@3.0.5) (2022-05-27)
7
+
8
+ **Note:** Version bump only for package @kiva/kv-components
9
+
10
+
11
+
12
+
13
+
14
+ ## [3.0.4](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@3.0.3...@kiva/kv-components@3.0.4) (2022-05-23)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * remove usage of currentInstance, re-implement indicator count update mechanism ([21dae02](https://github.com/kiva/kv-ui-elements/commit/21dae029094bdeecd4d352eea70a116c08af504c))
20
+
21
+
22
+
23
+
24
+
25
+ ## [3.0.3](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@3.0.2...@kiva/kv-components@3.0.3) (2022-05-16)
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * added back initial uuid value. ([aa4a88c](https://github.com/kiva/kv-ui-elements/commit/aa4a88c5a65846e9103ce25985bd7d1cc7bfd025))
31
+ * label and input uuids didn't match ([742452a](https://github.com/kiva/kv-ui-elements/commit/742452a9ffe03980f10f444a99f253429d028170))
32
+
33
+
34
+
35
+
36
+
6
37
  ## [3.0.2](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@3.0.1...@kiva/kv-components@3.0.2) (2022-03-18)
7
38
 
8
39
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kiva/kv-components",
3
- "version": "3.0.2",
3
+ "version": "3.0.5",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -68,5 +68,5 @@
68
68
  "optional": true
69
69
  }
70
70
  },
71
- "gitHead": "8704a80f645946a36d1f4ae7a7696770177b4b47"
71
+ "gitHead": "755f33ac5b3f1dc771a42881da3a449feff69df2"
72
72
  }
@@ -14,7 +14,7 @@
14
14
  :key="index"
15
15
  class="tw-flex-none tw-relative"
16
16
  role="group"
17
- :aria-label="`slide ${index} of ${componentSlotKeys.length}`"
17
+ :aria-label="`slide ${index + 1} of ${componentSlotKeys.length}`"
18
18
  :aria-current="true ? currentIndex + 1 === index : false"
19
19
  :aria-hidden="isAriaHidden(index)"
20
20
  :tab-index="isAriaHidden(index) ? '-1' : false"
@@ -28,6 +28,7 @@
28
28
  </div>
29
29
  <!-- Carousel Controls -->
30
30
  <div
31
+ v-if="slideIndicatorCount > 1"
31
32
  class="tw-flex
32
33
  tw-justify-between md:tw-justify-center tw-items-center
33
34
  tw-mt-4 tw-w-full"
@@ -48,8 +49,11 @@
48
49
  />
49
50
  <span class="tw-sr-only">Show previous slide</span>
50
51
  </button>
51
- <div class="tw-mx-2 md:tw-mx-3 lg:tw-mx-4 tw-invisible md:tw-visible">
52
- {{ currentIndex + 1 }}/{{ slideIndicatorListLength() }}
52
+ <div
53
+ :aria-label="`screen ${currentIndex + 1} of ${slideIndicatorCount}`"
54
+ class="tw-mx-2 md:tw-mx-3 lg:tw-mx-4 tw-invisible md:tw-visible"
55
+ >
56
+ {{ currentIndex + 1 }}/{{ slideIndicatorCount }}
53
57
  </div>
54
58
  <button
55
59
  class="tw-text-primary
@@ -79,7 +83,6 @@ import {
79
83
  ref,
80
84
  toRefs,
81
85
  nextTick,
82
- getCurrentInstance,
83
86
  } from 'vue-demi';
84
87
  import EmblaCarousel from 'embla-carousel';
85
88
  import { mdiChevronLeft, mdiChevronRight } from '@mdi/js';
@@ -144,11 +147,8 @@ export default {
144
147
  const embla = ref(null);
145
148
  const slides = ref([]);
146
149
  const currentIndex = ref(0);
147
-
148
- const forceUpdate = () => {
149
- const instance = getCurrentInstance();
150
- instance.proxy.$forceUpdate();
151
- };
150
+ // The indicator count may differ from the slide count when multiple slides are in view
151
+ const slideIndicatorCount = ref(0);
152
152
 
153
153
  const componentSlotKeys = computed(() => {
154
154
  const keys = Object.keys(slots);
@@ -193,6 +193,18 @@ export default {
193
193
  */
194
194
  emit('interact-carousel', interactionType);
195
195
  };
196
+
197
+ /**
198
+ * Returns number of slides in the carousel
199
+ *
200
+ * @returns {Number}
201
+ */
202
+ const slideIndicatorListLength = () => {
203
+ const indicator = embla.value ? embla.value.scrollSnapList().length : 0;
204
+ slideIndicatorCount.value = indicator;
205
+ return indicator;
206
+ };
207
+
196
208
  /**
197
209
  * Reinitialize the carousel.
198
210
  * Used after adding slides dynamically.
@@ -214,7 +226,7 @@ export default {
214
226
  reInitVisible();
215
227
  }
216
228
  slides.value = embla.value.slideNodes();
217
- forceUpdate(); // force a re-render so embla.canScrollNext() gets called in the template
229
+ slideIndicatorListLength();
218
230
  };
219
231
  const onCarouselContainerClick = (e) => {
220
232
  // If we're dragging, block click handlers within slides
@@ -238,18 +250,8 @@ export default {
238
250
  }
239
251
  return false;
240
252
  };
241
- /**
242
- * Returns number of slides in the carousel
243
- *
244
- * @returns {Number}
245
- */
246
- const slideIndicatorListLength = () => {
247
- const indicator = embla.value ? embla.value.scrollSnapList().length : 0;
248
- return indicator;
249
- };
250
253
 
251
254
  onMounted(async () => {
252
- getCurrentInstance();
253
255
  embla.value = EmblaCarousel(rootEl.value, {
254
256
  loop: true,
255
257
  containScroll: 'trimSnaps',
@@ -268,23 +270,26 @@ export default {
268
270
  slidesToScroll: embla.value.slidesInView(true).length,
269
271
  inViewThreshold: 0.9,
270
272
  });
271
- forceUpdate();
273
+ slides.value = embla.value.slideNodes();
274
+ slideIndicatorListLength();
272
275
  }, 250),
273
276
  );
274
277
  }
275
278
 
276
279
  // get slide components
277
280
  slides.value = embla.value.slideNodes();
281
+ slideIndicatorListLength();
278
282
 
279
283
  embla.value.on('select', () => {
280
284
  currentIndex.value = embla.value.selectedScrollSnap();
281
-
282
285
  /**
283
286
  * The index of the slide that the carousel has changed to
284
287
  * @event change
285
288
  * @type {Event}
286
289
  */
287
- emit('change', currentIndex);
290
+ nextTick(() => {
291
+ emit('change', currentIndex);
292
+ });
288
293
  });
289
294
  });
290
295
 
@@ -303,6 +308,7 @@ export default {
303
308
  componentSlotKeys,
304
309
  nextIndex,
305
310
  previousIndex,
311
+ slideIndicatorCount,
306
312
  handleUserInteraction,
307
313
  goToSlide,
308
314
  reInit,
package/vue/KvRadio.vue CHANGED
@@ -151,7 +151,7 @@ export default {
151
151
  modelValue,
152
152
  } = toRefs(props);
153
153
 
154
- let uuid = ref(`kvr-${nanoid(10)}`);
154
+ const uuid = ref(`kvr-${nanoid(10)}`);
155
155
  const radioRef = ref(null);
156
156
 
157
157
  const {
@@ -169,7 +169,7 @@ export default {
169
169
  });
170
170
 
171
171
  onMounted(() => {
172
- uuid = `kvr-${nanoid(10)}`;
172
+ uuid.value = `kvr-${nanoid(10)}`;
173
173
  });
174
174
 
175
175
  const onChange = (event) => {
@@ -164,6 +164,78 @@ export const MultipleLoanCards2 = () => ({
164
164
  `,
165
165
  });
166
166
 
167
+ export const MultipleLoanCardsReInit = () => ({
168
+ components: {
169
+ KvCarousel,
170
+ KvButton,
171
+ },
172
+ template: `
173
+ <div data-testid="carousel-container">
174
+ <kv-carousel
175
+ ref="myCarouselRef"
176
+ :multiple-slides-visible="true"
177
+ slides-to-scroll="visible"
178
+ style="max-width: 800px;"
179
+ >
180
+ <template #slide1>
181
+ ${generateLoanCardTemplate(1)}
182
+ </template>
183
+ <template #slide2>
184
+ ${generateLoanCardTemplate(2)}
185
+ </template>
186
+ <template #slide3>
187
+ ${generateLoanCardTemplate(3)}
188
+ </template>
189
+ <template #slide4>
190
+ ${generateLoanCardTemplate(4)}
191
+ </template>
192
+ <template #slide5>
193
+ ${generateLoanCardTemplate(5)}
194
+ </template>
195
+ <template #slide6>
196
+ ${generateLoanCardTemplate(6)}
197
+ </template>
198
+ <template #slide7>
199
+ ${generateLoanCardTemplate(7)}
200
+ </template>
201
+ <template #slide8>
202
+ ${generateLoanCardTemplate(8)}
203
+ </template>
204
+ </kv-carousel>
205
+ <kv-button @click.native.prevent="removeSlide()" role="removeSlideButton">Remove Slide</kv-button>
206
+ <p>Slide Count: {{ slideCount }} | Indicator Count: {{ slideIndicatorCount }} | Removed Slides: {{ removedSlides.length }}</p>
207
+ </div>
208
+ `,
209
+ data() {
210
+ return {
211
+ removedSlides: [],
212
+ slideCount: null,
213
+ slideIndicatorCount: null,
214
+ };
215
+ },
216
+ mounted() {
217
+ this.$nextTick(() => {
218
+ this.slideCount = this.$refs?.myCarouselRef?.slides?.length;
219
+ this.slideIndicatorCount = this.$refs?.myCarouselRef?.slideIndicatorCount;
220
+ });
221
+ },
222
+ methods: {
223
+ removeSlide() {
224
+ // Fetch slides + remove one
225
+ const slides = this.$refs?.myCarouselRef?.embla?.slideNodes();
226
+ const slideToRemove = slides.pop();
227
+ this.removedSlides.push(slideToRemove);
228
+ this.$refs?.myCarouselRef?.embla?.containerNode()?.removeChild(slideToRemove);
229
+ // Call our component reInit method
230
+ this.$refs?.myCarouselRef?.reInit();
231
+ // Update values for reflection in story
232
+ this.slideCount = this.$refs?.myCarouselRef?.slides?.length;
233
+ this.selectedIndexCheck = this.$refs?.myCarouselRef?.currentIndex;
234
+ this.slideIndicatorCount = this.$refs?.myCarouselRef?.slideIndicatorCount;
235
+ },
236
+ },
237
+ });
238
+
167
239
  export const loadingLoanCardExample = () => ({
168
240
  components: {
169
241
  KvCarousel,