mirror of
https://github.com/hanzoai/shadcn.git
synced 2026-10-30 18:22:59 +00:00
- 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
28 lines
631 B
TypeScript
28 lines
631 B
TypeScript
"use client"
|
|
|
|
import { CodeSnippet } from "@/registry/default/ui/code-snippet"
|
|
|
|
const exampleCode = `function fibonacci(n: number): number {
|
|
if (n <= 1) return n;
|
|
return fibonacci(n - 1) + fibonacci(n - 2);
|
|
}
|
|
|
|
// Calculate the 10th Fibonacci number
|
|
const result = fibonacci(10);
|
|
console.log(\`Fibonacci(10) = \${result}\`);`
|
|
|
|
export default function CodeSnippetDemo() {
|
|
return (
|
|
<div className="w-full space-y-6">
|
|
<CodeSnippet
|
|
code={exampleCode}
|
|
language="typescript"
|
|
filename="fibonacci.ts"
|
|
showLineNumbers
|
|
showCopyButton
|
|
showLanguageBadge
|
|
/>
|
|
</div>
|
|
)
|
|
}
|