ChatCodeBlock API
API reference docs for the React ChatCodeBlock component. Learn about the props, CSS, and other APIs of this exported module.
Demos
Import
import { ChatCodeBlock } from '@mui/x-chat/ChatCodeBlock';
// or
import { ChatCodeBlock } from '@mui/x-chat';Learn about the difference by reading this guide on minimizing bundle size.
Props of the native component are also available.
| Name | Type | Description |
|---|---|---|
| children* | string | The code string to display. |
| highlighter | func | Optional syntax highlighter. Receives the code string and a language identifier, and should return highlighted React nodes. When omitted, raw code is displayed. Signature: function(code: string, language: string) => React.ReactNode
|
| language | string | Language identifier shown in the header (e.g. "typescript", "python"). |
These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.
| Class name | Rule name | Description |
|---|---|---|
| .MuiChatCodeBlock-code | code | Styles applied to the code element. |
| .MuiChatCodeBlock-copyButton | copyButton | Styles applied to the copy button element. |
| .MuiChatCodeBlock-header | header | Styles applied to the header element. |
| .MuiChatCodeBlock-languageLabel | languageLabel | Styles applied to the language label element. |
| .MuiChatCodeBlock-pre | pre | Styles applied to the pre element. |
| .MuiChatCodeBlock-root | root | Styles applied to the root element. |
You can override the style of the component using one of these customization options:
- With a global class name.
- With a rule name as part of the component's
styleOverridesproperty in a custom theme.
Source code
If you did not find the information in this page, consider having a look at the implementation of the component for more detail.