Skip to content

Commit 32718b3

Browse files
committed
fix(hero): optimize background image in carousel via next/image
1 parent 9614f0c commit 32718b3

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

public/home/Main Building 4.webp

7.26 MB
Loading
6.11 MB
Loading

src/components/sections/hero.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
CarouselPrevious,
99
} from "@/components/ui/carousel";
1010
import Autoplay from "embla-carousel-autoplay";
11+
import Image from "next/image";
1112

1213
type HeroSlide = {
1314
imageSrc: string;
@@ -49,10 +50,15 @@ export function Hero({ slides, heightClassName }: HeroProps) {
4950
<CarouselContent>
5051
{slides.map((slide, index) => (
5152
<CarouselItem key={index}>
52-
<div
53-
className={`relative flex ${heightClassName} items-center justify-center bg-cover bg-center bg-no-repeat`}
54-
style={{ backgroundImage: `url('${slide.imageSrc}')` }}
55-
>
53+
<div className={`relative flex ${heightClassName} items-center justify-center`}>
54+
<Image
55+
src={slide.imageSrc}
56+
alt="Carousel Image"
57+
fill
58+
priority={index === 0}
59+
sizes="100vw"
60+
className="object-cover"
61+
/>
5662
{slide.content ? <div className="absolute inset-0 bg-black/55" /> : null}
5763
{slide.content ? (
5864
<span className="z-10 text-center text-2xl font-semibold text-white md:text-4xl">

0 commit comments

Comments
 (0)