Skip to content

Commit 6a69324

Browse files
committed
feat: add useHover composable for hover state management in Carousel
1 parent c6f16cf commit 6a69324

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

src/components/Carousel/Carousel.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from 'vue'
1717

1818
import { ARIA as ARIAComponent } from '@/components/ARIA'
19-
import { useDragging } from '@/composables'
19+
import { useDragging, useHover } from '@/composables'
2020
import {
2121
CarouselConfig,
2222
createSlideRegistry,
@@ -331,14 +331,7 @@ export const Carousel = defineComponent({
331331
/**
332332
* Carousel Event listeners
333333
*/
334-
const isHover = ref(false)
335-
336-
const handleMouseEnter = (): void => {
337-
isHover.value = true
338-
}
339-
const handleMouseLeave = (): void => {
340-
isHover.value = false
341-
}
334+
const { isHover, handleMouseEnter, handleMouseLeave } = useHover()
342335

343336
const handleArrowKeys = throttle((event: KeyboardEvent): void => {
344337
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)