-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
621 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<template> | ||
<div | ||
:class="styles({ class: props.class })" | ||
role="region" | ||
aria-roledescription="carousel" | ||
tabindex="0" | ||
@keydown="onKeyDown" | ||
> | ||
<slot | ||
:can-scroll-next | ||
:can-scroll-prev | ||
:carousel-api | ||
:carousel-ref | ||
:orientation | ||
:scroll-next | ||
:scroll-prev | ||
/> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import type { CarouselEmits, CarouselProps, WithClassAsProps } from "~/composables/useCarousel"; | ||
const styles = tv({ | ||
base: "relative focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-border", | ||
}); | ||
const props = withDefaults(defineProps<CarouselProps & WithClassAsProps>(), { | ||
orientation: "horizontal", | ||
}); | ||
const emits = defineEmits<CarouselEmits>(); | ||
const { | ||
canScrollNext, | ||
canScrollPrev, | ||
carouselApi, | ||
carouselRef, | ||
orientation, | ||
scrollNext, | ||
scrollPrev, | ||
} = useProvideCarousel(props, emits); | ||
defineExpose({ | ||
canScrollNext, | ||
canScrollPrev, | ||
carouselApi, | ||
carouselRef, | ||
orientation: props.orientation, | ||
scrollNext, | ||
scrollPrev, | ||
}); | ||
function onKeyDown(event: KeyboardEvent) { | ||
const prevKey = props.orientation === "vertical" ? "ArrowUp" : "ArrowLeft"; | ||
const nextKey = props.orientation === "vertical" ? "ArrowDown" : "ArrowRight"; | ||
if (event.key === prevKey) { | ||
event.preventDefault(); | ||
scrollPrev(); | ||
return; | ||
} | ||
if (event.key === nextKey) { | ||
event.preventDefault(); | ||
scrollNext(); | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<template> | ||
<div ref="carouselRef" :class="styles().base({ orientation })"> | ||
<div :class="styles().content({ orientation, class: props.class })" v-bind="$attrs"> | ||
<slot /> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import type { WithClassAsProps } from "~/composables/useCarousel"; | ||
defineOptions({ inheritAttrs: false }); | ||
const props = defineProps<WithClassAsProps>(); | ||
const { carouselRef, orientation } = useCarousel(); | ||
const styles = tv({ | ||
slots: { | ||
base: "overflow-hidden", | ||
content: "flex", | ||
}, | ||
variants: { | ||
orientation: { | ||
horizontal: { content: "-ml-4" }, | ||
vertical: { content: "-mt-4 flex-col" }, | ||
}, | ||
}, | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<template> | ||
<div | ||
role="group" | ||
aria-roledescription="slide" | ||
:class="styles({ orientation, class: `${props.class} ${grabbingClass}` })" | ||
@mousedown="isGrabbing = true" | ||
@mouseup="isGrabbing = false" | ||
@mouseleave="isGrabbing = false" | ||
> | ||
<slot /> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import type { WithClassAsProps } from "~/composables/useCarousel"; | ||
const props = defineProps< | ||
WithClassAsProps & { | ||
/** | ||
* Whether to show the grab cursor when hovering over the item. | ||
* @default false | ||
*/ | ||
grabCursor?: boolean; | ||
} | ||
>(); | ||
const { orientation } = useCarousel(); | ||
const styles = tv({ | ||
base: "min-w-0 shrink-0 grow-0 basis-full", | ||
variants: { | ||
orientation: { | ||
horizontal: "pl-4", | ||
vertical: "pt-4", | ||
}, | ||
}, | ||
}); | ||
const isGrabbing = ref(false); | ||
const grabbingClass = computed(() => { | ||
if (!props.grabCursor) return ""; | ||
return isGrabbing.value ? "cursor-grabbing" : "cursor-grab"; | ||
}); | ||
</script> |
Oops, something went wrong.