Cursor
v3cn/cursorFreeComponent
A component for displaying Cursor.
Live preview
live · rendered by the registry
Rendered by v3cn on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://v3cn.vineet.pro/r/cursor.jsonSource
1"use client";23import { useEffect, useRef, useState } from "react";45import { cn } from "@/lib/utils";6import { motion } from "framer-motion";78type CursorProps = {9 cursorClass?: string;10};1112type Position = {13 x: number;14 y: number;15};1617type TrailerType = "default" | "video";1819export const Cursor = ({ cursorClass }: CursorProps) => {20 const [trailerType, setTrailerType] = useState<TrailerType>("default");21 const [isInteracting, setIsInteracting] = useState(false);22 const [isClicked, setIsClicked] = useState(false);2324 const position:Position = {25 x: 0,26 y: 0,27 };28 const cursorRef = useRef<HTMLDivElement>(null);2930 const animateTrailer = (e: MouseEvent) => {31 if (!cursorRef.current) return;3233 const x = e.clientX - cursorRef.current.offsetWidth / 2;34 const y = e.clientY - cursorRef.current.offsetHeight / 2;3536 const keyframes = {37 transform: `translate(${x}px, ${y}px) scale(${isInteracting ? 3 : 1})`,38 };3940 cursorRef.current.animate(keyframes, {41 duration: 100,42 fill: "forwards",43 });44 };4546 useEffect(() => {47 const handleMouseMove = (e: MouseEvent) => {48 const interactable = (e.target as HTMLElement).closest(".interactable");49 const interacting = interactable !== null;5051 animateTrailer(e);5253 setTrailerType(interacting ? (interactable as HTMLElement).dataset.type as TrailerType : "default");54 setIsInteracting(interacting);55 };5657 window.addEventListener("mousemove", handleMouseMove);5859 return () => {60 window.removeEventListener("mousemove", handleMouseMove);61 };62 }, [isInteracting]);6364 useEffect(() => {65 const handleClick = () => {66 setIsClicked(true);67 setTimeout(() => {68 setIsClicked(false);69 }, 100);70 };7172 window.addEventListener("click", handleClick);7374 return () => {75 window.removeEventListener("click", handleClick);76 };77 }, []);7879 return (80 <motion.div81 whileTap={{ scale: 0.9 }}82 id="trailer"83 style={{ top: `${position.y}px`, left: `${position.x}px` }}84 className={cn(85 "bg-transparent rounded-full fixed z-50 pointer-events-none border-[3px] border-slate-500 border-solid w-10 h-10 transition-all",86 cursorClass,87 isClicked && "w-8 h-8"88 )}89 data-type={trailerType}90 ref={cursorRef}91 />92 );93};
Files it writes
More from v3cn
All 6 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Discord Presencediscord | v3cn | Components | Free | no deps | |
| GitHub Graphgithub | v3cn | Components | Free | no deps |
