Cursor
unlumen-ui/cursor-primitiveFreeComponent
An animated cursor component that allows you to customize both the cursor and cursor follow elements with smooth animations.
Live preview
live · rendered by the registry
Rendered by Unlumen Ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://ui.unlumen.com/r/cursor-primitive.jsonSource
1"use client";23import * as React from "react";4import {5 motion,6 useMotionValue,7 useSpring,8 AnimatePresence,9 type HTMLMotionProps,10 type SpringOptions,11} from "motion/react";1213import { getStrictContext } from "@/lib/get-strict-context";14import { Slot, type WithAsChild } from "@/components/unlumen-ui/primitives/slot";1516type CursorContextType = {17 cursorPos: { x: number; y: number };18 active: boolean;19 global: boolean;20 containerRef: React.RefObject<HTMLDivElement | null>;21 cursorRef: React.RefObject<HTMLDivElement | null>;22};2324const [LocalCursorProvider, useCursor] =25 getStrictContext<CursorContextType>("CursorContext");2627type CursorProviderProps = {28 children: React.ReactNode;29 global?: boolean;30};3132function CursorProvider({ children, global = false }: CursorProviderProps) {33 const [cursorPos, setCursorPos] = React.useState({ x: 0, y: 0 });34 const [active, setActive] = React.useState(false);3536 const containerRef = React.useRef<HTMLDivElement>(null);37 const cursorRef = React.useRef<HTMLDivElement>(null);3839 React.useEffect(() => {40 const id = "__cursor_none_style__";41 if (document.getElementById(id)) return;4243 const style = document.createElement("style");44 style.id = id;45 style.textContent = `46 .animate-ui-cursor-none, .animate-ui-cursor-none * { cursor: none !important; }47 `;48 document.head.appendChild(style);49 }, []);5051 React.useEffect(() => {52 let removeListeners: () => void;5354 if (global) {55 const handlePointerMove = (e: PointerEvent) => {56 setCursorPos({ x: e.clientX, y: e.clientY });57 setActive(true);58 };5960 const handlePointerOut = (e: PointerEvent | MouseEvent) => {61 if (e instanceof PointerEvent && e.relatedTarget === null) {62 setActive(false);63 }64 };6566 const handleVisibilityChange = () => {67 if (document.visibilityState === "hidden") setActive(false);68 };6970 window.addEventListener("pointermove", handlePointerMove, {71 passive: true,72 });73 window.addEventListener("pointerout", handlePointerOut, {74 passive: true,75 });76 window.addEventListener("mouseout", handlePointerOut, { passive: true });77 document.addEventListener("visibilitychange", handleVisibilityChange);7879 removeListeners = () => {80 window.removeEventListener("pointermove", handlePointerMove);81 window.removeEventListener("pointerout", handlePointerOut);82// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from Unlumen Ui
All 225 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 | |
| Animate Text Input Typinganimate-text-input-typing | Unlumen Ui | Components | Free | 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 |
