Code Block Command
Tabbed CLI command block with package manager switching (pnpm, yarn, npm, bun, shadcn), SVG icons, copy button, and localStorage persistence. Remembers the user's preferred package manager across visits.
lucide-react
Preview
$ shadcn add buttonInstallation
$ shadcn add https://ui.justinlevine.me/r/code-block-command.jsonUsage
import { CodeBlockCommand } from "@/components/code-block-command"import { convertNpmCommand } from "@/lib/convert-npm-command"<CodeBlockCommand {...convertNpmCommand("npm install zod")} />Client component. Uses localStorage to persist the selected package manager across visits. Use the convertNpmCommand helper to generate equivalent commands for all managers from a single npm command.
Examples
Command types
shadcn add
$ shadcn add buttonnpm install
$ pnpm add zodnpx create
$ pnpm create next-app@latestnpm run
$ pnpm devIcon styles
Colored (default)
$ pnpm add zodMuted
$ pnpm add zodNo Icons
$ pnpm add zodFiltered tabs
pnpm + npm only
$ pnpm add zodshadcn + bun only
$ shadcn add buttonAPI Reference
CodeBlockCommand
PropType
Notes
- convertNpmCommand helper. Pass a single npm/npx command and get all 5 package manager equivalents automatically. Handles shadcn, create, install, run, and generic npx commands.
- Icons via SVGL. Package manager icons are fetched from the SVGL API at build time. Use
fetchPackageManagerIcons()in a server component and pass the result as theiconsprop.