Skip to content
Unkey Design Docs
Esc
↑↓navigate↵open⌘Jpreview
On this page

Code

A block of code or config text with a copy button.

import { Code, CopyButton } from "@unkey/ui";

const SNIPPET = `curl -X POST https://api.unkey.com/v2/keys.verifyKey \\
  -H "Content-Type: application/json" \\
  -d '{"key": "sk_1234"}'`;

export default function CodeVariants() {
  return (
    <div className="flex w-full max-w-md flex-col gap-4">
      <Code copyButton={<CopyButton value={SNIPPET} />}>{SNIPPET}</Code>
      <Code
        variant="compact"
        copyValue="DATABASE_URL=<connection-string>"
        copyLabel="Copy .env line"
      >
        DATABASE_URL=&lt;connection-string&gt;
      </Code>
      <Code
        variant="compact"
        copyValue={"process.env.DATABASE_URL\nprocess.env.DATABASE_PREVIEW_URL"}
        copyLabel="Copy code to read the variables"
      >
        {"process.env.DATABASE_URL\nprocess.env.DATABASE_PREVIEW_URL"}
      </Code>
    </div>
  );
}

Variants

  • Default: a snippet or a config block on its own, for example an API key or a request body. Long lines wrap.
  • ghost: the same block without the frame, inside a surface that already has one.
  • compact: a short value in a step or a settings row, for example an environment variable. One line is 32px high. Each line of the value keeps its own row, and the copy button stays centered. A long line scrolls horizontally and does not wrap. Pass copyValue and copyLabel, and the block renders a small ghost copy button.

Copy button

Pass one of these, or neither for a block with no copy button:

  • copyValue and copyLabel: the text to copy and the button’s name for screen readers and its tooltip. The button matches the variant. Both are required together.
  • copyButton: a custom button, for a value that differs from the shown text or a button with its own behavior. It cannot be combined with copyValue.