v0.3.1 StableFoundation ComponentReact 18 & 19Zero Runtime CSS
CodeBlock
Plain, selectable code with an optional copy action.
Interactive preview
:root {
--dvy-brand: #282724;
--dvy-radius-md: 0.5rem;
}
Usage
import { CodeBlock } from "@devvy-ui/react";
<CodeBlock label="Theme token" language="css" code="--dvy-brand: #282724;" />API reference
Native HTML attributes, className, style and a forwarded ref are supported. Component-specific props:
| Prop | Type | Default | Description |
|---|---|---|---|
| code | string | required | Literal code text. |
| label / language | string | Code example / text | Figure and code description. |
| copyable | boolean | true | Copy action. |
| lineNumbers | boolean | false | Decorative line markers excluded from copying. |
Accessibility & behavior
Platform Behavior & Guidelines
Code renders as escaped text, never HTML. Native horizontal scrolling preserves formatting. Copy uses the existing clipboard/manual fallback; no syntax-highlighting dependency.
Source ownership
Run npx @devvy-ui/cli init once in your React project, then add the source:
npx @devvy-ui/cli add code-blockMake the source yours.
Start from the canonical implementation used by the package and registry. Change the code, keep the MIT notice, and build the behavior your project needs.
CodeBlock.tsxREACT / TSX
Edit your own copy. Downloaded source uses your changes; the component preview above uses the shipped version. Run the source installer first to include shared helpers.