53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
import { Card, CardContent } from "@/components/ui/card";
|
|
import {
|
|
Carousel,
|
|
CarouselContent,
|
|
CarouselItem,
|
|
CarouselNext,
|
|
CarouselPrevious,
|
|
type CarouselApi,
|
|
} from "@/components/ui/carousel";
|
|
import * as React from "react";
|
|
|
|
export function OutputPreview() {
|
|
const [api, setApi] = React.useState<CarouselApi>();
|
|
const [current, setCurrent] = React.useState(0);
|
|
const [count, setCount] = React.useState(0);
|
|
|
|
React.useEffect(() => {
|
|
if (!api) {
|
|
return;
|
|
}
|
|
|
|
setCount(api.scrollSnapList().length);
|
|
setCurrent(api.selectedScrollSnap() + 1);
|
|
|
|
api.on("select", () => {
|
|
setCurrent(api.selectedScrollSnap() + 1);
|
|
});
|
|
}, [api]);
|
|
|
|
return (
|
|
<div>
|
|
<Carousel setApi={setApi} className="w-full max-w-xs">
|
|
<CarouselContent>
|
|
{Array.from({ length: 5 }).map((_, index) => (
|
|
<CarouselItem key={index}>
|
|
<Card>
|
|
<CardContent className="flex aspect-square items-center justify-center p-6">
|
|
<span className="text-4xl font-semibold">{index + 1}</span>
|
|
</CardContent>
|
|
</Card>
|
|
</CarouselItem>
|
|
))}
|
|
</CarouselContent>
|
|
<CarouselPrevious />
|
|
<CarouselNext />
|
|
</Carousel>
|
|
<div className="py-2 text-center text-sm text-muted-foreground">
|
|
Slide {current} of {count}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|