Merge pull request 'fix(web): show carousel controls on touch devices' (#29) from t3code/fix-carousel-buttons into main
This commit was merged in pull request #29.
This commit is contained in:
commit
1ec2d28501
1 file changed
+46
-21
@@ -15,6 +15,7 @@ import {
|
||||
CarouselItem,
|
||||
CarouselNext,
|
||||
CarouselPrevious,
|
||||
useCarousel,
|
||||
} from "@/components/ui/carousel"
|
||||
import { cn } from "@/lib/utils"
|
||||
import { ArtistCard } from "./artist-card"
|
||||
@@ -34,6 +35,34 @@ function CarouselCard({
|
||||
return <ArtistCard artist={item} />
|
||||
}
|
||||
|
||||
const carouselNavButtonClassName =
|
||||
"pointer-events-none z-10 h-16! w-6! border-0 bg-primary text-primary-foreground opacity-0 shadow-md transition-opacity hover:bg-primary/80 hover:text-primary-foreground focus-visible:pointer-events-auto! focus-visible:opacity-100! group-hover/carousel:pointer-events-auto! group-hover/carousel:opacity-100! group-focus-within/carousel:pointer-events-auto! group-focus-within/carousel:opacity-100! active:not-aria-[haspopup]:-translate-y-1/2 dark:bg-primary dark:text-primary-foreground dark:hover:bg-primary/80 [@media(hover:none)]:pointer-events-auto! [@media(hover:none)]:opacity-100!"
|
||||
|
||||
function CarouselControls() {
|
||||
const { canScrollPrev, canScrollNext } = useCarousel()
|
||||
|
||||
if (!canScrollPrev && !canScrollNext) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="pointer-events-none absolute inset-x-8 top-0 z-10 aspect-[2/1] sm:aspect-[3/1] md:aspect-[4/1] lg:aspect-[5/1] xl:aspect-[6/1]">
|
||||
{canScrollPrev ? (
|
||||
<CarouselPrevious
|
||||
variant="default"
|
||||
className={cn(carouselNavButtonClassName, "-left-8")}
|
||||
/>
|
||||
) : null}
|
||||
{canScrollNext ? (
|
||||
<CarouselNext
|
||||
variant="default"
|
||||
className={cn(carouselNavButtonClassName, "-right-8")}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export function ContentCarousel({
|
||||
title,
|
||||
href,
|
||||
@@ -51,40 +80,36 @@ export function ContentCarousel({
|
||||
}) {
|
||||
return (
|
||||
<section className={cn("flex min-w-0 flex-col gap-4", className)}>
|
||||
{href ? (
|
||||
<Link
|
||||
href={href}
|
||||
className="group inline-flex w-fit items-center gap-1 text-xl font-bold tracking-tight"
|
||||
>
|
||||
{title}
|
||||
<ChevronRightIcon className="size-5 text-muted-foreground transition-transform group-hover:translate-x-0.5" />
|
||||
</Link>
|
||||
) : (
|
||||
<h2 className="text-xl font-bold tracking-tight">{title}</h2>
|
||||
)}
|
||||
<div className="px-8">
|
||||
{href ? (
|
||||
<Link
|
||||
href={href}
|
||||
className="group inline-flex w-fit items-center gap-1 text-xl font-bold tracking-tight"
|
||||
>
|
||||
{title}
|
||||
<ChevronRightIcon className="size-5 text-muted-foreground transition-transform group-hover:translate-x-0.5" />
|
||||
</Link>
|
||||
) : (
|
||||
<h2 className="text-xl font-bold tracking-tight">{title}</h2>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Carousel
|
||||
opts={{
|
||||
align: "start",
|
||||
dragFree: true,
|
||||
containScroll: false,
|
||||
slidesToScroll: 5,
|
||||
slidesToScroll: "auto",
|
||||
}}
|
||||
className="relative min-w-0"
|
||||
className="group/carousel relative min-w-0 px-8"
|
||||
>
|
||||
<CarouselContent
|
||||
className={cn("w-full", carouselContentClassName)}
|
||||
>
|
||||
<CarouselContent className={cn("w-full", carouselContentClassName)}>
|
||||
{content.map((item) => (
|
||||
<CarouselItem key={item.id} className={slideClassName}>
|
||||
<CarouselCard item={item} />
|
||||
</CarouselItem>
|
||||
))}
|
||||
</CarouselContent>
|
||||
<div className="pointer-events-none absolute top-1/2 flex w-1/2 -translate-y-1/2 justify-between sm:w-2/3 md:w-3/4 lg:w-4/5 xl:w-5/6">
|
||||
<CarouselPrevious className="relative -left-4 h-16 w-6 bg-primary/90 opacity-0 pointer-events-none hover:pointer-events-auto hover:opacity-100 disabled:pointer-events-none disabled:opacity-0" />
|
||||
<CarouselNext className="relative -right-2 h-16 w-6 bg-primary/90 opacity-0 pointer-events-none hover:pointer-events-auto hover:opacity-100 disabled:pointer-events-none disabled:opacity-0" />
|
||||
</div>
|
||||
<CarouselControls />
|
||||
</Carousel>
|
||||
</section>
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user