@kiva/kv-components 4.8.3 → 4.8.4
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 +11 -0
- package/dist/components/stories/KvVerticalCarousel.stories.js +61 -0
- package/dist/utils/carousels.cjs +15 -12
- package/dist/utils/carousels.js +1 -1
- package/dist/utils/{chunk-WJV72VFJ.js → chunk-NP3OH5YJ.js} +15 -12
- package/dist/utils/index.cjs +15 -12
- package/dist/utils/index.js +1 -1
- package/package.json +2 -2
- package/utils/carousels.js +21 -12
- package/vue/stories/KvVerticalCarousel.stories.js +61 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
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
|
+
## [4.8.4](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@4.8.3...@kiva/kv-components@4.8.4) (2025-01-10)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* carousel autoplay issues ([ae1e7eb](https://github.com/kiva/kv-ui-elements/commit/ae1e7ebf82181b3c9fed505d3ad5afce41dcabba))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [4.8.3](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@4.8.2...@kiva/kv-components@4.8.3) (2025-01-10)
|
|
7
18
|
|
|
8
19
|
|
|
@@ -189,12 +189,18 @@ export const AutoPlayButton = () => ({
|
|
|
189
189
|
},
|
|
190
190
|
data: () => ({
|
|
191
191
|
isAutoplaying: false,
|
|
192
|
+
currentSlide: 0,
|
|
192
193
|
}),
|
|
193
194
|
mounted() {
|
|
194
195
|
watch(() => this.$refs?.sampleCarousel?.isAutoplaying, (newValue) => {
|
|
195
196
|
this.isAutoplaying = newValue;
|
|
196
197
|
});
|
|
197
198
|
},
|
|
199
|
+
methods: {
|
|
200
|
+
changeEvent(index) {
|
|
201
|
+
this.currentSlide = index;
|
|
202
|
+
},
|
|
203
|
+
},
|
|
198
204
|
template: `
|
|
199
205
|
<div>
|
|
200
206
|
<kv-vertical-carousel
|
|
@@ -202,6 +208,7 @@ export const AutoPlayButton = () => ({
|
|
|
202
208
|
style="max-width: 400px;"
|
|
203
209
|
:embla-options="{ loop: false }"
|
|
204
210
|
:autoplay-options="{ playOnInit: true, delay: 3000 }"
|
|
211
|
+
@change="changeEvent"
|
|
205
212
|
>
|
|
206
213
|
${defaultCarouselSlides}
|
|
207
214
|
</kv-vertical-carousel>
|
|
@@ -209,6 +216,60 @@ export const AutoPlayButton = () => ({
|
|
|
209
216
|
<br/>
|
|
210
217
|
<p>AutoPlay is: {{ isAutoplaying ? 'ON' : 'OFF' }}</p>
|
|
211
218
|
<a href="#" @click.native.prevent="$refs.sampleCarousel.goToSlide(0)">Go To Slide 0</a>
|
|
219
|
+
<p>Current Slide: {{ currentSlide }}</p>
|
|
220
|
+
</div>
|
|
221
|
+
`,
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
export const AutoPlayWithDynamicSlides = () => ({
|
|
225
|
+
components: {
|
|
226
|
+
KvVerticalCarousel,
|
|
227
|
+
},
|
|
228
|
+
data: () => ({
|
|
229
|
+
isAutoplaying: false,
|
|
230
|
+
currentSlide: 0,
|
|
231
|
+
}),
|
|
232
|
+
mounted() {
|
|
233
|
+
watch(() => this.$refs?.sampleCarousel?.isAutoplaying, (newValue) => {
|
|
234
|
+
this.isAutoplaying = newValue;
|
|
235
|
+
});
|
|
236
|
+
},
|
|
237
|
+
methods: {
|
|
238
|
+
changeEvent(index) {
|
|
239
|
+
this.currentSlide = index;
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
template: `
|
|
243
|
+
<div>
|
|
244
|
+
<kv-vertical-carousel
|
|
245
|
+
ref="sampleCarousel"
|
|
246
|
+
style="max-width: 400px;"
|
|
247
|
+
:embla-options="{ loop: false }"
|
|
248
|
+
:autoplay-options="{ playOnInit: true, delay: 3000 }"
|
|
249
|
+
@change="changeEvent"
|
|
250
|
+
>
|
|
251
|
+
<template #slide1 >
|
|
252
|
+
<img src="https://placehold.co/400x150/${randomHexColor(1)}/000000">
|
|
253
|
+
<p style="background-color: #${randomHexColor(1)};" v-if="currentSlide === 0" >Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
|
|
254
|
+
</template>
|
|
255
|
+
<template #slide2>
|
|
256
|
+
<img src="https://placehold.co/400x150/${randomHexColor(2)}/000000">
|
|
257
|
+
<p style="background-color: #${randomHexColor(2)};" v-if="currentSlide === 1">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
|
|
258
|
+
</template>
|
|
259
|
+
<template #slide3>
|
|
260
|
+
<img src="https://placehold.co/400x150/${randomHexColor(3)}/000000">
|
|
261
|
+
<p style="background-color: #${randomHexColor(3)};" v-if="currentSlide === 2">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
|
|
262
|
+
</template>
|
|
263
|
+
<template #slide4>
|
|
264
|
+
<img src="https://placehold.co/400x150/${randomHexColor(4)}/000000">
|
|
265
|
+
<p style="background-color: #${randomHexColor(4)};" v-if="currentSlide === 3">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
|
|
266
|
+
</template>
|
|
267
|
+
</kv-vertical-carousel>
|
|
268
|
+
<a href="#" @click.native.prevent="$refs.sampleCarousel.toggleAutoPlay()" role="toggleAutoPlayButton">Toggle AutoPlay</a>
|
|
269
|
+
<br/>
|
|
270
|
+
<p>AutoPlay is: {{ isAutoplaying ? 'ON' : 'OFF' }}</p>
|
|
271
|
+
<a href="#" @click.native.prevent="$refs.sampleCarousel.goToSlide(0)">Go To Slide 0</a>
|
|
272
|
+
<p>Current Slide: {{ currentSlide }}</p>
|
|
212
273
|
</div>
|
|
213
274
|
`,
|
|
214
275
|
});
|
package/dist/utils/carousels.cjs
CHANGED
|
@@ -92,15 +92,10 @@ function carouselUtil(props, { emit, slots }, extraEmblaOptions) {
|
|
|
92
92
|
embla.value.scrollTo(index);
|
|
93
93
|
};
|
|
94
94
|
const handleUserInteraction = async (index, interactionType) => {
|
|
95
|
-
var _a2, _b;
|
|
96
95
|
if (index !== null && typeof index !== "undefined") {
|
|
97
96
|
await (0, import_vue_demi.nextTick)();
|
|
98
97
|
goToSlide(index);
|
|
99
98
|
}
|
|
100
|
-
const autoplay = (_b = (_a2 = embla.value) == null ? void 0 : _a2.plugins()) == null ? void 0 : _b.autoplay;
|
|
101
|
-
if (autoplay) {
|
|
102
|
-
autoplay.stop();
|
|
103
|
-
}
|
|
104
99
|
emit("interact-carousel", interactionType);
|
|
105
100
|
};
|
|
106
101
|
const toggleAutoPlay = () => {
|
|
@@ -134,7 +129,7 @@ function carouselUtil(props, { emit, slots }, extraEmblaOptions) {
|
|
|
134
129
|
slideIndicatorListLength();
|
|
135
130
|
};
|
|
136
131
|
const onCarouselContainerClick = (e) => {
|
|
137
|
-
if (embla.value
|
|
132
|
+
if (embla.value) {
|
|
138
133
|
e.preventDefault();
|
|
139
134
|
e.stopPropagation();
|
|
140
135
|
}
|
|
@@ -145,15 +140,18 @@ function carouselUtil(props, { emit, slots }, extraEmblaOptions) {
|
|
|
145
140
|
}
|
|
146
141
|
return false;
|
|
147
142
|
};
|
|
148
|
-
(0, import_vue_demi.
|
|
149
|
-
|
|
150
|
-
const combinedPluginOptions = [];
|
|
143
|
+
const combinedPluginOptions = (0, import_vue_demi.computed)(() => {
|
|
144
|
+
const options = [];
|
|
151
145
|
if (Object.keys(autoplayOptions.value).length !== 0) {
|
|
152
|
-
|
|
146
|
+
options.push((0, import_embla_carousel_autoplay.default)(autoplayOptions.value));
|
|
153
147
|
}
|
|
154
148
|
if (fadeEnabled.value) {
|
|
155
|
-
|
|
149
|
+
options.push((0, import_embla_carousel_fade.default)());
|
|
156
150
|
}
|
|
151
|
+
return options;
|
|
152
|
+
});
|
|
153
|
+
(0, import_vue_demi.onMounted)(async () => {
|
|
154
|
+
var _a2, _b, _c;
|
|
157
155
|
embla.value = (0, import_embla_carousel.default)(rootEl.value, {
|
|
158
156
|
loop: true,
|
|
159
157
|
containScroll: "trimSnaps",
|
|
@@ -161,7 +159,7 @@ function carouselUtil(props, { emit, slots }, extraEmblaOptions) {
|
|
|
161
159
|
align: "start",
|
|
162
160
|
...extraEmblaOptions,
|
|
163
161
|
...emblaOptions.value
|
|
164
|
-
}, combinedPluginOptions);
|
|
162
|
+
}, combinedPluginOptions.value);
|
|
165
163
|
if (slidesToScroll.value === "visible") {
|
|
166
164
|
reInitVisible();
|
|
167
165
|
embla.value.on(
|
|
@@ -179,7 +177,12 @@ function carouselUtil(props, { emit, slots }, extraEmblaOptions) {
|
|
|
179
177
|
slides.value = embla.value.slideNodes();
|
|
180
178
|
slideIndicatorListLength();
|
|
181
179
|
(_a2 = embla == null ? void 0 : embla.value) == null ? void 0 : _a2.on("select", () => {
|
|
180
|
+
var _a3, _b2;
|
|
182
181
|
currentIndex.value = embla.value.selectedScrollSnap();
|
|
182
|
+
const autoplay = (_b2 = (_a3 = embla.value) == null ? void 0 : _a3.plugins()) == null ? void 0 : _b2.autoplay;
|
|
183
|
+
if (autoplay) {
|
|
184
|
+
embla.value.plugins().autoplay.options.playOnInit = autoplay.isPlaying();
|
|
185
|
+
}
|
|
183
186
|
(0, import_vue_demi.nextTick)(() => {
|
|
184
187
|
emit("change", currentIndex);
|
|
185
188
|
});
|
package/dist/utils/carousels.js
CHANGED
|
@@ -56,15 +56,10 @@ function carouselUtil(props, { emit, slots }, extraEmblaOptions) {
|
|
|
56
56
|
embla.value.scrollTo(index);
|
|
57
57
|
};
|
|
58
58
|
const handleUserInteraction = async (index, interactionType) => {
|
|
59
|
-
var _a2, _b;
|
|
60
59
|
if (index !== null && typeof index !== "undefined") {
|
|
61
60
|
await nextTick();
|
|
62
61
|
goToSlide(index);
|
|
63
62
|
}
|
|
64
|
-
const autoplay = (_b = (_a2 = embla.value) == null ? void 0 : _a2.plugins()) == null ? void 0 : _b.autoplay;
|
|
65
|
-
if (autoplay) {
|
|
66
|
-
autoplay.stop();
|
|
67
|
-
}
|
|
68
63
|
emit("interact-carousel", interactionType);
|
|
69
64
|
};
|
|
70
65
|
const toggleAutoPlay = () => {
|
|
@@ -98,7 +93,7 @@ function carouselUtil(props, { emit, slots }, extraEmblaOptions) {
|
|
|
98
93
|
slideIndicatorListLength();
|
|
99
94
|
};
|
|
100
95
|
const onCarouselContainerClick = (e) => {
|
|
101
|
-
if (embla.value
|
|
96
|
+
if (embla.value) {
|
|
102
97
|
e.preventDefault();
|
|
103
98
|
e.stopPropagation();
|
|
104
99
|
}
|
|
@@ -109,15 +104,18 @@ function carouselUtil(props, { emit, slots }, extraEmblaOptions) {
|
|
|
109
104
|
}
|
|
110
105
|
return false;
|
|
111
106
|
};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const combinedPluginOptions = [];
|
|
107
|
+
const combinedPluginOptions = computed(() => {
|
|
108
|
+
const options = [];
|
|
115
109
|
if (Object.keys(autoplayOptions.value).length !== 0) {
|
|
116
|
-
|
|
110
|
+
options.push(Autoplay(autoplayOptions.value));
|
|
117
111
|
}
|
|
118
112
|
if (fadeEnabled.value) {
|
|
119
|
-
|
|
113
|
+
options.push(Fade());
|
|
120
114
|
}
|
|
115
|
+
return options;
|
|
116
|
+
});
|
|
117
|
+
onMounted(async () => {
|
|
118
|
+
var _a2, _b, _c;
|
|
121
119
|
embla.value = EmblaCarousel(rootEl.value, {
|
|
122
120
|
loop: true,
|
|
123
121
|
containScroll: "trimSnaps",
|
|
@@ -125,7 +123,7 @@ function carouselUtil(props, { emit, slots }, extraEmblaOptions) {
|
|
|
125
123
|
align: "start",
|
|
126
124
|
...extraEmblaOptions,
|
|
127
125
|
...emblaOptions.value
|
|
128
|
-
}, combinedPluginOptions);
|
|
126
|
+
}, combinedPluginOptions.value);
|
|
129
127
|
if (slidesToScroll.value === "visible") {
|
|
130
128
|
reInitVisible();
|
|
131
129
|
embla.value.on(
|
|
@@ -143,7 +141,12 @@ function carouselUtil(props, { emit, slots }, extraEmblaOptions) {
|
|
|
143
141
|
slides.value = embla.value.slideNodes();
|
|
144
142
|
slideIndicatorListLength();
|
|
145
143
|
(_a2 = embla == null ? void 0 : embla.value) == null ? void 0 : _a2.on("select", () => {
|
|
144
|
+
var _a3, _b2;
|
|
146
145
|
currentIndex.value = embla.value.selectedScrollSnap();
|
|
146
|
+
const autoplay = (_b2 = (_a3 = embla.value) == null ? void 0 : _a3.plugins()) == null ? void 0 : _b2.autoplay;
|
|
147
|
+
if (autoplay) {
|
|
148
|
+
embla.value.plugins().autoplay.options.playOnInit = autoplay.isPlaying();
|
|
149
|
+
}
|
|
147
150
|
nextTick(() => {
|
|
148
151
|
emit("change", currentIndex);
|
|
149
152
|
});
|
package/dist/utils/index.cjs
CHANGED
|
@@ -200,15 +200,10 @@ function carouselUtil(props, { emit, slots }, extraEmblaOptions) {
|
|
|
200
200
|
embla.value.scrollTo(index);
|
|
201
201
|
};
|
|
202
202
|
const handleUserInteraction = async (index, interactionType) => {
|
|
203
|
-
var _a2, _b;
|
|
204
203
|
if (index !== null && typeof index !== "undefined") {
|
|
205
204
|
await (0, import_vue_demi.nextTick)();
|
|
206
205
|
goToSlide(index);
|
|
207
206
|
}
|
|
208
|
-
const autoplay = (_b = (_a2 = embla.value) == null ? void 0 : _a2.plugins()) == null ? void 0 : _b.autoplay;
|
|
209
|
-
if (autoplay) {
|
|
210
|
-
autoplay.stop();
|
|
211
|
-
}
|
|
212
207
|
emit("interact-carousel", interactionType);
|
|
213
208
|
};
|
|
214
209
|
const toggleAutoPlay = () => {
|
|
@@ -242,7 +237,7 @@ function carouselUtil(props, { emit, slots }, extraEmblaOptions) {
|
|
|
242
237
|
slideIndicatorListLength();
|
|
243
238
|
};
|
|
244
239
|
const onCarouselContainerClick = (e) => {
|
|
245
|
-
if (embla.value
|
|
240
|
+
if (embla.value) {
|
|
246
241
|
e.preventDefault();
|
|
247
242
|
e.stopPropagation();
|
|
248
243
|
}
|
|
@@ -253,15 +248,18 @@ function carouselUtil(props, { emit, slots }, extraEmblaOptions) {
|
|
|
253
248
|
}
|
|
254
249
|
return false;
|
|
255
250
|
};
|
|
256
|
-
(0, import_vue_demi.
|
|
257
|
-
|
|
258
|
-
const combinedPluginOptions = [];
|
|
251
|
+
const combinedPluginOptions = (0, import_vue_demi.computed)(() => {
|
|
252
|
+
const options = [];
|
|
259
253
|
if (Object.keys(autoplayOptions.value).length !== 0) {
|
|
260
|
-
|
|
254
|
+
options.push((0, import_embla_carousel_autoplay.default)(autoplayOptions.value));
|
|
261
255
|
}
|
|
262
256
|
if (fadeEnabled.value) {
|
|
263
|
-
|
|
257
|
+
options.push((0, import_embla_carousel_fade.default)());
|
|
264
258
|
}
|
|
259
|
+
return options;
|
|
260
|
+
});
|
|
261
|
+
(0, import_vue_demi.onMounted)(async () => {
|
|
262
|
+
var _a2, _b, _c;
|
|
265
263
|
embla.value = (0, import_embla_carousel.default)(rootEl.value, {
|
|
266
264
|
loop: true,
|
|
267
265
|
containScroll: "trimSnaps",
|
|
@@ -269,7 +267,7 @@ function carouselUtil(props, { emit, slots }, extraEmblaOptions) {
|
|
|
269
267
|
align: "start",
|
|
270
268
|
...extraEmblaOptions,
|
|
271
269
|
...emblaOptions.value
|
|
272
|
-
}, combinedPluginOptions);
|
|
270
|
+
}, combinedPluginOptions.value);
|
|
273
271
|
if (slidesToScroll.value === "visible") {
|
|
274
272
|
reInitVisible();
|
|
275
273
|
embla.value.on(
|
|
@@ -287,7 +285,12 @@ function carouselUtil(props, { emit, slots }, extraEmblaOptions) {
|
|
|
287
285
|
slides.value = embla.value.slideNodes();
|
|
288
286
|
slideIndicatorListLength();
|
|
289
287
|
(_a2 = embla == null ? void 0 : embla.value) == null ? void 0 : _a2.on("select", () => {
|
|
288
|
+
var _a3, _b2;
|
|
290
289
|
currentIndex.value = embla.value.selectedScrollSnap();
|
|
290
|
+
const autoplay = (_b2 = (_a3 = embla.value) == null ? void 0 : _a3.plugins()) == null ? void 0 : _b2.autoplay;
|
|
291
|
+
if (autoplay) {
|
|
292
|
+
embla.value.plugins().autoplay.options.playOnInit = autoplay.isPlaying();
|
|
293
|
+
}
|
|
291
294
|
(0, import_vue_demi.nextTick)(() => {
|
|
292
295
|
emit("change", currentIndex);
|
|
293
296
|
});
|
package/dist/utils/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kiva/kv-components",
|
|
3
|
-
"version": "4.8.
|
|
3
|
+
"version": "4.8.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -98,5 +98,5 @@
|
|
|
98
98
|
"peerDependencies": {
|
|
99
99
|
"vue": ">=3.0.0"
|
|
100
100
|
},
|
|
101
|
-
"gitHead": "
|
|
101
|
+
"gitHead": "234b9a444b181da8f198a9dbb456e5b4162a4838"
|
|
102
102
|
}
|
package/utils/carousels.js
CHANGED
|
@@ -71,12 +71,6 @@ export function carouselUtil(props, { emit, slots }, extraEmblaOptions) {
|
|
|
71
71
|
goToSlide(index);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
/** Stop autoplay on user interaction */
|
|
75
|
-
const autoplay = embla.value?.plugins()?.autoplay;
|
|
76
|
-
if (autoplay) {
|
|
77
|
-
autoplay.stop();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
74
|
/**
|
|
81
75
|
* Fires when the user interacts with the carousel.
|
|
82
76
|
* Contains the interaction type (swipe-left, click-left-arrow, etc.)
|
|
@@ -134,7 +128,7 @@ export function carouselUtil(props, { emit, slots }, extraEmblaOptions) {
|
|
|
134
128
|
};
|
|
135
129
|
const onCarouselContainerClick = (e) => {
|
|
136
130
|
// If we're dragging, block click handlers within slides
|
|
137
|
-
if (embla.value
|
|
131
|
+
if (embla.value) {
|
|
138
132
|
e.preventDefault();
|
|
139
133
|
e.stopPropagation();
|
|
140
134
|
}
|
|
@@ -153,14 +147,18 @@ export function carouselUtil(props, { emit, slots }, extraEmblaOptions) {
|
|
|
153
147
|
return false;
|
|
154
148
|
};
|
|
155
149
|
|
|
156
|
-
|
|
157
|
-
const
|
|
150
|
+
const combinedPluginOptions = computed(() => {
|
|
151
|
+
const options = [];
|
|
158
152
|
if (Object.keys(autoplayOptions.value).length !== 0) {
|
|
159
|
-
|
|
153
|
+
options.push(Autoplay(autoplayOptions.value));
|
|
160
154
|
}
|
|
161
155
|
if (fadeEnabled.value) {
|
|
162
|
-
|
|
156
|
+
options.push(Fade());
|
|
163
157
|
}
|
|
158
|
+
return options;
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
onMounted(async () => {
|
|
164
162
|
embla.value = EmblaCarousel(rootEl.value, {
|
|
165
163
|
loop: true,
|
|
166
164
|
containScroll: 'trimSnaps',
|
|
@@ -168,7 +166,7 @@ export function carouselUtil(props, { emit, slots }, extraEmblaOptions) {
|
|
|
168
166
|
align: 'start',
|
|
169
167
|
...extraEmblaOptions,
|
|
170
168
|
...emblaOptions.value,
|
|
171
|
-
}, combinedPluginOptions);
|
|
169
|
+
}, combinedPluginOptions.value);
|
|
172
170
|
|
|
173
171
|
if (slidesToScroll.value === 'visible') {
|
|
174
172
|
reInitVisible();
|
|
@@ -192,6 +190,17 @@ export function carouselUtil(props, { emit, slots }, extraEmblaOptions) {
|
|
|
192
190
|
|
|
193
191
|
embla?.value?.on('select', () => {
|
|
194
192
|
currentIndex.value = embla.value.selectedScrollSnap();
|
|
193
|
+
|
|
194
|
+
/** After the select event, it is possible that embla will itself trigger a reinit.
|
|
195
|
+
* For example, if the act of selecting a slide causes it to change dimensions and the carousel
|
|
196
|
+
* needs to recalculate.
|
|
197
|
+
* When this reinit happens, autoplay settings will reset to the initial plugin options.
|
|
198
|
+
* Set playOnInit equal to the current state of autoplay to prevent this.
|
|
199
|
+
*/
|
|
200
|
+
const autoplay = embla.value?.plugins()?.autoplay;
|
|
201
|
+
if (autoplay) {
|
|
202
|
+
embla.value.plugins().autoplay.options.playOnInit = autoplay.isPlaying();
|
|
203
|
+
}
|
|
195
204
|
/**
|
|
196
205
|
* The index of the slide that the carousel has changed to
|
|
197
206
|
* @event change
|
|
@@ -189,12 +189,18 @@ export const AutoPlayButton = () => ({
|
|
|
189
189
|
},
|
|
190
190
|
data: () => ({
|
|
191
191
|
isAutoplaying: false,
|
|
192
|
+
currentSlide: 0,
|
|
192
193
|
}),
|
|
193
194
|
mounted() {
|
|
194
195
|
watch(() => this.$refs?.sampleCarousel?.isAutoplaying, (newValue) => {
|
|
195
196
|
this.isAutoplaying = newValue;
|
|
196
197
|
});
|
|
197
198
|
},
|
|
199
|
+
methods: {
|
|
200
|
+
changeEvent(index) {
|
|
201
|
+
this.currentSlide = index;
|
|
202
|
+
},
|
|
203
|
+
},
|
|
198
204
|
template: `
|
|
199
205
|
<div>
|
|
200
206
|
<kv-vertical-carousel
|
|
@@ -202,6 +208,7 @@ export const AutoPlayButton = () => ({
|
|
|
202
208
|
style="max-width: 400px;"
|
|
203
209
|
:embla-options="{ loop: false }"
|
|
204
210
|
:autoplay-options="{ playOnInit: true, delay: 3000 }"
|
|
211
|
+
@change="changeEvent"
|
|
205
212
|
>
|
|
206
213
|
${defaultCarouselSlides}
|
|
207
214
|
</kv-vertical-carousel>
|
|
@@ -209,6 +216,60 @@ export const AutoPlayButton = () => ({
|
|
|
209
216
|
<br/>
|
|
210
217
|
<p>AutoPlay is: {{ isAutoplaying ? 'ON' : 'OFF' }}</p>
|
|
211
218
|
<a href="#" @click.native.prevent="$refs.sampleCarousel.goToSlide(0)">Go To Slide 0</a>
|
|
219
|
+
<p>Current Slide: {{ currentSlide }}</p>
|
|
220
|
+
</div>
|
|
221
|
+
`,
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
export const AutoPlayWithDynamicSlides = () => ({
|
|
225
|
+
components: {
|
|
226
|
+
KvVerticalCarousel,
|
|
227
|
+
},
|
|
228
|
+
data: () => ({
|
|
229
|
+
isAutoplaying: false,
|
|
230
|
+
currentSlide: 0,
|
|
231
|
+
}),
|
|
232
|
+
mounted() {
|
|
233
|
+
watch(() => this.$refs?.sampleCarousel?.isAutoplaying, (newValue) => {
|
|
234
|
+
this.isAutoplaying = newValue;
|
|
235
|
+
});
|
|
236
|
+
},
|
|
237
|
+
methods: {
|
|
238
|
+
changeEvent(index) {
|
|
239
|
+
this.currentSlide = index;
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
template: `
|
|
243
|
+
<div>
|
|
244
|
+
<kv-vertical-carousel
|
|
245
|
+
ref="sampleCarousel"
|
|
246
|
+
style="max-width: 400px;"
|
|
247
|
+
:embla-options="{ loop: false }"
|
|
248
|
+
:autoplay-options="{ playOnInit: true, delay: 3000 }"
|
|
249
|
+
@change="changeEvent"
|
|
250
|
+
>
|
|
251
|
+
<template #slide1 >
|
|
252
|
+
<img src="https://placehold.co/400x150/${randomHexColor(1)}/000000">
|
|
253
|
+
<p style="background-color: #${randomHexColor(1)};" v-if="currentSlide === 0" >Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
|
|
254
|
+
</template>
|
|
255
|
+
<template #slide2>
|
|
256
|
+
<img src="https://placehold.co/400x150/${randomHexColor(2)}/000000">
|
|
257
|
+
<p style="background-color: #${randomHexColor(2)};" v-if="currentSlide === 1">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
|
|
258
|
+
</template>
|
|
259
|
+
<template #slide3>
|
|
260
|
+
<img src="https://placehold.co/400x150/${randomHexColor(3)}/000000">
|
|
261
|
+
<p style="background-color: #${randomHexColor(3)};" v-if="currentSlide === 2">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
|
|
262
|
+
</template>
|
|
263
|
+
<template #slide4>
|
|
264
|
+
<img src="https://placehold.co/400x150/${randomHexColor(4)}/000000">
|
|
265
|
+
<p style="background-color: #${randomHexColor(4)};" v-if="currentSlide === 3">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
|
|
266
|
+
</template>
|
|
267
|
+
</kv-vertical-carousel>
|
|
268
|
+
<a href="#" @click.native.prevent="$refs.sampleCarousel.toggleAutoPlay()" role="toggleAutoPlayButton">Toggle AutoPlay</a>
|
|
269
|
+
<br/>
|
|
270
|
+
<p>AutoPlay is: {{ isAutoplaying ? 'ON' : 'OFF' }}</p>
|
|
271
|
+
<a href="#" @click.native.prevent="$refs.sampleCarousel.goToSlide(0)">Go To Slide 0</a>
|
|
272
|
+
<p>Current Slide: {{ currentSlide }}</p>
|
|
212
273
|
</div>
|
|
213
274
|
`,
|
|
214
275
|
});
|