-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from RotaractMora/design-fixes
Design fixes
- Loading branch information
Showing
3 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,4 +59,6 @@ | |
--chart-5: 340 75% 55%; | ||
} | ||
} | ||
|
||
html { | ||
scroll-behavior: smooth; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<boolean>(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 && ( | ||
<button | ||
onClick={scrollToTop} | ||
className="fixed bottom-6 right-6 z-50 bg-gray-700 text-white p-3 rounded-full shadow-lg hover:bg-gray-900 transition-all duration-300 ease-in-out" | ||
aria-label="Scroll to top" | ||
> | ||
<ArrowUpIcon className="h-6 w-6" /> | ||
</button> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default BackToTopButton; |