import React from "react"; import { cn } from "#/utils/utils"; import { readScrollFadeState, type ScrollFadeState, } from "#/utils/scroll-fade-state"; export { readScrollFadeState }; const FADE_WIDTH_CLASS = "w-10"; interface MarkdownTableScrollProps { children: React.ReactNode; } export function MarkdownTableScroll({ children }: MarkdownTableScrollProps) { const scrollRef = React.useRef(null); const [fadeState, setFadeState] = React.useState({ left: false, right: false, }); const updateFadeState = React.useCallback(() => { const element = scrollRef.current; if (!element) { return; } setFadeState(readScrollFadeState(element)); }, []); React.useLayoutEffect(() => { updateFadeState(); const element = scrollRef.current; if (!element) { return undefined; } const resizeObserver = new ResizeObserver(updateFadeState); resizeObserver.observe(element); const table = element.firstElementChild; if (table) { resizeObserver.observe(table); } return () => resizeObserver.disconnect(); }, [updateFadeState, children]); return (
{children}
{/* The fades blend into whatever surface the table sits on, which differs between the chat stream and cards like the markdown artifact preview. Set `--oh-scroll-fade-from` on any ancestor to match another surface. The value is inlined at both edges because Tailwind only extracts classes from literal strings, not interpolated constants. */}
); }