Command Palette

Search for a command to run...

1.4k
Components
PreviousNext

Code Block Command

A code block command component for displaying installation commands with copy functionality.

Loading...
import { CodeBlockCommand } from "@/components/ncdai/code-block-command"
 
export function CodeBlockCommandDemo() {
  return (
    <div className="w-full max-w-md">
      <CodeBlockCommand
        pnpm="pnpm dlx shadcn add @ncdai/code-block-command"
        yarn="yarn shadcn add @ncdai/code-block-command"
        npm="npx shadcn add @ncdai/code-block-command"
        bun="bunx --bun shadcn add @ncdai/code-block-command"
      />
    </div>
  )
}

Features

  • Switch between pnpm, yarn, npm, and bun with a single click.
  • Automatically saves the user's preferred package manager for future visits.
  • Copy commands instantly with smooth animations showing success or failure states.

Installation

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

Usage

import { CodeBlockCommand } from "@/components/ncdai/code-block-command"
<CodeBlockCommand
  pnpm="pnpm dlx shadcn add @ncdai/code-block-command"
  yarn="yarn shadcn add @ncdai/code-block-command"
  npm="npx shadcn add @ncdai/code-block-command"
  bun="bunx --bun shadcn add @ncdai/code-block-command"
/>

API Reference

Props

PropTypeDescription
pnpmstringCommand for pnpm package manager
yarnstringCommand for yarn package manager
npmstringCommand for npm package manager
bunstringCommand for bun package manager
onCopy(data: { packageManager: PackageManager; command: string }) => voidCallback when command is successfully copied to clipboard
onCopyError(error: Error) => voidCallback when copy operation fails

Types

type PackageManager = "pnpm" | "yarn" | "npm" | "bun"

Examples

Analytics Tracking

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

"use client"
 
import { CodeBlockCommand } from "@/components/ncdai/code-block-command"
import { trackEvent } from "@/lib/events"
 
export function InstallCommand() {
  return (
    <CodeBlockCommand
      pnpm="pnpm dlx shadcn add @ncdai/code-block-command"
      yarn="yarn shadcn add @ncdai/code-block-command"
      npm="npx shadcn add @ncdai/code-block-command"
      bun="bunx --bun shadcn add @ncdai/code-block-command"
      onCopy={({ packageManager, command }) => {
        trackEvent({
          name: "command_copied",
          properties: {
            packageManager,
            command,
          },
        })
      }}
      onCopyError={(error) => {
        trackEvent({
          name: "command_copy_failed",
          properties: { error: error.message },
        })
      }}
    />
  )
}