Skip to content

Instantly share code, notes, and snippets.

@bobylito
Created October 13, 2023 05:12
Show Gist options
  • Save bobylito/c006fd53daaccb7ea719e0531fe66e59 to your computer and use it in GitHub Desktop.
Save bobylito/c006fd53daaccb7ea719e0531fe66e59 to your computer and use it in GitHub Desktop.
React-email (resend) component in a StoryBook story
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>
);
};
/* 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