Skip to content
Marketing block

Package Manager Code Tabs

One install command behind npm/pnpm/yarn/bun tabs with a working copy button — every reader uses exactly one package manager, so showing all four wastes three lines.

152 lineslucide-reactAdded 13 Aug 2026Updated 11 Sept 2026
  • code
  • tabs
  • install
  • copy
  • developer

What's included

  • components/code-tabs-panel.tsx
  • Needs lucide-react

Works with

  • React
  • Next.js
  • Tailwind CSS
  • TypeScript

npx hoverlab add code-tabs-panel

Or over MCP, from your editor's agent — no account needed.

License

Free to read, copy and install, for personal and non-commercial projects. Shipping it in client work or a paid product needs Pro ($79 once). The source lands in your repo and stops being ours — no attribution, nothing to upgrade.

Was this useful?

Start a page with this section — add more, order them, and leave with the page source.

Preview

Install the SDK
npm install @acme/sdk

Rendered live in your current theme — this is the same component whose source is below, not a screenshot of it.

Source

components/code-tabs-panel.tsx
'use client'

/**
 * <CodeTabsPanel> — one install command, four package managers, real tabs.
 *
 * Every reader uses exactly one package manager, so printing all four
 * commands at once wastes three lines and forces a mental filter on every
 * snippet down the page. The tab remembers the choice the reader already
 * made everywhere else in their life — they click "pnpm" once and stop
 * seeing npm.
 *
 * This block keeps that memory local on purpose. Syncing the selection
 * across every instance on a page (and into localStorage) is a docs-
 * framework concern; wiring it here would smuggle in global state.
 */

import * as React from 'react'
import { Copy, Check } from 'lucide-react'

export interface CodeTab {
  label: string
  code: string
  language?: string
}

export interface CodeTabsPanelProps {
  tabs?: CodeTab[]
  title?: string
  className?: string
}

const DEFAULT_TABS: CodeTab[] = [
  { label: 'npm', code: 'npm install @acme/sdk', language: 'bash' },
  { label: 'pnpm', code: 'pnpm add @acme/sdk', language: 'bash' },
  { label: 'yarn', code: 'yarn add @acme/sdk', language: 'bash' },
  { label: 'bun', code: 'bun add @acme/sdk', language: 'bash' },
]

export function CodeTabsPanel({
  tabs = DEFAULT_TABS,
  title = 'Install the SDK',
  className = '',
}: CodeTabsPanelProps) {
  const [active, setActive] = React.useState(0)
  const [copied, setCopied] = React.useState(false)
  const tabRefs = React.useRef<(HTMLButtonElement | null)[]>([])
  const baseId = React.useId()

  const tab = tabs[active] ?? tabs[0]

  function select(index: number) {
    setActive(index)
    setCopied(false)
    tabRefs.current[index]?.focus()
  }

  function onKeyDown(event: React.KeyboardEvent) {
    const last = tabs.length - 1
    if (event.key === 'ArrowRight') select(active === last ? 0 : active + 1)
    else if (event.key === 'ArrowLeft') select(active === 0 ? last : active - 1)
    else if (event.key === 'Home') select(0)
    else if (event.key === 'End') select(last)
    else return
    event.preventDefault()
  }

  function copy() {
    if (typeof navigator === 'undefined' || !navigator.clipboard) return
    void navigator.clipboard.writeText(tab.code).then(() => {
      setCopied(true)
      window.setTimeout(() => setCopied(false), 2000)
    })
  }

  return (
    <div
      className={`w-full max-w-2xl overflow-hidden rounded-2xl border border-border/60 bg-zinc-950 ${className}`}
    >
      <div className="flex flex-wrap items-center gap-3 border-b border-white/10 px-4 py-2.5">
        <div aria-hidden className="flex shrink-0 gap-1.5">
          <span className="h-2.5 w-2.5 rounded-full bg-red-500/80 border border-transparent" />
          <span className="h-2.5 w-2.5 rounded-full bg-amber-500/80 border border-transparent" />
          <span className="h-2.5 w-2.5 rounded-full bg-emerald-500/80 border border-transparent" />
        </div>
        <span className="min-w-0 truncate font-mono text-xs text-white/60">{title}</span>

        <div
          role="tablist"
          aria-label="Package manager"
          onKeyDown={onKeyDown}
          className="ms-auto flex flex-wrap gap-1"
        >
          {tabs.map((t, i) => (
            <button
              key={t.label}
              ref={(el) => {
                tabRefs.current[i] = el
              }}
              role="tab"
              type="button"
              id={`${baseId}-tab-${i}`}
              aria-selected={i === active}
              aria-controls={`${baseId}-panel-${i}`}
              tabIndex={i === active ? 0 : -1}
              onClick={() => select(i)}
              className={`shrink-0 rounded-md px-2.5 py-1 font-mono text-xs transition-colors ${
                i === active
                  ? 'bg-white/10 text-white'
                  : 'text-white/50 hover:text-white/80'
              }`}
            >
              {t.label}
            </button>
          ))}
        </div>
      </div>

      <div
        role="tabpanel"
        id={`${baseId}-panel-${active}`}
        aria-labelledby={`${baseId}-tab-${active}`}
        className="relative"
      >
        <pre className="overflow-x-auto p-4 pe-14 text-sm leading-relaxed">
          <code
            className="font-mono text-zinc-300"
            data-language={tab.language ?? 'bash'}
          >
            <span aria-hidden className="select-none text-white/30">
              ${' '}
            </span>
            {tab.code}
          </code>
        </pre>

        <button
          type="button"
          onClick={copy}
          aria-label={copied ? 'Copied' : `Copy ${tab.label} command`}
          className="absolute end-3 top-3 inline-flex items-center rounded-md p-1.5 text-white/50 transition-colors hover:bg-white/10 hover:text-white"
        >
          {copied ? (
            <Check aria-hidden className="h-4 w-4 text-emerald-400" />
          ) : (
            <Copy aria-hidden className="h-4 w-4" />
          )}
        </button>
      </div>
    </div>
  )
}

