72 lines
1.8 KiB
TypeScript
72 lines
1.8 KiB
TypeScript
import { Play, Pause } from "lucide-react";
|
|
import { useRef, useState } from "react";
|
|
|
|
import IconCircleButton from "@/front/Components/Layout/IconCircleButton";
|
|
import useDeviceType from "@/hooks/use-device-type";
|
|
|
|
interface HeroVideoProps {
|
|
src: string;
|
|
overlayImage?: string;
|
|
}
|
|
|
|
export default function HeroVideo({
|
|
src,
|
|
overlayImage,
|
|
}: Readonly<HeroVideoProps>) {
|
|
const { isMobile } = useDeviceType();
|
|
const videoRef = useRef<HTMLVideoElement>(null);
|
|
const [isPlaying, setIsPlaying] = useState(true);
|
|
|
|
const togglePlay = () => {
|
|
const video = videoRef.current;
|
|
if (!video) return;
|
|
|
|
if (isPlaying) {
|
|
video.pause();
|
|
} else {
|
|
void video.play();
|
|
}
|
|
setIsPlaying(!isPlaying);
|
|
};
|
|
|
|
return (
|
|
<div className="absolute inset-0 h-screen w-screen">
|
|
<video
|
|
ref={videoRef}
|
|
autoPlay
|
|
loop
|
|
muted
|
|
playsInline
|
|
className={`h-full w-full object-cover ${
|
|
isMobile ? "object-[50%_center]" : "object-center rounded-b-[120px]"
|
|
}`}
|
|
>
|
|
<source src={src} type="video/mp4" />
|
|
</video>
|
|
|
|
{overlayImage && (
|
|
<img
|
|
src={overlayImage}
|
|
alt=""
|
|
className="absolute -bottom-[75px] -right-[58px] z-10 object-contain md:-bottom-16 md:right-0"
|
|
/>
|
|
)}
|
|
|
|
<IconCircleButton
|
|
icon={
|
|
isPlaying ? (
|
|
<Pause size={24} />
|
|
) : (
|
|
<Play size={24} className="ml-0.5" />
|
|
)
|
|
}
|
|
ariaLabel={isPlaying ? "Mettre en pause la vidéo" : "Lire la vidéo"}
|
|
onClick={togglePlay}
|
|
variant="outline"
|
|
outlineColor="border-gris text-gris hover:bg-gris/70 hover:text-white"
|
|
size={isMobile ? 48 : 64}
|
|
className="absolute bottom-12 right-8 z-10 md:bottom-12 md:right-18"
|
|
/>
|
|
</div>
|
|
);
|
|
}
|