Files
hatchet/frontend/docs/components/code/CodeTabs.tsx
Gabe Ruttner 5babd09679 docs: chunky overhaul (#3129)
* improve overall docs structure and things
2026-03-04 14:33:15 -08:00

49 lines
1.1 KiB
TypeScript

import React from "react";
import { DOC_LANGUAGES } from "@/lib/docs-languages";
import UniversalTabs from "../UniversalTabs";
const languages = [...DOC_LANGUAGES];
type CodeSource = {
path?: string;
};
type GitHubIssue = {
issueUrl: string;
};
type Src = CodeSource | GitHubIssue | undefined;
interface CodeTabsProps {
children: React.ReactNode;
src?: {
[key: string]: Src;
};
}
export const CodeTabs: React.FC<CodeTabsProps> = ({ children }) => {
// Convert children to a dictionary keyed by language
const childrenDict = React.useMemo(() => {
const dict: { [key: string]: React.ReactNode } = {};
React.Children.forEach(children, (child) => {
if (React.isValidElement(child)) {
dict[child.props.title] = child;
}
});
return dict;
}, [children]);
// Create ordered array based on languages order
const orderedChildren = React.useMemo(() => {
return languages.map((lang) => childrenDict[lang]).filter(Boolean);
}, [childrenDict]);
return (
<>
<UniversalTabs items={languages}>{orderedChildren}</UniversalTabs>
</>
);
};
export default UniversalTabs;