Before you paste

  • Styling is Tailwind utility classes on semantic tokens (bg-card, text-muted-foreground) — it inherits your theme instead of overriding it.
  • Install: npm i lucide-react
  • Every prop has a default, so it renders standalone before you wire it up.

Where it goes

Drop it at components/code-tabs-panel.tsx and import it where you need the section:

import { CodeTabsPanel } from '@/components/code-tabs-panel'

Customize

1 of this block’s props are simple enough to drive from here. Change them and the block below re-renders — it is the same component whose source is above, not a mock of it. Everything else it accepts is in the table underneath.

Props

Read out of the component’s own type and signature, so this cannot drift from the source below. Every prop has a default — the component renders standalone before you pass it anything.

PropTypeDefault
tabsCodeTab[]DEFAULT_TABS
titlestring'Install the SDK'
classNamestring''

Not using React?

The same block rendered once to markup, wrapped as a file your framework compiles. Tailwind classes are framework-agnostic, so the design transfers intact — the behaviour does not.

This block is interactive. The markup below is its initial state with the event handlers stripped — you will need to re-wire the behaviour in your framework.

code-tabs-panel.html
<!--
  Package Manager Code Tabs — markup from the Hoverlab catalog.

  This is the block rendered once to HTML and wrapped as a component
  file. It is not a port of the React source: the Tailwind classes carry
  the design, which is the part that took the work, and they are the same
  in every framework.

  This block is interactive in React and the handlers are NOT here.
  Buttons, toggles and menus render in their initial state and do
  nothing until you wire them up.
-->
<div class="w-full max-w-2xl overflow-hidden rounded-2xl border border-border/60 bg-zinc-950 ">
  <div class="flex flex-wrap items-center gap-3 border-b border-white/10 px-4 py-2.5">
    <div aria-hidden="true" class="flex shrink-0 gap-1.5">
      <span class="h-2.5 w-2.5 rounded-full bg-red-500/80 border border-transparent"></span>
      <span class="h-2.5 w-2.5 rounded-full bg-amber-500/80 border border-transparent"></span>
      <span class="h-2.5 w-2.5 rounded-full bg-emerald-500/80 border border-transparent"></span>
    </div>
    <span class="min-w-0 truncate font-mono text-xs text-white/60">Install the SDK</span>
    <div role="tablist" aria-label="Package manager" class="ms-auto flex flex-wrap gap-1">
      <button role="tab" type="button" id="_R_0_-tab-0" aria-selected="true" aria-controls="_R_0_-panel-0" tabindex="0" class="shrink-0 rounded-md px-2.5 py-1 font-mono text-xs transition-colors bg-white/10 text-white">npm</button>
      <button role="tab" type="button" id="_R_0_-tab-1" aria-selected="false" aria-controls="_R_0_-panel-1" tabindex="-1" class="shrink-0 rounded-md px-2.5 py-1 font-mono text-xs transition-colors text-white/50 hover:text-white/80">pnpm</button>
      <button role="tab" type="button" id="_R_0_-tab-2" aria-selected="false" aria-controls="_R_0_-panel-2" tabindex="-1" class="shrink-0 rounded-md px-2.5 py-1 font-mono text-xs transition-colors text-white/50 hover:text-white/80">yarn</button>
      <button role="tab" type="button" id="_R_0_-tab-3" aria-selected="false" aria-controls="_R_0_-panel-3" tabindex="-1" class="shrink-0 rounded-md px-2.5 py-1 font-mono text-xs transition-colors text-white/50 hover:text-white/80">bun</button>
    </div>
  </div>
  <div role="tabpanel" id="_R_0_-panel-0" aria-labelledby="_R_0_-tab-0" class="relative">
    <pre class="overflow-x-auto p-4 pe-14 text-sm leading-relaxed"><code class="font-mono text-zinc-300" data-language="bash"><span aria-hidden="true" class="select-none text-white/30">$ </span>npm install @acme/sdk</code></pre>
    <button type="button" aria-label="Copy npm command" class="absolute end-3 top-3 inline-flex items-center rounded-md p-1.5 text-white/50 transition-colors hover:bg-white/10 hover:text-white">
      <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-copy h-4 w-4" aria-hidden="true">
        <rect width="14" height="14" x="8" y="8" rx="2" ry="2"></rect>
        <path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"></path>
      </svg>
    </button>
  </div>
