Compare commits
5
Commits
@@ -15,6 +15,7 @@ import {
|
|||||||
CarouselItem,
|
CarouselItem,
|
||||||
CarouselNext,
|
CarouselNext,
|
||||||
CarouselPrevious,
|
CarouselPrevious,
|
||||||
|
useCarousel,
|
||||||
} from "@/components/ui/carousel"
|
} from "@/components/ui/carousel"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
import { ArtistCard } from "./artist-card"
|
import { ArtistCard } from "./artist-card"
|
||||||
@@ -34,6 +35,34 @@ function CarouselCard({
|
|||||||
return <ArtistCard artist={item} />
|
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({
|
export function ContentCarousel({
|
||||||
title,
|
title,
|
||||||
href,
|
href,
|
||||||
@@ -51,6 +80,7 @@ export function ContentCarousel({
|
|||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<section className={cn("flex min-w-0 flex-col gap-4", className)}>
|
<section className={cn("flex min-w-0 flex-col gap-4", className)}>
|
||||||
|
<div className="px-8">
|
||||||
{href ? (
|
{href ? (
|
||||||
<Link
|
<Link
|
||||||
href={href}
|
href={href}
|
||||||
@@ -62,29 +92,24 @@ export function ContentCarousel({
|
|||||||
) : (
|
) : (
|
||||||
<h2 className="text-xl font-bold tracking-tight">{title}</h2>
|
<h2 className="text-xl font-bold tracking-tight">{title}</h2>
|
||||||
)}
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
<Carousel
|
<Carousel
|
||||||
opts={{
|
opts={{
|
||||||
align: "start",
|
align: "start",
|
||||||
dragFree: true,
|
dragFree: true,
|
||||||
containScroll: false,
|
slidesToScroll: "auto",
|
||||||
slidesToScroll: 5,
|
|
||||||
}}
|
}}
|
||||||
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) => (
|
{content.map((item) => (
|
||||||
<CarouselItem key={item.id} className={slideClassName}>
|
<CarouselItem key={item.id} className={slideClassName}>
|
||||||
<CarouselCard item={item} />
|
<CarouselCard item={item} />
|
||||||
</CarouselItem>
|
</CarouselItem>
|
||||||
))}
|
))}
|
||||||
</CarouselContent>
|
</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">
|
<CarouselControls />
|
||||||
<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>
|
|
||||||
</Carousel>
|
</Carousel>
|
||||||
</section>
|
</section>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in new issue
Block a user