From be96d3fc0c81769b23daf7263c290af3831a9d07 Mon Sep 17 00:00:00 2001 From: Krishna Ayyalasomayajula Date: Mon, 1 Jun 2026 19:53:47 -0500 Subject: [PATCH] feat: add scroll progress indicator --- components/ui/ScrollProgress.tsx | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 components/ui/ScrollProgress.tsx diff --git a/components/ui/ScrollProgress.tsx b/components/ui/ScrollProgress.tsx new file mode 100644 index 0000000..7f11eb5 --- /dev/null +++ b/components/ui/ScrollProgress.tsx @@ -0,0 +1,33 @@ +"use client"; + +import { useEffect, useState } from "react"; + +export function ScrollProgress() { + const [progress, setProgress] = useState(0); + + useEffect(() => { + const update = () => { + const total = document.documentElement.scrollHeight - window.innerHeight; + setProgress(total > 0 ? (window.scrollY / total) * 100 : 0); + }; + + if (window.CSS?.supports("animation-timeline", "scroll()")) { + return; + } + + update(); + window.addEventListener("scroll", update, { passive: true }); + return () => window.removeEventListener("scroll", update); + }, []); + + return ( +
+ ); +}