Created
October 13, 2023 05:12
-
-
Save bobylito/c006fd53daaccb7ea719e0531fe66e59 to your computer and use it in GitHub Desktop.
React-email (resend) component in a StoryBook story
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { render } from "@react-email/render"; | |
import type { Meta, StoryFn } from "@storybook/react"; | |
import Email from "./email"; | |
const meta: Meta<typeof Email> = { | |
title: "components/Email", | |
component: Email, | |
parameters: { | |
layout: "fullscreen", | |
}, | |
argTypes: {}, | |
}; | |
export default meta; | |
// Uses a storybook function to control the rendering | |
export const Email: StoryFn<typeof Email> = (props) => { | |
// Rendering is done using react-email render function | |
const doc = render(<Email {...props} />); | |
return ( | |
<iframe | |
// the rendered email is provided to an iframe like in the preview app from Resend | |
srcDoc={doc} | |
style={{ border: "0px", width: "100%", height: "100%" }} | |
></iframe> | |
); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Import this file in .storybook/preview.ts */ | |
/* This allows full height components / pages / emails */ | |
html, | |
#storybook-root, | |
body { | |
height: 100%; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment