-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
792726a
commit ba7dc82
Showing
11 changed files
with
416 additions
and
780 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "warp-background", | ||
"type": "registry:ui", | ||
"dependencies": [ | ||
"framer-motion" | ||
], | ||
"files": [ | ||
{ | ||
"path": "magicui/warp-background.tsx", | ||
"content": "import { cn } from \"@/lib/utils\";\nimport { motion } from \"framer-motion\";\nimport React, { HTMLAttributes, useCallback, useMemo } from \"react\";\n\ninterface WarpBackgroundProps extends HTMLAttributes<HTMLDivElement> {\n children: React.ReactNode;\n perspective?: number;\n beamsPerSide?: number;\n beamSize?: number;\n beamDelayMax?: number;\n beamDelayMin?: number;\n beamDuration?: number;\n gridColor?: string;\n}\n\nconst Beam = ({\n width,\n x,\n delay,\n duration,\n}: {\n width: string | number;\n x: string | number;\n delay: number;\n duration: number;\n}) => {\n const hue = Math.floor(Math.random() * 360);\n const ar = Math.floor(Math.random() * 10) + 1;\n\n return (\n <motion.div\n style={\n {\n \"--x\": `${x}`,\n \"--width\": `${width}`,\n \"--aspect-ratio\": `${ar}`,\n \"--background\": `linear-gradient(hsl(${hue} 80% 60%), transparent)`,\n } as React.CSSProperties\n }\n className={`absolute left-[var(--x)] top-0 [aspect-ratio:1/var(--aspect-ratio)] [background:var(--background)] [width:var(--width)]`}\n initial={{ y: \"100cqmax\", x: \"-50%\" }}\n animate={{ y: \"-100%\", x: \"-50%\" }}\n transition={{\n duration,\n delay,\n repeat: Infinity,\n ease: \"linear\",\n }}\n />\n );\n};\n\nexport const WarpBackground: React.FC<WarpBackgroundProps> = ({\n children,\n perspective = 100,\n className,\n beamsPerSide = 3,\n beamSize = 5,\n beamDelayMax = 3,\n beamDelayMin = 0,\n beamDuration = 3,\n gridColor = \"hsl(var(--border))\",\n ...props\n}) => {\n const generateBeams = useCallback(() => {\n const beams = [];\n const cellsPerSide = Math.floor(100 / beamSize);\n const step = cellsPerSide / beamsPerSide;\n\n for (let i = 0; i < beamsPerSide; i++) {\n const x = Math.floor(i * step);\n const delay =\n Math.random() * (beamDelayMax - beamDelayMin) + beamDelayMin;\n beams.push({ x, delay });\n }\n return beams;\n }, [beamsPerSide, beamSize, beamDelayMax, beamDelayMin]);\n\n const topBeams = useMemo(() => generateBeams(), [generateBeams]);\n const rightBeams = useMemo(() => generateBeams(), [generateBeams]);\n const bottomBeams = useMemo(() => generateBeams(), [generateBeams]);\n const leftBeams = useMemo(() => generateBeams(), [generateBeams]);\n\n return (\n <div className={cn(\"relative rounded border p-20\", className)} {...props}>\n <div\n style={\n {\n \"--perspective\": `${perspective}px`,\n \"--grid-color\": gridColor,\n \"--beam-size\": `${beamSize}%`,\n } as React.CSSProperties\n }\n className={\n \"pointer-events-none absolute left-0 top-0 size-full overflow-hidden [clip-path:inset(0)] [container-type:size] [perspective:var(--perspective)] [transform-style:preserve-3d]\"\n }\n >\n {/* top side */}\n <div className=\"absolute [transform-style:preserve-3d] [background-size:var(--beam-size)_var(--beam-size)] [background:linear-gradient(var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_-0.5px_/var(--beam-size)_var(--beam-size),linear-gradient(90deg,_var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_50%_/var(--beam-size)_var(--beam-size)] [container-type:inline-size] [height:100cqmax] [transform-origin:50%_0%] [transform:rotateX(-90deg)] [width:100cqi]\">\n {topBeams.map((beam, index) => (\n <Beam\n key={`top-${index}`}\n width={`${beamSize}%`}\n x={`${beam.x * beamSize}%`}\n delay={beam.delay}\n duration={beamDuration}\n />\n ))}\n </div>\n {/* bottom side */}\n <div className=\"absolute top-full [transform-style:preserve-3d] [background-size:var(--beam-size)_var(--beam-size)] [background:linear-gradient(var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_-0.5px_/var(--beam-size)_var(--beam-size),linear-gradient(90deg,_var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_50%_/var(--beam-size)_var(--beam-size)] [container-type:inline-size] [height:100cqmax] [transform-origin:50%_0%] [transform:rotateX(-90deg)] [width:100cqi]\">\n {bottomBeams.map((beam, index) => (\n <Beam\n key={`bottom-${index}`}\n width={`${beamSize}%`}\n x={`${beam.x * beamSize}%`}\n delay={beam.delay}\n duration={beamDuration}\n />\n ))}\n </div>\n {/* left side */}\n <div className=\"absolute left-0 top-0 [transform-style:preserve-3d] [background-size:var(--beam-size)_var(--beam-size)] [background:linear-gradient(var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_-0.5px_/var(--beam-size)_var(--beam-size),linear-gradient(90deg,_var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_50%_/var(--beam-size)_var(--beam-size)] [container-type:inline-size] [height:100cqmax] [transform-origin:0%_0%] [transform:rotate(90deg)_rotateX(-90deg)] [width:100cqh]\">\n {leftBeams.map((beam, index) => (\n <Beam\n key={`left-${index}`}\n width={`${beamSize}%`}\n x={`${beam.x * beamSize}%`}\n delay={beam.delay}\n duration={beamDuration}\n />\n ))}\n </div>\n {/* right side */}\n <div className=\"absolute right-0 top-0 [transform-style:preserve-3d] [background-size:var(--beam-size)_var(--beam-size)] [background:linear-gradient(var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_-0.5px_/var(--beam-size)_var(--beam-size),linear-gradient(90deg,_var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_50%_/var(--beam-size)_var(--beam-size)] [container-type:inline-size] [height:100cqmax] [width:100cqh] [transform-origin:100%_0%] [transform:rotate(-90deg)_rotateX(-90deg)]\">\n {rightBeams.map((beam, index) => (\n <Beam\n key={`right-${index}`}\n width={`${beamSize}%`}\n x={`${beam.x * beamSize}%`}\n delay={beam.delay}\n duration={beamDuration}\n />\n ))}\n </div>\n </div>\n <div className=\"relative\">{children}</div>\n </div>\n );\n};\n", | ||
"type": "registry:ui", | ||
"target": "" | ||
} | ||
] | ||
} |
26 changes: 0 additions & 26 deletions
26
registry/default/example/warp-animation-container-demo.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { WarpBackground } from "@/components/magicui/warp-background"; | ||
import { | ||
Card, | ||
CardContent, | ||
CardDescription, | ||
CardTitle, | ||
} from "@/components/ui/card"; | ||
|
||
export default function ExampleComponentDemo() { | ||
return ( | ||
<WarpBackground> | ||
<Card className="w-80"> | ||
<CardContent className="flex flex-col gap-2 p-4"> | ||
<CardTitle>Congratulations on Your Promotion!</CardTitle> | ||
<CardDescription> | ||
Your hard work and dedication have paid off. We're thrilled to | ||
see you take this next step in your career. Keep up the fantastic | ||
work! | ||
</CardDescription> | ||
</CardContent> | ||
</Card> | ||
</WarpBackground> | ||
); | ||
} |
Oops, something went wrong.