Skip to content

UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.

fix: update pointer API (#572)

Dillion Vermad448bbbcd42c
diff --git a/content/docs/components/pointer.mdx b/content/docs/components/pointer.mdx
index 8d9bf11f..90218832 100644
--- a/content/docs/components/pointer.mdx
+++ b/content/docs/components/pointer.mdx
@@ -40,9 +40,12 @@ npx shadcn@latest add "https://magicui.design/r/pointer"
</Tabs>
-## Props
+## Usage
-| Property | Type | Default | Description |
-| ----------- | ----------------- | ------- | ----------------------------------------------- |
-| `children` | `React.ReactNode` | - | The content that will be wrapped by the pointer |
-| `className` | `string` | - | The className of the pointer |
+```tsx
+import { Pointer } from "@/components/magicui/pointer";
+```
+
+```tsx
+<Pointer />
+```
diff --git a/public/r/pointer-demo-1.json b/public/r/pointer-demo-1.json
index d4238e7c..ad2e4f43 100644
--- a/public/r/pointer-demo-1.json
+++ b/public/r/pointer-demo-1.json
@@ -10,7 +10,7 @@
"files": [
{
"path": "registry/example/pointer-demo-1.tsx",
- "content": "\"use client\";\n\nimport { PointerWrapper } from \"@/components/magicui/pointer\";\n\nexport default function PointerDemo1() {\n return (\n <PointerWrapper>\n <div className=\"relative flex size-[500px] items-center justify-center overflow-hidden rounded-lg border bg-background\">\n <span className=\"pointer-events-none whitespace-pre-wrap bg-gradient-to-b from-black to-gray-300/80 bg-clip-text text-center text-8xl font-semibold leading-none text-transparent dark:from-white dark:to-slate-900/10\">\n Pointer\n </span>\n </div>\n </PointerWrapper>\n );\n}\n",
+ "content": "\"use client\";\n\nimport {\n Card,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from \"@/components/ui/card\";\nimport { Pointer } from \"@/components/magicui/pointer\";\nimport { motion } from \"motion/react\";\n\nexport default function PointerDemo1() {\n return (\n <div className=\"grid grid-cols-1 gap-6 md:grid-cols-2 md:grid-rows-2\">\n <Card className=\"col-span-1 row-span-1 overflow-hidden border-none bg-gradient-to-br from-slate-50 to-slate-100 shadow-lg transition-all hover:shadow-xl dark:from-slate-900 dark:to-slate-800\">\n <CardHeader className=\"relative pb-2\">\n <CardTitle className=\"text-xl font-bold\">Animated Pointer</CardTitle>\n <CardDescription className=\"text-sm text-slate-600 dark:text-slate-400\">\n Animated pointer\n </CardDescription>\n </CardHeader>\n <CardContent className=\"relative flex h-40 items-center justify-center p-6\">\n <span className=\"pointer-events-none text-center text-xl font-medium text-slate-800 dark:text-slate-200\">\n Move your cursor here\n </span>\n </CardContent>\n <Pointer>\n <motion.div\n animate={{\n scale: [0.8, 1, 0.8],\n rotate: [0, 5, -5, 0],\n }}\n transition={{\n duration: 1.5,\n repeat: Infinity,\n ease: \"easeInOut\",\n }}\n >\n <svg\n width=\"40\"\n height=\"40\"\n viewBox=\"0 0 40 40\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n className=\"text-pink-600\"\n >\n <motion.path\n d=\"M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z\"\n fill=\"currentColor\"\n animate={{ scale: [1, 1.2, 1] }}\n transition={{\n duration: 0.8,\n repeat: Infinity,\n ease: \"easeInOut\",\n }}\n />\n </svg>\n </motion.div>\n </Pointer>\n </Card>\n\n <Card className=\"col-span-1 row-span-1 overflow-hidden border-none bg-gradient-to-br from-blue-50 to-blue-100 shadow-lg transition-all hover:shadow-xl dark:from-blue-900 dark:to-blue-800\">\n <CardHeader className=\"relative pb-2\">\n <CardTitle className=\"text-xl font-bold\">Colored Pointer</CardTitle>\n <CardDescription className=\"text-sm text-blue-700 dark:text-blue-300\">\n A custom pointer with different color\n </CardDescription>\n </CardHeader>\n <CardContent className=\"relative flex h-40 items-center justify-center p-6\">\n <span className=\"pointer-events-none text-center text-xl font-medium text-blue-800 dark:text-blue-200\">\n Try me out\n </span>\n </CardContent>\n <Pointer className=\"fill-blue-500\" />\n </Card>\n\n <Card className=\"col-span-1 row-span-1 overflow-hidden border-none bg-gradient-to-br from-purple-50 to-purple-100 shadow-lg transition-all hover:shadow-xl dark:from-purple-900 dark:to-purple-800\">\n <CardHeader className=\"relative pb-2\">\n <CardTitle className=\"text-xl font-bold\">Custom Shape</CardTitle>\n <CardDescription className=\"text-sm text-purple-700 dark:text-purple-300\">\n A pointer with a custom SVG shape\n </CardDescription>\n </CardHeader>\n <CardContent className=\"relative flex h-40 items-center justify-center p-6\">\n <span className=\"pointer-events-none text-center text-xl font-medium text-purple-800 dark:text-purple-200\">\n Hover here\n </span>\n </CardContent>\n <Pointer>\n <svg\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <circle cx=\"12\" cy=\"12\" r=\"10\" className=\"fill-purple-500\" />\n <circle cx=\"12\" cy=\"12\" r=\"5\" className=\"fill-white\" />\n </svg>\n </Pointer>\n </Card>\n\n <Card className=\"col-span-1 row-span-1 overflow-hidden border-none bg-gradient-to-br from-green-50 to-green-100 shadow-lg transition-all hover:shadow-xl dark:from-green-900 dark:to-green-800\">\n <CardHeader className=\"relative pb-2\">\n <CardTitle className=\"text-xl font-bold\">Emoji Pointer</CardTitle>\n <CardDescription className=\"text-sm text-green-700 dark:text-green-300\">\n Using an emoji as a custom pointer\n </CardDescription>\n </CardHeader>\n <CardContent className=\"relative flex h-40 items-center justify-center p-6\">\n <span className=\"pointer-events-none text-center text-xl font-medium text-green-800 dark:text-green-200\">\n Check this out\n </span>\n </CardContent>\n <Pointer>\n <div className=\"text-2xl\">πŸ‘†</div>\n </Pointer>\n </Card>\n </div>\n );\n}\n",
"type": "registry:example",
"target": "components/pointer-demo-1.tsx"
}
diff --git a/public/r/pointer.json b/public/r/pointer.json
index a5adc2cd..866cf75b 100644
--- a/public/r/pointer.json
+++ b/public/r/pointer.json
@@ -10,7 +10,7 @@
"files": [
{
"path": "registry/magicui/pointer.tsx",
- "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport { AnimatePresence, motion, useMotionValue } from \"motion/react\";\nimport React, { useEffect, useRef, useState } from \"react\";\n\n/**\n * @property {React.ReactNode} children - The child elements to be wrapped\n */\ninterface PointerWrapperProps extends React.HTMLAttributes<HTMLDivElement> {\n children?: React.ReactNode;\n}\n\n/**\n * A component that wraps content and adds a custom pointer animation when hovering\n * over the wrapped area. The pointer follows the mouse movement within the wrapped area.\n *\n * @component\n * @param {PointerWrapperProps} props - The component props\n */\nexport function PointerWrapper({\n children,\n className,\n ...props\n}: PointerWrapperProps) {\n const x = useMotionValue(0);\n const y = useMotionValue(0);\n\n const ref = useRef<HTMLDivElement>(null);\n const [rect, setRect] = useState<DOMRect | null>(null);\n const [isInside, setIsInside] = useState<boolean>(false);\n\n useEffect(() => {\n function updateRect() {\n if (ref.current) {\n setRect(ref.current.getBoundingClientRect());\n }\n }\n\n // Initial rect calculation\n updateRect();\n\n // Update rect on window resize\n window.addEventListener(\"resize\", updateRect);\n\n return () => {\n window.removeEventListener(\"resize\", updateRect);\n };\n }, []);\n\n function handleMouseMove(e: React.MouseEvent<HTMLDivElement>) {\n if (rect) {\n x.set(e.clientX - rect.left);\n y.set(e.clientY - rect.top);\n }\n }\n\n function handleMouseLeave() {\n setIsInside(false);\n }\n\n function handleMouseEnter() {\n if (ref.current) {\n setRect(ref.current.getBoundingClientRect());\n setIsInside(true);\n }\n }\n\n return (\n <div\n ref={ref}\n className={cn(\"relative cursor-none\", className)}\n onMouseLeave={handleMouseLeave}\n onMouseEnter={handleMouseEnter}\n onMouseMove={handleMouseMove}\n {...props}\n >\n <AnimatePresence>{isInside && <Pointer x={x} y={y} />}</AnimatePresence>\n {children}\n </div>\n );\n}\n\n/**\n * @property {MotionValue<number>} x - The x-coordinate position of the pointer\n * @property {MotionValue<number>} y - The y-coordinate position of the pointer\n */\ninterface PointerProps {\n x: any;\n y: any;\n}\n\n/**\n * A custom pointer component that displays an animated arrow cursor\n *\n * @description Used internally by PointerWrapper to show the custom cursor\n *\n * @component\n * @param {PointerProps} props - The component props\n */\nfunction Pointer({ x, y }: PointerProps): JSX.Element {\n return (\n <motion.div\n className=\"pointer-events-none absolute z-50 h-4 w-4 rounded-full\"\n style={{\n top: y,\n left: x,\n }}\n initial={{\n scale: 1,\n opacity: 1,\n }}\n animate={{\n scale: 1,\n opacity: 1,\n }}\n exit={{\n scale: 0,\n opacity: 0,\n }}\n >\n <svg\n stroke=\"currentColor\"\n fill=\"currentColor\"\n strokeWidth=\"1\"\n viewBox=\"0 0 16 16\"\n className=\"h-6 w-6 translate-x-[-12px] translate-y-[-10px] rotate-[-70deg] stroke-white text-black\"\n height=\"1em\"\n width=\"1em\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path d=\"M14.082 2.182a.5.5 0 0 1 .103.557L8.528 15.467a.5.5 0 0 1-.917-.007L5.57 10.694.803 8.652a.5.5 0 0 1-.006-.916l12.728-5.657a.5.5 0 0 1 .556.103z\"></path>\n </svg>\n </motion.div>\n );\n}\n",
+ "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport {\n AnimatePresence,\n HTMLMotionProps,\n motion,\n useMotionValue,\n} from \"motion/react\";\nimport { useEffect, useRef, useState } from \"react\";\n\ninterface PointerProps extends Omit<HTMLMotionProps<\"div\">, \"ref\"> {}\n\n/**\n * A custom pointer component that displays an animated cursor.\n * Add this as a child to any component to enable a custom pointer when hovering.\n * You can pass custom children to render as the pointer.\n *\n * @component\n * @param {PointerProps} props - The component props\n */\nexport function Pointer({\n className,\n style,\n children,\n ...props\n}: PointerProps): JSX.Element {\n const x = useMotionValue(0);\n const y = useMotionValue(0);\n const [isActive, setIsActive] = useState<boolean>(false);\n const containerRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (typeof window !== \"undefined\" && containerRef.current) {\n // Get the parent element directly from the ref\n const parentElement = containerRef.current.parentElement;\n\n if (parentElement) {\n // Add cursor-none to parent\n parentElement.style.cursor = \"none\";\n\n // Add event listeners to parent\n const handleMouseMove = (e: MouseEvent) => {\n x.set(e.clientX);\n y.set(e.clientY);\n };\n\n const handleMouseEnter = () => {\n setIsActive(true);\n };\n\n const handleMouseLeave = () => {\n setIsActive(false);\n };\n\n parentElement.addEventListener(\"mousemove\", handleMouseMove);\n parentElement.addEventListener(\"mouseenter\", handleMouseEnter);\n parentElement.addEventListener(\"mouseleave\", handleMouseLeave);\n\n return () => {\n parentElement.style.cursor = \"\";\n parentElement.removeEventListener(\"mousemove\", handleMouseMove);\n parentElement.removeEventListener(\"mouseenter\", handleMouseEnter);\n parentElement.removeEventListener(\"mouseleave\", handleMouseLeave);\n };\n }\n }\n }, [x, y]);\n\n return (\n <>\n <div ref={containerRef} />\n <AnimatePresence>\n {isActive && (\n <motion.div\n className=\"transform-[translate(-50%,-50%)] pointer-events-none fixed z-50\"\n style={{\n top: y,\n left: x,\n ...style,\n }}\n initial={{\n scale: 0,\n opacity: 0,\n }}\n animate={{\n scale: 1,\n opacity: 1,\n }}\n exit={{\n scale: 0,\n opacity: 0,\n }}\n {...props}\n >\n {children || (\n <svg\n stroke=\"currentColor\"\n fill=\"currentColor\"\n strokeWidth=\"1\"\n viewBox=\"0 0 16 16\"\n height=\"24\"\n width=\"24\"\n xmlns=\"http://www.w3.org/2000/svg\"\n className={cn(\n \"rotate-[-70deg] stroke-white text-black\",\n className,\n )}\n >\n <path d=\"M14.082 2.182a.5.5 0 0 1 .103.557L8.528 15.467a.5.5 0 0 1-.917-.007L5.57 10.694.803 8.652a.5.5 0 0 1-.006-.916l12.728-5.657a.5.5 0 0 1 .556.103z\" />\n </svg>\n )}\n </motion.div>\n )}\n </AnimatePresence>\n </>\n );\n}\n",
"type": "registry:ui",
"target": "components/magicui/pointer.tsx"
}
diff --git a/registry/example/pointer-demo-1.tsx b/registry/example/pointer-demo-1.tsx
index bccc548d..ab943ef5 100644
--- a/registry/example/pointer-demo-1.tsx
+++ b/registry/example/pointer-demo-1.tsx
@@ -1,15 +1,122 @@
"use client";
-import { PointerWrapper } from "@/registry/magicui/pointer";
+import {
+ Card,
+ CardContent,
+ CardDescription,
+ CardHeader,
+ CardTitle,
+} from "@/components/ui/card";
+import { Pointer } from "@/registry/magicui/pointer";
+import { motion } from "motion/react";
export default function PointerDemo1() {
return (
- <PointerWrapper>
- <div className="relative flex size-[500px] items-center justify-center overflow-hidden rounded-lg border bg-background">
- <span className="pointer-events-none whitespace-pre-wrap bg-gradient-to-b from-black to-gray-300/80 bg-clip-text text-center text-8xl font-semibold leading-none text-transparent dark:from-white dark:to-slate-900/10">
- Pointer
- </span>
- </div>
- </PointerWrapper>
+ <div className="grid grid-cols-1 gap-6 md:grid-cols-2 md:grid-rows-2">
+ <Card className="col-span-1 row-span-1 overflow-hidden border-none bg-gradient-to-br from-slate-50 to-slate-100 shadow-lg transition-all hover:shadow-xl dark:from-slate-900 dark:to-slate-800">
+ <CardHeader className="relative pb-2">
+ <CardTitle className="text-xl font-bold">Animated Pointer</CardTitle>
+ <CardDescription className="text-sm text-slate-600 dark:text-slate-400">
+ Animated pointer
+ </CardDescription>
+ </CardHeader>
+ <CardContent className="relative flex h-40 items-center justify-center p-6">
+ <span className="pointer-events-none text-center text-xl font-medium text-slate-800 dark:text-slate-200">
+ Move your cursor here
+ </span>
+ </CardContent>
+ <Pointer>
+ <motion.div
+ animate={{
+ scale: [0.8, 1, 0.8],
+ rotate: [0, 5, -5, 0],
+ }}
+ transition={{
+ duration: 1.5,
+ repeat: Infinity,
+ ease: "easeInOut",
+ }}
+ >
+ <svg
+ width="40"
+ height="40"
+ viewBox="0 0 40 40"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+ className="text-pink-600"
+ >
+ <motion.path
+ d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"
+ fill="currentColor"
+ animate={{ scale: [1, 1.2, 1] }}
+ transition={{
+ duration: 0.8,
+ repeat: Infinity,
+ ease: "easeInOut",
+ }}
+ />
+ </svg>
+ </motion.div>
+ </Pointer>
+ </Card>
+
+ <Card className="col-span-1 row-span-1 overflow-hidden border-none bg-gradient-to-br from-blue-50 to-blue-100 shadow-lg transition-all hover:shadow-xl dark:from-blue-900 dark:to-blue-800">
+ <CardHeader className="relative pb-2">
+ <CardTitle className="text-xl font-bold">Colored Pointer</CardTitle>
+ <CardDescription className="text-sm text-blue-700 dark:text-blue-300">
+ A custom pointer with different color
+ </CardDescription>
+ </CardHeader>
+ <CardContent className="relative flex h-40 items-center justify-center p-6">
+ <span className="pointer-events-none text-center text-xl font-medium text-blue-800 dark:text-blue-200">
+ Try me out
+ </span>
+ </CardContent>
+ <Pointer className="fill-blue-500" />
+ </Card>
+
+ <Card className="col-span-1 row-span-1 overflow-hidden border-none bg-gradient-to-br from-purple-50 to-purple-100 shadow-lg transition-all hover:shadow-xl dark:from-purple-900 dark:to-purple-800">
+ <CardHeader className="relative pb-2">
+ <CardTitle className="text-xl font-bold">Custom Shape</CardTitle>
+ <CardDescription className="text-sm text-purple-700 dark:text-purple-300">
+ A pointer with a custom SVG shape
+ </CardDescription>
+ </CardHeader>
+ <CardContent className="relative flex h-40 items-center justify-center p-6">
+ <span className="pointer-events-none text-center text-xl font-medium text-purple-800 dark:text-purple-200">
+ Hover here
+ </span>
+ </CardContent>
+ <Pointer>
+ <svg
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <circle cx="12" cy="12" r="10" className="fill-purple-500" />
+ <circle cx="12" cy="12" r="5" className="fill-white" />
+ </svg>
+ </Pointer>
+ </Card>
+
+ <Card className="col-span-1 row-span-1 overflow-hidden border-none bg-gradient-to-br from-green-50 to-green-100 shadow-lg transition-all hover:shadow-xl dark:from-green-900 dark:to-green-800">
+ <CardHeader className="relative pb-2">
+ <CardTitle className="text-xl font-bold">Emoji Pointer</CardTitle>
+ <CardDescription className="text-sm text-green-700 dark:text-green-300">
+ Using an emoji as a custom pointer
+ </CardDescription>
+ </CardHeader>
+ <CardContent className="relative flex h-40 items-center justify-center p-6">
+ <span className="pointer-events-none text-center text-xl font-medium text-green-800 dark:text-green-200">
+ Check this out
+ </span>
+ </CardContent>
+ <Pointer>
+ <div className="text-2xl">πŸ‘†</div>
+ </Pointer>
+ </Card>
+ </div>
);
}
diff --git a/registry/magicui/pointer.tsx b/registry/magicui/pointer.tsx
index 5abb1cc1..be75d4e1 100644
--- a/registry/magicui/pointer.tsx
+++ b/registry/magicui/pointer.tsx
@@ -1,136 +1,118 @@
"use client";
import { cn } from "@/lib/utils";
-import { AnimatePresence, motion, useMotionValue } from "motion/react";
-import React, { useEffect, useRef, useState } from "react";
+import {
+ AnimatePresence,
+ HTMLMotionProps,
+ motion,
+ useMotionValue,
+} from "motion/react";
+import { useEffect, useRef, useState } from "react";
-/**
- * @property {React.ReactNode} children - The child elements to be wrapped
- */
-interface PointerWrapperProps extends React.HTMLAttributes<HTMLDivElement> {
- children?: React.ReactNode;
-}
+interface PointerProps extends Omit<HTMLMotionProps<"div">, "ref"> {}
/**
- * A component that wraps content and adds a custom pointer animation when hovering
- * over the wrapped area. The pointer follows the mouse movement within the wrapped area.
+ * A custom pointer component that displays an animated cursor.
+ * Add this as a child to any component to enable a custom pointer when hovering.
+ * You can pass custom children to render as the pointer.
*
* @component
- * @param {PointerWrapperProps} props - The component props
+ * @param {PointerProps} props - The component props
*/
-export function PointerWrapper({
- children,
+export function Pointer({
className,
+ style,
+ children,
...props
-}: PointerWrapperProps) {
+}: PointerProps): JSX.Element {
const x = useMotionValue(0);
const y = useMotionValue(0);
-
- const ref = useRef<HTMLDivElement>(null);
- const [rect, setRect] = useState<DOMRect | null>(null);
- const [isInside, setIsInside] = useState<boolean>(false);
+ const [isActive, setIsActive] = useState<boolean>(false);
+ const containerRef = useRef<HTMLDivElement>(null);
useEffect(() => {
- function updateRect() {
- if (ref.current) {
- setRect(ref.current.getBoundingClientRect());
- }
- }
+ if (typeof window !== "undefined" && containerRef.current) {
+ // Get the parent element directly from the ref
+ const parentElement = containerRef.current.parentElement;
- // Initial rect calculation
- updateRect();
+ if (parentElement) {
+ // Add cursor-none to parent
+ parentElement.style.cursor = "none";
- // Update rect on window resize
- window.addEventListener("resize", updateRect);
+ // Add event listeners to parent
+ const handleMouseMove = (e: MouseEvent) => {
+ x.set(e.clientX);
+ y.set(e.clientY);
+ };
- return () => {
- window.removeEventListener("resize", updateRect);
- };
- }, []);
+ const handleMouseEnter = () => {
+ setIsActive(true);
+ };
- function handleMouseMove(e: React.MouseEvent<HTMLDivElement>) {
- if (rect) {
- x.set(e.clientX - rect.left);
- y.set(e.clientY - rect.top);
- }
- }
+ const handleMouseLeave = () => {
+ setIsActive(false);
+ };
- function handleMouseLeave() {
- setIsInside(false);
- }
+ parentElement.addEventListener("mousemove", handleMouseMove);
+ parentElement.addEventListener("mouseenter", handleMouseEnter);
+ parentElement.addEventListener("mouseleave", handleMouseLeave);
- function handleMouseEnter() {
- if (ref.current) {
- setRect(ref.current.getBoundingClientRect());
- setIsInside(true);
+ return () => {
+ parentElement.style.cursor = "";
+ parentElement.removeEventListener("mousemove", handleMouseMove);
+ parentElement.removeEventListener("mouseenter", handleMouseEnter);
+ parentElement.removeEventListener("mouseleave", handleMouseLeave);
+ };
+ }
}
- }
+ }, [x, y]);
return (
- <div
- ref={ref}
- className={cn("relative cursor-none", className)}
- onMouseLeave={handleMouseLeave}
- onMouseEnter={handleMouseEnter}
- onMouseMove={handleMouseMove}
- {...props}
- >
- <AnimatePresence>{isInside && <Pointer x={x} y={y} />}</AnimatePresence>
- {children}
- </div>
- );
-}
-
-/**
- * @property {MotionValue<number>} x - The x-coordinate position of the pointer
- * @property {MotionValue<number>} y - The y-coordinate position of the pointer
- */
-interface PointerProps {
- x: any;
- y: any;
-}
-
-/**
- * A custom pointer component that displays an animated arrow cursor
- *
- * @description Used internally by PointerWrapper to show the custom cursor
- *
- * @component
- * @param {PointerProps} props - The component props
- */
-function Pointer({ x, y }: PointerProps): JSX.Element {
- return (
- <motion.div
- className="pointer-events-none absolute z-50 h-4 w-4 rounded-full"
- style={{
- top: y,
- left: x,
- }}
- initial={{
- scale: 1,
- opacity: 1,
- }}
- animate={{
- scale: 1,
- opacity: 1,
- }}
- exit={{
- scale: 0,
- opacity: 0,
- }}
- >
- <svg
- stroke="currentColor"
- fill="currentColor"
- strokeWidth="1"
- viewBox="0 0 16 16"
- className="h-6 w-6 translate-x-[-12px] translate-y-[-10px] rotate-[-70deg] stroke-white text-black"
- height="1em"
- width="1em"
- xmlns="http://www.w3.org/2000/svg"
- >
- <path d="M14.082 2.182a.5.5 0 0 1 .103.557L8.528 15.467a.5.5 0 0 1-.917-.007L5.57 10.694.803 8.652a.5.5 0 0 1-.006-.916l12.728-5.657a.5.5 0 0 1 .556.103z"></path>
- </svg>
- </motion.div>
+ <>
+ <div ref={containerRef} />
+ <AnimatePresence>
+ {isActive && (
+ <motion.div
+ className="transform-[translate(-50%,-50%)] pointer-events-none fixed z-50"
+ style={{
+ top: y,
+ left: x,
+ ...style,
+ }}
+ initial={{
+ scale: 0,
+ opacity: 0,
+ }}
+ animate={{
+ scale: 1,
+ opacity: 1,
+ }}
+ exit={{
+ scale: 0,
+ opacity: 0,
+ }}
+ {...props}
+ >
+ {children || (
+ <svg
+ stroke="currentColor"
+ fill="currentColor"
+ strokeWidth="1"
+ viewBox="0 0 16 16"
+ height="24"
+ width="24"
+ xmlns="http://www.w3.org/2000/svg"
+ className={cn(
+ "rotate-[-70deg] stroke-white text-black",
+ className,
+ )}
+ >
+ <path d="M14.082 2.182a.5.5 0 0 1 .103.557L8.528 15.467a.5.5 0 0 1-.917-.007L5.57 10.694.803 8.652a.5.5 0 0 1-.006-.916l12.728-5.657a.5.5 0 0 1 .556.103z" />
+ </svg>
+ )}
+ </motion.div>
+ )}
+ </AnimatePresence>
+ </>
);
}