import { useScrollPositionBlocker, useTabs, } from "@docusaurus/theme-common/internal"; import useIsBrowser from "@docusaurus/useIsBrowser"; import clsx from "clsx"; import React, { cloneElement } from "react"; function TabList({ className, block, selectedValue, selectValue, tabValues, wrapContent = true, smallTabs = false, }) { const tabRefs = []; const { blockElementScrollPositionUntilNextRender } = useScrollPositionBlocker(); const handleTabChange = (event) => { const newTab = event.currentTarget; const newTabIndex = tabRefs.indexOf(newTab); const newTabValue = tabValues[newTabIndex].value; if (newTabValue !== selectedValue) { blockElementScrollPositionUntilNextRender(newTab); selectValue(newTabValue); } }; const handleKeydown = (event) => { let focusElement = null; switch (event.key) { case "Enter": { handleTabChange(event); break; } case "ArrowRight": { const nextTab = tabRefs.indexOf(event.currentTarget) + 1; focusElement = tabRefs[nextTab] ?? tabRefs[0]; break; } case "ArrowLeft": { const prevTab = tabRefs.indexOf(event.currentTarget) - 1; focusElement = tabRefs[prevTab] ?? tabRefs[tabRefs.length - 1]; break; } default: break; } focusElement?.focus(); }; return ( ); } function TabContent({ lazy, children, selectedValue, smallTabs }) { const childTabs = (Array.isArray(children) ? children : [children]).filter( Boolean, ); if (lazy) { const selectedTabItem = childTabs.find( (tabItem) => tabItem.props.value === selectedValue, ); if (!selectedTabItem) { // fail-safe or fail-fast? not sure what's best here return null; } return cloneElement(selectedTabItem, { className: "margin-top--md refine-tab-content", }); } return (
{childTabs.map((tabItem, i) => cloneElement(tabItem, { key: i, hidden: tabItem.props.value !== selectedValue, className: clsx( tabItem.props.className ?? [], "refine-tab-content", ), }), )}
); } function TabsComponent(props) { const tabs = useTabs(props); const { wrapContent = true } = props; return (
); } export default function CommonTabs(props) { const isBrowser = useIsBrowser(); return ( ); }