Polyglot

API Code Snippet Tabs for React

An API quickstart with language tabs. The values every language shares glide to their new places when you switch, you can edit them right in the code, and Run streams the response in underneath.

  • Code
  • Developer
  • AI

Uses motion, clsx, tailwind-merge

Open in ChatGPTOpen in Claude
glideDuration0.42s
glideStagger0.025s
glideBounce0.00
<Polyglot />

The demo follows as you drag.

Take this demo to your coding agent.
Add this moment from KeyframeUI to our project and adapt it to our content.

Polyglot: An API quickstart with language tabs. The values every language shares glide to their new places when you switch, you can edit them right in the code, and Run streams the response in underneath.
This demo, Chat Quickstart: An AI API's quickstart in cURL, Python and TypeScript, with the response beside the code (`layout="split"`). Switch tabs and the key, model and prompt glide to their new lines. Click the prompt to rewrite it, pick a model, hover the key, then Run: the smaller model answers sooner and streams faster.

1. Install it:
   npx shadcn@latest add @keyframeui/polyglot-demo
   (If the CLI can't find @keyframeui, use https://keyframeui.com/r/polyglot-demo.json instead.)
   It adds the demo, components/polyglot-demo.tsx, and the component, components/ui/polyglot.tsx.

2. Make it ours: our copy, data, images and colors. Keep the structure the motion depends on. If we only need the effect, use <Polyglot> on its own.

3. These props set its feel. Change them before you change the file:
   - glideDuration (default 0.42): How long a shared value takes to glide to its new place when you switch languages, in seconds. Its tint stays lit until it lands.
   - glideStagger (default 0.025): Seconds between the shared values setting off, in reading order.
   - glideBounce (default 0): How much a gliding value overshoots its new place before it settles, from `0` (none) up.

4. Don't change, in components/ui/polyglot.tsx:
   - A switch is interruptible: each shared value glides from wherever it is on screen now, as a translate written by a plain 0 → 1 spring, so nothing resets it while its stagger delay runs.
   - A switch runs in order: the old code fades out with a slight blur, the values glide in reading order, the new code fades in line by line behind them, and the box's height springs from its pinned old height to the new line count.
   - Editing a value changes every language at once, escaped for its own quotes, and cancels a run; switching tabs leaves the stream alone.
   - A run lives in its own store read through `useRun` selectors, and the wait counts up by writing `textContent` each frame; the reply is announced once, when it's complete.
   - Reduced motion is a crossfade: nothing glides or flies and the panel opens at once, and `reduced` waits for hydration so the server markup matches.
   Its timing is all in the TIMING block at the top of that file.

Docs: https://keyframeui.com/components/polyglot.md

Installation

Add the component on its own with the CLI, or copy the file in by hand.

The CLI writes components/ui/polyglot.tsx and installs motion, clsx and tailwind-merge. It needs the @keyframeui registry in components.json; add it once per project.

npx shadcn@latest add @keyframeui/polyglot

Examples

Finished sections built with Polyglot. Each one installs whole, with the component included.

Three-Step Quickstart

Install, authenticate and a first request as three blocks sharing one `syncKey`. Switch any of them and all three change together; the package name slides from `pip install nova` into the Go import path. Your choice is remembered.

Take this demo to your coding agent.
Add this moment from KeyframeUI to our project and adapt it to our content.

Polyglot: An API quickstart with language tabs. The values every language shares glide to their new places when you switch, you can edit them right in the code, and Run streams the response in underneath.
This demo, Three-Step Quickstart: Install, authenticate and a first request as three blocks sharing one `syncKey`. Switch any of them and all three change together; the package name slides from `pip install nova` into the Go import path. Your choice is remembered.

1. Install it:
   npx shadcn@latest add @keyframeui/polyglot-steps-demo
   (If the CLI can't find @keyframeui, use https://keyframeui.com/r/polyglot-steps-demo.json instead.)
   It adds the demo, components/polyglot-steps-demo.tsx, and the component, components/ui/polyglot.tsx.

2. Make it ours: our copy, data, images and colors. Keep the structure the motion depends on. If we only need the effect, use <Polyglot> on its own.

3. These props set its feel. Change them before you change the file:
   - glideDuration (default 0.42): How long a shared value takes to glide to its new place when you switch languages, in seconds. Its tint stays lit until it lands.
   - glideStagger (default 0.025): Seconds between the shared values setting off, in reading order.
   - glideBounce (default 0): How much a gliding value overshoots its new place before it settles, from `0` (none) up.

4. Don't change, in components/ui/polyglot.tsx:
   - A switch is interruptible: each shared value glides from wherever it is on screen now, as a translate written by a plain 0 → 1 spring, so nothing resets it while its stagger delay runs.
   - A switch runs in order: the old code fades out with a slight blur, the values glide in reading order, the new code fades in line by line behind them, and the box's height springs from its pinned old height to the new line count.
   - Editing a value changes every language at once, escaped for its own quotes, and cancels a run; switching tabs leaves the stream alone.
   - A run lives in its own store read through `useRun` selectors, and the wait counts up by writing `textContent` each frame; the reply is announced once, when it's complete.
   - Reduced motion is a crossfade: nothing glides or flies and the panel opens at once, and `reduced` waits for hydration so the server markup matches.
   Its timing is all in the TIMING block at the top of that file.

Docs: https://keyframeui.com/components/polyglot.md

Send an Email

Not only for chat: an email API with the recipient and subject editable in the code. Run streams the JSON the API returns (`responseLang="json"`), and the recipient flies in as the request.

Take this demo to your coding agent.
Add this moment from KeyframeUI to our project and adapt it to our content.

Polyglot: An API quickstart with language tabs. The values every language shares glide to their new places when you switch, you can edit them right in the code, and Run streams the response in underneath.
This demo, Send an Email: Not only for chat: an email API with the recipient and subject editable in the code. Run streams the JSON the API returns (`responseLang="json"`), and the recipient flies in as the request.

1. Install it:
   npx shadcn@latest add @keyframeui/polyglot-email-demo
   (If the CLI can't find @keyframeui, use https://keyframeui.com/r/polyglot-email-demo.json instead.)
   It adds the demo, components/polyglot-email-demo.tsx, and the component, components/ui/polyglot.tsx.

2. Make it ours: our copy, data, images and colors. Keep the structure the motion depends on. If we only need the effect, use <Polyglot> on its own.

3. These props set its feel. Change them before you change the file:
   - glideDuration (default 0.42): How long a shared value takes to glide to its new place when you switch languages, in seconds. Its tint stays lit until it lands.
   - glideStagger (default 0.025): Seconds between the shared values setting off, in reading order.
   - glideBounce (default 0): How much a gliding value overshoots its new place before it settles, from `0` (none) up.

4. Don't change, in components/ui/polyglot.tsx:
   - A switch is interruptible: each shared value glides from wherever it is on screen now, as a translate written by a plain 0 → 1 spring, so nothing resets it while its stagger delay runs.
   - A switch runs in order: the old code fades out with a slight blur, the values glide in reading order, the new code fades in line by line behind them, and the box's height springs from its pinned old height to the new line count.
   - Editing a value changes every language at once, escaped for its own quotes, and cancels a run; switching tabs leaves the stream alone.
   - A run lives in its own store read through `useRun` selectors, and the wait counts up by writing `textContent` each frame; the reply is announced once, when it's complete.
   - Reduced motion is a crossfade: nothing glides or flies and the panel opens at once, and `reduced` waits for hydration so the server markup matches.
   Its timing is all in the TIMING block at the top of that file.

Docs: https://keyframeui.com/components/polyglot.md

Props

slots Required

TypeRecord<string, PolyglotSlot>

The values every snippet shares, keyed by the name used in {{name}}. Each has a value, and optionally editable (click and type), options (a small dropdown), secret (prefix and dots until hovered; Copy uses the real value) and label for screen readers.

snippets Required

TypePolyglotSnippet[]

One tab per language: { label, lang, code }. Write {{name}} wherever a slot's value goes; it's escaped for the quotes around it, so a typed " becomes \" in Python and stays valid inside a shell-quoted JSON body. lang picks the built-in highlighting: bash, python, js/ts, go, ruby or json.

response

Typestring | ((values) => string)

The reply Run streams, token by token. Passing it (or onRun) adds the Run footer and the response panel. Build it from the values to follow what the visitor typed.

onRun

Type(values, signal: AbortSignal) => AsyncIterable<string>

Call a real API instead: yield the reply in chunks. Stop, a new run or an edited value aborts signal.

speed

Typenumber | ((values) => number)Default60

Tokens per second for response, with a little jitter so it reads like a real stream.

latency

Typenumber | ((values) => number)Default350

Milliseconds before the first token of response. The status line counts it up.

glideDuration

TypenumberDefault0.42

How long a shared value takes to glide to its new place when you switch languages, in seconds. Its tint stays lit until it lands.

glideStagger

TypenumberDefault0.025

Seconds between the shared values setting off, in reading order.

glideBounce

TypenumberDefault0

How much a gliding value overshoots its new place before it settles, from 0 (none) up.

syncKey

Typestring

Blocks with the same key switch language together and animate at once, matching tabs by label. The choice is remembered on this device.

defaultLabel

Typestring

The tab shown first, by label. Defaults to the first snippet.

lineNumbers

TypebooleanDefaultfalse

Show a line-number gutter. It stays put while the code scrolls sideways.

layout

Type"stack" | "split"Default"stack"

stack opens the response panel under the code on the first run. split puts it beside the code once the block is 48rem wide (a container query), waiting with an empty state, and stacks it below on narrower blocks.

echo

Typestring | false

The slot whose value flies into the response as its first line when you run. Defaults to the first editable slot; false turns it off.

responseLang

TypestringDefault"text"

Highlighting for the response, e.g. json.

statusText

TypestringDefault"200 OK"

Shown when a run finishes, before the time and the token count.

className

Typestring

Classes for the block, e.g. a max width. Colors come from the theme's foreground, muted and border; the highlighter's hues are one map at the top of the file.