</div>
  • This is rendered HTML, not a translation of the React source. The Tailwind classes carry the design and work in any framework.
  • It is one frame: the component in its initial state, with no props applied beyond the defaults.
  • This block is interactive in React — toggles, menus or form state. None of that survives here; the markup is the closed/default state and the handlers are gone. Re-wire them in your own framework.
  • Requires Tailwind, and the design tokens the classes reference (bg-card, text-muted-foreground, and so on). The template ZIPs ship a globals.css that defines them.

What each framework gets across the whole catalog — effects convert properly; this rung is markup.

For AI

The component, its props, the design tokens it expects and the command that installs it — as one prompt. Paste it into Claude, Cursor, v0 or ChatGPT and what they build around it will match the rest of the catalog instead of inventing its own system.

See the prompt

Used in these pages

Want the whole screen instead of this one section? Open a page and copy it entire.

11 more blocks in Content & Blog

All of them free to read, copy and install — no account, no locked tiles, no watermarked preview. The whole catalog is open, and so are the API and the CLI.

Browse Content & Blog

Shipping one commercially

Copying the code is free. Putting it in client work or a paid product is what Pro is for — the licence, not the access.

  • A commercial licence for everything in the catalog
  • Unlimited bundle exports, in Vue, Svelte and Tailwind
  • One payment — no subscription, nothing to renew
Pro — $79 once

More Content & Blog blocks

View category
Open the full page for this block

Release Timeline

A dated changelog on a vertical rail with added/changed/fixed tags and machine-readable <time> values.

Content & Blog145 linesNo deps
Open the full page for this block

Public Roadmap Columns

Shipped / in progress / planned in three columns, with status carried by icon as well as colour.

Content & Blog122 lines1 dep

Blog Index Grid

A featured post at full width above a card grid, with drawn covers built from tokens — a blog index with no image pipeline and no broken-thumbnail state.

Content & Blog188 lines1 dep

Case Study Card Grid

A grid of case-study cards that lead with the metric rather than the company name, each one linking out to the full write-up — the block a customer-stories section or a home page needed and only had a full case-study page for.

Content & Blog136 lines1 dep
Open the full page for this block

Article Header & Byline

Kicker, headline, standfirst, byline and share row, with the opening prose and a pull quote included — the type scale of a post, decided once instead of per-article.

Content & Blog171 lines1 dep
Open the full page for this block

Team Grid

An about-page team section on initials avatars rather than photos, so shipping it never waits on headshots and there is no broken-image state to design.

Content & Blog166 lines1 dep

Careers Openings Board

Openings grouped by department with location, type and salary on every row — candidates self-select by craft first, and a flat list makes them scan for it.

Content & Blog186 lines1 dep
Open the full page for this block

Three-Column Docs Frame

Sidebar, article and on-this-page rail — each column answers a different question, and they collapse on mobile in the order that keeps the article alive.

Content & Blog290 lines1 dep
Open the full page for this block

API Endpoint Reference

Method badge, path, parameter table and a request/response pair kept side by side — an example request whose response is a scroll away gets pasted blind.

Content & Blog237 lines1 dep
Open the full page for this block

Résumé Document

A CV as a document rather than a timeline of cards — one column, dates on the end edge, and a print layer that puts it on paper without a separate PDF to keep in step.

Content & Blog347 lines1 dep
Open the full page for this block

Video Player Shell

The watch screen with no playback in it: a ratio-locked stage, a control bar drawn down to the buffered layer, and an up-next rail. Drop a video element in and wire your own player.

Content & Blog327 lines1 dep