When to use
- Install and run commands in docs, onboarding and empty states.
- Anything a reader pastes into a terminal as one line.
When not to use
- Multi-line code: use Code Block. A choice of package manager shown as tabs: use Code Tabs.
Installation
pnpm dlx shadcn add https://eased.dev/r/snippet.jsonnpx shadcn add https://eased.dev/r/snippet.jsonyarn dlx shadcn add https://eased.dev/r/snippet.jsonbunx --bun shadcn add https://eased.dev/r/snippet.jsonThe command adds Snippet, everything it builds on and Eased’s tokens to your project.
Install the dependencies
pnpm add motion shikinpm install motion shikiyarn add motion shikibun add motion shikiAdd the Eased pieces it builds on
Copy each item’s files the same way, or install them with the CLI:
Copy the source into your project
components/eased/snippet/snippet.tsxTSX "use client";import { useRef } from "react";import { TextSwap } from "../_primitives/text-swap/text-swap";import { CopyButton } from "../_primitives/code-core/copy";import { CODE_SCHEME, useCodeLines } from "../_primitives/code-core/code-lines";import type { CodeLang } from "../_primitives/code-core/highlighter";import { useScrollFades } from "../lib/dom";export type SnippetProps = { /** The one-line command. Changing it swaps the text and springs the width. */ text: string; /** Shown before the command and never copied. Default "$"; null hides it. */ prefix?: string | null; /** Grammar for the command. Default "bash". */ lang?: CodeLang | (string & {}); /** Accessible name of the copy button. Default "Copy command". */ label?: string; onCopy?: (text: string) => void; className?: string;};/** * Snippet: a one-line command with a `$` prompt and a copy button. When the command changes * (pnpm ↔ npm) the old text lifts away, the new one rises in, and the pill's width springs to * fit, so the copy button glides instead of jumping. Too long for its container, the line * scrolls sideways under 20px edge fades rather than wrapping. */export function Snippet({ text, prefix = "$", lang = "bash", label = "Copy command", onCopy, className = "" }: SnippetProps) { const { lines } = useCodeLines(text, lang); const scroller = useRef<HTMLDivElement>(null); useScrollFades(scroller, "x"); const line = lines[0] ?? []; return ( <div className={`inline-flex h-control-lg max-w-full min-w-0 items-center rounded-control border border-line-subtle bg-surface-sunken pr-0.75 pl-3.5 font-mono text-ui-sm text-text [--pad:3px] [--radius-outer:var(--eased-radius-control)] ${CODE_SCHEME} ${className}`} > {prefix !== null && ( <span aria-hidden className="mr-2 shrink-0 text-text-muted select-none"> {prefix} </span> )} <div ref={scroller} className="fade-x mr-1 min-w-0 flex-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden"> <code className="block whitespace-pre"> <TextSwap swapKey={text}> <span> {line.map((t, i) => ( <span key={i} style={{ color: t.light && t.dark ? `light-dark(${t.light}, ${t.dark})` : t.light ?? t.dark }}> {t.content} </span> ))} </span> </TextSwap> </code> </div> <CopyButton text={text} label={label} showLabel={false} radius="radius-nested" onCopy={onCopy} className="font-sans" /> </div> );}Keep the folder layout
The files import each other by relative path (
../lib/motion), so keep each one at the path shown, undercomponents/eased/.
Usage
import { Snippet } from "@/components/eased/snippet/snippet";import { useChoice } from "@/components/eased/_primitives/code-core/choice";import { PACKAGE_MANAGERS, packageCommand, type PackageManager } from "@/components/eased/code-tabs/code-tabs";const [pm] = useChoice("package-manager", "pnpm", PACKAGE_MANAGERS);<Snippet text={packageCommand(pm as PackageManager, { dlx: "shadcn add https://eased.dev/r/code-block.json" })} />Examples
A fixed command
With no package manager to follow, pass the command as it is.
<Snippet text="git clone https://github.com/eased-dev/starter.git my-app" />No prompt
prefix={null} drops the $, for a value rather than a command; lang changes the grammar and label the copy button's name.
<Snippet prefix={null} lang="json" text={`"motion": "^12.23.0"`} label="Copy version" />API reference
Snippet
| Prop | Type | Default | Description |
|---|---|---|---|
text | string | The command. Changing it swaps the text and springs the width. | |
prefix | string | null | "$" | Shown, never copied. null hides it. |
lang | CodeLang | string | "bash" | Grammar for the command. |
label | string | "Copy command" | Accessible name of the copy button. |
onCopy | (text: string) => void | After a successful copy. | |
className | string | "" | Appended to the root's classes. |
The root is inline-flex and never wider than its container; a command wider than that scrolls sideways under 20px edge fades rather than wrapping.
Accessibility
- The prompt is hidden from screen readers and cannot be selected, so neither copying nor reading picks it up.
- The copy button is a native button named by
label, with a 44px hit area, and a polite status line announces "Copied".
Motion
When text changes, the old command lifts 3px and blurs out while the new one rises 4px from below and sharpens on the snappy spring, and the pill's width springs to fit on the smooth spring, so the copy button glides. Copying lifts the sheets away while a check draws itself in, and the copy icon returns after 1.6s. Reduced motion: a 100ms cross-fade and an instant width.
Notes for AI
Use Snippet for one shell command. To follow the reader's package manager, read it with useChoice("package-manager", "pnpm", PACKAGE_MANAGERS) and build the command with packageCommand: the same choice drives every Code Tabs with groupId="package-manager".
Do not put $ in text (the prompt is drawn for you and kept out of the copy), and do not use it for multi-line code: the text never wraps.
Related components
- Package Manager Code Tabs: the same command for each package manager as tabs.
- Code Block with Syntax Highlighting: multi-line code with a title bar.
- Terminal