// — tabbed view of the same region rendered against // multiple integration frameworks' cells. // // Usage: // // // Each tab runs . When a // framework is missing that region/cell the Snippet's built-in warning // box surfaces inline, so authors get a clear signal to tag the missing // region in the corresponding cell. // // FrameworkTabs is intentionally **client-side** (uses useState for the // active tab). The inner is a server component — Next.js will // transport its rendered HTML across the boundary, which keeps syntax // highlighting sharp and avoids duplicating the highlight.js dependency // in the client bundle. "use client"; import React, { useState } from "react"; interface FrameworkTabsProps { frameworks: string[]; cell: string; region: string; /** Render an alternative label for each framework (e.g. pretty names). */ labels?: Record; /** Pre-rendered content, keyed by framework slug. Populated by * the parent MDX renderer which walks the `frameworks` list and emits * a Snippet per framework on the server side. */ children: React.ReactNode; } export function FrameworkTabs({ frameworks, labels, children, }: FrameworkTabsProps) { const [active, setActive] = useState(frameworks[0] ?? ""); // children should be an array of
wrappers. // We filter + render the active one. This keeps all snippets rendered // on the server (good: syntax highlighting) and client only swaps. const wrapped = React.Children.toArray(children); const displayLabel = (slug: string) => labels?.[slug] ?? slug .split("-") .map((s) => s.charAt(0).toUpperCase() + s.slice(1)) .join(" "); return (
{frameworks.map((fw) => { const isActive = fw === active; return ( ); })}
{wrapped.map((child, i) => { const fw = frameworks[i]; if (fw !== active) return null; return {child}; })}
); }