import { onMount, For, Show, createSignal } from 'solid-js' import { clsx } from 'clsx' import { DEFAULT_HEADER_OFFSET } from '../../stores/router' import { useLocalize } from '../../context/localize' import { Icon } from '../_shared/Icon' import styles from './TableOfContents.module.scss' interface Props { variant: 'article' | 'editor' parentSelector: string } const scrollToHeader = (element) => { window.scrollTo({ behavior: 'smooth', top: element.getBoundingClientRect().top - document.body.getBoundingClientRect().top - DEFAULT_HEADER_OFFSET }) } export const TableOfContents = (props: Props) => { const { t } = useLocalize() const [headings, setHeadings] = createSignal([]) const [areHeadingsLoaded, setAreHeadingsLoaded] = createSignal(false) const [isVisible, setIsVisible] = createSignal(true) const toggleIsVisible = () => { setIsVisible((visible) => !visible) } onMount(() => { const { parentSelector } = props // eslint-disable-next-line unicorn/prefer-spread setHeadings(Array.from(document.querySelector(parentSelector).querySelectorAll('h2, h3, h4'))) setAreHeadingsLoaded(true) }) return (

{t('contents')}

    {(h) => (
  • )}
) }