Files
hatchet/frontend/docs/components/code/CodeTabs.tsx
Gabe Ruttner c88a18180a docs: git driven snips -- on failure page (#1043)
* feat: universal tabs

* fix: consistent tab naming

* feat: paths

* wip: chunk parser

* wip: dynamic snips

* wip: components

* docs: annotated go

* docs: improved annotations

* chore: fix

* feat: on-failure

* todo: switch branch to main

* chore: lint

* chore: lint

* fix: resolved theme

* cache

* fix: theme again...

* todo list

* docs: shadcn

* docs: code example uses shadcn

* fix: build

* python note

* chore: lint

* chore: swap main

* feat: local story

* fix: is dev

* revert the change that broke vercel

* fix: redirect?

* feat: seo title
2024-11-18 15:50:51 -08:00

54 lines
1.2 KiB
TypeScript

import React from 'react';
import UniversalTabs from '../UniversalTabs';
const languages = ['Python', 'Typescript', 'Go'];
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;
function useMemo(arg0: () => any, arg1: any[]) {
throw new Error('Function not implemented.');
}