"use client"; import { useRef, useState, UIEvent, useEffect } from "react"; export default function CustomScrollArea({ children }: { children: React.ReactNode }) { // Scroll indicator size (default 20) const thumbHeight = 20; const scrollRef = useRef(null); const [scrollProgress, setScrollProgress] = useState(0); const [needsScroll, setNeedsScroll] = useState(true); const handleScroll = (e: UIEvent) => { const target = e.currentTarget; const maxScroll = target.scrollHeight - target.clientHeight; if (maxScroll > 0) { // 0 : top, 1 : bottom setScrollProgress(target.scrollTop / maxScroll); } }; // Check if content is larger than screen on load useEffect(() => { if (scrollRef.current) { setNeedsScroll(scrollRef.current.scrollHeight > scrollRef.current.clientHeight); } }, []); return (
{/* Scroll area */}
{children}
{/* Custom scrollbar */} {needsScroll && (
)}
); }