/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import React, {useMemo} from 'react'; import type {TOCItemsProps} from '@theme/TOCItems'; import {TOCItem} from '@docusaurus/types'; import { TOCHighlightConfig, useThemeConfig, useTOCFilter, useTOCHighlight, } from '@docusaurus/theme-common'; // Recursive component rendering the toc tree /* eslint-disable jsx-a11y/control-has-associated-label */ function TOCItemList({ toc, className = 'table-of-contents table-of-contents__left-border', linkClassName = 'table-of-contents__link', isChild, }: { readonly toc: readonly TOCItem[]; readonly className: string; readonly linkClassName: string; readonly isChild?: boolean; }): JSX.Element | null { if (!toc.length) { return null; } return (
); } export default function TOCItems({ toc, className = 'table-of-contents table-of-contents__left-border', linkClassName = 'table-of-contents__link', linkActiveClassName = undefined, minHeadingLevel: minHeadingLevelOption, maxHeadingLevel: maxHeadingLevelOption, ...props }: TOCItemsProps): JSX.Element | null { const themeConfig = useThemeConfig(); const minHeadingLevel = minHeadingLevelOption ?? themeConfig.tableOfContents.minHeadingLevel; const maxHeadingLevel = maxHeadingLevelOption ?? themeConfig.tableOfContents.maxHeadingLevel; const tocFiltered = useTOCFilter({toc, minHeadingLevel, maxHeadingLevel}); const tocHighlightConfig: TOCHighlightConfig | undefined = useMemo(() => { if (linkClassName && linkActiveClassName) { return { linkClassName, linkActiveClassName, minHeadingLevel, maxHeadingLevel, }; } return undefined; }, [linkClassName, linkActiveClassName, minHeadingLevel, maxHeadingLevel]); useTOCHighlight(tocHighlightConfig); return (