Snippet
A command or one line of code to copy, with package manager tabs that every snippet on the page follows.
On this page
Pick a package manager in either snippet and both follow.
Installation
Usage
import { Snippet, packageManagerTabs } from "@/components/ui/chatcn/snippet"
<Snippet tabs={packageManagerTabs("ai @ai-sdk/react zod")} />
<Snippet code="npx shadcn@latest add @chatcn/tool-call" />With tabs it holds the same command for several package managers; the choice is remembered under storageKey and every snippet with that key follows it, on this page and the next. Long lines scroll sideways inside the snippet with a soft edge rather than wrapping, so what you copy is what you see. packageManagerTabs builds the pnpm, npm, yarn and bun versions of an install. Replaces AI Elements' Snippet.
Examples
States
One line, a long line that scrolls, and no prompt glyph.
Props
| Prop | Type | Notes |
|---|---|---|
code | string | One line |
tabs | SnippetTab[] | { label, code } |
prefix | ReactNode | Default $; null for none |
storageKey | string | null | Where the tab choice is kept. null turns it off |
copyLabel, onCopyCode | string, (code) => void |
Keyboard
| Key | Action |
|---|---|
| Left, Right on the tabs | Switch package manager |
Accessibility
- Tabs follow the tabs pattern with one tab stop and arrow keys.
- The prompt glyph is hidden from screen readers and from the copied text.