fix: don't show carousel buttons when only one image is present and image dimensions
This commit is contained in:
parent
fb399734c0
commit
68eed4e5fd
1 changed files with 20 additions and 16 deletions
|
|
@ -30,28 +30,32 @@ export default function Carousel({ images, className }: Props) {
|
||||||
<div className="flex">
|
<div className="flex">
|
||||||
{images.map((src, index) => (
|
{images.map((src, index) => (
|
||||||
<div key={index} className="flex-[0_0_100%]">
|
<div key={index} className="flex-[0_0_100%]">
|
||||||
<img src={src} alt="" className="w-full h-auto" />
|
<img src={src} alt="" className="w-full h-auto aspect-[3/2] object-contain" />
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button onClick={scrollPrev} className="absolute left-2 top-1/2 -translate-y-1/2 bg-white p-1 rounded-full shadow text-xl cursor-pointer">
|
{images.length > 1 && (
|
||||||
<Icon icon="ic:round-chevron-left" />
|
<>
|
||||||
</button>
|
<button onClick={scrollPrev} className="absolute left-2 top-1/2 -translate-y-1/2 bg-white p-1 rounded-full shadow text-xl cursor-pointer">
|
||||||
<button onClick={scrollNext} className="absolute right-2 top-1/2 -translate-y-1/2 bg-white p-1 rounded-full shadow text-xl cursor-pointer">
|
<Icon icon="ic:round-chevron-left" />
|
||||||
<Icon icon="ic:round-chevron-right" />
|
</button>
|
||||||
</button>
|
<button onClick={scrollNext} className="absolute right-2 top-1/2 -translate-y-1/2 bg-white p-1 rounded-full shadow text-xl cursor-pointer">
|
||||||
|
<Icon icon="ic:round-chevron-right" />
|
||||||
|
</button>
|
||||||
|
|
||||||
<div className="flex justify-center gap-2 absolute left-1/2 -translate-x-1/2 bottom-2">
|
<div className="flex justify-center gap-2 absolute left-1/2 -translate-x-1/2 bottom-2">
|
||||||
{scrollSnaps.map((_, index) => (
|
{scrollSnaps.map((_, index) => (
|
||||||
<button
|
<button
|
||||||
key={index}
|
key={index}
|
||||||
onClick={() => scrollTo(index)}
|
onClick={() => scrollTo(index)}
|
||||||
className={`size-1.5 rounded-full ${index === selectedIndex ? "bg-black" : "bg-black/25"}`}
|
className={`size-1.5 rounded-full ${index === selectedIndex ? "bg-black" : "bg-black/25"}`}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue