Custom tabs

Extending

Custom 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:

tsxStudio.tsx
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#

PropertyControlsDefault
kind: blockOne block of any type, with the values you give ittype, values
kind: htmlA snippet of HTML in an HTML blockhtml
kind: rowA row of up to three columns, each with its blockscolumns, 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.

tstab.ts
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#

tsplugins.ts
// At any time, on the editor you already have (Unlayer registerTab style)
unlayer.registerTab(brandTab);

The tab object#

PropTypeDefaultDescription
idstring-Unique. A tab without an id, a label or anything to show is left out.
labelstring-The name on the rail and at the top of the panel.
iconstring-A built-in icon name, or an https:// or data:image address. Anything else is ignored.
hintstring-The line under the panel's title.
buildersstring[]-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.
In a read-only editor (the viewer role) the cards are shown but cannot add anything.