Skip to content
Sign upPro
ContentSnippetMenu

Snippet

A command or one line of code to copy, with package manager tabs that every snippet on the page follows.

Pick a package manager in either snippet and both follow.

Installation

$ pnpm dlx shadcn@latest add https://chatcn.dev/r/snippet.json

Usage

tsx
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

PropTypeNotes
codestringOne line
tabsSnippetTab[]{ label, code }
prefixReactNodeDefault $; null for none
storageKeystring | nullWhere the tab choice is kept. null turns it off
copyLabel, onCopyCodestring, (code) => void

Keyboard

KeyAction
Left, Right on the tabsSwitch 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.