Code Block
A component for displaying code snippets with syntax highlighting and copy functionality.
In this guide, you'll learn how to use the Code Block component.
curl 'http://localhost:9000/store/products/PRODUCT_ID'-H 'x-publishable-key: YOUR_API_KEY'
Usage#
API Reference#
CodeBlock#
This component is based on the div
element and supports all of its props
Prop | Type | Default |
---|---|---|
snippets | CodeSnippet[] | - |
CodeBlock.Header#
This component is based on the div
element and supports all of its props
Prop | Type | Default |
---|---|---|
hideLabels | boolean | false |
CodeBlock.Header.Meta#
This component is based on the div
element and supports all of its props
CodeBlock.Body#
This component is based on the div
element and supports all of its props
Usage Outside Medusa Admin#
If you're using the CodeBlock
component in a project other than the Medusa Admin, make sure to include the TooltipProvider
somewhere up in your component tree, as the CodeBlock.Header
component uses a Tooltip:
Examples#
Single Snippet#
If you want to only show a code sample for one language or API, you can choose to hide the snippet labels:
1console.log("Hello, World!")
No Header#
You can also omit the header entirely:
1console.log("Hello, World!")
No Line Numbers#
console.log("Hello, ")console.log("World!")
No Copy Button#
1console.log("Hello, World!")