From 67a7b899f72506fb6b3f0232be46bd8c8dd1f31e Mon Sep 17 00:00:00 2001 From: Krishna Ayyalasomayajula Date: Mon, 1 Jun 2026 19:56:13 -0500 Subject: [PATCH] feat: add vertical reading progress indicator --- components/ui/ReadingProgress.tsx | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 components/ui/ReadingProgress.tsx diff --git a/components/ui/ReadingProgress.tsx b/components/ui/ReadingProgress.tsx new file mode 100644 index 0000000..8fcd42b --- /dev/null +++ b/components/ui/ReadingProgress.tsx @@ -0,0 +1,35 @@ +"use client"; + +import { useEffect, useState } from "react"; + +export function ReadingProgress() { + const [progress, setProgress] = useState(0); + + useEffect(() => { + if (window.CSS?.supports("animation-timeline", "scroll()")) { + return; + } + + const update = () => { + const article = document.querySelector("article"); + if (!article) return; + const rect = article.getBoundingClientRect(); + const total = article.scrollHeight; + const scrolled = Math.max(0, -rect.top + window.innerHeight * 0.3); + setProgress(total > 0 ? Math.min(100, (scrolled / total) * 100) : 0); + }; + + update(); + window.addEventListener("scroll", update, { passive: true }); + return () => window.removeEventListener("scroll", update); + }, []); + + return ( +
+
+
+ ); +}