Create Custom Tool & Property

Register a Custom Tool #

To integrate custom tools, utilize the customJS property. This property includes methods for registering tools and properties, such as registerTool and registerProperty.

Init Script #

mailui.init({ customJS: [ 'https://example.com/custom-tools.js' ] });

To add multiple custom tools, you can either use multiple customJS files or consolidate all tools into a single file for simplicity and ease of management.

Simple Example Script #

custom-tool.js
const { React, icons } = mailui; // or window.mailui mailui.registerTool({ name: "custom", label: "Custom Tool", icon: icons.IoRocketOutline, // or () => <span>🚀</span>, settings: { color: "#ff0", // "#8624E1", amp: false, badges: [{ label: "Pro" }], dropAccept: [] }, initialState: { content: "This is a Custom Tool" }, toolbar: [ { name: "group", label: "Custom Settings", isOpen: true, properties: [ { name: "input", label: "Custom Text", path: "content", formGroup: { className: "mb-6" }, responsive: false, showLabel: true, showDeviceSelectionMenu: true, }, { name: "range", label: "Font Size", path: "style.fontSize", formGroup: { className: "mb-6" }, min: 0, max: 20, unit: "px", responsive: true, showLabel: true, showDeviceSelectionMenu: true, }, { name: "color", label: "Text Color", path: "style.color", formGroup: {}, responsive: true, showLabel: true, showDeviceSelectionMenu: true, } ] } ], Edit: ({ state, children, attributes, styleElement }) => { return ( <div> {styleElement} <h4 {...attributes} style={{ ...attributes.style }}> {state?.content} </h4> </div> ); }, View: ({ state, children, attributes }) => { return ( <div> <h4 {...attributes} style={{ ...attributes.style }}> {state?.content} </h4> </div> ); }, });

Configuration Options #

Certain configuration settings are needed to effectively use custom tools. The necessary options are outlined below.
OptionRequiredDescriptionType
nameYesUnique name for your toolstring
labelYesThis is the label that users will see in the tools panel.string
iconYes
The icon property can accept a React element (e.g., CustomIcon), an inline component (e.g., () => <div>Icon</div>), or a `react-icons/io5`component (e.g., IoRocketOutline)
ReactElement
settingsNo
Settings contains tool customization options, like: color, amp, badges, dropAccept
Settings Options
object
initialStateNo
This is an object that defines the default values for this tool.
object
toolbaryes
Toolbar is a array of properties and custom propertiesToolbar Options
array
Edityes
Component for editing the tool, allowing changes to state and appearance.Edit API
Component
Viewyes
Component for viewing the tool, displaying its state and style.View API
Component

Settings Options #

OptionRequiredDescriptionType
colorNoThe primary color for the tool.string
ampNoA boolean flag indicating if AMP (Accelerated Mobile Pages) is enabled.string
badgesNoAn array of badges or labels to display (e.g., [{ label: "Pro", variant: 'warning' }])array
dropAcceptNo All available element tools and custom tools
dropAccept allow you to make nested drag structure
Available Tools
array

Edit / View API #

PropDescriptionType
stateEntire object of this selected toolobject
attributesAll HTML data attrsobject
styleElementThe styleElement is an HTML <style> element used for embedding CSS styles.object
childrenReact native children props { children }
This allow you to make nested drag structure
ReactNode

Register Custom Property #

custom-tool.js
... mailui.registerProperty({ name: "custom_property", // unique type name View: ({ value, state, setState, label }) => { return ( <div> <label>{label}</label> <textarea className="w-full" value={value} onChange={(event) => setState(event.target.value)} rows="10" /> </div> ); } });

Configuration Options #

Certain configuration settings are needed to effectively use custom property. The necessary options are outlined below.
OptionRequiredDescriptionType
nameYesUnique name for your propertystring
ViewYes
Component for view the property, allowing changes to state and appearance.
Component

View API #

PropDescriptionType
labelUser provided labelstring
valueUser provided valueany
stateEntire object of this selected toolobject
setValuePass every time the value is changedevent
setStateThe entire state can be updated with full flexibility using setState. A specific state property can be updated by passing an object structured as {path: '', value: ''}. Multiple state properties can be updated simultaneously by passing an array of such objects.

[ {path: '', value: ''}, {path: '', value: ''} ]

This approach ensures that state updates are managed efficiently and concisely.
event
[...]You can access other API's provided with the toolbar.

Explore Our Email Builder