From d5f08f7416c9ea8e1bd700aca5379f5455206a4a Mon Sep 17 00:00:00 2001 From: No0ne003 Date: Sun, 12 May 2024 16:54:40 +0100 Subject: [PATCH] make cursor variant can access from any component --- src/App.jsx | 21 +++++++++++++++++++-- src/components/Cursor.jsx | 2 +- src/layouts/header.jsx | 38 ++++++++++++++++++++++++++------------ src/pages/Home.jsx | 2 -- 4 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index eabccc4..174dd65 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -26,14 +26,22 @@ import UseFetchHookTest from "./pages/CustomHooks/use-fetch/test"; import UseOnClickOutsideTest from "./pages/CustomHooks/use-outside-click/test"; import { UseWindowResizeTest } from "./pages/CustomHooks/use-window-resize/test"; import ScrollToSection from "./pages/ScrollToSection"; +import { useState } from "react"; +import Cursor from "./components/Cursor"; function App() { + const [cursorVariant, setCursorVariant] = useState("default"); + return ( -
+
- } /> + } + /> + {/* Accordion component */} } /> {/* Random color generator */} @@ -97,4 +105,13 @@ function App() { ); } +function HomeWithCursor({ cursorVariant }) { + return ( + <> + + + + ); +} + export default App; diff --git a/src/components/Cursor.jsx b/src/components/Cursor.jsx index 2a20130..6810957 100644 --- a/src/components/Cursor.jsx +++ b/src/components/Cursor.jsx @@ -32,7 +32,7 @@ const Cursor = ({ cursorVariant }) => { }, link: { scale: 3, - } + }, }; return ( diff --git a/src/layouts/header.jsx b/src/layouts/header.jsx index 694bd28..ab9529a 100644 --- a/src/layouts/header.jsx +++ b/src/layouts/header.jsx @@ -11,13 +11,11 @@ import { Button } from "@/components/ui/button"; import { useTheme } from "@/components/theme-provider"; import { useEffect } from "react"; -function Header() { +function Header({ setCursorVariant }) { const { theme, setTheme } = useTheme(); useEffect(() => { - // Set the theme based on system preference if (theme === "system") { - // Use the system's color scheme preference setTheme( window.matchMedia("(prefers-color-scheme: dark)")?.matches ? "dark" @@ -29,8 +27,13 @@ function Header() { return (
- - + setCursorVariant("text")} + onMouseLeave={() => setCursorVariant("default")} + > + + +
); @@ -49,17 +52,28 @@ function Logo() { ); } -function Navigation() { +function Navigation({ setCursorVariant }) { const { theme } = useTheme(); return ( ); diff --git a/src/pages/Home.jsx b/src/pages/Home.jsx index 7d9859f..8aee85e 100644 --- a/src/pages/Home.jsx +++ b/src/pages/Home.jsx @@ -1,5 +1,4 @@ import { useState } from "react"; -import Cursor from "@/components/Cursor"; import { projects } from "@/data/projects"; import { Link } from "react-router-dom"; @@ -33,7 +32,6 @@ function Home() { ))} - ); }