UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
feat: box-reveal (#57)
Tomonari Feehan3a1b85bdde71
diff --git a/config/docs.ts b/config/docs.tsindex 9c21e829..ccca5e7d 100644--- a/config/docs.ts+++ b/config/docs.ts@@ -225,6 +225,12 @@ export const docsConfig: DocsConfig = {items: [],label: "New",},+ {+ title: "Box Reveal",+ href: `/docs/components/box-reveal`,+ items: [],+ label: "New",+ },],},{diff --git a/content/docs/components/box-reveal.mdx b/content/docs/components/box-reveal.mdxnew file mode 100644index 00000000..de3bf17b--- /dev/null+++ b/content/docs/components/box-reveal.mdx@@ -0,0 +1,31 @@+---+title: Box Reveal Animation+date: 2024-05-23+description: Sliding box animation that reveals text behind it.+author: tomonarifeehan+published: true+---++<ComponentPreview name="box-reveal-demo" />++<Steps>++### Installation++Copy and paste the following code into your project.++```text+components/magicui/box-reveal.tsx+```++<ComponentSource name="box-reveal" />++</Steps>++## Props++| Prop | Type | Description | Default |+| --------- | ------ | --------------------------------------------- | ------- |+| className | string | The class name to be applied to the component | |+| boxColor | string | Color of the box overlaying the text | #5046e6 |+| duration | number | Durations (seconds) of the animation | 0.5 |diff --git a/registry/components/example/box-reveal-demo.tsx b/registry/components/example/box-reveal-demo.tsxnew file mode 100644index 00000000..aa69bc09--- /dev/null+++ b/registry/components/example/box-reveal-demo.tsx@@ -0,0 +1,41 @@+import BoxReveal from "@/registry/components/magicui/box-reveal";++import { Button } from "@/components/ui/button";++export default async function BoxRevealDemo() {+ return (+ <div className="h-full w-full max-w-[32rem] items-center justify-center overflow-hidden pt-8">+ <BoxReveal boxColor={"#5046e6"} duration={0.5}>+ <p className="text-[3.5rem] font-semibold">+ Magic UI<span className="text-[#5046e6]">.</span>+ </p>+ </BoxReveal>++ <BoxReveal boxColor={"#5046e6"} duration={0.5}>+ <h2 className="mt-[.5rem] text-[1rem]">+ UI library for{" "}+ <span className="text-[#5046e6]">Design Engineers</span>+ </h2>+ </BoxReveal>++ <BoxReveal boxColor={"#5046e6"} duration={0.5}>+ <div className="mt-[1.5rem]">+ <p>+ -> 20+ free and open-source animated components built with+ <span className="font-semibold text-[#5046e6]"> React</span>,+ <span className="font-semibold text-[#5046e6]"> Typescript</span>,+ <span className="font-semibold text-[#5046e6]"> Tailwind CSS</span>,+ and+ <span className="font-semibold text-[#5046e6]"> Framer Motion</span>+ . <br />+ -> 100% open-source, and customizable. <br />+ </p>+ </div>+ </BoxReveal>++ <BoxReveal boxColor={"#5046e6"} duration={0.5}>+ <Button className="mt-[1.6rem] bg-[#5046e6]">Explore</Button>+ </BoxReveal>+ </div>+ );+}diff --git a/registry/components/magicui/box-reveal.tsx b/registry/components/magicui/box-reveal.tsxnew file mode 100644index 00000000..acf5f1d3--- /dev/null+++ b/registry/components/magicui/box-reveal.tsx@@ -0,0 +1,71 @@+"use client";++import { motion, useAnimation, useInView } from "framer-motion";+import { useEffect, useRef } from "react";++interface BoxRevealProps {+ children: JSX.Element;+ width?: "fit-content" | "100%";+ boxColor?: string;+ duration?: number;+}++export const BoxReveal = ({+ children,+ width = "fit-content",+ boxColor,+ duration,+}: BoxRevealProps) => {+ const mainControls = useAnimation();+ const slideControls = useAnimation();++ const ref = useRef(null);+ const isInView = useInView(ref, { once: true });++ useEffect(() => {+ if (isInView) {+ slideControls.start("visible");+ mainControls.start("visible");+ } else {+ slideControls.start("hidden");+ mainControls.start("hidden");+ }+ }, [isInView, mainControls, slideControls]);++ return (+ <div ref={ref} style={{ position: "relative", width, overflow: "hidden" }}>+ <motion.div+ variants={{+ hidden: { opacity: 0, y: 75 },+ visible: { opacity: 1, y: 0 },+ }}+ initial="hidden"+ animate={mainControls}+ transition={{ duration: duration ? duration : 0.5, delay: 0.25 }}+ >+ {children}+ </motion.div>++ <motion.div+ variants={{+ hidden: { left: 0 },+ visible: { left: "100%" },+ }}+ initial="hidden"+ animate={slideControls}+ transition={{ duration: duration ? duration : 0.5, ease: "easeIn" }}+ style={{+ position: "absolute",+ top: 4,+ bottom: 4,+ left: 0,+ right: 0,+ zIndex: 20,+ background: boxColor ? boxColor : "#5046e6",+ }}+ />+ </div>+ );+};++export default BoxReveal;diff --git a/registry/index.tsx b/registry/index.tsxindex b69c7e41..b2be9297 100644--- a/registry/index.tsx+++ b/registry/index.tsx@@ -212,6 +212,11 @@ const ui: Registry = {type: "components:ui",files: ["registry/components/magicui/shiny-button.tsx"],},+ "box-reveal": {+ name: "box-reveal",+ type: "components:ui",+ files: ["registry/components/magicui/box-reveal.tsx"],+ },};const example: Registry = {@@ -747,6 +752,14 @@ const example: Registry = {() => import("@/registry/components/example/shiny-button-demo"),),},+ "box-reveal-demo": {+ name: "box-reveal-demo",+ type: "components:example",+ files: ["registry/components/example/box-reveal-demo.tsx"],+ component: React.lazy(+ () => import("@/registry/components/example/box-reveal-demo"),+ ),+ },};export const registry: Registry = {...ui,