Components
Document model
The serialisable NewsletterDocument, block types, themes and factory helpers.
NewsletterDocument
A document is JSON. Nothing in it is a function, class instance or DOM node, so it round-trips through JSON.stringify and any database.
interface NewsletterDocument {
version: 1
subject: string // merge tags allowed
preheader: string // inbox preview text
theme: NewsletterTheme
blocks: NewsletterBlock[]
}Block types
Blocks are a discriminated union on type. columns is the only container and can only live at the root; its cells hold leaf blocks.
Blocks
- Fields:
text,level(1-3),align, optionalcolor. Renders a real<h1>-<h3>. - Fields:
html(sanitised inline HTML),align,fontSize. Allowed tags:b,strong,i,em,u,a,br. - Fields:
src,alt,widthPercent,align,href. The linter flags missing alt text anddata:sources. - Fields:
thickness,style(solid, dashed, dotted),widthPercent. - Field:
heightin pixels. - Two to four cells with
widthPercentandblocks, agap, andstackOnMobile.
Theme
NewsletterTheme
- Body font. One of
system,helvetica,verdana,trebuchet,tahoma,georgia,palatino,times,courier. - Heading font.
- Width of the content column in pixels (480-720).
- Default text size in pixels.
- Corner radius of the content container.
- Light palette. Written inline on every element.
- Dark palette. Only emitted inside dark-mode rules.
Factories and tree helpers
import {
createBlankDocument,
createWelcomeTemplate,
createProductUpdateTemplate,
createBlock,
createColumns,
insertBlock,
} from 'newsletter-builder-react'
const doc = createBlankDocument()
const withButton = {
...doc,
blocks: insertBlock(doc.blocks, createBlock('button'), { parentId: null, index: 0 }),
}