Code
The
Code
component displays a block of code in the specified language.Basic usage
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
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
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
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.