diff --git a/components/search/ScrollToTop.tsx b/components/search/ScrollToTop.tsx new file mode 100644 index 0000000..f896f32 --- /dev/null +++ b/components/search/ScrollToTop.tsx @@ -0,0 +1,64 @@ +import React, { useEffect, useState } from "react"; + +const ScrollToTop = () => { + const [isVisible, setIsVisible] = useState(false); + + const toggleVisibility = () => { + if (window.scrollY > 700) { + setIsVisible(true); + } else { + setIsVisible(false); + } + }; + + const scrollToTop = () => { + window.scrollTo({ + top: 0, + behavior: "smooth", + }); + }; + + useEffect(() => { + window.addEventListener("scroll", toggleVisibility); + return () => { + window.removeEventListener("scroll", toggleVisibility); + }; + }, []); + + return ( +
+
+ + + + +

+ Back to top +

+
+
+
+ ); +}; + +export default ScrollToTop; diff --git a/components/search/Search.tsx b/components/search/Search.tsx index bfe7b59..dbf4ed9 100644 --- a/components/search/Search.tsx +++ b/components/search/Search.tsx @@ -6,6 +6,7 @@ import { SortDropdown } from "./FilterComponents"; import { useRouter, useSearchParams } from "next/navigation"; import { queryDatabase } from "./query-db"; import SearchResults from "./SearchResults"; +import ScrollToTop from "./ScrollToTop"; import { FaFilter } from "react-icons/fa6"; import { SearchFilterPage, SearchFilters } from "./Filters"; import SearchBlurb from "./Blurb"; @@ -369,6 +370,7 @@ const Search = () => { ge={ge} /> )} + diff --git a/tailwind.config.ts b/tailwind.config.ts index e262fa4..492229b 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -82,8 +82,10 @@ const config = { "accordion-up": "accordion-up 0.2s ease-out", }, }, + }, plugins: [require("tailwindcss-animate")], + width: ["responsive", "hover", "focus"], } satisfies Config; export default config;