From 41ecd2a3d553886db3e32d9f48a477268d93f3c6 Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Thu, 1 Feb 2024 18:07:39 +0100 Subject: [PATCH] feat(Carousel): expose methods to allow autoplay Resolves #1300 --- .../examples/CarouselExampleAutoplay.vue | 37 +++++++++++++++++++ docs/content/2.components/carousel.md | 30 ++++++++++++++- src/runtime/components/elements/Carousel.vue | 32 ++++++++++------ 3 files changed, 86 insertions(+), 13 deletions(-) create mode 100644 docs/components/content/examples/CarouselExampleAutoplay.vue diff --git a/docs/components/content/examples/CarouselExampleAutoplay.vue b/docs/components/content/examples/CarouselExampleAutoplay.vue new file mode 100644 index 00000000..e9a6bcd2 --- /dev/null +++ b/docs/components/content/examples/CarouselExampleAutoplay.vue @@ -0,0 +1,37 @@ + + + diff --git a/docs/content/2.components/carousel.md b/docs/content/2.components/carousel.md index b1269d01..bfd4ae13 100644 --- a/docs/content/2.components/carousel.md +++ b/docs/content/2.components/carousel.md @@ -100,6 +100,12 @@ The number of indicators will be automatically generated based on the number of :component-example{component="carousel-example-indicators-size"} +## Autoplay + +You can easily implement an autoplay behavior using the exposed [API](#api) through a template ref. + +:component-example{component="carousel-example-autoplay"} + ## Slots ### `default` @@ -120,7 +126,7 @@ You can customize the position of the buttons through `ui.arrows.wrapper`. ### `indicator` -With the `indicators` prop enabled, use the `#indicator` slot to set the content of the indicators. You will have access to the `active`, `index` properties and `on-click` method in the slot scope. +With the `indicators` prop enabled, use the `#indicator` slot to set the content of the indicators. You will have access to the `active`, `page` properties and `on-click` method in the slot scope. :component-example{component="carousel-example-slots-indicator"} @@ -132,6 +138,28 @@ You can customize the position of the buttons through `ui.indicators.wrapper`. :component-props +## API + +When accessing the component via a template ref, you can use the following: + +::field-group + ::field{name="page" type="number"} + The current page. + :: + ::field{name="pages" type="number"} + The total number of pages. + :: + ::field{name="select (page)"} + Go to a specific page. + :: + ::field{name="next ()"} + Go to the next page. + :: + ::field{name="prev ()"} + Go to the previous page. + :: +:: + ## Config :component-preset diff --git a/src/runtime/components/elements/Carousel.vue b/src/runtime/components/elements/Carousel.vue index 905039e5..ac951719 100644 --- a/src/runtime/components/elements/Carousel.vue +++ b/src/runtime/components/elements/Carousel.vue @@ -35,16 +35,16 @@
-