-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcarousel-with-dots.tsx
More file actions
76 lines (71 loc) · 2.26 KB
/
carousel-with-dots.tsx
File metadata and controls
76 lines (71 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'use client';
import { useState } from 'react';
import Image from 'next/image';
import {
Carousel,
CarouselContent,
CarouselItem,
type CarouselApi,
} from '@/components/ui/carousel';
import { useCarouselDots } from './use-carousel-dots';
import { DotNavigation } from './dot-navigation';
import Autoplay from 'embla-carousel-autoplay';
import { Advertisement } from '@/types/domain/advertisement';
interface CarouselWithDotsProps {
advertisements: Advertisement[];
}
export default function CarouselWithDots({
advertisements,
}: CarouselWithDotsProps) {
if (advertisements.length === 0) return null;
const [api, setApi] = useState<CarouselApi>();
const { current, count, scrollTo } = useCarouselDots(api);
return (
<div
className="w-screen max-w-200"
role="region"
aria-roledescription="carousel"
aria-label="배너 광고"
>
<Carousel
setApi={setApi}
opts={{
loop: true,
}}
plugins={[
Autoplay({
delay: 3000,
stopOnInteraction: false,
}),
]}
>
<CarouselContent className="m-0 max-h-125 w-full">
{advertisements.map((item, index) => (
<CarouselItem key={item.id} className="p-0">
<div className="relative aspect-380/275 h-full w-full overflow-hidden">
<Image
src={item.imageUrl}
alt={item.title}
fill
className="object-cover"
priority={index === 0}
sizes="(max-width: 800px) 100vw, 800px"
/>
<div className="absolute inset-0 bg-gradient-to-t from-black/60 to-transparent" />
<div className="absolute bottom-0 left-0 right-0 p-6 text-white">
<h3 className="mb-2 text-2xl font-black break-keep">
{item.title}
</h3>
<p className="text-lg font-medium break-keep opacity-90">
{item.description}
</p>
</div>
</div>
</CarouselItem>
))}
</CarouselContent>
</Carousel>
<DotNavigation count={count} current={current} onDotClick={scrollTo} />
</div>
);
}