UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
🚧 wip: animated grid pattern wip
Dillion Vermaa6a469349647
diff --git a/app/(docs)/blocks/layout.tsx b/app/(docs)/blocks/layout.tsxnew file mode 100644index 00000000..7bfb0ea8--- /dev/null+++ b/app/(docs)/blocks/layout.tsx@@ -0,0 +1,18 @@+interface BlocksLayoutProps {+ children: React.ReactNode;+}++export default function BlocksLayout({ children }: BlocksLayoutProps) {+ return (+ <div className="border-b">+ <div className="container flex-1 items-start">+ {/* <aside className="fixed top-14 z-30 -ml-2 hidden h-[calc(100vh-3.5rem)] w-full shrink-0 md:sticky md:block">+ <ScrollArea className="h-full py-6 pl-8 pr-6 lg:py-8">+ <DocsSidebarNav items={docsConfig.sidebarNav} />+ </ScrollArea>+ </aside> */}+ {children}+ </div>+ </div>+ );+}diff --git a/app/(docs)/blocks/page.tsx b/app/(docs)/blocks/page.tsxnew file mode 100644index 00000000..b24a336d--- /dev/null+++ b/app/(docs)/blocks/page.tsx@@ -0,0 +1,78 @@+import { allComponents } from "@/.contentlayer/generated";+import { constructMetadata } from "@/lib/utils";+import FadeIn from "@/registry/components/magicui/fade-in";+import { compareDesc } from "date-fns";+import { Link } from "lucide-react";++export const metadata = constructMetadata({+ title: "Blocks | Magic UI",+ description: "Beautiful building blocks for your next project.",+});++export default async function BlocksPage() {+ const posts = allComponents+ .filter((post) => post.date <= new Date().toISOString() && post.published)+ .sort((a, b) => {+ return compareDesc(new Date(a.date), new Date(b.date));+ });++ return (+ <div className="container max-w-4xl py-6 lg:py-10">+ <div className="flex flex-col items-start gap-4 md:flex-row md:justify-between md:gap-8">+ <div className="flex-1 space-y-4">+ <h1 className="font-heading inline-block text-4xl tracking-tight lg:text-5xl">+ Blocks+ </h1>+ <p className="text-xl text-muted-foreground">+ A collection of ready to use building blocks for your next project.+ </p>+ </div>+ </div>+ <hr className="my-8" />+ {posts?.length ? (+ <div className="grid grid-cols-1 gap-4 md:grid-cols-2">+ {posts.map((post, index) => (+ <FadeIn key={post._id} delay={index * 0.04}>+ <article+ key={post._id}+ className="group relative flex h-full w-full grow flex-col overflow-hidden rounded-xl border bg-background transition-all duration-300 hover:border-gray-300 dark:border-gray-800 dark:hover:border-gray-700"+ >+ {post.video && (+ <div className="overflow-hidden">+ <video+ src={post.video}+ autoPlay+ loop+ muted+ playsInline+ className="pointer-events-none relative -bottom-1 aspect-video" // needed because random black line at bottom of video+ />+ </div>+ )}+ <div className="flex flex-1 flex-col justify-end p-3">+ <h2>{post.title}</h2>+ {/* {post.date && (+ <p className="text-sm text-gray-500">+ {formatDate(post.date)}+ </p>+ )} */}+ {post.summary && (+ <p className="mb-2 text-base text-muted-foreground">+ {post.summary}+ </p>+ )}+ </div>++ <Link href={post.url} className="absolute inset-0">+ <span className="sr-only">View Article</span>+ </Link>+ </article>+ </FadeIn>+ ))}+ </div>+ ) : (+ <p>No components yet.</p>+ )}+ </div>+ );+}diff --git a/content/components/animated-grid-pattern.mdx b/content/components/animated-grid-pattern.mdxnew file mode 100644index 00000000..e543bb00--- /dev/null+++ b/content/components/animated-grid-pattern.mdx@@ -0,0 +1,55 @@+---+title: Animated Grid Pattern+date: 2024-02-07+summary: A animated background grid pattern made with SVGs, fully customizable using Tailwind CSS.+author: dillionverma+published: false+video: https://cdn.magicui.design/grid-pattern.mp4+---++<ComponentPreview name="animated-grid-pattern-demo" />++<Steps>++<Step>++## Installation++Copy and paste the following code into your project.++```typescript+// lib/utils.ts+import clsx, { ClassValue } from "clsx";+import { twMerge } from "tailwind-merge";++export function cn(...inputs: ClassValue[]) {+ return twMerge(clsx(inputs));+}+```++```text+components/magicui/animated-grid-pattern.tsx+```++<ComponentSource name="animated-grid-pattern" />++</Step>++</Steps>++## Props++### GridPattern++| Prop | Type | Description | Default |+| --------------- | ------ | --------------------------------------------- | ------- |+| className | string | Additional classes to be added to the pattern | - |+| width | number | Width of the pattern | 40 |+| height | number | Height of the pattern | 40 |+| x | number | X offset of the pattern | -1 |+| y | number | Y offset of the pattern | -1 |+| strokeDasharray | number | Stroke dash array of the pattern | 0 |+| numSquares | number | Number of squares in the pattern | 200 |+| maxOpacity | number | Maximum opacity of the pattern | 0.5 |+| duration | number | Duration of the animation | 1 |+| repeatDelay | number | Repeat delay of the animation | 0.5 |diff --git a/contentlayer.config.ts b/contentlayer.config.tsindex 6a41e699..80a9122b 100644--- a/contentlayer.config.ts+++ b/contentlayer.config.ts@@ -55,6 +55,7 @@ export const Component = defineDocumentType(() => ({contentType: "mdx",fields: {title: { type: "string", required: true },+ type: { type: "string", required: false },date: { type: "date", required: true },video: { type: "string", required: false },summary: { type: "string", required: true },diff --git a/registry/blocks/magicui/hero.tsx b/registry/blocks/magicui/hero.tsxnew file mode 100644index 00000000..fee433ad--- /dev/null+++ b/registry/blocks/magicui/hero.tsx@@ -0,0 +1,129 @@+"use client";++import { cn } from "@/lib/utils";+import { BorderBeam } from "@/registry/components/magicui/border-beam";+import ShimmerButton from "@/registry/components/magicui/shimmer-button";+import TextShimmer from "@/registry/components/magicui/text-shimmer";+import { ArrowRightIcon } from "@radix-ui/react-icons";+import { useInView } from "framer-motion";+import { useRef } from "react";++interface HeroElementProps {+ children: React.ReactNode;+ className?: string;+}++export const HeroPill = ({ children, className }: HeroElementProps) => {+ return (+ <div+ className={cn(+ "backdrop-filter-[12px] inline-flex h-7 items-center justify-between rounded-full border border-white/5 bg-white/10 px-3 text-xs text-white transition-all ease-in hover:cursor-pointer hover:bg-white/20",+ "group gap-1",+ "animate-fade-in translate-y-[-1rem] opacity-0",+ className,+ )}+ >+ {children}+ </div>+ );+};++export const HeroTitle = ({ children, className }: HeroElementProps) => {+ return (+ <h1+ className={cn(+ "bg-gradient-to-br from-white from-30% to-white/40 bg-clip-text py-6 text-5xl font-medium leading-none tracking-tighter text-transparent sm:text-6xl md:text-7xl lg:text-8xl",+ "animate-fade-in translate-y-[-1rem] opacity-0 [--animation-delay:200ms]",+ className,+ )}+ >+ {children}+ </h1>+ );+};++export const HeroSubtitle = ({ children, className }: HeroElementProps) => {+ return (+ <p+ className={cn(+ "mb-12 text-lg tracking-tight text-gray-400 md:text-xl",+ "animate-fade-in translate-y-[-1rem] opacity-0 [--animation-delay:400ms]",+ className,+ )}+ >+ {children}+ </p>+ );+};++export const HeroImage = () => {+ const ref = useRef(null);+ const inView = useInView(ref, { once: true, margin: "-100px" });++ return (+ <div+ ref={ref}+ className="animate-fade-up relative my-[8rem] opacity-0 [--animation-delay:400ms] [perspective:2000px] after:absolute after:inset-0 after:z-50 after:[background:linear-gradient(to_top,#09090b_30%,transparent)]"+ >+ <div+ className={cn(+ "bg-hero-gradient relative rounded-xl border border-white/10 bg-white bg-opacity-[0.01] ",+ // inView ? "animate-image-rotate" : "[transform:rotateX(25deg)]",+ "before:absolute before:bottom-1/2 before:left-0 before:top-0 before:h-full before:w-full before:opacity-0 before:[filter:blur(180px)]",+ "before:[background-image:linear-gradient(to_bottom,var(--color-one),var(--color-one),transparent_40%)]",+ inView && "before:animate-image-glow",+ )}+ >+ <BorderBeam+ duration={12}+ delay={11}+ colorFrom="var(--color-one)"+ colorTo="var(--color-two)"+ />+ <BorderBeam+ duration={12}+ delay={8}+ colorFrom="var(--color-one)"+ colorTo="var(--color-two)"+ />++ <img+ src="/hero.webp"+ alt="Hero Image"+ className={cn("relative w-full rounded-[inherit] object-contain")}+ />+ </div>+ </div>+ );+};++export const HeroSection = () => {+ return (+ <section id="hero" className="mx-auto max-w-[80rem] px-6 md:px-8">+ <HeroPill>+ <TextShimmer className="inline-flex items-center justify-center">+ <span>✨ Introducing Magic UI Template</span>{" "}+ <ArrowRightIcon className="size-3 ml-1 transition-transform duration-300 ease-in-out group-hover:translate-x-0.5" />+ </TextShimmer>+ </HeroPill>+ <HeroTitle>+ Magic UI is the new way+ <br className="hidden md:block" /> to build landing pages.+ </HeroTitle>+ <HeroSubtitle>+ Beautifully designed, animated components and templates built with+ <br className="hidden md:block" /> Tailwind CSS, React, and Framer+ Motion.+ </HeroSubtitle>+ <ShimmerButton+ className="animate-fade-in translate-y-[-1rem] gap-1 rounded-lg text-black opacity-0 ease-in-out [--animation-delay:600ms]"+ background="hsl(var(--primary))"+ shimmerColor="#000"+ >+ <span>Get Started for free </span>+ <ArrowRightIcon className="size-4 ml-1 transition-transform duration-300 ease-in-out group-hover:translate-x-1" />+ </ShimmerButton>+ <HeroImage />+ </section>+ );+};diff --git a/registry/components/example/animated-grid-pattern-demo.tsx b/registry/components/example/animated-grid-pattern-demo.tsxnew file mode 100644index 00000000..8b58a0a5--- /dev/null+++ b/registry/components/example/animated-grid-pattern-demo.tsx@@ -0,0 +1,26 @@+"use client";++import { cn } from "@/lib/utils";+import AnimatedGridPattern from "@/registry/components/magicui/animated-grid-pattern";++const AnimatedGridPatternDemo = () => {+ return (+ <div className="relative flex h-full w-full items-center justify-center overflow-hidden rounded-lg border bg-background p-20 shadow-2xl">+ <p className="z-10 whitespace-pre-wrap text-center text-5xl font-medium tracking-tighter text-black dark:text-white">+ Animated Grid Pattern+ </p>+ <AnimatedGridPattern+ numSquares={30}+ maxOpacity={0.5}+ duration={3}+ repeatDelay={1}+ className={cn(+ "[mask-image:radial-gradient(300px_circle_at_center,white,transparent)]",+ "inset-x-0 inset-y-[-30%] h-[200%] skew-y-12",+ )}+ />+ </div>+ );+};++export default AnimatedGridPatternDemo;diff --git a/registry/components/magicui/animated-grid-pattern.tsx b/registry/components/magicui/animated-grid-pattern.tsxnew file mode 100644index 00000000..117521ac--- /dev/null+++ b/registry/components/magicui/animated-grid-pattern.tsx@@ -0,0 +1,149 @@+"use client";++import { cn } from "@/lib/utils";+import { motion } from "framer-motion";+import { useEffect, useId, useRef, useState } from "react";++interface GridPatternProps {+ width?: number;+ height?: number;+ x?: number;+ y?: number;+ strokeDasharray?: any;+ numSquares?: number;+ className?: string;+ maxOpacity?: number;+ duration?: number;+ repeatDelay?: number;+}++export function GridPattern({+ width = 40,+ height = 40,+ x = -1,+ y = -1,+ strokeDasharray = 0,+ numSquares = 50,+ className,+ maxOpacity = 0.5,+ duration = 4,+ repeatDelay = 0.5,+ ...props+}: GridPatternProps) {+ const id = useId();+ const containerRef = useRef(null);+ const [dimensions, setDimensions] = useState({ width: 0, height: 0 });+ const [squares, setSquares] = useState(() => generateSquares(numSquares));++ function getPos() {+ return [+ Math.floor((Math.random() * dimensions.width) / width),+ Math.floor((Math.random() * dimensions.height) / height),+ ];+ }++ // Adjust the generateSquares function to return objects with an id, x, and y+ function generateSquares(count: number) {+ return Array.from({ length: count }, (_, i) => ({+ id: i,+ pos: getPos(),+ }));+ }++ // Function to update a single square's position+ const updateSquarePosition = (id: number) => {+ setSquares((currentSquares) =>+ currentSquares.map((sq) =>+ sq.id === id+ ? {+ ...sq,+ pos: getPos(),+ }+ : sq,+ ),+ );+ };++ // Update squares to animate in+ useEffect(() => {+ if (dimensions.width && dimensions.height) {+ setSquares(generateSquares(numSquares));+ }+ }, [dimensions, numSquares]);++ // Resize observer to update container dimensions+ useEffect(() => {+ const resizeObserver = new ResizeObserver((entries) => {+ for (let entry of entries) {+ setDimensions({+ width: entry.contentRect.width,+ height: entry.contentRect.height,+ });+ }+ });++ if (containerRef.current) {+ resizeObserver.observe(containerRef.current);+ }++ return () => {+ if (containerRef.current) {+ resizeObserver.unobserve(containerRef.current);+ }+ };+ }, [containerRef]);++ return (+ <svg+ ref={containerRef}+ aria-hidden="true"+ className={cn(+ "pointer-events-none absolute inset-0 h-full w-full fill-gray-400/30 stroke-gray-400/30",+ className,+ )}+ {...props}+ >+ <defs>+ <pattern+ id={id}+ width={width}+ height={height}+ patternUnits="userSpaceOnUse"+ x={x}+ y={y}+ >+ <path+ d={`M.5 ${height}V.5H${width}`}+ fill="none"+ strokeDasharray={strokeDasharray}+ />+ </pattern>+ </defs>+ <rect width="100%" height="100%" fill={`url(#${id})`} />+ <svg x={x} y={y} className="overflow-visible">+ {squares.map(({ pos: [x, y], id }, index) => (+ <motion.rect+ initial={{ opacity: 0 }}+ animate={{ opacity: maxOpacity }}+ transition={{+ duration,+ repeat: 1,+ delay: index * 0.1,+ repeatType: "reverse",+ }}+ onAnimationComplete={() => updateSquarePosition(id)}+ key={`${x}-${y}-${index}`}+ width={width - 1}+ height={height - 1}+ x={x * width + 1}+ y={y * height + 1}+ fill="currentColor"+ strokeWidth="0"+ />+ ))}+ </svg>+ </svg>+ );+}++export default GridPattern;