Skip to content

Commit

Permalink
Merge branch 'staging' into rafael/navbar-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
izruff committed Oct 15, 2024
2 parents c12e150 + f55e1d7 commit a48ec7e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 20 deletions.
47 changes: 47 additions & 0 deletions app/components/scroll-to-top.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"use client";

import {useEffect} from "react";
import {useAnimationControls, useScroll, motion, Variants} from "framer-motion";
import {FaArrowAltCircleUp, FaArrowCircleUp, FaArrowUp} from "react-icons/fa"

const isBrowser = () => typeof window != 'undefined';

const ScrollToTopContainerVariants: Variants = {
hide: {opacity: 0, y: 100},
show: {opacity: 1, y: 0},
}

const scrollToTop = () => {
if (!isBrowser()) {
return;
}
window.scrollTo({top: 0, behavior: 'smooth'});
};

const ScrollToTopButton = () => {
const {scrollY} = useScroll();
const controls = useAnimationControls();

useEffect(() => {
return scrollY.on('change', (latestValue) => {
if (latestValue > window.innerHeight) {
controls.start('show');
} else {
controls.start('hide');
}
});
});

return (
<motion.button
className="fixed bottom-10 right-0 p-10"
variants={ScrollToTopContainerVariants}
initial="hide"
animate={controls}
onClick={scrollToTop}>
<FaArrowCircleUp className="text-4xl text-white" />
</motion.button>
);
};

export default ScrollToTopButton;
2 changes: 2 additions & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Navbar from "./components/navbar";
import ModalOverlay from "./components/modal-overlay";
import Link from "next/link";
import Footer from "./components/footer";
import ScrollToTopButton from "@/app/components/scroll-to-top";

const inter = Inter({ subsets: ["latin"] });

Expand All @@ -23,6 +24,7 @@ export default function RootLayout({
<body className={inter.className}>
<Navbar />
{children}
<ScrollToTopButton />
<Footer />
</body>
</html>
Expand Down
23 changes: 4 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"test": "jest --coverage"
},
"dependencies": {
"framer-motion": "^11.5.6",
"framer-motion": "^11.9.0",
"next": "^14.2.5",
"react": "^18",
"react-dom": "^18",
Expand Down

0 comments on commit a48ec7e

Please sign in to comment.