Skip to content

Commit c75ad36

Browse files
committed
feat: add useHover composable for hover state management in Carousel
1 parent d87b8a3 commit c75ad36

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

src/components/Carousel/Carousel.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
} from 'vue'
1818

1919
import { ARIA as ARIAComponent } from '@/components/ARIA'
20+
import { useDragging, useHover } from '@/composables'
2021
import {
2122
CarouselConfig,
2223
createSlideRegistry,
@@ -49,8 +50,6 @@ import {
4950
} from './Carousel.types'
5051
import { carouselProps } from './carouselProps'
5152

52-
import { useDragging } from '@/composables'
53-
5453
export const Carousel = defineComponent({
5554
name: 'VueCarousel',
5655
props: carouselProps,
@@ -333,14 +332,7 @@ export const Carousel = defineComponent({
333332
/**
334333
* Carousel Event listeners
335334
*/
336-
const isHover = ref(false)
337-
338-
const handleMouseEnter = (): void => {
339-
isHover.value = true
340-
}
341-
const handleMouseLeave = (): void => {
342-
isHover.value = false
343-
}
335+
const { isHover, handleMouseEnter, handleMouseLeave } = useHover()
344336

345337
const handleArrowKeys = throttle((event: KeyboardEvent): void => {
346338
if (event.ctrlKey) return

src/composables/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './useDragging'
2+
export * from './useHover'

src/composables/useHover.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { ref } from 'vue'
2+
3+
export function useHover() {
4+
const isHover = ref(false)
5+
6+
const handleMouseEnter = (): void => {
7+
isHover.value = true
8+
}
9+
10+
const handleMouseLeave = (): void => {
11+
isHover.value = false
12+
}
13+
14+
return {
15+
isHover,
16+
handleMouseEnter,
17+
handleMouseLeave,
18+
}
19+
}

0 commit comments

Comments
 (0)