From bff9d42cab0d36d35e6ce08ca5c260d08d77cd12 Mon Sep 17 00:00:00 2001 From: nethmalgunawardhana Date: Tue, 26 Nov 2024 06:32:31 +0530 Subject: [PATCH 1/2] Add BackToTopButton component for improved navigation and user experience --- src/app/page.tsx | 3 +- src/components/ui/back-to-top.tsx | 49 +++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/components/ui/back-to-top.tsx diff --git a/src/app/page.tsx b/src/app/page.tsx index ad81281..1145361 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -42,7 +42,7 @@ import Lottie from "react-lottie-player"; import { IContact } from "@/interfaces/IContacts"; import { getReachUs } from "@/services/reachus.service"; import RegistrationStatus from "@/components/ui/google-gemini-effect"; - +import BackToTopButton from "@/components/ui/back-to-top"; export const products = [ { title: "Are You Ready?", @@ -291,6 +291,7 @@ export default function Home() { return ( + { ( isLoading || !isLoadingAnimComplete ) && (
diff --git a/src/components/ui/back-to-top.tsx b/src/components/ui/back-to-top.tsx new file mode 100644 index 0000000..f254593 --- /dev/null +++ b/src/components/ui/back-to-top.tsx @@ -0,0 +1,49 @@ +import React, { useState, useEffect } from 'react'; +import { ArrowUpIcon } from '@heroicons/react/24/solid'; + +const BackToTopButton: React.FC = () => { + const [isVisible, setIsVisible] = useState(false); + + // Show button when page is scrolled up to given distance + const toggleVisibility = () => { + if (window.pageYOffset > 300) { + setIsVisible(true); + } else { + setIsVisible(false); + } + }; + + // Scroll to top when button is clicked + const scrollToTop = () => { + window.scrollTo({ + top: 0, + behavior: 'smooth' + }); + }; + + useEffect(() => { + // Add scroll event listener + window.addEventListener('scroll', toggleVisibility); + + // Clean up the event listener + return () => { + window.removeEventListener('scroll', toggleVisibility); + }; + }, []); + + return ( + <> + {isVisible && ( + + )} + + ); +}; + +export default BackToTopButton; \ No newline at end of file From 5c8d04de49bd774660fcd7462b5e8b0d6dbd9084 Mon Sep 17 00:00:00 2001 From: nethmalgunawardhana Date: Tue, 26 Nov 2024 16:37:49 +0530 Subject: [PATCH 2/2] Add smooth scrolling behavior and update BackToTopButton styling for better visibility --- src/app/globals.css | 4 +++- src/components/ui/back-to-top.tsx | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/app/globals.css b/src/app/globals.css index 7110efb..4680eaa 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -59,4 +59,6 @@ --chart-5: 340 75% 55%; } } - +html { + scroll-behavior: smooth; +} diff --git a/src/components/ui/back-to-top.tsx b/src/components/ui/back-to-top.tsx index f254593..899ccc8 100644 --- a/src/components/ui/back-to-top.tsx +++ b/src/components/ui/back-to-top.tsx @@ -36,7 +36,7 @@ const BackToTopButton: React.FC = () => { {isVisible && (