Code

import Code from 'frui/dist/formats/Code';
Copy

Props

NameTypeRequiredNotes
childrenstringYesGet code from children
languagestringYesSet programming language
copybooleanNoShow copy button
copyFunctionfunctionNoAdditional behavior for copy button
classNamestringNoAdditional classes to the code block
inlinebooleanNoInline code block
numbersbooleanNoShow line numbers
syntaxStyleReact ObjectNoCustom syntax style
quotebooleanNoWrap inline code block in quotes

Basics

print("Hello, world!")
<Code language="python">
  print("Hello, world!")
</Code>
Copy

Defining a code block requires passing a  language  prop to the component.

 attributes: [Object object] 
<Code>{`attributes: [Object object]`}</Code>
Copy

Not supplying a  language  prop will instead create an inline component.

Customize

You can use different languages for a code block.

Line Numbers

Line numbers can be added to a code block by passing the  numbers  prop.

console.log("Hello, world!");
<Code language="typescript" numbers>
  console.log("Hello, world!");
</Code>
Copy

Copy Button

A copy button can be added to a code block by passing the  copy  prop. To customize the behavior of the copy button, you can pass a function to the  onCopy  prop.

console.log("Hello, world!");
Copy
<Code language="typescript"
  copy onCopy={() => alert("Code copied!")}
>
  console.log("Hello, world!");
</Code>
Copy