Files
zeekay f21b520d17 fix: Correct snippet component reference and fix syntax highlighting
- Update snippet.mdx to reference correct component name (code-snippet-demo)
- Create proper working demo for CodeSnippet component with TypeScript example
- Fix syntax highlighting by updating to Shiki v3 API with bundledLanguages
- Add language validation to prevent unsupported language errors
- Improve error handling with HTML escaping fallback
- Rebuild registry with updated component
2025-11-06 13:45:30 -08:00

84 lines
1.4 KiB
Plaintext

---
title: Code Snippet
description: A syntax-highlighted code snippet component with copy, expand, and line number features.
component: true
---
<ComponentPreview name="code-snippet-demo" />
## Installation
<Tabs defaultValue="cli">
<TabsList>
<TabsTrigger value="cli">CLI</TabsTrigger>
<TabsTrigger value="manual">Manual</TabsTrigger>
</TabsList>
<TabsContent value="cli">
<Steps>
<Step>Run the following command:</Step>
```bash
npx @hanzo/ui@latest add code-snippet
```
</Steps>
</TabsContent>
<TabsContent value="manual">
<Steps>
<Step>Copy and paste the following code into your project</Step>
<ComponentSource name="code-snippet" />
<Step>Update the import paths to match your project setup</Step>
</Steps>
</TabsContent>
</Tabs>
## Usage
```tsx
import { CodeSnippet } from "@/registry/default/ui/code-snippet"
export default function Example() {
return (
<CodeSnippet
code={`function hello() {\n console.log("Hello, world!");\n}`}
language="javascript"
filename="hello.js"
/>
)
}
```
## Examples
### Default
<ComponentPreview name="code-snippet-demo" />
## API
Documentation coming soon.
## Features
- Built with Radix UI and Tailwind CSS
- Fully accessible and keyboard navigable
- Customizable styling with CSS variables
- TypeScript support
## Notes
For more examples and advanced usage, see the [examples](/examples).