Skip to content

Commit 283a9a6

Browse files
committed
feat: added loader
1 parent 76d0792 commit 283a9a6

File tree

4 files changed

+67
-12
lines changed

4 files changed

+67
-12
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
"@fontsource/league-gothic": "^5.0.18",
1919
"@fontsource/poppins": "^5.0.8",
2020
"@vitejs/plugin-react": "^4.2.1",
21+
"baffle": "^0.3.6",
22+
"baffle-react": "^0.0.2",
2123
"framer-motion": "^11.5.4",
2224
"lodash": "^4.17.21",
2325
"prop-types": "^15.8.1",

src/App.jsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import routes from "@/routes/index";
55
import Navbar from "@/components/Navbar/index";
66
import Cursor from "./components/Cursor";
77
import CursorVariantProvider from "@/context/CursorVariantProvider";
8+
import Loader from "@/components/Loader";
89

910
const navLinks = [
1011
{ name: "About Us", path: "/about-us" },
@@ -17,22 +18,22 @@ const navLinks = [
1718
function App() {
1819
return (
1920
<CursorVariantProvider>
21+
<Loader />
2022
<AnimatePresence>
21-
<Router>
23+
<Router>
2224
<Navbar links={navLinks} />
2325
<Cursor />
24-
2526
<ToastContainer />
26-
<Routes>
27-
{routes.map((route) => (
28-
<Route
29-
path={route.path}
30-
element={route.render}
31-
key={route.label}
32-
/>
33-
))}
34-
</Routes>
35-
</Router>
27+
<Routes>
28+
{routes.map((route) => (
29+
<Route
30+
path={route.path}
31+
element={route.render}
32+
key={route.label}
33+
/>
34+
))}
35+
</Routes>
36+
</Router>
3637
</AnimatePresence>
3738
</CursorVariantProvider>
3839
);

src/components/Loader/index.jsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import baffle from "baffle";
2+
import { useEffect, useState } from "react";
3+
4+
function Loader() {
5+
const [isVisible, setIsVisible] = useState(true);
6+
const [isDisplayed, setIsDisplayed] = useState(true);
7+
8+
useEffect(() => {
9+
const target = baffle('.loader');
10+
target.set({
11+
characters: "█▓█ ▒░/▒░ █░▒▓/ █▒▒ ▓▒▓/█<░▒ ▓/░>",
12+
speed: 120
13+
});
14+
target.start();
15+
target.reveal(3000, 100);
16+
17+
const timer = setTimeout(() => {
18+
setIsVisible(false);
19+
setTimeout(() => {
20+
setIsDisplayed(false);
21+
}, 1000);
22+
}, 5000);
23+
24+
return () => clearTimeout(timer);
25+
}, []);
26+
27+
if (!isDisplayed) {
28+
return null;
29+
}
30+
31+
return (
32+
<div
33+
className={`absolute top-0 left-0 w-full h-full flex justify-center items-center bg-secondary-dark bg-opacity-100 transition-opacity duration-1000 ${
34+
isVisible ? 'opacity-100' : 'opacity-0'
35+
}`}
36+
style={{ display: isDisplayed ? 'flex' : 'none' }}
37+
>
38+
<div className="loader text-secondary-light font-poppins text-4xl sm:text-5xl md:text-6xl lg:text-7xl xl:text-8xl">
39+
Welcome to CodeX
40+
</div>
41+
</div>
42+
);
43+
}
44+
45+
export default Loader;

src/routes/index.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ import About from "@/pages/About/index";
44
import Gallery from "@/pages/Gallery/Gallery";
55
import Contact from "@/pages/Contact";
66
import PageNotFound from "../pages/PageNotFound";
7+
import Loader from "@/components/Loader";
78

89
const routes = [
10+
{
11+
label: "Loader",
12+
path: "/loader",
13+
requireAuth: false,
14+
render: <Loader />,
15+
},
916
{
1017
label: "Contact",
1118
path: "/contact",

0 commit comments

Comments
 (0)