Snippet
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.
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.
"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
The command, shown on one line.
Text copied instead of the shown command.
Prefix such as "$" or ">". Defaults to "$"; null hides it. Never copied.
Runs after a successful copy, with the copied text.
Copy button name. Defaults to "Copy".
Name and announcement once copied. Defaults to "Copied".
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
| Hook | Values |
|---|---|
.cherry-snippet | Root element |
data-copied | Present 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.