Skip to content

Commit

Permalink
add component preview to the code block
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmfern committed Oct 14, 2024
1 parent 4f95efe commit 19b9a49
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion apps/docs/components/code-block.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ icon: 'file-lines'
---

import Support from '/snippets/support.mdx'
import { ComponentPreview } from '/snippets/component-preview.mdx'

## Install

Expand Down Expand Up @@ -43,8 +44,31 @@ pnpm add @react-email/code-block -E

Add the component into your email component as follows.

<ComponentPreview code='
import { CodeBlock, dracula } from "@react-email/components";
const Email = () => {
const code = `export default async (req, res) => {
try {
const html = await renderAsync(
EmailTemplate({ firstName: "John" })
);
return NextResponse.json({ html });
} catch (error) {
return NextResponse.json({ error });
}
}`;
return (<CodeBlock
code={code}
lineNumbers // add this so that there are line numbers beside each code line
theme={{ ...dracula, base: { ...dracula.base, margin: 0 } }}
language="javascript"
/>);
};
'>
```jsx
import { CodeBlock, dracula } from '@react-email/code-block';
import { CodeBlock, dracula } from "@react-email/components";

const Email = () => {
const code = `export default async (req, res) => {
Expand All @@ -66,6 +90,7 @@ const Email = () => {
/>);
};
```
</ComponentPreview>

This should render a code-block with the desired theme.

Expand Down

0 comments on commit 19b9a49

Please sign in to comment.