Code Block Command
ncdai/code-block-commandUnverifiedComponent
Display install commands with package manager switcher and copy button.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/Sumeet011/Portfolio/main/public/r/code-block-command.jsonSource
1"use client"23import { useMemo } from "react"4import { ScrollArea } from "@base-ui/react/scroll-area"5import { useAtom } from "jotai"6import { atomWithStorage } from "jotai/utils"78import { cn } from "@/lib/utils"9import {10 Tabs,11 TabsContent,12 TabsIndicator,13 TabsList,14 TabsTrigger,15} from "@/components/base/ui/tabs"16import { CopyButton } from "@/registry/components/copy-button"17import { IconSwap, IconSwapItem } from "@/registry/components/icon-swap"18import { IconPlaceholder } from "@/registry/icons/icon-placeholder"1920export type PackageManager = "prompt" | "pnpm" | "yarn" | "npm" | "bun"2122const packageManagerAtom = atomWithStorage<PackageManager>(23 "packageManager",24 "pnpm"25)2627export function usePackageManager() {28 return useAtom(packageManagerAtom)29}3031/**32 * Props for the CodeBlockCommand component.33 */34export type CodeBlockCommandProps = {35 /**36 * Natural language instruction for AI agents to install a package or component.37 */38 prompt?: string39 /**40 * Command to execute with pnpm package manager.41 */42 pnpm?: string4344 /**45 * Command to execute with yarn package manager.46 */47 yarn?: string4849 /**50 * Command to execute with npm package manager.51 */52 npm?: string5354 /**55 * Command to execute with bun package manager.56 */57 bun?: string5859 /**60 * Callback invoked when a command is successfully copied to clipboard.61 *62 * Receives an object containing the selected package manager and the copied command text.63 * Useful for tracking user interactions or showing custom success notifications.64 *65 * @param data - Object containing copy operation details66 * @param data.packageManager - The package manager that was selected when copying67 * @param data.command - The actual command text that was copied68 *69 * @example70 * ```tsx71 * <CodeBlockCommand72 * pnpm="pnpm add react"73 * onCopySuccess={({ packageManager, command }) => {74 * console.log(`Copied ${command} for ${packageManager}`)75 * }}76 * />77 * ```78 */79 onCopySuccess?: (data: {80 packageManager: PackageManager81 command: string82 }) => void8384 /**85 * Callback invoked when copying to clipboard fails.86 *87 * Receives the error object for debugging or showing custom error messages.88 *89 * @param error - The error that occurred during the copy operation90 *91 * @example92 * ```tsx93 * <CodeBlockCommand94 * pnpm="pnpm add react"95 * onCopyError={(error) => {96 * console.error('Copy failed:', error)97 * }}98// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from ncdai
All 48 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Apple Hello Effectapple-hello-effect | ncdai | Components | Unverified | 1 dep | |
| Apple Hello Effect - Hindiapple-hello-effect-hindi | ncdai | Components | Unverified | 1 dep | |
| Apple Hello Effect - Spanishapple-hello-effect-spanish | ncdai | Components | Unverified | 1 dep | |
| Apple Hello Effect - Vietnameseapple-hello-effect-vietnamese | ncdai | Components | Unverified | 1 dep | |
| Brand Assets Menubrand-assets-menu | ncdai | Components | Unverified | 1 dep | |
| chevrons-up-down-iconchevrons-up-down-icon | ncdai | Components | Unverified | 1 dep | |
| Consent Managerconsent-manager | ncdai | Components | Unverified | 1 dep | |
| Contribution Graphcontribution-graph | ncdai | Components | Unverified | 1 dep |
