Switch to version 12: modified src/components/sections/hero/HeroBillboardScroll.tsx
This commit is contained in:
@@ -1,82 +1,79 @@
|
||||
import { ArrowDown } from 'lucide-react';
|
||||
import { useRef } from "react";
|
||||
import { useScroll, useTransform, motion } from "motion/react";
|
||||
import Button from "@/components/ui/Button";
|
||||
import HeroBackgroundSlot from "@/components/ui/HeroBackgroundSlot";
|
||||
import TextAnimation from "@/components/ui/TextAnimation";
|
||||
import ImageOrVideo from "@/components/ui/ImageOrVideo";
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { cn } from '@/lib/utils';
|
||||
type HeroBillboardScrollProps = {
|
||||
tag: string;
|
||||
title: string;
|
||||
description: string;
|
||||
primaryButton: { text: string; href: string };
|
||||
secondaryButton: { text: string; href: string };
|
||||
} & ({ imageSrc: string; videoSrc?: never } | { videoSrc: string; imageSrc?: never });
|
||||
|
||||
const HeroBillboardScroll = ({
|
||||
className,
|
||||
tag,
|
||||
title,
|
||||
description,
|
||||
primaryButton,
|
||||
secondaryButton,
|
||||
imageSrc,
|
||||
}: {
|
||||
className?: string;
|
||||
tag?: string;
|
||||
title?: string;
|
||||
description?: string;
|
||||
primaryButton?: {
|
||||
text: string;
|
||||
href: string;
|
||||
};
|
||||
secondaryButton?: {
|
||||
text: string;
|
||||
href: string;
|
||||
};
|
||||
imageSrc?: string;
|
||||
}) => {
|
||||
videoSrc,
|
||||
}: HeroBillboardScrollProps) => {
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const { scrollYProgress } = useScroll({ target: containerRef });
|
||||
|
||||
const rotate = useTransform(scrollYProgress, [0, 1], [20, 0]);
|
||||
const scale = useTransform(scrollYProgress, [0, 1], [1.05, 1]);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'relative flex h-svh w-full flex-col items-center justify-center overflow-hidden',
|
||||
className,
|
||||
)}
|
||||
>
|
||||
<section aria-label="Hero section" className="relative mb-20">
|
||||
<HeroBackgroundSlot />
|
||||
<div
|
||||
className="absolute inset-0 z-0"
|
||||
style={{
|
||||
backgroundImage: `url(${imageSrc})`,
|
||||
backgroundPosition: 'bottom',
|
||||
backgroundSize: 'cover',
|
||||
}}
|
||||
/>
|
||||
<div className="absolute inset-0 z-10 bg-gradient-to-t from-black/80 to-transparent" />
|
||||
<div
|
||||
className="z-20 flex flex-col items-center justify-center gap-4 p-5 text-center text-white"
|
||||
ref={containerRef}
|
||||
className="pt-25 pb-20 md:py-30 perspective-distant"
|
||||
>
|
||||
{tag && (
|
||||
<div className="inline-block rounded-theme-full bg-white/10 px-3 py-1 text-sm">
|
||||
{tag}
|
||||
<div className="w-content-width mx-auto">
|
||||
<div className="flex flex-col items-center gap-2 text-center">
|
||||
<span className="px-3 py-1 mb-1 text-sm card rounded">{tag}</span>
|
||||
|
||||
<TextAnimation
|
||||
text={title}
|
||||
variant="fade"
|
||||
gradientText={true}
|
||||
tag="h1"
|
||||
className="text-6xl font-medium text-balance"
|
||||
/>
|
||||
|
||||
<TextAnimation
|
||||
text={description}
|
||||
variant="fade"
|
||||
gradientText={false}
|
||||
tag="p"
|
||||
className="text-base md:text-lg leading-tight text-balance"
|
||||
/>
|
||||
|
||||
<div className="flex flex-wrap justify-center gap-3 mt-3">
|
||||
<Button text={primaryButton.text} href={primaryButton.href} variant="primary"/>
|
||||
<Button text={secondaryButton.text} href={secondaryButton.href} variant="secondary"animationDelay={0.1} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{title && (
|
||||
<h1 className="text-4xl font-bold md:text-6xl">
|
||||
{title}
|
||||
</h1>
|
||||
)}
|
||||
{description && (
|
||||
<p className="max-w-prose text-lg text-white/80">{description}</p>
|
||||
)}
|
||||
<div className="mt-4 flex gap-2">
|
||||
{primaryButton && (
|
||||
<Button as="a" href={primaryButton.href}>
|
||||
{primaryButton.text}
|
||||
</Button>
|
||||
)}
|
||||
{secondaryButton && (
|
||||
<Button as="a" href={secondaryButton.href} variant="secondary">
|
||||
{secondaryButton.text}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="w-content-width mx-auto mt-8 p-3 card rounded overflow-hidden rotate-x-20 md:hidden">
|
||||
<ImageOrVideo imageSrc={imageSrc} videoSrc={videoSrc} className="aspect-4/5" />
|
||||
</div>
|
||||
|
||||
<motion.div
|
||||
style={{ rotateX: rotate, scale }}
|
||||
className="w-content-width mx-auto mt-5 2xl:mt-2 p-3 xl:p-4 2xl:p-5 card rounded overflow-hidden hidden md:block"
|
||||
>
|
||||
<ImageOrVideo imageSrc={imageSrc} videoSrc={videoSrc} className="aspect-video" />
|
||||
</motion.div>
|
||||
</div>
|
||||
<div
|
||||
className="absolute bottom-5 z-20"
|
||||
>
|
||||
<ArrowDown className="animate-bounce text-white" />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user