drfeely.com/website/app/(pages)/articles/(content)/layout.tsx

52 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-08-29 04:50:52 +00:00
"use client";
import { ArrowLongLeftIcon, ArrowSmallUpIcon } from "@heroicons/react/24/solid";
2023-08-26 02:18:11 +00:00
import Link from "next/link";
2023-08-29 04:50:52 +00:00
import { ReactNode, useEffect, useState } from "react";
2023-08-26 02:18:11 +00:00
interface Props {
children: ReactNode;
}
const ArticlesLayout = ({ children }: Props) => {
2023-08-29 04:50:52 +00:00
const [isTopOfPage, setIsTopOfPage] = useState(true);
useEffect(() => {
const handleScroll = () => {
if (window.scrollY <= 500) {
setIsTopOfPage(true);
} else {
setIsTopOfPage(false);
}
};
window.addEventListener("scroll", handleScroll);
return () => window.removeEventListener("scroll", handleScroll);
}, []);
2023-08-26 02:18:11 +00:00
return (
2023-08-29 17:16:19 +00:00
<div className="w-11/12 md:w-2/5 mx-auto mt-20">
<Link href="/articles" className="font-bold block my-5">
2023-08-26 02:18:11 +00:00
<ArrowLongLeftIcon className="w-[24px] inline "></ArrowLongLeftIcon>{" "}
Back to Articles
</Link>
{children}
2023-08-29 17:16:19 +00:00
<Link href="/articles" className="font-bold block my-5">
2023-08-26 02:18:11 +00:00
<ArrowLongLeftIcon className="w-[24px] inline "></ArrowLongLeftIcon>{" "}
Back to Articles
</Link>
2023-08-29 04:50:52 +00:00
{isTopOfPage ? (
<></>
) : (
<a
href="#"
2023-08-29 17:16:19 +00:00
className=" fixed bottom-0 md:right-1/4 md:mr-[-4rem] right-0 mr-5 mb-5 p-3 bg-primary-100 rounded-lg drop-shadow-2xl flex flex-col items-center hover:drop-shadow-xl transition-all duration-300"
2023-08-29 04:50:52 +00:00
>
<ArrowSmallUpIcon className="w-[24px]"></ArrowSmallUpIcon>
<div className="text-sm italic">To Top</div>
</a>
)}
2023-08-26 02:18:11 +00:00
</div>
);
};
export default ArticlesLayout;