---
layout: ~/layouts/MdxDocLayout.astro
title: "Clipboard Text"
description: "A text component with a copy-to-clipboard button."
sourceFile: "components/clipboard-text"
---

import ComponentExample from "~/components/docs/ComponentExample.astro";
import ComponentSection from "~/components/docs/ComponentSection.astro";
import CodeBlock from "~/components/docs/CodeBlock.astro";
import PropsTable from "~/components/docs/PropsTable.astro";
import Heading from "~/components/docs/Heading.astro";
import {
  ClipboardTextBasicDemo,
  ClipboardTextShortDemo,
  ClipboardTextApiKeyDemo,
  ClipboardTextLongDemo,
  ClipboardTextWithTooltipDemo,
} from "~/components/demos/ClipboardTextDemo";

{/* Demo */}

<ComponentSection>
  <ComponentExample code={`<ClipboardText text="0c239dd2" />`}>
    <ClipboardTextBasicDemo client:visible />
  </ComponentExample>
</ComponentSection>

{/* Installation */}

<ComponentSection>
  <Heading level={2}>Installation</Heading>
  <Heading level={3}>Barrel</Heading>
  <CodeBlock
    code={`import { ClipboardText } from "@cloudflare/kumo";`}
    lang="tsx"
  />
  <Heading level={3}>Granular</Heading>
  <CodeBlock
    code={`import { ClipboardText } from "@cloudflare/kumo/components/clipboard-text";`}
    lang="tsx"
  />
</ComponentSection>

{/* Usage */}

<ComponentSection>
  <Heading level={2}>Usage</Heading>
  <CodeBlock
    code={`import { ClipboardText } from "@cloudflare/kumo";

export default function Example() {
  return <ClipboardText text="Copy this text" />;
}`}
    lang="tsx"
  />
</ComponentSection>

{/* Examples */}

<ComponentSection>
  <Heading level={2}>Examples</Heading>

<Heading level={3}>Short Text</Heading>
<ComponentExample code={`<ClipboardText text="abc123" />`}>
  <ClipboardTextShortDemo client:visible />
</ComponentExample>

<Heading level={3}>API Key</Heading>
<ComponentExample code={`<ClipboardText text="sk_live_51H8..." />`}>
  <ClipboardTextApiKeyDemo client:visible />
</ComponentExample>

<Heading level={3}>Long Text</Heading>
<ComponentExample
  code={`<ClipboardText text="https://example.com/very/long/url/path" />`}
>
  <ClipboardTextLongDemo client:visible />
</ComponentExample>

  <Heading level={3}>With Tooltip</Heading>
  <p>Shows "Copy" tooltip on hover, "Copied!" toast on click.</p>
  <ComponentExample
    code={`<ClipboardText

text="npx kumo add button"
tooltip={{ text: "Copy", copiedText: "Copied!", side: "top" }}
/>`} >

<ClipboardTextWithTooltipDemo client:visible />
</ComponentExample>
</ComponentSection>

{/* API Reference */}

<ComponentSection>
  <Heading level={2}>API Reference</Heading>
  <PropsTable component="ClipboardText" />
</ComponentSection>
