Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/wix-incubator/mjml-react

React component library to generate the HTML emails on the fly
https://github.com/wix-incubator/mjml-react

email email-marketing email-templates html mjml node react

Last synced: 1 day ago
JSON representation

React component library to generate the HTML emails on the fly

Awesome Lists containing this project

README

        

# mjml-react · [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/wix-incubator/mjml-react/blob/master/LICENSE) npm version [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/wix-incubator/mjml-react/pulls)

---

## NOTICE: This project is no longer maintained. :warning:

This project is no longer maintained. There will be no more new features, fixes and releases. Feel free to fork this repository, use different build system and release this project under different name.

Known forks:

* [Faire mjml-react fork](https://github.com/Faire/mjml-react)

---

·

There is an awesome library [mjml](https://mjml.io/) with github repo here [https://github.com/mjmlio/mjml](https://github.com/mjmlio/mjml).

`MJML` is a markup language created by [Mailjet](https://www.mailjet.com/).
So in order to create emails on the fly we created a library with `React` components.

## How it works

Install the required dependencies first:

```bash
npm install react react-dom mjml mjml-react
```

And afterwards write a code like a pro:

```js
import {
render,
Mjml,
MjmlHead,
MjmlTitle,
MjmlPreview,
MjmlBody,
MjmlSection,
MjmlColumn,
MjmlButton,
MjmlImage,
} from "mjml-react";

const { html, errors } = render(


Last Minute Offer
Last Minute Offer...










I like it!




,
{ validationLevel: "soft" }
);
```

And as the result you will get a nice looking email HTML (works in mobile too!)

![preview](https://user-images.githubusercontent.com/10008149/41058394-59b8ce9e-69d2-11e8-9eb9-c294f35bae9f.png)

## Options

mjml-react sets the following MJML options when rendering to HTML:

```js
{
keepComments: false,
beautify: false,
minify: true,
validationLevel: 'strict'
}
```

If you want to override these, you can pass an object to `render` as a second argument. See the [MJML docs](https://documentation.mjml.io/#inside-node-js) for the full list of options you can set.

## Extensions

```js
import {
MjmlHtml,
MjmlComment,
MjmlConditionalComment
} from 'mjml-react/extensions';

Built with ... at ...
//

MSO conditionals
//

MSO conditionals
//

//

Hello World!

```

## Utils

We do have also some utils for post processing the output HTML.
Because not all mail clients do support named HTML entities, like `'`.
So we need to replace them to hex.

```js
import { namedEntityToHexCode, fixConditionalComment } from "mjml-react/utils";

const html = "

'
";
namedEntityToHexCode(html);
//
'

fixConditionalComment(
"",
"Hello",
"if IE"
);
//
```

## Limitations

Currently `mjml` and `mjml-react` libraries are meant to be run inside a node.

## Example project

You can find an example project here
[https://github.com/wix-incubator/mjml-react-example](https://github.com/wix-incubator/mjml-react-example)