From 9c1bea3bdc88f2bcf72ec1e8e9b68142d3582e34 Mon Sep 17 00:00:00 2001 From: Shubhashish-Chakraborty Date: Sat, 15 Nov 2025 23:21:00 +0530 Subject: [PATCH 1/2] feat(ui): Added the Scroll to top button --- src/App.tsx | 2 ++ src/components/ScrollToTop.tsx | 42 ++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/components/ScrollToTop.tsx diff --git a/src/App.tsx b/src/App.tsx index 51b9d660..d0f43d0d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,7 @@ import { useEffect } from 'react'; import { RouterProvider } from 'react-router-dom'; import router from '@/routes'; +import ScrollToTop from './components/ScrollToTop'; const App = () => { useEffect(() => { @@ -24,6 +25,7 @@ const App = () => { return (
+
); diff --git a/src/components/ScrollToTop.tsx b/src/components/ScrollToTop.tsx new file mode 100644 index 00000000..6c90e412 --- /dev/null +++ b/src/components/ScrollToTop.tsx @@ -0,0 +1,42 @@ +import { useEffect, useState } from 'react'; + +export default function ScrollToTop() { + const [visible, setVisible] = useState(false); + + useEffect(() => { + const onScroll = () => setVisible(window.scrollY > 300); + window.addEventListener('scroll', onScroll, { passive: true }); + onScroll(); + return () => window.removeEventListener('scroll', onScroll); + }, []); + + if (!visible) return null; + + return ( + + ); +} \ No newline at end of file From f52a462db6769824745e1be0d80518bca2a195fc Mon Sep 17 00:00:00 2001 From: Shubhashish-Chakraborty Date: Sat, 15 Nov 2025 23:44:56 +0530 Subject: [PATCH 2/2] fixed formatting --- src/components/ScrollToTop.tsx | 56 +++++++++++++++++----------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/components/ScrollToTop.tsx b/src/components/ScrollToTop.tsx index 6c90e412..aa6d333f 100644 --- a/src/components/ScrollToTop.tsx +++ b/src/components/ScrollToTop.tsx @@ -1,23 +1,23 @@ import { useEffect, useState } from 'react'; export default function ScrollToTop() { - const [visible, setVisible] = useState(false); + const [visible, setVisible] = useState(false); - useEffect(() => { - const onScroll = () => setVisible(window.scrollY > 300); - window.addEventListener('scroll', onScroll, { passive: true }); - onScroll(); - return () => window.removeEventListener('scroll', onScroll); - }, []); + useEffect(() => { + const onScroll = () => setVisible(window.scrollY > 300); + window.addEventListener('scroll', onScroll, { passive: true }); + onScroll(); + return () => window.removeEventListener('scroll', onScroll); + }, []); - if (!visible) return null; + if (!visible) return null; - return ( - - ); -} \ No newline at end of file + > + + + + + ); +}