Skip to content

Data display

Snippet

tsx
import { Snippet } from "@cherry-design-system/react";

export function Install() {
  return <Snippet>pnpm add @cherry-design-system/react lucide-react</Snippet>;
}

Snippet shows a one-line command, such as an install command, with a copy button. After a copy the icon swaps to a check, then back. Without clipboard access (an insecure context or a denied permission) the command text is selected instead, ready for Ctrl/Cmd+C. For multi-line code, use CodeBlock.

Examples

Custom prompt or none

The prompt defaults to $ and is never copied. Pass null to hide it.

tsx
import { Snippet } from "@cherry-design-system/react";

export function Prompts() {
  return (
    <>
      <Snippet prompt=">">npm run dev</Snippet>
      <Snippet prompt={null}>npx cherry init</Snippet>
    </>
  );
}

Copy different text

copyText replaces what goes to the clipboard, while the shown command stays the same. onCopy runs after a successful copy.

tsx
"use client";

import { Snippet } from "@cherry-design-system/react";

export function ApiKey({ apiKey }: { apiKey: string }) {
  return (
    <Snippet
      prompt={null}
      copyText={apiKey}
      copyLabel="Copy API key"
      onCopy={() => console.log("Key copied")}
    >
      {`${apiKey.slice(0, 6)}••••••••`}
    </Snippet>
  );
}

Properties

childrenstringrequired

The command, shown on one line.

copyTextstring

Text copied instead of the shown command.

promptReactNode

Prefix such as "$" or ">". Defaults to "$"; null hides it. Never copied.

onCopy(text: string) => void

Runs after a successful copy, with the copied text.

copyLabelstring

Copy button name. Defaults to "Copy".

copiedLabelstring

Name and announcement once copied. Defaults to "Copied".

resetAfternumber

Milliseconds before the check turns back into the copy icon. Defaults to 2000.

Snippet renders a <div>, forwards its ref to it and passes every other <div> attribute through. It is a client component.

Styling

HookValues
.cherry-snippetRoot element
data-copiedPresent after a copy, until resetAfter
Parts.cherry-snippet__prompt, __code, __copy, __icons, __icon

The pill reads --cherry-bg-subtle, --cherry-border-default and --cherry-radius-full; the command uses --cherry-font-mono with the mono-sm tokens; the copied state reads --cherry-success-bg and --cherry-success-fg.

Accessibility

  • The copy button is labelled (copyLabel) and "Copied" (copiedLabel) is announced through a status region.
  • A command wider than the pill becomes a keyboard-scrollable tab stop. The prompt is hidden from assistive tech.