Skip to content

Commit

Permalink
mask cursor on home page
Browse files Browse the repository at this point in the history
  • Loading branch information
No0ne003 committed Apr 2, 2024
1 parent 0fd0db8 commit a5cb5e4
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 1 deletion.
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@radix-ui/react-slot": "^1.0.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"framer-motion": "^11.0.24",
"lucide-react": "^0.344.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
54 changes: 54 additions & 0 deletions src/components/Cursor.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { useEffect, useState } from "react";
import { motion } from "framer-motion";
import { FaArrowAltCircleRight } from "react-icons/fa";

const Cursor = ({ cursorVariant }) => {
const [mousePosition, setMousePosition] = useState({
x: 0,
y: 0,
});

useEffect(() => {
const mouseMove = (e) => {
setMousePosition({
x: e.clientX,
y: e.clientY,
});
};

window.addEventListener("mousemove", mouseMove);

return () => {
window.removeEventListener("mousemove", mouseMove);
};
}, []);

const variants = {
default: {
x: mousePosition.x - 16,
y: mousePosition.y - 16,
},
text: {
x: mousePosition.x - 75,
y: mousePosition.y - 75,
height: 150,
width: 150,
},
};

return (
<motion.div
className="cursor size-8 bg-primary fixed rounded-full z-50 pointer-events-none mix-blend-darken dark:mix-blend-difference top-0 left-0 flex justify-center items-center color-black"
variants={variants}
animate={cursorVariant}
>
{cursorVariant === "text" ? (
<p className="mix-blend-darken dark:mix-blend-difference -rotate-45">
<FaArrowAltCircleRight size={50} />
</p>
) : null}
</motion.div>
);
};

export default Cursor;
3 changes: 3 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
-webkit-appearance: none;
margin: 0;
}

input[type="number"] {
-moz-appearance: textfield;
}
Expand All @@ -92,3 +93,5 @@
@apply bg-gradient-to-br from-primary-foreground to-secondary;
}
}

/*Cursor*/
22 changes: 21 additions & 1 deletion src/pages/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import { useState } from "react";
import Cursor from "@/components/Cursor";
import { projects } from "@/data/projects";
import { Link } from "react-router-dom";

function Home() {
const [cursorVariant, setCursorVariant] = useState("default");

const handleMouseEnter = () => {
setCursorVariant("text");
};

const handleMouseLeave = () => {
setCursorVariant("default");
};

return (
<div className="flex flex-col gap-3 justify-start items-center">
<p className="text-xl">
Expand All @@ -12,10 +24,18 @@ function Home() {
I&apos;ll start on it when add the first componenet (project)
</p>
{projects.map((item) => (
<Link key={item.id} to={item.path}>
<Link
className="py-4 px-6 border-border border-b-[1px] w-full flex"
key={item.id}
to={item.path}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
{item.name}
</Link>
))}

<Cursor cursorVariant={cursorVariant} />
</div>
);
}
Expand Down

0 comments on commit a5cb5e4

Please sign in to comment.