Compare commits
No commits in common. "6bc02c930ffef13fb54a2382e37a8d956e2d94ef" and "33d1bd55d41c381d32745086c30c77719d447fe3" have entirely different histories.
6bc02c930f
...
33d1bd55d4
|
|
@ -1,6 +1,5 @@
|
||||||
import { CarouselDemo } from "@/components/Carousel";
|
import { CarouselDemo } from "@/components/Carousel";
|
||||||
import {FireNewsList} from "./FireNewsList";
|
import {FireNewsList} from "./FireNewsList";
|
||||||
import { CarouselPreset } from "@/components/untils/CarouselPreset";
|
|
||||||
|
|
||||||
export function ImportantNews() {
|
export function ImportantNews() {
|
||||||
return(
|
return(
|
||||||
|
|
|
||||||
|
|
@ -1,96 +0,0 @@
|
||||||
import * as React from "react"
|
|
||||||
import Autoplay from "embla-carousel-autoplay"
|
|
||||||
import {
|
|
||||||
Carousel,
|
|
||||||
CarouselContent,
|
|
||||||
CarouselItem,
|
|
||||||
CarouselNext,
|
|
||||||
CarouselPrevious,
|
|
||||||
type CarouselApi,
|
|
||||||
} from "@/ui/carousel"
|
|
||||||
import { CardContent } from "@/ui/card"
|
|
||||||
import { cn } from "@/lib/utils"
|
|
||||||
|
|
||||||
type Slide = {
|
|
||||||
key?: React.Key
|
|
||||||
content: React.ReactNode
|
|
||||||
}
|
|
||||||
|
|
||||||
type CarouselPresetProps = {
|
|
||||||
slides: Slide[]
|
|
||||||
autoplayDelay?: number
|
|
||||||
showControls?: boolean
|
|
||||||
showIndicators?: boolean
|
|
||||||
indicatorVariant?: "dot" | "pill"
|
|
||||||
className?: string
|
|
||||||
contentClassName?: string
|
|
||||||
itemClassName?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export function CarouselPreset({
|
|
||||||
slides,
|
|
||||||
autoplayDelay = 3000,
|
|
||||||
showControls = true,
|
|
||||||
showIndicators = true,
|
|
||||||
indicatorVariant = "dot",
|
|
||||||
className,
|
|
||||||
contentClassName,
|
|
||||||
itemClassName,
|
|
||||||
}: CarouselPresetProps) {
|
|
||||||
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())
|
|
||||||
api.on("select", () => setCurrent(api.selectedScrollSnap()))
|
|
||||||
}, [api])
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={cn("relative w-full h-full", className)}>
|
|
||||||
<Carousel
|
|
||||||
opts={{ loop: true }}
|
|
||||||
plugins={[Autoplay({ delay: autoplayDelay, stopOnInteraction: false })]}
|
|
||||||
setApi={setApi}
|
|
||||||
className="w-full h-full"
|
|
||||||
>
|
|
||||||
<CarouselContent className={cn("h-full w-full -ml-0", contentClassName)}>
|
|
||||||
{slides.map((slide, index) => (
|
|
||||||
<CarouselItem
|
|
||||||
key={slide.key ?? index}
|
|
||||||
className={cn("w-full h-full pl-0", itemClassName)}
|
|
||||||
>
|
|
||||||
<CardContent className="p-0 w-full h-full m-0">{slide.content}</CardContent>
|
|
||||||
</CarouselItem>
|
|
||||||
))}
|
|
||||||
</CarouselContent>
|
|
||||||
|
|
||||||
{showControls && (
|
|
||||||
<>
|
|
||||||
<CarouselPrevious className="absolute left-2 top-1/2 -translate-y-1/2 z-10" />
|
|
||||||
<CarouselNext className="absolute right-2 top-1/2 -translate-y-1/2 z-10" />
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Carousel>
|
|
||||||
|
|
||||||
{showIndicators && (
|
|
||||||
<div className="absolute bottom-4 right-4 flex gap-2 z-10">
|
|
||||||
{Array.from({ length: count }).map((_, index) => (
|
|
||||||
<button
|
|
||||||
key={index}
|
|
||||||
onClick={() => api?.scrollTo(index)}
|
|
||||||
className={cn(
|
|
||||||
"transition-colors bg-white/50 hover:bg-white",
|
|
||||||
indicatorVariant === "dot" ? "h-2 w-2 rounded-full" : "h-2 w-8 rounded",
|
|
||||||
index === current && "bg-white"
|
|
||||||
)}
|
|
||||||
aria-label={`第 ${index + 1} 张`}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue