Cursor
unlumen-ui/cursorFreeComponent
An animated cursor component that allows you to customize both the cursor and cursor follow elements with smooth animations.
Install it
npx shadcn@latest add https://ui.unlumen.com/r/cursor.jsonSource
1import * as React from "react";2import {3 motion,4 useMotionValue,5 useSpring,6 useVelocity,7 useTransform,8} from "motion/react";910import {11 CursorProvider as CursorProviderPrimitive,12 Cursor as CursorPrimitive,13 CursorFollow as CursorFollowPrimitive,14 CursorContainer as CursorContainerPrimitive,15 useCursor,16 type CursorProviderProps as CursorProviderPropsPrimitive,17 type CursorContainerProps as CursorContainerPropsPrimitive,18 type CursorProps as CursorPropsPrimitive,19 type CursorFollowProps as CursorFollowPropsPrimitive,20} from "@/components/unlumen-ui/primitives/cursor-primitive";21import { cn } from "@/lib/utils";2223type CursorProviderProps = Omit<CursorProviderPropsPrimitive, "children"> &24 CursorContainerPropsPrimitive;2526function CursorProvider({ global, ...props }: CursorProviderProps) {27 return (28 <CursorProviderPrimitive global={global}>29 <CursorContainerPrimitive {...props} />30 </CursorProviderPrimitive>31 );32}3334type CursorProps = Omit<CursorPropsPrimitive, "children" | "asChild">;3536function Cursor({ className, ...props }: CursorProps) {37 const { cursorPos } = useCursor();38 const x = useMotionValue(0);39 const y = useMotionValue(0);4041 React.useEffect(() => {42 x.set(cursorPos.x);43 y.set(cursorPos.y);44 }, [cursorPos, x, y]);4546 const springConfig = { damping: 25, stiffness: 300 };47 const smoothX = useSpring(x, springConfig);48 const smoothY = useSpring(y, springConfig);4950 const velocityX = useVelocity(smoothX);51 const velocityY = useVelocity(smoothY);5253 // tilt the cursor based on velocity for a gravity feel54 const rotateVelocity = useTransform([velocityX, velocityY], ([vx, vy]) => {55 const rx = ((vx as number) / 1000) * 30;56 const ry = ((vy as number) / 1000) * 30;57 return Math.max(-45, Math.min(45, rx + ry));58 });59 const rotate = useSpring(rotateVelocity, { damping: 15, stiffness: 200 });6061 const scale = useTransform([velocityX, velocityY], ([vx, vy]) => {62 const velocity = Math.sqrt((vx as number) ** 2 + (vy as number) ** 2);63 return 1 - Math.min(velocity / 2000, 0.1);64 });6566 return (67 <CursorPrimitive68 style={{69 top: smoothY,70 left: smoothX,71 transform: "translate(-4.5%, -11%)", // Override default centering to align tip72 }}73 {...props}74 >75 <motion.svg76 className={cn("size-6 text-foreground", className)}77 xmlns="http://www.w3.org/2000/svg"78 viewBox="0 0 40 40"79 style={{80 rotate,81 scale,82// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from Unlumen Ui
All 233 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| AI Chatai-chat | Unlumen Ui | Components | Paid | 2 deps | |
| Vercel Animate Countanimate-count | Unlumen Ui | Components | Free | 1 dep | |
| Animate Digitsanimate-digits | Unlumen Ui | Components | Free | 1 dep | |
| Animated Inputanimate-text-input-typing | Unlumen Ui | Components | Paid | 1 dep | |
| Animated Listanimated-list | Unlumen Ui | Components | Free | 1 dep | |
| Apple Switchapple-switch | Unlumen Ui | Components | Free | 1 dep | |
| Aurora Barsaurora-bars | Unlumen Ui | Components | Free | 1 dep | |
| Aurora Bluraurora-blur | Unlumen Ui | Components | Free | 2 deps |
