diff --git a/content/docs/components/magic-card.mdx b/content/docs/components/magic-card.mdx index c6afc5f95..9071da77a 100644 --- a/content/docs/components/magic-card.mdx +++ b/content/docs/components/magic-card.mdx @@ -44,14 +44,15 @@ npx shadcn@latest add "https://magicui.design/r/magic-card" ### MagicCard -| Prop name | Type | Default | Description | -| -------------------- | --------------- | --------- | ------------------------------------------- | -| children | React.ReactNode | - | The content to be rendered inside the card | -| className | string | - | Additional CSS classes to apply to the card | -| gradientSize | number | 200 | Size of the gradient effect | -| gradientColor | string | "#262626" | Color of the gradient effect | -| gradientOpacity | number | - | Opacity of the gradient effect | -| gradientTransparency | number | 80 | Transparency level of the gradient effect | +| Prop name | Type | Default | Description | +| --------------- | --------------- | --------- | ------------------------------------------- | +| children | React.ReactNode | - | The content to be rendered inside the card | +| className | string | - | Additional CSS classes to apply to the card | +| gradientSize | number | 200 | Size of the gradient effect | +| gradientColor | string | "#262626" | Color of the gradient effect | +| gradientOpacity | number | 0.8 | Opacity of the gradient effect | +| gradientFrom | string | "#9E7AFF" | Start color of the gradient border | +| gradientTo | string | "#FE8BBB" | End color of the gradient border | ## Credits diff --git a/public/r/styles/default/magic-card.json b/public/r/styles/default/magic-card.json index 8d93efa66..7fa1d6f96 100644 --- a/public/r/styles/default/magic-card.json +++ b/public/r/styles/default/magic-card.json @@ -7,7 +7,7 @@ "files": [ { "path": "magicui/magic-card.tsx", - "content": "\"use client\";\n\nimport React, { useCallback, useEffect, useRef } from \"react\";\nimport { motion, useMotionTemplate, useMotionValue } from \"framer-motion\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport interface MagicCardProps extends React.HTMLAttributes {\n gradientSize?: number;\n gradientColor?: string;\n gradientOpacity?: number;\n}\n\nexport function MagicCard({\n children,\n className,\n gradientSize = 200,\n gradientColor = \"#262626\",\n gradientOpacity = 0.8,\n}: MagicCardProps) {\n const cardRef = useRef(null);\n const mouseX = useMotionValue(-gradientSize);\n const mouseY = useMotionValue(-gradientSize);\n\n const handleMouseMove = useCallback(\n (e: MouseEvent) => {\n if (cardRef.current) {\n const { left, top } = cardRef.current.getBoundingClientRect();\n const clientX = e.clientX;\n const clientY = e.clientY;\n mouseX.set(clientX - left);\n mouseY.set(clientY - top);\n }\n },\n [mouseX, mouseY],\n );\n\n const handleMouseOut = useCallback(\n (e: MouseEvent) => {\n if (!e.relatedTarget) {\n document.removeEventListener(\"mousemove\", handleMouseMove);\n mouseX.set(-gradientSize);\n mouseY.set(-gradientSize);\n }\n },\n [handleMouseMove, mouseX, gradientSize, mouseY],\n );\n\n const handleMouseEnter = useCallback(() => {\n document.addEventListener(\"mousemove\", handleMouseMove);\n mouseX.set(-gradientSize);\n mouseY.set(-gradientSize);\n }, [handleMouseMove, mouseX, gradientSize, mouseY]);\n\n useEffect(() => {\n document.addEventListener(\"mousemove\", handleMouseMove);\n document.addEventListener(\"mouseout\", handleMouseOut);\n document.addEventListener(\"mouseenter\", handleMouseEnter);\n\n return () => {\n document.removeEventListener(\"mousemove\", handleMouseMove);\n document.removeEventListener(\"mouseout\", handleMouseOut);\n document.removeEventListener(\"mouseenter\", handleMouseEnter);\n };\n }, [handleMouseEnter, handleMouseMove, handleMouseOut]);\n\n useEffect(() => {\n mouseX.set(-gradientSize);\n mouseY.set(-gradientSize);\n }, [gradientSize, mouseX, mouseY]);\n\n return (\n \n
{children}
\n \n \n );\n}\n", + "content": "\"use client\";\n\nimport React, { useCallback, useEffect, useRef } from \"react\";\nimport { motion, useMotionTemplate, useMotionValue } from \"framer-motion\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport interface MagicCardProps extends React.HTMLAttributes {\n gradientSize?: number;\n gradientColor?: string;\n gradientOpacity?: number;\n gradientColors?: [string, string, string];\n}\n\nexport function MagicCard({\n children,\n className,\n gradientSize = 200,\n gradientColor = \"#262626\",\n gradientOpacity = 0.8,\n gradientColors = [\"#FF0080\", \"#4096FF\", \"#78FF78\"],\n}: MagicCardProps) {\n const cardRef = useRef(null);\n const mouseX = useMotionValue(-gradientSize);\n const mouseY = useMotionValue(-gradientSize);\n\n const handleMouseMove = useCallback(\n (e: MouseEvent) => {\n if (cardRef.current) {\n const { left, top } = cardRef.current.getBoundingClientRect();\n const clientX = e.clientX;\n const clientY = e.clientY;\n mouseX.set(clientX - left);\n mouseY.set(clientY - top);\n }\n },\n [mouseX, mouseY]\n );\n\n const handleMouseOut = useCallback(\n (e: MouseEvent) => {\n if (!e.relatedTarget) {\n document.removeEventListener(\"mousemove\", handleMouseMove);\n mouseX.set(-gradientSize);\n mouseY.set(-gradientSize);\n }\n },\n [handleMouseMove, mouseX, gradientSize, mouseY]\n );\n\n const handleMouseEnter = useCallback(() => {\n document.addEventListener(\"mousemove\", handleMouseMove);\n mouseX.set(-gradientSize);\n mouseY.set(-gradientSize);\n }, [handleMouseMove, mouseX, gradientSize, mouseY]);\n\n useEffect(() => {\n document.addEventListener(\"mousemove\", handleMouseMove);\n document.addEventListener(\"mouseout\", handleMouseOut);\n document.addEventListener(\"mouseenter\", handleMouseEnter);\n\n return () => {\n document.removeEventListener(\"mousemove\", handleMouseMove);\n document.removeEventListener(\"mouseout\", handleMouseOut);\n document.removeEventListener(\"mouseenter\", handleMouseEnter);\n };\n }, [handleMouseEnter, handleMouseMove, handleMouseOut]);\n\n useEffect(() => {\n mouseX.set(-gradientSize);\n mouseY.set(-gradientSize);\n }, [gradientSize, mouseX, mouseY]);\n\n return (\n \n
\n
{children}
\n \n \n
\n );\n}\n", "type": "registry:ui", "target": "" } diff --git a/registry/default/example/magic-card-demo.tsx b/registry/default/example/magic-card-demo.tsx index 7128bff3b..5c3c77e15 100644 --- a/registry/default/example/magic-card-demo.tsx +++ b/registry/default/example/magic-card-demo.tsx @@ -11,13 +11,13 @@ export default function MagicCardDemo() { } > Magic Card diff --git a/registry/default/magicui/magic-card.tsx b/registry/default/magicui/magic-card.tsx index bbd55d7c7..cf5e90a95 100644 --- a/registry/default/magicui/magic-card.tsx +++ b/registry/default/magicui/magic-card.tsx @@ -1,14 +1,16 @@ "use client"; +import { motion, useMotionTemplate, useMotionValue } from "motion/react"; import React, { useCallback, useEffect, useRef } from "react"; -import { motion, useMotionTemplate, useMotionValue } from "framer-motion"; import { cn } from "@/lib/utils"; -export interface MagicCardProps extends React.HTMLAttributes { +interface MagicCardProps extends React.HTMLAttributes { gradientSize?: number; gradientColor?: string; gradientOpacity?: number; + gradientFrom?: string; + gradientTo?: string; } export function MagicCard({ @@ -17,6 +19,8 @@ export function MagicCard({ gradientSize = 200, gradientColor = "#262626", gradientOpacity = 0.8, + gradientFrom = "#9E7AFF", + gradientTo = "#FE8BBB", }: MagicCardProps) { const cardRef = useRef(null); const mouseX = useMotionValue(-gradientSize); @@ -72,14 +76,12 @@ export function MagicCard({ return (
-
{children}
+
+
{children}
+
); }