Magic Card
magicui/magic-cardFreeComponent
A spotlight effect that follows your mouse cursor and highlights borders on hover.
Live preview
live · rendered by the registry
Rendered by magicui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://magicui.design/r/magic-card.jsonSource
1"use client"23import React, { useCallback, useEffect, useMemo, useRef, useState } from "react"4import {5 motion,6 useMotionTemplate,7 useMotionValue,8 useSpring,9} from "motion/react"10import { useTheme } from "next-themes"1112import { cn } from "@/lib/utils"1314interface MagicCardBaseProps {15 children?: React.ReactNode16 className?: string17 gradientSize?: number18 gradientFrom?: string19 gradientTo?: string20}2122interface MagicCardGradientProps extends MagicCardBaseProps {23 mode?: "gradient"2425 gradientColor?: string26 gradientOpacity?: number2728 glowFrom?: never29 glowTo?: never30 glowAngle?: never31 glowSize?: never32 glowBlur?: never33 glowOpacity?: never34}3536interface MagicCardOrbProps extends MagicCardBaseProps {37 mode: "orb"3839 glowFrom?: string40 glowTo?: string41 glowAngle?: number42 glowSize?: number43 glowBlur?: number44 glowOpacity?: number4546 gradientColor?: never47 gradientOpacity?: never48}4950type MagicCardProps = MagicCardGradientProps | MagicCardOrbProps51type ResetReason = "enter" | "leave" | "global" | "init"5253function isOrbMode(props: MagicCardProps): props is MagicCardOrbProps {54 return props.mode === "orb"55}5657export function MagicCard(props: MagicCardProps) {58 const {59 children,60 className,61 gradientSize = 200,62 gradientColor = "#262626",63 gradientOpacity = 0.8,64 gradientFrom = "#9E7AFF",65 gradientTo = "#FE8BBB",66 mode = "gradient",67 } = props6869 const glowFrom = isOrbMode(props) ? (props.glowFrom ?? "#ee4f27") : "#ee4f27"70 const glowTo = isOrbMode(props) ? (props.glowTo ?? "#6b21ef") : "#6b21ef"71 const glowAngle = isOrbMode(props) ? (props.glowAngle ?? 90) : 9072 const glowSize = isOrbMode(props) ? (props.glowSize ?? 420) : 42073 const glowBlur = isOrbMode(props) ? (props.glowBlur ?? 60) : 6074 const glowOpacity = isOrbMode(props) ? (props.glowOpacity ?? 0.9) : 0.975 const { theme, systemTheme } = useTheme()76 const [mounted, setMounted] = useState(false)7778 useEffect(() => setMounted(true), [])7980 const isDarkTheme = useMemo(() => {81 if (!mounted) return true82 const currentTheme = theme === "system" ? systemTheme : theme83 return currentTheme === "dark"84 }, [theme, systemTheme, mounted])8586 const mouseX = useMotionValue(-gradientSize)87 const mouseY = useMotionValue(-gradientSize)8889 const orbX = useSpring(mouseX, { stiffness: 250, damping: 30, mass: 0.6 })90 const orbY = useSpring(mouseY, { stiffness: 250, damping: 30, mass: 0.6 })91// … truncated
What it pulls in
npm packages
Files it writes
More from magicui
All 247 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Androidandroid | magicui | Components | Free | no deps | |
| Animated Beamanimated-beam | magicui | Components | Free | 1 dep | |
| Animated Circular Progress Baranimated-circular-progress-bar | magicui | Components | Free | no deps | |
| Animated Gradient Textanimated-gradient-text | magicui | Components | Free | no deps | |
| Animated Grid Patternanimated-grid-pattern | magicui | Components | Free | 1 dep | |
| Animated Listanimated-list | magicui | Components | Free | 1 dep | |
| Animated Shiny Textanimated-shiny-text | magicui | Components | Free | no deps | |
| Theme Toggleranimated-theme-toggler | magicui | Components | Free | 1 dep |
