bysages

Clipboard

Component

About

A labeled text field with an icon trigger that copies its value to the clipboard and flashes a success state for a moment after copying.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Clipboard to your project and fits it to your theme.

Code

How Clipboard is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

import { Clipboard } from "@/components/ui/clipboard";
import { applyTheme, attachDynamicLight } from "@bysages/core";
import { useState } from "react";

const copyGlyph = (
  <svg
    width={16}
    height={16}
    viewBox="0 0 24 24"
    fill="none"
    stroke="currentColor"
    strokeWidth={1.75}
    aria-hidden="true"
  >
    <rect x={9} y={9} width={11} height={11} rx={1.5} />
    <path d="M5 15H4.5A1.5 1.5 0 0 1 3 13.5v-9A1.5 1.5 0 0 1 4.5 3h9A1.5 1.5 0 0 1 15 4.5V5" />
  </svg>
);

const checkGlyph = (
  <svg
    width={16}
    height={16}
    viewBox="0 0 24 24"
    fill="none"
    stroke="currentColor"
    strokeWidth={1.75}
    aria-hidden="true"
  >
    <path d="m5 12.5 4.5 4.5L19 7.5" />
  </svg>
);

applyTheme({ mode: "light", accent: "ink", density: "default" });
attachDynamicLight();

export default function ClipboardCopyStatusDemo() {
  // Each confirmed copy is counted — the machine reports through the
  // status change.
  const [copyCount, setCopyCount] = useState(0);

  return (
    <div
      style={{
        background: "var(--bs-color-surface-1, #fff)",
        color: "var(--bs-color-text-primary, #111)",
        padding: "2rem",
        display: "grid",
        placeItems: "center",
        minHeight: "240px",
        width: "100%",
      }}
    >
      <Clipboard.Root
        defaultValue="https://ark-ui.com"
        onStatusChange={(e: { copied: boolean }) => {
          if (e.copied) setCopyCount((count) => count + 1);
        }}
      >
        <Clipboard.Label>Copied {copyCount} times</Clipboard.Label>
        <Clipboard.Control>
          <Clipboard.Input />
          <Clipboard.Trigger>
            <Clipboard.Indicator copied={checkGlyph}>
              {copyGlyph}
            </Clipboard.Indicator>
          </Clipboard.Trigger>
        </Clipboard.Control>
      </Clipboard.Root>
    </div>
  );
}

Dependencies

More by bysages

View all
  • Switch

    Switch

    18
  • Avatar Group

    Avatar Group

    14
  • Typography

    Typography

    12
  • Spinner

    Spinner

    7
  • Block UI

    Block UI

    2
  • Rating Group

    Rating Group

  • Date Input

    Date Input

  • Grid

    Grid