Code
The
Code
component displays a block of code in the specified language.Basic usage
tsxCopied1const code = dedent(`2export default async function (params) {3console.log("parameters:", params);4return [5{ element: "hydrogen", weight: 1.008 },6{ element: "helium", weight: 4.0026 },7];8}`);9return <Code language="typescript">{code}</Code>;
Supported languages
The
Code
component supports the following languages:- markup
- bash
- clike
- c
- cpp
- css
- css-extras
- javascript
- jsx
- js-extras
- js-templates
- coffeescript
- diff
- git
- go
- graphql
- markup-templating
- handlebars
- json
- less
- makefile
- markdown
- objectivec
- ocaml
- python
- reason
- sass
- scss
- sql
- mysql
- pgsql
- stylus
- tsx
- typescript
- wasm
- yaml
Line numbers
Set
withLineNumbers
to display line numbers.tsxCopied1const code = dedent(`2export default async function (params) {3console.log("parameters:", params);4return [5{ element: "hydrogen", weight: 1.008 },6{ element: "helium", weight: 4.0026 },7];8}`);9return (10<Code language="typescript" withLineNumbers>11{code}12</Code>13);
Component API
children
REQUIRED
The code content.
copy
optional
default: true
If true, a button will be rendered to copy code to clipboard.
copyLabel
optional
default: "Copy code"
Copy button label.
grow
optional
If true, the element will grow to fill available space.
This prop works only if the element is a direct child of a Stack.
height
optional
default: auto
language
REQUIRED
The code language.
radius
optional
Border radius of the code block.
theme
optional
default: light
Theme of the code.
width
optional
default: auto
withLineNumbers
optional
default: false
Whether to render line numbers.