Command Snippet
NewInstall command with npm, pnpm, yarn and bun tabs. Write it once for npm; the choice is remembered and shared across snippets.
pnpm dlx shadcn@latest add @synccn/command-snippetpnpm add -D tailwindcss @tailwindcss/viteBoth snippets switch together, and the choice is remembered.
Installation
$ pnpm dlx shadcn@latest add @synccn/command-snippetFirst time in this project? Connect synccn with one command.
Usage
import { CommandSnippet, convertCommand } from "@/components/ui/command-snippet";<CommandSnippet command="npm install motion" />API reference
Generated from the component's TypeScript types, so it always matches the code.
CommandSnippet
An install command with npm, pnpm, yarn and bun tabs and a copy button. Write the command once for npm; the others are worked out, and the choice is remembered.
- commandrequired
stringThe command written for npm, e.g. `npm install motion` or `npx shadcn@latest add button`. Converted for each manager.
- managers
"npm" | "pnpm" | "yarn" | "bun"[]Default
ALLManagers offered, in order.
- value
"npm" | "pnpm" | "yarn" | "bun"Controlled manager.
- defaultValue
"npm" | "pnpm" | "yarn" | "bun"Manager at first, when uncontrolled and nothing is saved. Defaults to the first of `managers`.
- onValueChange
(manager: "npm" | "pnpm" | "yarn" | "bun") => voidCalled when the person picks a manager.
- storageKey
string | falseDefault
"package-manager"Saves the choice in localStorage under this key and keeps every snippet with the same key in step. Pass false to turn off.
- className
stringExtra classes for the root element.
convertCommand
Rewrites an npm command for another package manager.
Takes no props.
Dependencies
Read from the component's imports when the site builds. The CLI installs all of these for you.
Helpers
- lib/clipboardcopyText (copies to the clipboard)
- lib/utilscn (merges class names)
npm packages
- clsx for cn()
- tailwind-merge for cn()
- lucide-react for Check, Copy, Terminal
Keyboard
- ←or→Switch package manager
Accessibility
- Managers are tabs with one tab stop; the copy button changes its label to Copied.
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA roles: tab, tablist, tabpanel
- ARIA attributes: aria-label, aria-selected
- Keys handled: ArrowLeft, ArrowRight, Space
- Shows a visible focus ring for keyboard users