Command Palette

Search for a command to run...

1.8k

Command Palette

Search for a command to run...

Blog

Code Block Command

Display install commands with package manager switcher and copy button.

Loading…

Features

  • Switch between pnpm, yarn, npm, and bun with a single click.
  • Optional prompt tab for displaying a natural language instruction for AI agents to install packages or components.
  • Automatically saves the user’s preferred package manager for future visits.
  • Copy commands instantly with smooth animations showing success or failure states.
  • convertNpmCommand utility to auto-convert a standard npm command to all package managers.

Installation

$ pnpm dlx shadcn@latest add @ncdai/code-block-command

Usage

import {
  CodeBlockCommand,
  convertNpmCommand,
} from "@/components/code-block-command"
<CodeBlockCommand
  prompt="Add the @ncdai/code-block-command component to my project"
  pnpm="pnpm dlx shadcn add @ncdai/code-block-command"
  yarn="yarn dlx shadcn add @ncdai/code-block-command"
  npm="npx shadcn add @ncdai/code-block-command"
  bun="bunx --bun shadcn add @ncdai/code-block-command"
/>

Or use convertNpmCommand to auto-convert from a standard npm command:

<CodeBlockCommand
  prompt="Add the @ncdai/code-block-command component to my project"
  {...convertNpmCommand("npx shadcn add @ncdai/code-block-command")}
/>

API Reference

CodeBlockCommand

Prop

Type

convertNpmCommand

Converts a standard npm/npx command into equivalent commands for all package managers. The result can be spread directly into CodeBlockCommand props.

Prop

Type

Supported command patterns:

npm commandpnpmyarnbun
npm installpnpm addyarn addbun add
npx create-<name>pnpm create <name>yarn create <name>bunx --bun create-<name>
npm createpnpm createyarn createbun create
npxpnpm dlxyarn dlxbunx --bun
npm runpnpmyarnbun

Examples

Convert from npm

Use convertNpmCommand to avoid manually writing commands for each package manager.

Loading…

Analytics Tracking

Track user interactions with analytics services like PostHog, OpenPanel, or Google Analytics.

<CodeBlockCommand
  {...convertNpmCommand("npx shadcn add @ncdai/code-block-command")}
  onCopySuccess={({ packageManager, command }) => {
    trackEvent({
      name: "command_copied",
      properties: {
        packageManager,
        command,
      },
    })
  }}
  onCopyError={(error) => {
    trackEvent({
      name: "command_copy_failed",
      properties: { error: error.message },
    })
  }}
/>