UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
feat: add hero video dialog component (#285)
Arghya Dasf8468cd38b70
diff --git a/config/docs.ts b/config/docs.tsindex 53d6066f..e66f304e 100644--- a/config/docs.ts+++ b/config/docs.ts@@ -100,6 +100,12 @@ export const docsConfig: DocsConfig = {{title: "Components",items: [+ {+ title: "Hero Video Dialog",+ href: `/docs/components/hero-video-dialog`,+ items: [],+ label: "New",+ },{title: "Marquee",href: `/docs/components/marquee`,diff --git a/content/docs/components/hero-video-dialog.mdx b/content/docs/components/hero-video-dialog.mdxnew file mode 100644index 00000000..ff3ed482--- /dev/null+++ b/content/docs/components/hero-video-dialog.mdx@@ -0,0 +1,73 @@+---+title: Hero Video Dialog+date: 2024-08-26+description: A hero video dialog component.+author: dillionverma+published: true+---++<ComponentPreview name="hero-video-dialog-demo" />++## Installation++<Tabs defaultValue="cli">++<TabsList>+ <TabsTrigger value="cli">CLI</TabsTrigger>+ <TabsTrigger value="manual">Manual</TabsTrigger>+</TabsList>+<TabsContent value="cli">++```bash+npx magicui-cli add hero-video-dialog+```++</TabsContent>++<TabsContent value="manual">++<Steps>++<Step>Copy and paste the following code into your project.</Step>++<ComponentSource name="hero-video-dialog" />++<Step>Update the import paths to match your project setup.</Step>++</Steps>++</TabsContent>++</Tabs>++## Examples++### Top-in-bottom-out++<ComponentPreview name="hero-video-dialog-demo-top-in-bottom-out" />++## Props++| Prop | Type | Description | Default |+| -------------- | ------ | -------------------------------- | ----------------- |+| animationStyle | string | Animation style for the dialog | "from-center" |+| videoSrc | string | URL of the video to be played | - |+| thumbnailSrc | string | URL of the thumbnail image | - |+| thumbnailAlt | string | Alt text for the thumbnail image | "Video thumbnail" |++## Animation Styles++The `animationStyle` prop accepts the following values:++- `"from-bottom"`: Dialog enters from the bottom and exits to the bottom+- `"from-center"`: Dialog scales up from the center and scales down to the center+- `"from-top"`: Dialog enters from the top and exits to the top+- `"from-left"`: Dialog enters from the left and exits to the left+- `"from-right"`: Dialog enters from the right and exits to the right+- `"fade"`: Dialog fades in and out+- `"top-in-bottom-out"`: Dialog enters from the top and exits to the bottom+- `"left-in-right-out"`: Dialog enters from the left and exits to the right++## Note++- If using a YouTube video, make sure to use the `embed` version of the video URL.diff --git a/registry/components/example/hero-video-dialog-demo-top-in-bottom-out.tsx b/registry/components/example/hero-video-dialog-demo-top-in-bottom-out.tsxnew file mode 100644index 00000000..da905673--- /dev/null+++ b/registry/components/example/hero-video-dialog-demo-top-in-bottom-out.tsx@@ -0,0 +1,18 @@+import { BorderBeam } from "@/registry/components/magicui/border-beam";+import HeroVideoDialog from "@/registry/components/magicui/hero-video-dialog";++export default function HeroVideoDialogDemoTopInBottomOut() {+ return (+ <section className="max-w-5xl mx-auto h-screen flex flex-col justify-center items-center px-7 lg:px-0 relative">+ <div className="relative rounded-2xl p-1 overflow-hidden">+ <BorderBeam />+ <HeroVideoDialog+ animationStyle="top-in-bottom-out"+ videoSrc="https://www.youtube.com/embed/qh3NGpYRG3I?si=4rb-zSdDkVK9qxxb"+ thumbnailSrc="https://startup-template-sage.vercel.app/hero-dark.png"+ thumbnailAlt="Hero Video"+ />+ </div>+ </section>+ );+}diff --git a/registry/components/example/hero-video-dialog-demo.tsx b/registry/components/example/hero-video-dialog-demo.tsxnew file mode 100644index 00000000..1a0bd7e0--- /dev/null+++ b/registry/components/example/hero-video-dialog-demo.tsx@@ -0,0 +1,18 @@+import { BorderBeam } from "@/registry/components/magicui/border-beam";+import HeroVideoDialog from "@/registry/components/magicui/hero-video-dialog";++export default function HeroVideoDialogDemo() {+ return (+ <section className="max-w-5xl mx-auto h-screen flex flex-col justify-center items-center px-7 lg:px-0 relative">+ <div className="relative rounded-2xl p-1 overflow-hidden">+ <BorderBeam />+ <HeroVideoDialog+ animationStyle="from-center"+ videoSrc="https://www.youtube.com/embed/qh3NGpYRG3I?si=4rb-zSdDkVK9qxxb"+ thumbnailSrc="https://startup-template-sage.vercel.app/hero-dark.png"+ thumbnailAlt="Hero Video"+ />+ </div>+ </section>+ );+}diff --git a/registry/components/magicui/hero-video-dialog.tsx b/registry/components/magicui/hero-video-dialog.tsxnew file mode 100644index 00000000..8dfba825--- /dev/null+++ b/registry/components/magicui/hero-video-dialog.tsx@@ -0,0 +1,156 @@+/* eslint-disable @next/next/no-img-element */+"use client";++import { useState } from "react";+import { AnimatePresence, motion } from "framer-motion";+import { Play, XIcon } from "lucide-react";++type AnimationStyle =+ | "from-bottom"+ | "from-center"+ | "from-top"+ | "from-left"+ | "from-right"+ | "fade"+ | "top-in-bottom-out"+ | "left-in-right-out";++interface HeroVideoProps {+ animationStyle?: AnimationStyle;+ videoSrc: string;+ thumbnailSrc: string;+ thumbnailAlt?: string;+}++const animationVariants = {+ "from-bottom": {+ initial: { y: "100%", opacity: 0 },+ animate: { y: 0, opacity: 1 },+ exit: { y: "100%", opacity: 0 },+ },+ "from-center": {+ initial: { scale: 0.5, opacity: 0 },+ animate: { scale: 1, opacity: 1 },+ exit: { scale: 0.5, opacity: 0 },+ },+ "from-top": {+ initial: { y: "-100%", opacity: 0 },+ animate: { y: 0, opacity: 1 },+ exit: { y: "-100%", opacity: 0 },+ },+ "from-left": {+ initial: { x: "-100%", opacity: 0 },+ animate: { x: 0, opacity: 1 },+ exit: { x: "-100%", opacity: 0 },+ },+ "from-right": {+ initial: { x: "100%", opacity: 0 },+ animate: { x: 0, opacity: 1 },+ exit: { x: "100%", opacity: 0 },+ },+ fade: {+ initial: { opacity: 0 },+ animate: { opacity: 1 },+ exit: { opacity: 0 },+ },+ "top-in-bottom-out": {+ initial: { y: "-100%", opacity: 0 },+ animate: { y: 0, opacity: 1 },+ exit: { y: "100%", opacity: 0 },+ },+ "left-in-right-out": {+ initial: { x: "-100%", opacity: 0 },+ animate: { x: 0, opacity: 1 },+ exit: { x: "100%", opacity: 0 },+ },+};++export default function HeroVideoDialog({+ animationStyle = "from-center",+ videoSrc,+ thumbnailSrc,+ thumbnailAlt = "Video thumbnail",+}: HeroVideoProps) {+ const [isVideoOpen, setIsVideoOpen] = useState(false);+ const [isCloseHovered, setIsCloseHovered] = useState(false);+ const [isPlayHovered, setIsPlayHovered] = useState(false);++ const openVideo = () => setIsVideoOpen(true);+ const closeVideo = () => setIsVideoOpen(false);++ const selectedAnimation = animationVariants[animationStyle];++ return (+ <div className="relative">+ <div className="relative cursor-pointer" onClick={openVideo}>+ <img+ src={thumbnailSrc}+ alt={thumbnailAlt}+ width={1920}+ height={1080}+ className="w-full rounded-2xl"+ />+ <div className="absolute inset-0 flex items-center justify-center">+ <div+ className="border border-neutral-800 flex items-center justify-center rounded-full backdrop-blur-md transition-transform duration-300 ease-out size-24"+ onMouseEnter={() => setIsPlayHovered(true)}+ onMouseLeave={() => setIsPlayHovered(false)}+ >+ <div+ className={`flex items-center justify-center border border-neutral-800 rounded-full size-20 transition-all ease-out duration-300 backdrop-blur-2xl relative ${+ isPlayHovered ? " scale-105" : "scale-100"+ }`}+ >+ <Play+ className="size-8 text-white"+ style={{+ transform: isPlayHovered ? "scale(1.1)" : "scale(1)",+ transition: "transform 0.3s ease",+ }}+ />+ </div>+ </div>+ </div>+ </div>+ <AnimatePresence>+ {isVideoOpen && (+ <motion.div+ initial={{ opacity: 0 }}+ animate={{ opacity: 1 }}+ exit={{ opacity: 0 }}+ className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-md"+ >+ <motion.div+ {...selectedAnimation}+ transition={{ type: "spring", damping: 30, stiffness: 300 }}+ className="relative w-full max-w-4xl aspect-video mx-4 md:mx-0"+ >+ <motion.button+ className="absolute -top-16 right-0 text-white text-xl bg-neutral-900/50 ring-1 backdrop-blur-md rounded-full p-2"+ onClick={closeVideo}+ onHoverStart={() => setIsCloseHovered(true)}+ onHoverEnd={() => setIsCloseHovered(false)}+ whileHover={{ scale: 1.1 }}+ whileTap={{ scale: 0.95 }}+ >+ <XIcon className="size-5" />+ </motion.button>+ <motion.div+ className="size-full border-2 border-white rounded-2xl overflow-hidden isolate z-[1] relative"+ animate={{ scale: isCloseHovered ? 0.98 : 1 }}+ transition={{ duration: 0.2 }}+ >+ <iframe+ src={videoSrc}+ className="size-full rounded-2xl"+ allowFullScreen+ allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"+ ></iframe>+ </motion.div>+ </motion.div>+ </motion.div>+ )}+ </AnimatePresence>+ </div>+ );+}diff --git a/registry/index.tsx b/registry/index.tsxindex 568af1b0..3bd25919 100644--- a/registry/index.tsx+++ b/registry/index.tsx@@ -33,6 +33,11 @@ const ui: Registry = {type: "components:ui",files: ["registry/components/magicui/flickering-grid.tsx"],},+ "hero-video-dialog": {+ name: "hero-video-dialog",+ type: "components:ui",+ files: ["registry/components/magicui/hero-video-dialog.tsx"],+ },marquee: {name: "marquee",type: "components:magicui",@@ -346,6 +351,27 @@ const example: Registry = {import("@/registry/components/example/flickering-grid-rounded-demo"),),},+ "hero-video-dialog-demo": {+ name: "hero-video-dialog",+ type: "components:example",+ files: ["registry/components/example/hero-video-dialog-demo.tsx"],+ component: React.lazy(+ () => import("@/registry/components/example/hero-video-dialog-demo"),+ ),+ },+ "hero-video-dialog-demo-top-in-bottom-out": {+ name: "hero-video-dialog",+ type: "components:example",+ files: [+ "registry/components/example/hero-video-dialog-demo-top-in-bottom-out.tsx",+ ],+ component: React.lazy(+ () =>+ import(+ "@/registry/components/example/hero-video-dialog-demo-top-in-bottom-out"+ ),+ ),+ },"marquee-demo": {name: "marquee-demo",type: "components:example",