# Copy button

Copy text with clear loading, success and retry feedback.

Access: free. Category: Essentials. Kind: primitive.

## When to use

- Use it when a product interface needs copy text with clear loading, success and retry feedback.
- Choose it when the host application can supply the required state and keep business logic outside the presentation component.

## Alternatives

- Choose tidal-button instead when press, loading, success and disabled states is the actual interface need, rather than copy button.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install Copy button

```sh
npx shadcn@latest add https://tidalui.com/r/copy-button.json
```

Stylesheets: `components/ui/tidal.css`, `components/ui/copy-button.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/copy-button.css";
import{TidalCopyButton}from"./components/ui/copy-button";
export default()=><div className="tidal-scope"><TidalCopyButton text="Copy this"/></div>;
```

## Structured props

- `TidalCopyButton.clipboard?: TidalClipboardAdapter | undefined` (default browserClipboard): Optional clipboard value accepted by this exported component.
- `TidalCopyButton.disabled?: boolean | undefined` (default false): Optional disabled value accepted by this exported component.
- `TidalCopyButton.feedbackDuration?: number | undefined`: Optional feedback duration value accepted by this exported component.
- `TidalCopyButton.getText?: (() => string | Promise<string>) | undefined`: Optional get text value accepted by this exported component.
- `TidalCopyButton.labels?: Partial<TidalCopyButtonLabels> | undefined`: Optional labels value accepted by this exported component.
- `TidalCopyButton.onCopy?: (ClipboardEventHandler<HTMLButtonElement> & ((value: string) => void)) | undefined`: Callback invoked when the copy interaction is proposed.
- `TidalCopyButton.onCopyError?: ((kind: TidalCopyErrorKind, error: unknown) => void) | undefined`: Callback invoked when the copy error interaction is proposed.
- `TidalCopyButton.onStatusChange?: ((status: TidalCopyStatus) => void) | undefined`: Callback invoked when the status change interaction is proposed.
- `TidalCopyButton.text?: string | undefined`: Optional text value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/copy-button.tsx) | [Manifest](https://tidalui.com/examples/copy-button.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
"use client";

import "./components/ui/tidal.css";

import { useMemo, useState } from "react";

import { TidalCopyButton, type TidalClipboardAdapter, type TidalCopyStatus } from "./components/ui/copy-button";

import "./components/ui/copy-button.css";



const tidalExampleStyles = ".tidal-scope .copy-demo,\n.tidal-scope .copy-demo * {\n  box-sizing: border-box;\n}\n\n.tidal-scope .copy-demo {\n  width: 100%;\n  min-width: 0;\n  padding: clamp(12px, 4cqi, 30px);\n  color: var(--t-ink);\n  container: copy-demo / inline-size;\n  font-family: Inter, ui-sans-serif, system-ui, sans-serif;\n}\n\n.tidal-scope .copy-demo-control {\n  position: relative;\n  display: grid;\n  grid-template-columns: minmax(0, 1fr) auto;\n  gap: 12px;\n  align-items: stretch;\n  width: min(100%, 620px);\n  padding: 9px;\n  border: 1px solid var(--t-border);\n  border-radius: 18px;\n  background: var(--t-surface);\n  box-shadow:\n    0 16px 38px color-mix(in srgb, var(--t-ink) 8%, transparent),\n    inset 0 1px 0 color-mix(in srgb, var(--t-surface) 80%, transparent);\n  transition:\n    border-color 180ms,\n    box-shadow 240ms var(--t-ease-out);\n}\n\n.tidal-scope .copy-demo-control[data-copy-status=\"success\"] {\n  border-color: var(--t-ink);\n  box-shadow:\n    0 18px 42px color-mix(in srgb, var(--t-ink) 12%, transparent),\n    inset 0 0 0 1px var(--t-ink);\n}\n\n.tidal-scope .copy-demo-control[data-copy-status=\"error\"] {\n  border-color: var(--t-danger);\n  box-shadow: inset 0 0 0 1px var(--t-danger);\n}\n\n.tidal-scope .copy-demo-code-row {\n  position: relative;\n  display: grid;\n  min-width: 0;\n  min-height: 56px;\n  align-content: center;\n  gap: 4px;\n  padding: 9px 16px;\n  overflow: hidden;\n  border: 1px solid var(--t-border);\n  border-radius: 12px;\n  background:\n    linear-gradient(var(--t-border) 1px, transparent 1px) 0 0 / 100% 18px,\n    var(--t-subtle);\n}\n\n.tidal-scope .copy-demo-field-label {\n  color: var(--t-muted);\n  font-size: 11px;\n  font-weight: 720;\n  letter-spacing: 0.08em;\n  line-height: 1.2;\n  text-transform: uppercase;\n}\n\n.tidal-scope .copy-demo-code-row code {\n  min-width: 0;\n  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n  font-size: clamp(17px, 3.4cqi, 24px);\n  font-weight: 660;\n  letter-spacing: 0.075em;\n  line-height: 1.15;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .copy-demo-control .tidal-copy-button {\n  min-width: 188px;\n}\n\n.tidal-scope .copy-demo-permission {\n  display: grid;\n  grid-template-columns: 44px minmax(0, 1fr);\n  align-items: center;\n  width: min(100%, 620px);\n  min-height: 54px;\n  margin-top: 12px;\n  color: var(--t-muted);\n  cursor: pointer;\n}\n\n.tidal-scope .copy-demo-permission input {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  opacity: 0;\n}\n\n.tidal-scope .copy-demo-check {\n  position: relative;\n  width: 24px;\n  height: 24px;\n  margin-inline: 10px;\n  border: 1px solid var(--t-border);\n  border-radius: 8px;\n  background: var(--t-surface);\n  transition:\n    background 160ms,\n    border-color 160ms,\n    transform 180ms var(--t-ease-spring);\n}\n\n.tidal-scope .copy-demo-check::after {\n  position: absolute;\n  width: 8px;\n  height: 4px;\n  border-block-end: 1.5px solid var(--t-surface);\n  border-inline-start: 1.5px solid var(--t-surface);\n  content: \"\";\n  inset-block-start: 7px;\n  inset-inline-start: 7px;\n  opacity: 0;\n  transform: rotate(-45deg) scale(0.6);\n}\n\n.tidal-scope .copy-demo-permission input:checked + .copy-demo-check {\n  border-color: var(--t-ink);\n  background: var(--t-ink);\n  transform: scale(0.94);\n}\n\n.tidal-scope .copy-demo-permission input:checked + .copy-demo-check::after {\n  opacity: 1;\n  transform: rotate(-45deg) scale(1);\n}\n\n.tidal-scope .copy-demo-permission input:focus-visible + .copy-demo-check {\n  outline: 2px solid var(--t-accent);\n  outline-offset: 3px;\n}\n\n.tidal-scope .copy-demo-permission strong,\n.tidal-scope .copy-demo-permission small {\n  display: block;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .copy-demo-permission strong {\n  color: var(--t-ink);\n  font-size: 12px;\n  font-weight: 680;\n}\n\n.tidal-scope .copy-demo-permission small {\n  margin-top: 2px;\n  font-size: 11px;\n  line-height: 1.4;\n}\n\n.tidal-scope .copy-demo-note {\n  width: min(100%, 620px);\n  margin: 9px 0 0;\n  color: var(--t-muted);\n  font-size: 11px;\n  line-height: 1.45;\n}\n\n@container copy-demo (max-width: 500px) {\n  .tidal-scope .copy-demo-control {\n    grid-template-columns: minmax(0, 1fr);\n  }\n\n  .tidal-scope .copy-demo-control .tidal-copy-button {\n    width: 100%;\n    min-width: 0;\n  }\n}\n\n@container copy-demo (max-width: 340px) {\n  .tidal-scope .copy-demo {\n    padding-inline: 10px;\n  }\n\n  .tidal-scope .copy-demo-code-row {\n    padding-inline-start: 12px;\n  }\n}\n\n@media (hover: none) and (pointer: coarse) {\n  .tidal-scope .copy-demo-permission {\n    font-size: 16px;\n  }\n}\n\n@media (prefers-reduced-motion: reduce) {\n  .tidal-scope .copy-demo-control,\n  .tidal-scope .copy-demo-check,\n  .tidal-scope .copy-demo-check::after {\n    transition: none !important;\n  }\n}";

const SAMPLE_CODE = "NORTH-2048";

export function CopyButtonDemo({ theme }: { theme?: "light" | "dark" }) {
  const [denyPermission, setDenyPermission] = useState(false);
  const [status, setStatus] = useState<TidalCopyStatus>("idle");

  const clipboard = useMemo<TidalClipboardAdapter>(
    () => ({
      async writeText(value) {
        if (denyPermission) {
          const error = new Error("Permission denied by the sample control");
          error.name = "NotAllowedError";
          throw error;
        }
        const nativeClipboard = globalThis.navigator?.clipboard;
        if (!nativeClipboard?.writeText) {
          const error = new Error("Clipboard API unavailable");
          error.name = "ClipboardUnavailableError";
          throw error;
        }
        await nativeClipboard.writeText(value);
      },
    }),
    [denyPermission],
  );

  return (
    <section
      className="copy-demo"
      aria-label="Copy button preview"
      data-theme={theme}
    >
      <div className="copy-demo-control" data-copy-status={status}>
        <div className="copy-demo-code-row">
          <span className="copy-demo-field-label">Project code</span>
          <code>{SAMPLE_CODE}</code>
        </div>

        <TidalCopyButton
          text={SAMPLE_CODE}
          clipboard={clipboard}
          onStatusChange={setStatus}
          aria-label={`Copy sample project code ${SAMPLE_CODE}`}
        />
      </div>

      <label className="copy-demo-permission">
        <input
          type="checkbox"
          checked={denyPermission}
          onChange={(event) => setDenyPermission(event.currentTarget.checked)}
        />
        <span className="copy-demo-check" aria-hidden="true" />
        <span>
          <strong>Simulate denied permission</strong>
          <small>The next attempt stays local and shows the retry state.</small>
        </span>
      </label>

      <p className="copy-demo-note">
        Fictional sample code. Successful attempts use your browser clipboard.
      </p>
    </section>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <CopyButtonDemo />
    </div>
  );
}

```

## Gotchas

- Install the declared registry dependencies and render inside a tidal-scope with the foundation stylesheet loaded.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"keyboard":["Tab and Shift+Tab follow the component's native focus order."],"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

Exactly one copy source is required: text for a ready string, or getText for a string or Promise resolved at activation time. clipboard injects a writeText adapter and defaults to navigator.clipboard. Partial labels localize idle, pending, success, general error, permission-denied and unavailable states. feedbackDuration is clamped from 600 to 10000ms and defaults to 1800ms. onCopy receives the accepted string; onCopyError receives a normalized kind and the original source or adapter error; onStatusChange reports idle, pending, success and error. Observer callbacks are queued after internal lifecycle commits, so their exceptions surface asynchronously to the host and are never reclassified as copy failures. Native button attributes, type, form ownership, data/ARIA attributes, className and the forwarded button ref are preserved. The native onClick handler runs before the copy request and preventDefault cancels it. Native disabled is respected; explicit aria-disabled true and pending suppress activation while retaining focus. The source owns no navigation, storage or copied content.
