Custom tabs
ExtendingCustom tabs
Add your own tab to the editor, next to Content, Blocks and Body. Fill it with cards: click one and your block, snippet or row lands on the canvas. Brand kits, legal footers, approved layouts, product pickers.
The short way#
Give the editor a tabs list. Each tab has sections, each section has cards:
import EmailEditor from "react-email-craft";
const brandTab = {
id: "brand", label: "Brand kit", icon: "palette",
sections: [{
title: "Approved pieces",
items: [
{ id: "legal", label: "Legal footer", hint: "Always include",
insert: { kind: "html", html: "<p>Registered office, Mumbai</p>" } },
{ id: "apply", label: "Apply button",
insert: { kind: "block", type: "button", values: { label: "Apply now" } } },
{ id: "split", label: "Image and text",
insert: { kind: "row", columns: [[{ type: "image" }], [{ type: "heading", values: { text: "Hello" } }]] } }
]
}]
};
<EmailEditor token={token} tabs={[brandTab]} />A card puts its block in the selected column, or as a new row when no column is selected. That is all: no code runs in the editor, so the same tab works in the hosted iframe editor too.
What a card can add#
| Property | Controls | Default |
|---|---|---|
kind: block | One block of any type, with the values you give it | type, values |
kind: html | A snippet of HTML in an HTML block | html |
kind: row | A row of up to three columns, each with its blocks | columns, layout |
Draw the tab yourself#
For anything a card cannot do (a search box, your own product list), use render. It gets a plain element to draw into and a small API, so any UI library works. Return a function to clean up when the tab closes.
const productTab = {
id: "products", label: "Products",
render: (host, api) => {
const button = document.createElement("button");
button.textContent = "Add trail runners";
button.onclick = () => api.insertHtml("<p>Trail Runners, $120</p>");
host.appendChild(button);
return () => button.remove();
}
};The API has insertBlock(type, values), insertHtml(html), insertRow(row) and getDesign(). render is a function, so it cannot cross the hosted iframe: there, use cards.
Other ways to add a tab#
// At any time, on the editor you already have (Unlayer registerTab style)
unlayer.registerTab(brandTab);The tab object#
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | - | Unique. A tab without an id, a label or anything to show is left out. |
label | string | - | The name on the rail and at the top of the panel. |
icon | string | - | A built-in icon name, or an https:// or data:image address. Anything else is ignored. |
hint | string | - | The line under the panel's title. |
builders | string[] | - | Only show the tab in these builders (email, page, document, popup). Default: all. |
sections | { title?, items[] }[] | - | The cards. Each item has id, label, an optional hint and thumbnail (https or data:image), and insert. |
render | (host, api) => void | cleanup | - | Draw the tab yourself instead of using sections. |