docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10
Build a component library system that bundles custom email components together for reuse across different email templates. The system should allow loading different component libraries when compiling templates.
Create two component libraries:
Brand Library: Contains brand-specific components
mj-brand-button: A styled button component with brand colorsmj-brand-header: A header component with brand stylingAlert Library: Contains notification components
mj-alert-box: An alert/notification box componentmj-alert-button: A button styled for alertsEach component should:
color, background-color, padding)Define which standard MJML components can be used inside your custom components. For example, a button component might allow mj-text as a child, or a header might allow mj-image and mj-text.
Create a function compileWithLibrary(mjmlTemplate, libraryName) that:
Input:
const template = `
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-brand-header>Welcome to Our Service</mj-brand-header>
<mj-brand-button href="https://example.com">Get Started</mj-brand-button>
</mj-column>
</mj-section>
</mj-body>
</mjml>
`
const result = compileWithLibrary(template, "brand")Expected Output:
Input:
const template = `
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-alert-box>Your password will expire soon</mj-alert-box>
<mj-alert-button href="https://example.com/reset">Update Password</mj-alert-button>
</mj-column>
</mj-section>
</mj-body>
</mjml>
`
const result = compileWithLibrary(template, "alert")Expected Output:
Input:
// Compile with brand library
const brandTemplate = `
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-brand-button>Brand Button</mj-brand-button>
</mj-column>
</mj-section>
</mj-body>
</mjml>
`
const brandResult = compileWithLibrary(brandTemplate, "brand")
// Then compile with alert library
const alertTemplate = `
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-alert-button>Alert Button</mj-alert-button>
</mj-column>
</mj-section>
</mj-body>
</mjml>
`
const alertResult = compileWithLibrary(alertTemplate, "alert")Expected Behavior:
src/
├── index.js # Main entry with compileWithLibrary function
├── libraries/
│ ├── brandLibrary.js # Brand component library definition
│ └── alertLibrary.js # Alert component library definition
└── components/
├── brand/
│ ├── BrandButton.js # mj-brand-button component
│ └── BrandHeader.js # mj-brand-header component
└── alert/
├── AlertBox.js # mj-alert-box component
└── AlertButton.js # mj-alert-button component
test/
└── index.test.js # Test file with all test casesEmail framework for creating responsive email templates. Use this to compile MJML templates to HTML and create custom components.