Code Block
<mcp-code-block>Code block component with copy button and optional line numbers. Optimized for AI chat interfaces.
AIWeb Component
Overview
Code block component with copy button and optional line numbers. Optimized for AI chat interfaces.
Preview
Preview
Loading components...
Import
javascript
// Import all components (recommended)
import '@mcpsystem/ui';
// Or import the class for TypeScript
import { McpCodeBlock } from '@mcpsystem/ui';Basic Usage
html
<mcp-code-block language="javascript">
const greeting = "Hello, World!";
</mcp-code-block>API Reference
Properties(4)
| Property | Attribute | Type |
|---|---|---|
language | language | string |
filename | filename | string |
showLineNumbers | show-line-numbers | boolean |
code | code | string |
Slots(1)
| Slot | Description |
|---|---|
(default) | Code content (plain text) |
Events(1)
| Event | Detail |
|---|---|
mcp-copy | { code: string } |
CSS Parts(5)
Style internal elements using ::part() selector.
| Part | Description |
|---|---|
::part(container) | The outer container |
::part(header) | The header with language/filename |
::part(code) | The code element |
::part(copy-button) | The copy button |
::part(line-numbers) | The line numbers gutter |
CSS Custom Properties(6)
Customize appearance by setting these CSS variables.
| Property | Description |
|---|---|
--mcp-code-bg | Code block background |
--mcp-code-fg | Code text color |
--mcp-code-header-bg | Header background |
--mcp-code-font | Code font family |
--mcp-code-font-size | Code font size |
--mcp-code-radius | Border radius |
Examples
Basic Usage
Preview
Loading components...
html
<mcp-code-block language="javascript">
const greeting = "Hello, World!";
</mcp-code-block>With Line Numbers
Preview
Loading components...
html
<mcp-code-block language="python" show-line-numbers>
return "Hello, World!"
</mcp-code-block>