mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 12:14:41 +01:00
feat(Carousel): add select event (#3678)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
@@ -252,6 +252,10 @@ class: 'p-8 px-16'
|
|||||||
|
|
||||||
:component-slots
|
:component-slots
|
||||||
|
|
||||||
|
### Emits
|
||||||
|
|
||||||
|
:component-emits
|
||||||
|
|
||||||
### Expose
|
### Expose
|
||||||
|
|
||||||
You can access the typed component instance using [`useTemplateRef`](https://vuejs.org/api/composition-api-helpers.html#usetemplateref).
|
You can access the typed component instance using [`useTemplateRef`](https://vuejs.org/api/composition-api-helpers.html#usetemplateref).
|
||||||
|
|||||||
@@ -99,6 +99,13 @@ export type CarouselSlots<T extends CarouselItem = CarouselItem> = {
|
|||||||
default(props: { item: T, index: number }): any
|
default(props: { item: T, index: number }): any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CarouselEmits {
|
||||||
|
/**
|
||||||
|
* Emitted when the selected slide changes
|
||||||
|
* @param selectedIndex The index of the selected slide
|
||||||
|
*/
|
||||||
|
select: [selectedIndex: number]
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script setup lang="ts" generic="T extends CarouselItem">
|
<script setup lang="ts" generic="T extends CarouselItem">
|
||||||
@@ -141,6 +148,7 @@ const props = withDefaults(defineProps<CarouselProps<T>>(), {
|
|||||||
wheelGestures: false
|
wheelGestures: false
|
||||||
})
|
})
|
||||||
defineSlots<CarouselSlots<T>>()
|
defineSlots<CarouselSlots<T>>()
|
||||||
|
const emits = defineEmits<CarouselEmits>()
|
||||||
|
|
||||||
const { dir, t } = useLocale()
|
const { dir, t } = useLocale()
|
||||||
const appConfig = useAppConfig() as Carousel['AppConfig']
|
const appConfig = useAppConfig() as Carousel['AppConfig']
|
||||||
@@ -242,6 +250,8 @@ function onSelect(api: EmblaCarouselType) {
|
|||||||
canScrollNext.value = api?.canScrollNext() || false
|
canScrollNext.value = api?.canScrollNext() || false
|
||||||
canScrollPrev.value = api?.canScrollPrev() || false
|
canScrollPrev.value = api?.canScrollPrev() || false
|
||||||
selectedIndex.value = api?.selectedScrollSnap() || 0
|
selectedIndex.value = api?.selectedScrollSnap() || 0
|
||||||
|
|
||||||
|
emits('select', selectedIndex.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user