import type { JSX } from "solid-js"; import { For, createSignal } from "solid-js"; import { Highlight } from "./Highlight"; import clsx from "clsx"; function TrafficLightsIcon(props: JSX.IntrinsicElements["svg"]) { return ( ); } type SnippetTab = { name: string; codeLanguage: string; code: string; withLineNumbers?: boolean; children?: never; }; type CommonTab = { name: string; children: JSX.Element; codeLanguage?: never; code?: never; withLineNumbers?: never; }; type SnippetProps = { children?: JSX.Element; class?: string; snippets: (SnippetTab | CommonTab)[]; dark?: boolean; }; export function Snippet(props: SnippetProps) { const [selectedTab, setSelectedTab] = createSignal( props.snippets[0], ); const isActive = (tab: SnippetTab | CommonTab) => { return selectedTab()?.name === tab.name; }; const selectTab = (name: string) => { const tab = props.snippets.find((tab) => tab.name === name); if (tab) setSelectedTab(tab); }; const canBeSelected = (tab: SnippetTab | CommonTab) => { return (tab.code || tab.children) !== undefined; }; return ( {(tab) => ( selectTab(tab.name)} > {tab.name} )} {selectedTab() && ( {selectedTab().code && ( {(selectedTab() as SnippetTab).code} )} {!selectedTab().code && ( {(selectedTab() as CommonTab).children} )} )} ); }