A React-based email template editor component that allows users to create and customize email templates through a visual interface. This component can be embedded in any React application.
- Visual email template builder
- Rich set of components (text, buttons, images, dividers, containers, columns, etc.)
- Markdown support for text editing
- Responsive email templates
- Embeddable into React applications
npm install @kontakto/email-template-editorYou can easily embed the EmailEditor into any React application:
import { EmailEditor } from '@kontakto/email-template-editor';
function MyApp() {
return (
<div className="my-container">
<EmailEditor
persistenceEnabled={true}
minHeight="80vh"
/>
</div>
);
}| Prop | Type | Default | Description |
|---|---|---|---|
minHeight |
string | '100vh' | Sets the minimum height of the editor container |
persistenceEnabled |
boolean | false | When true, enables save functionality and shows save buttons. Requires callbacks for persistence operations. |
samplesDrawerEnabled |
boolean | true | Controls whether the templates/samples drawer is shown |
drawerEnterDuration |
number | 225 | Duration for drawer enter transition (ms) |
drawerExitDuration |
number | 225 | Duration for drawer exit transition (ms) |
initialTemplate |
object | - | Initial template to load when editor first mounts |
initialTemplateId |
string | - | ID of the initial template |
initialTemplateName |
string | - | Name of the initial template |
onSave |
function | - | Callback when template is saved: (template) => void |
onChange |
function | - | Callback when template changes: (template) => void |
loadSamples |
function | - | Loads sample templates: () => Promise<SampleTemplate[]> |
loadTemplates |
function | - | Loads user templates: () => Promise<SampleTemplate[]> |
loadTemplate |
function | - | Loads specific template: (id) => Promise<Template> |
deleteTemplate |
function | - | Deletes a template: (id) => void |
copyTemplate |
function | - | Copies a template: (name, content) => void |
saveAs |
function | - | Saves template with new name: (name, content) => Promise<{id, name}> |
theme |
object | theme.ts | Custom theme for the EmailEditor, must be a Material UI theme object |
You can access the EmailEditor's methods using a ref:
import { EmailEditor } from 'kontakto-email-editor';
import { useRef } from 'react';
function MyApp() {
const editorRef = useRef(null);
const handleSave = () => {
const template = editorRef.current.saveTemplate();
console.log('Saved template:', template);
};
const handleLoad = (template) => {
editorRef.current.loadTemplate(template);
};
const handleGetCurrent = () => {
const current = editorRef.current.getTemplate();
console.log('Current template:', current);
};
return (
<div>
<button onClick={handleSave}>Save</button>
<button onClick={handleGetCurrent}>Get Current</button>
<EmailEditor ref={editorRef} minHeight="600px" />
</div>
);
}This project includes a standalone version that can be run using Vite:
# Install dependencies
npm install
# Run the development server
npm run devThis will start a development server with the EmailEditor running as a standalone application that uses browsers local storage to save and load templates.
The EmailEditor component has the CssBaseline and ThemeProvider components from Material UI applied by default. However, if you need to supply a custom theme, you can do so by passing a custom theme to the EmailEditor component. The theme should be a Material UI theme object.
To run this locally:
- Clone the repository
- Install dependencies:
npm install - Start the development server:
npm run dev - Visit http://localhost:5173/ in your browser
src/blocks/- Email components (text, images, buttons, etc.)src/editor/- Core editor functionalitysrc/app/- Main application componentssrc/email-builder/- Email template renderingsrc/core/- Core utilities and types
- React
- TypeScript
- Material UI
- Zustand for state management
- Vite as the build tool
- Marked and Highlight.js for markdown and code highlighting
Licensed under the MIT License. See LICENSE for details.
This project, Email-Template-Editor, is a substantial derivative work based on an original MIT-licensed project, email-builder-js by Waypoint (Metaccountant, Inc.). email-builder-js is a free and open-source block-based email template builder designed for developers to create emails with JSON or HTML output. While the original code was created by Waypoint, this project has been significantly refactored with:
- Restructuring of the project files and directories.
- Implementation of how external context is handled.
- Changes to the purpose of the project to be integrated and embedded into other React based projects.
The following parts (not limited to) of this project are derived from the original MIT-licensed project email-builder-js by Waypoint:
- The parsing logic is based on Waypoint's original block-based parsing approach
- The concepts for the blocks
- The concepts for the editor
- The concepts of the builder
This project gratefully acknowledges the original work by Waypoint (Metaccountant, Inc.) on email-builder-js as the foundation upon which this version was built.