import { useLang } from '@rspress/core/runtime'; import { ChevronDown } from 'lucide-react'; import { Children, type ReactNode, useEffect, useRef } from 'react'; import { revealModelConfigSection } from './model-config-section-anchor'; import './ModelConfigSection.css'; /** Keep a Markdown heading as the first child so Rspress retains its TOC entry. */ export function ModelConfigSection({ description, children, }: { description: string; children: ReactNode; }) { const lang = useLang(); const ref = useRef(null); const [heading, ...content] = Children.toArray(children); useEffect(() => { const section = ref.current; if (!section) return; const reveal = () => { if (revealModelConfigSection(section, window.location.hash)) { section.scrollIntoView({ block: 'start' }); } }; // Also handle selecting the current hash again after manually collapsing. const onClick = (event: MouseEvent) => { if (!(event.target instanceof Element)) return; const link = event.target.closest('a[href]'); if (!link) return; const url = new URL(link.getAttribute('href')!, window.location.href); if ( url.origin === window.location.origin && url.pathname === window.location.pathname && url.search === window.location.search ) { revealModelConfigSection(section, url.hash); } }; reveal(); window.addEventListener('hashchange', reveal); document.addEventListener('click', onClick, true); return () => { window.removeEventListener('hashchange', reveal); document.removeEventListener('click', onClick, true); }; }, []); return (
{heading} {description}
{lang === 'zh' ? '查看配置' : 'View configuration'} {lang === 'zh' ? '收起配置' : 'Hide configuration'}
{content}
); }