Components
Code Block
Read-only code with a title, line numbers, highlighting and Copy, or a command with one tab per package manager.
Ombelle · light
Code Block
pnpm dlx @ombelle-ui/cli add buttonsave.tsx
import { Button } from '../ui/button'
// Saves the draft.
export function Save() {
return <Button variant="outline" size="sm">Save</Button>
}
ui-style.css
:root {
--radius: 0.5rem;
--radius: 0.75rem;
--shadow-offset: 3px;
}
Installation
Run in a project initialized with an Ombelle preset (see Get started). The component uses the saved project preset. Run the command from your app folder; it shows the changes and asks before writing.
pnpm dlx @ombelle-ui/cli@1.1.2 add code-blockAdds components/ui/code-block.tsx and installs react, @radix-ui/react-tabs, clsx, tailwind-merge with lifecycle scripts disabled. This is a client component.
In a liquid glass project the plan adds a notice that accessibility is not guaranteed, because text contrast depends on the background behind the glass.
Usage
example.tsx
import { CodeBlock, CodeBlockCommand } from '@/components/ui/code-block'
const source = "import { Button } from '@/components/ui/button'\n\nexport function Save() {\n return <Button>Save</Button>\n}\n"
export function Example(){return <div style={{ display: "grid", gap: "1rem" }}><CodeBlockCommand args="@ombelle-ui/cli add button" /><CodeBlock title="save.tsx" language="tsx" code={source} /></div>}API and states
- API
- CodeBlock (code, language tsx, css, json, shell or text, title, lineNumbers, maxHeight, copyLabel, diff), CodeBlockCommand (args, managers, manager, defaultManager, onManagerChange, label, copyLabel, runners), CodeBlockRoot, CodeBlockHeader, CodeBlockTitle, CodeBlockCopy, CodeBlockCode (diff); diffLines, diffNewVersion, diffCounts
- Minimum states
- Default, scrolling, focus, copied, copy failed, selected tab, no line numbers
- Native basis
- Native pre and button with a polite status; Radix Tabs, or Base UI Tabs in the Base UI edition, for the command block
- Styles
- Stable in Ombelle, Papier, Organic, Retro futurism, minimalist, neo-brutalism and flat, light and dark. Liquid glass: stable, accessibility not guaranteed.