This commit is contained in:
parent
0572586552
commit
d3fcdbdf82
1 changed files with 33 additions and 63 deletions
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { AnimatePresence, motion } from 'motion/react';
|
|
||||||
import { ArrowRight } from 'lucide-react';
|
import { ArrowRight } from 'lucide-react';
|
||||||
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
|
|
@ -39,6 +38,15 @@ const slides: HeroSlide[] = [
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const SlideSummary = ({ slide }: { slide: HeroSlide }) => (
|
||||||
|
<>
|
||||||
|
<p className="text-sm font-medium text-foreground">{slide.title}</p>
|
||||||
|
{slide.description && (
|
||||||
|
<p className="mt-1 text-xs text-muted-foreground">{slide.description}</p>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
interface SvgPath {
|
interface SvgPath {
|
||||||
path: string;
|
path: string;
|
||||||
height: number;
|
height: number;
|
||||||
|
|
@ -114,9 +122,7 @@ const MaskedDiv: React.FC<MaskedDivProps> = ({
|
||||||
style={containerStyle}
|
style={containerStyle}
|
||||||
>
|
>
|
||||||
{React.cloneElement(children, {
|
{React.cloneElement(children, {
|
||||||
className: `w-full h-full object-cover transition-all duration-300 ${
|
className: `h-full w-full object-cover ${children.props.className || ''}`,
|
||||||
children.props.className || ''
|
|
||||||
}`,
|
|
||||||
})}
|
})}
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
|
|
@ -126,11 +132,18 @@ export default function Hero() {
|
||||||
const [currentIndex, setCurrentIndex] = useState(0);
|
const [currentIndex, setCurrentIndex] = useState(0);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timer = setTimeout(() => {
|
slides.forEach((slide) => {
|
||||||
|
const image = new Image();
|
||||||
|
image.src = slide.src;
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const timer = window.setInterval(() => {
|
||||||
setCurrentIndex((prevIndex) => (prevIndex + 1) % slides.length);
|
setCurrentIndex((prevIndex) => (prevIndex + 1) % slides.length);
|
||||||
}, 5000);
|
}, 5000);
|
||||||
return () => clearTimeout(timer);
|
return () => window.clearInterval(timer);
|
||||||
}, [currentIndex]);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="py-10 md:py-14 lg:py-16">
|
<section className="py-10 md:py-14 lg:py-16">
|
||||||
|
|
@ -161,71 +174,28 @@ export default function Hero() {
|
||||||
|
|
||||||
<div className="relative lg:-translate-y-4">
|
<div className="relative lg:-translate-y-4">
|
||||||
<MaskedDiv maskType="type-5">
|
<MaskedDiv maskType="type-5">
|
||||||
<AnimatePresence mode="popLayout">
|
<img
|
||||||
<motion.img
|
|
||||||
key={currentIndex}
|
|
||||||
className="h-full w-full object-cover"
|
className="h-full w-full object-cover"
|
||||||
style={{ objectPosition: slides[currentIndex].objectPosition }}
|
style={{ objectPosition: slides[currentIndex].objectPosition }}
|
||||||
src={slides[currentIndex].src}
|
src={slides[currentIndex].src}
|
||||||
alt={slides[currentIndex].alt}
|
alt={slides[currentIndex].alt}
|
||||||
initial={{ opacity: 0 }}
|
decoding="async"
|
||||||
animate={{ opacity: 1 }}
|
|
||||||
exit={{ opacity: 0 }}
|
|
||||||
transition={{ duration: 1.5 }}
|
|
||||||
/>
|
/>
|
||||||
</AnimatePresence>
|
|
||||||
</MaskedDiv>
|
</MaskedDiv>
|
||||||
|
|
||||||
{/* Top-right slide summary */}
|
{/* Top-right slide summary */}
|
||||||
<div className="absolute -top-26 right-0 flex gap-6">
|
<div className="absolute -top-26 right-0 flex gap-6">
|
||||||
<motion.div
|
<div className="hidden size-44 -translate-y-4 overflow-hidden rounded-3xl border border-border bg-muted/50 p-4 lg:flex lg:flex-col lg:justify-center xl:-translate-y-0">
|
||||||
initial={{ opacity: 0, y: 30, scale: 0.9 }}
|
<SlideSummary slide={slides[currentIndex]} />
|
||||||
animate={{ opacity: 1, y: 0, scale: 1 }}
|
</div>
|
||||||
transition={{ duration: 0.3, ease: 'easeOut' }}
|
|
||||||
className="hidden size-44 -translate-y-4 overflow-hidden rounded-3xl border border-border bg-muted/50 p-4 lg:flex lg:flex-col lg:justify-center xl:-translate-y-0"
|
|
||||||
>
|
|
||||||
<AnimatePresence mode="wait">
|
|
||||||
<motion.div
|
|
||||||
key={currentIndex}
|
|
||||||
initial={{ opacity: 0 }}
|
|
||||||
animate={{ opacity: 1 }}
|
|
||||||
exit={{ opacity: 0 }}
|
|
||||||
transition={{ duration: 0.5 }}
|
|
||||||
>
|
|
||||||
<p className="text-sm font-medium text-foreground">
|
|
||||||
{slides[currentIndex].title}
|
|
||||||
</p>
|
|
||||||
{slides[currentIndex].description && (
|
|
||||||
<p className="mt-1 text-xs text-muted-foreground">
|
|
||||||
{slides[currentIndex].description}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</motion.div>
|
|
||||||
</AnimatePresence>
|
|
||||||
</motion.div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Mobile: box below the image */}
|
{/* Mobile: box below the image */}
|
||||||
<div className="mt-5 flex w-full gap-6 lg:hidden">
|
<div className="mt-5 flex w-full gap-6 lg:hidden">
|
||||||
<div className="flex h-44 w-full items-center justify-center rounded-3xl border border-border bg-muted/50 p-4">
|
<div className="flex h-44 w-full items-center justify-center rounded-3xl border border-border bg-muted/50 p-4">
|
||||||
<AnimatePresence mode="wait">
|
<div>
|
||||||
<motion.div
|
<SlideSummary slide={slides[currentIndex]} />
|
||||||
key={currentIndex}
|
</div>
|
||||||
initial={{ opacity: 0 }}
|
|
||||||
animate={{ opacity: 1 }}
|
|
||||||
exit={{ opacity: 0 }}
|
|
||||||
transition={{ duration: 0.5 }}
|
|
||||||
>
|
|
||||||
<p className="text-sm font-medium text-foreground">
|
|
||||||
{slides[currentIndex].title}
|
|
||||||
</p>
|
|
||||||
{slides[currentIndex].description && (
|
|
||||||
<p className="mt-1 text-xs text-muted-foreground">
|
|
||||||
{slides[currentIndex].description}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</motion.div>
|
|
||||||
</AnimatePresence>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue