Cursor Gradient
rivelle/gradient-meshFreeComponent
An animated color mesh with a luminous pointer-following field.
Install it
npx shadcn@latest add https://rivelle.dev/r/gradient-mesh.jsonSource
1"use client";23import * as React from "react";45import { cn } from "@/lib/utils";67type GradientMeshProps = React.ComponentProps<"div"> & {8 followPointer?: boolean;9 speed?: "slow" | "normal";10};1112function GradientMesh({13 children,14 className,15 followPointer = true,16 onPointerLeave,17 onPointerMove,18 speed = "normal",19 style,20 ...props21}: GradientMeshProps) {22 const frame = React.useRef<number | null>(null);2324 const setPosition = (element: HTMLDivElement, x: number, y: number) => {25 if (frame.current !== null) cancelAnimationFrame(frame.current);26 frame.current = requestAnimationFrame(() => {27 element.style.setProperty("--mesh-x", `${x}%`);28 element.style.setProperty("--mesh-y", `${y}%`);29 });30 };3132 React.useEffect(33 () => () => {34 if (frame.current !== null) cancelAnimationFrame(frame.current);35 },36 [],37 );3839 return (40 <div41 className={cn(42 "relative isolate overflow-hidden rounded-[2.25rem] border border-foreground/10 bg-background text-foreground shadow-[0_40px_120px_-70px_var(--foreground)]",43 className,44 )}45 data-slot="gradient-mesh"46 onPointerLeave={(event) => {47 setPosition(event.currentTarget, 50, 50);48 onPointerLeave?.(event);49 }}50 onPointerMove={(event) => {51 if (52 followPointer &&53 !window.matchMedia("(prefers-reduced-motion: reduce)").matches54 ) {55 const bounds = event.currentTarget.getBoundingClientRect();56 setPosition(57 event.currentTarget,58 ((event.clientX - bounds.left) / bounds.width) * 100,59 ((event.clientY - bounds.top) / bounds.height) * 100,60 );61 }62 onPointerMove?.(event);63 }}64 style={65 {66 "--mesh-x": "50%",67 "--mesh-y": "50%",68 ...style,69 } as React.CSSProperties70 }71 {...props}72 >73 <div74 aria-hidden="true"75 className={cn(76 "absolute inset-[-45%] opacity-65 blur-3xl",77 speed === "slow"78 ? "motion-safe:animate-[spin_30s_linear_infinite]"79 : "motion-safe:animate-[spin_18s_linear_infinite]",80 )}81 style={{82 background:83// … truncated
What it pulls in
Other registry items
Files it writes
More from rivelle
All 83 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | rivelle | Components | Free | 2 deps | |
| Alertalert | rivelle | Components | Free | 1 dep | |
| Alert Dialogalert-dialog | rivelle | Components | Free | 1 dep | |
| Aspect Ratioaspect-ratio | rivelle | Components | Free | 1 dep | |
| Avataravatar | rivelle | Components | Free | 1 dep | |
| Badgebadge | rivelle | Components | Free | 2 deps | |
| Breadcrumbbreadcrumb | rivelle | Components | Free | 2 deps | |
| Buttonbutton | rivelle | Components | Free | 2 deps |
