CodeBlock
ProCodeBlock highlights a single code snippet with a light/dark-aware theme, filename header, and copy button.
clamp.ts
export function clamp(value: number, min: number, max: number): number {
return Math.min(Math.max(value, min), max)
}Installation
Add this component with the NateUI CLI.
Examples
Without Filename
Line Numbers
Multiple Languages
API
CodeBlock
| Prop | Description | Type | Default |
|---|---|---|---|
code | The source code to highlight. | string | — |
language | Shiki language id used for highlighting. | string | — |
filename | Optional filename shown in a header row above the code. | string | — |
showLineNumbers | Print a line number beside each row. | boolean | false |
...divProps | Standard <div> attributes forwarded to the root. | ComponentProps<'div'> | — |