Carregando…
Carregando…
Carregando…Syntax-highlighted code block with filename tab, line numbers, copy button and scrollable maxHeight.
$ npx kikitocn add code-block| Prop | Tipo | Padrão | Descrição |
|---|---|---|---|
code* | string | — | Código a ser exibido |
lang | string | 'tsx' | Linguagem para syntax highlight (shiki) |
filename | string | — | Nome do arquivo exibido no topo |
showLineNumbers | boolean | false | Exibe numeração de linhas |
maxHeight | number | — | Altura máxima em px com scroll vertical |
lang=tsx · filename · showLineNumbers
| 1 | import { Button } from "@/components/ui/cn/button/Button"; |
| 2 | |
| 3 | export function Example() { |
| 4 | async function handleSave() { |
| 5 | await saveData(); |
| 6 | } |
| 7 | |
| 8 | return ( |
| 9 | <Button intent="primary" onClick={handleSave}> |
| 10 | Salvar |
| 11 | </Button> |
| 12 | ); |
| 13 | } |
lang=ts · sem filename · sem linha
const greet = (name: string): string => { |
return `Olá, ${name}!`; |
}; |
console.log(greet("Mundo")); |
maxHeight=120px
| 1 | import { Button } from "@/components/ui/cn/button/Button"; |
| 2 | |
| 3 | export function Example() { |
| 4 | async function handleSave() { |
| 5 | await saveData(); |
| 6 | } |
| 7 | |
| 8 | return ( |
| 9 | <Button intent="primary" onClick={handleSave}> |
| 10 | Salvar |
| 11 | </Button> |
| 12 | ); |
| 13 | } |
import { KkCodeBlock } from "@/components/ui/kk-code-block";
// KkCodeBlock é um Server Component — use em .tsx sem "use client"
export async function CodeBlockExample() {
return (
<div className="flex flex-col gap-6">
{/* Básico */}
<KkCodeBlock
code={`const greeting = "Olá, mundo!";
console.log(greeting);`}
lang="ts"
/>
{/* Com filename e numeração de linhas */}
<KkCodeBlock
code={`import { Button } from "@/components/ui/cn/button/Button";
export function Example() {
return <Button intent="primary">Clique aqui</Button>;
}`}
lang="tsx"
filename="Example.tsx"
showLineNumbers
/>
{/* Com altura máxima */}
<KkCodeBlock
code={`// arquivo longo com scroll
const a = 1;
const b = 2;
const c = a + b;`}
lang="ts"
filename="long-file.ts"
maxHeight={200}
/>
</div>
);
}