Retour au catalogue

Developer SDK Showcase

Vitrine SDK multi-langage avec onglets de code, badges de version et boutons d'installation par ecosysteme.

developermedium Both Responsive a11y
minimaldarksaasuniversalcentered
Theme

How to build a multi-language SDK showcase section in React

A multi-language SDK showcase in React keeps an active language ID in state, renders language tabs as buttons, and swaps the code panel with AnimatePresence mode='wait' from Framer Motion so outgoing and incoming snippets don't overlap. Each panel shows the install command, a scrollable code block, and a copy button that resets after 2 seconds.

  • Stack: React 18, Framer Motion 11, lucide-react, approximately 385 lines, zero syntax highlighting library.
  • Copy feedback uses a 2-second setTimeout that resets copiedField state; the same handler covers both the install command and the code block.
  • Tab transitions: AnimatePresence mode='wait' with y-offset entry (y:16→0) and y-offset exit (y:0→-8), 350ms, custom ease [0.16,1,0.3,1].
  • Accessible: install command and code block both get independent copy buttons; no icon-only actions are used without a sibling label.
  • Fully responsive via flexWrap on the tab row and install bar; the code block scrolls horizontally on narrow viewports.

The SDK Showcase is a section that lets visitors switch between language-specific code examples, JavaScript, Python, Go, Ruby, in one animated panel. It handles the install command, a copyable code block, a version badge, and a direct link to the language's docs, all without reaching for a syntax-highlighting library. The result is a lightweight, theme-aware block that fits any developer product landing page.

Anatomy

The section is divided into three zones. A centered header holds an optional badge, a heading, and a subtitle. Below it, a horizontal row of pill-shaped tab buttons shows each language with a color dot, its name, and a monospaced version string. The active tab triggers an animated card that itself has three sub-zones: an install bar at the top (terminal icon, install command, Copy and Docs buttons), a code block in the middle (monospaced pre, floating copy button), and a footer that repeats the language name plus version badge and renders an Install CTA button.

How it works

Language switching relies on two pieces of state: activeId (which language tab is selected) and copiedField (which copy button is in its 'copied' state). When a tab is clicked, activeId updates and AnimatePresence catches the outgoing panel, animates it out (opacity 0, y -8), then mounts the new panel (opacity 0, y 16 → 1, y 0). The copy handler calls navigator.clipboard.writeText, sets copiedField to a string key ('install' or 'code'), then schedules a setTimeout to clear it. The ease constant [0.16, 1, 0.3, 1] is a custom cubic-bezier that gives transitions a fast-out-slow-in feel without needing a named preset.

How to build it in React

  1. Define the language data shape

    Create an SdkLanguage interface with id, name, version, installCmd, code, an optional docsUrl, and a color string for the dot. Feed it as a prop with sensible defaults so the component works out of the box. Keep actual code snippets as template literals in the default data array.

    interface SdkLanguage {
      id: string;
      name: string;
      version: string;
      installCmd: string;
      code: string;
      docsUrl?: string;
      color: string;
    }
  2. Wire up the tab state and copy logic

    Initialize activeId to the first language's id and copiedField to null. The handleCopy callback writes to the clipboard, sets copiedField to a string key, and clears it after 2000ms. Wrap it in useCallback so it doesn't rebuild on every render.

    const [activeId, setActiveId] = useState(languages[0]?.id ?? "");
    const [copiedField, setCopiedField] = useState<string | null>(null);
    
    const handleCopy = useCallback((text: string, field: string) => {
      navigator.clipboard.writeText(text).catch(() => {});
      setCopiedField(field);
      setTimeout(() => setCopiedField(null), 2000);
    }, []);
  3. Animate the panel swap with AnimatePresence

    Wrap the active panel in AnimatePresence with mode='wait'. Use the language id as the key so React unmounts the old panel before mounting the new one. Set initial to opacity:0, y:16, animate to opacity:1, y:0, and exit to opacity:0, y:-8 for a clean slide-and-fade.

    <AnimatePresence mode="wait">
      {active && (
        <motion.div
          key={active.id}
          initial={{ opacity: 0, y: 16 }}
          animate={{ opacity: 1, y: 0 }}
          exit={{ opacity: 0, y: -8 }}
          transition={{ duration: 0.35, ease: [0.16, 1, 0.3, 1] }}
        >
          {/* install bar + code block + footer */}
        </motion.div>
      )}
    </AnimatePresence>
  4. Build the install bar and code block

    The install bar is a flex row: a Terminal icon plus the installCmd in a monospace code element on the left, and Copy plus optional Docs link buttons on the right. The code block is a pre tag inside a padded div with overflowX:auto and a floating copy button in the top-right corner. Use CSS custom properties for all colors so it adapts to any theme preset.

When to use it

Reach for this section on any developer product landing page where you ship SDKs for multiple languages and need to prove it visually. It works well in a 'Get started in 2 minutes' block, just before a pricing section or a CTA. Skip it when your product only supports one language; a plain code block with a copy button is cleaner. On mobile the tab row wraps and the code block scrolls horizontally, which is fine for reading but not ideal for onboarding, consider a simplified mobile view if conversions matter there.

Used by

  • Stripe, Stripe's API reference uses language tabs (curl, Ruby, Python, PHP, Node, Go, .NET, Java) to show the same request across every SDK, with one-click copy on each snippet.
  • Twilio, Twilio's docs feature a persistent language selector at the top of code examples, keeping the chosen language across page navigation so developers stay in their stack.
  • Algolia, Algolia's documentation landing pages display multi-language install snippets with tabs for JavaScript, PHP, Python, Ruby, Go and others, each with a copy button and a version badge.
  • Resend, Resend's getting-started section shows SDK install commands for Node, Python, Ruby, PHP, Go and Rust in a tabbed code block, the same pattern, applied to email API onboarding.

FAQ

Why use AnimatePresence mode='wait' instead of just conditionally rendering?

mode='wait' ensures the exit animation of the outgoing panel completes before the entering panel mounts. Without it both panels are briefly in the DOM at once and the transition looks like a stack glitch rather than a deliberate swap.

Can I add syntax highlighting without breaking the animation?

Yes. Replace the pre tag content with the output of a library like shiki or prism-react-renderer. The AnimatePresence wrapper is around the whole panel, not the pre, so the animation is unaffected. Just make sure the highlighted output is stable between renders to avoid flicker.

What happens if navigator.clipboard is unavailable?

The handleCopy function calls .catch(() => {}) to silently swallow the error, so the UI doesn't crash. If you need a visible fallback, replace the catch with a state update that shows a 'Copy failed' tooltip.

How do I persist the selected language across page navigation?

Lift the activeId state out of the component and sync it to localStorage or a URL query parameter. On mount, read the stored value and initialise useState with it instead of defaulting to languages[0].id.

"use client";

import { useState, useCallback } from "react";
import { motion, AnimatePresence } from "framer-motion";
import { Copy, Check, Terminal, Download, ExternalLink } from "lucide-react";
import React from "react";

interface SdkLanguage {
  id: string;
  name: string;
  version: string;
  installCmd: string;
  code: string;
  docsUrl?: string;
  color: string;
}

interface DeveloperSdkShowcaseProps {
  title?: string;
  subtitle?: string;
  badge?: string;
  languages?: SdkLanguage[];

Code complet réservé à Pro

Code source intégral, export multi-framework et playground.

Passer en Pro, 9,99€/mois

Reviews

React SDK Language Tabs Component, Code + Tutorial