Code block
Code snippet with copy. 2 themes.
add-tea.sh
npx uix-ui@latest initnpx uix-ui@latest add button cardimport { CodeBlock } from "@/components/ui/code-block";
export default function Example() {
return (
<div style={{ width: 460, maxWidth: "100%" }}>
<CodeBlock filename="add-tea.sh" code={"npx uix-ui@latest init\nnpx uix-ui@latest add button card"} />
</div>
);
}
Installation
$ npx uix-ui@latest add code-blockThis copies the file into components/ui/code-block.tsx in your project. npx shadcn@latest add @uix/code-block works too.
Usage
import { CodeBlock } from "@/components/ui/code-block";
<div style={{ width: 460, maxWidth: "100%" }}>
<CodeBlock filename="add-tea.sh" code={"npx uix-ui@latest init\nnpx uix-ui@latest add button card"} />
</div>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
theme | dark | light | "dark" | |
code | string | – | Source text; each line gets a number and keywords / strings are colored. |
filename | React.ReactNode | – | |
showHeader | boolean | true | Bar with the file name and a copy button. |
showLineNumbers | boolean | true |
Everything else is passed to the root element, so className, aria-* and event handlers work as usual.
Dependencies
Installed for you by the CLI.
class-variance-authorityclsxtailwind-merge
lib/utils.tscomponents/ui/icons.tsx