Shows a shadcn add command with tabs for npm, pnpm, yarn and bun. You pass the package once, and each manager gets its own runner: npx, pnpm dlx, yarn dlx, bunx. Built on Tabs, so the pill glides to the chosen tab and the command cross-fades without moving the layout. With storageKey the choice is remembered and every block on the page, and in other browser tabs, follows it.
Browser Support
Anchor positioning moves the pill; the visible command is picked with :has(:checked).
Preview
Use the arrow keys to switch managers. The focus ring shows only for keyboard focus.
Installation
Usage
import { InstallCommand } from "@/components/ui/install-command"
export function GettingStarted() {
return <InstallCommand packageName="@gooseui/button" storageKey="package-manager" />
}Examples
Custom commands
commands replaces the generated command for any manager. Use it for packages that are not added with shadcn.
<InstallCommand
packageName="motion"
commands={{
npm: "npm install motion",
pnpm: "pnpm add motion",
yarn: "yarn add motion",
bun: "bun add motion",
}}
/>Commands and sync
Blocks with the same storageKey switch together. Pick a tab in one and the other follows.
Step 1. Add the dependency
Step 2. Add the component
<InstallCommand packageName="@gooseui/tabs" storageKey="pm" />
<InstallCommand packageName="@gooseui/timeline" storageKey="pm" />
// pnpm dlx shadcn@latest add @gooseui/timeline
// yarn dlx shadcn@latest add @gooseui/timelineProps
| Prop | Type | Default | Description |
|---|---|---|---|
| packageName | string | - | Package or registry URL to add, e.g. @gooseui/tabs |
| defaultPm | PackageManager | "npm" | Tab shown before the user picks one |
| storageKey | string | - | localStorage key. When set, the choice is remembered and blocks with the same key stay in sync |
| commands | Partial<Record<PackageManager, string>> | - | Exact commands that replace the generated ones |
| labels | { tabs?, copy?, copied? } | - | Texts for the tab list and the copy button |
| onCopy | (command, manager) => void | - | Called after the command is copied |
| onCopyError | (error: Error) => void | - | Called when the browser refuses to copy |
| className | string | - | Additional CSS classes |
Features
- One description. npx, pnpm dlx, yarn dlx and bunx shadcn@latest add for the package you pass.
- Shared choice. the choice goes to localStorage and a custom event, so blocks and other open browser tabs stay in step.
- Keyboard. native radios: Tab enters the group once, the arrow keys switch the manager. The focus ring shows for keyboard only.
- Exports. getInstallCommand is exported too, if you need the same strings elsewhere.