Skip to content
v0.2.10

CopyButton

A clipboard action with stable geometry and localized result feedback.

Preview

Use CopyButton

CopyButton is a named export of @flood-md/react. Connect the package once, then import what you use.

First time here? Connect Flood
Example import style
copy-button.tsxTSX
"use client";

import { FloodRoot, CopyButton } from "@flood-md/react";
import "@flood-md/react/styles.css";

export function Example() {
  return (
    <FloodRoot>
      <CopyButton value="npm install @flood-md/react" />
    </FloodRoot>
  );
}

Design notes

  • Copies only on a user click. Requires a secure context and Clipboard API; onCopyError receives unavailable/denied errors. The host owns any manual-copy fallback. Native button ref and disabled semantics are preserved.
  • Localize copyLabel/copiedLabel/errorLabel. resetDelay restores the idle state after success. Labels reserve their common width and a live status announces the result. No remote data transfer is built in. Available in 0.2.5.

API reference

PropValuesDefault
variant"solid" | "subtle" | "outline" | "ghost""subtle"
size"2xs" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl""md"
valuestringRequired
copyLabelstring"Copy"
copiedLabelstring"Copied"
errorLabelstring"Failed"
resetDelaynumber2000
onCopied() => void—
onCopyError(error: unknown) => void—
Native HTML propsOmit<ButtonHTMLAttributes<HTMLButtonElement>, "children" | "value" | "type" | "onClick" | "loading">Forwarded
View TypeScript source