Skip to content

Commit

Permalink
add back to top button
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Nov 24, 2023
1 parent 4fdfad6 commit 118b078
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Editori11y from "@components/tools/editorially";
import Script from "next/script";
import GoogleAnalytics from "@components/tools/google-analytics";
import {isDraftMode} from "@lib/drupal/utils";
import BackToTop from "@components/elements/back-to-top";

export const metadata = {
title: 'Stanford University'
Expand Down Expand Up @@ -35,6 +36,7 @@ const RootLayout = ({children, modal}: { children: React.ReactNode, modal: React
{children}
{modal}
</main>
<BackToTop/>
<PageFooter/>
</div>
</body>
Expand Down
22 changes: 22 additions & 0 deletions src/components/elements/back-to-top.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"use client";

import {useWindowScroll} from "@uidotdev/usehooks";
import Button from "@components/elements/button";
import {ChevronUpIcon} from "@heroicons/react/20/solid";

const BackToTop = () => {
const [{x, y}, scrollTo] = useWindowScroll();
const showButton = (y && y > 1500);
return (
<Button
buttonElem
className={"fixed bottom-10 right-10 transition-all duration-300 " + (showButton ? "opacity-100 visible" : "opacity-0 invisible")}
onClick={() => scrollTo({left: 0, top: 0, behavior: "smooth"})}
>
<span className="block flex gap-2">
<ChevronUpIcon width={30}/>Return to Top
</span>
</Button>
)
}
export default BackToTop;

1 comment on commit 118b078

@vercel
Copy link

@vercel vercel bot commented on 118b078 Nov 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.