3

Copy Button

An icon button that copies text to the clipboard, morphs its icon from a copy glyph to a checkmark (or an error state), and anchors a confirmation toast to itself — built on Tooltip and the anchored Toast. It brings its own toast manager and provider internally, so it drops in anywhere with zero setup.

Last updated August 9, 2026

Overview

"use client"
 
import { CopyButton } from "@/components/ui/copy-button"
 
export function CopyButtonDemoExample() {
  return <CopyButton text="https://persian-labs.ir" label="Copy link" />
}

Installation

$ npx shadcn@latest add https://ui.persian-labs.ir/r/copy-button.json

Usage

No provider to wrap — the copy confirmation is a toast anchored to the button itself (not a corner-stacked one), and CopyButton manages that internally by default.

import { CopyButton } from "@/components/ui/copy-button"
 
export function Example() {
  return <CopyButton text="https://persian-labs.ir" label="Copy link" />
}

With Text

It's a regular Button under the hood, so any variant, size, or children work — pass a label as children alongside the icon.

"use client"
 
import { CopyButton } from "@/components/ui/copy-button"
 
export function CopyButtonWithTextExample() {
  return (
    <CopyButton
      text="npx shadcn@latest add https://ui.persian-labs.ir/r/copy-button.json"
      label="Copy install command"
      variant="outline"
      size="default"
      className="w-fit"
    >
      Copy command
    </CopyButton>
  )
}

RTL

The default label is already Persian ("کپی"), and the anchored confirmation toast mirrors correctly since it goes through the same direction-aware AnchoredToastProvider as Toast.

"use client"
 
import { CopyButton } from "@/components/ui/copy-button"
 
export function CopyButtonRtlExample() {
  return (
    <CopyButton
      text="۰۹۱۲۳۴۵۶۷۸۹"
      variant="outline"
      size="default"
      className="w-fit"
    >
      کپی شماره
    </CopyButton>
  )
}

API Reference

CopyButton