1.2.2 • Published 2 years ago

mjml-bullet-list v1.2.2

Weekly downloads
-
License
AGPL-3.0-or-later
Repository
github
Last release
2 years ago

npm GitHub release (latest SemVer) Release Date MJML 4.0+ valid License: AGPL-3.0+ Pull Requests welcome


This MJML component is brought to you by Premail, and the following documentation can also be found at https://premail.dev/docs/components/mjml-bullet-list


<ul> and <li> HTML elements can be used in HTML emails, but getting them to render consistently takes a little work. This is a shortcut for these elements. Its output is predictably boring, but bulletproof (forgive the pun) for email clients:

Example of simple generated markup from the MJML Bullet List component

<mj-list> replaces <ul>. Use it alongside <mj-text> within <mj-column>.

<mj-li> replaces <li>. Use it inside <mj-list></mj-list>.

MJML Bullet List is designed for MJML 4+ and is unrelated to the v3 component mjml-list.


Usage

Coding

This MJML:

<mj-list>
  <mj-li>List item one.</mj-li>
  <mj-li>List item two.</mj-li>
  <mj-li>List item three.</mj-li>
  <mj-li>List item four.</mj-li>
</mj-list>

Will produce the following visual representation:

Example of simple generated markup from the MJML Bullet List component

Not very exciting, but reliably rendered in all email clients.

But you can get more creative. This MJML:

<mj-text>
  <p>
    Examples of the custom "mj-list" and "mj-li" tags. Here is a list with an
    option set on the entire list:
  </p>
</mj-text>
<mj-list background-color="#ddd">
  <mj-li>List item one.</mj-li>
  <mj-li>List item two.</mj-li>
  <mj-li>List item three.</mj-li>
  <mj-li>List item four.</mj-li>
</mj-list>
<mj-text>
  <p>And here's a list with options set on individual list items:</p>
</mj-text>
<mj-list>
  <mj-li
    >List item one. Lorem ipsum dolor sit amet, sed do eiusmod tempor incididunt
    ut labore et dolore magna aliqua.</mj-li
  >
  <mj-li color="blue"
    >List item two, customized color for the entire list item.</mj-li
  >
  <mj-li>List item three.</mj-li>
  <mj-li bullet-color="red" padding-left="40px"
    >List item four, customized bullet color and left padding. Duis aute irure
    dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
    pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
    officia deserunt mollit anim id est laborum.</mj-li
  >
  <mj-li gutter="20px">List item five, custom gutter size.</mj-li>
  <mj-li>List item six.</mj-li>
  <mj-li text-color="green"
    >List item seven, customized text (only) color. Ut enim ad minim veniam,
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
    consequat.</mj-li
  >
</mj-list>

Will produce the following visual representation:

Example of advanced generated markup from the MJML Bullet List component

MJML Head

In your <mj-head> component, you should also add the following:

<mj-html-attributes>
  <mj-selector path=".list table table">
    <mj-html-attribute name="role">list</mj-html-attribute>
  </mj-selector>
  <mj-selector path=".list table table > tbody">
    <mj-html-attribute name="role">presentation</mj-html-attribute>
  </mj-selector>
</mj-html-attributes>

This will ensure that these lists are properly described as such when the email is read using assistive technology.

Styling

In addition to setting attributes with the elements options (see below), you can also modify them through CSS. Use <mj-style> and target the .list and .list-item classes.

You can see this being done in the example MJML file.

Options

Available options for <mj-list>

optionunitdetailsdefault value
background-colorcolorApplies to entire listnone
borderstring (border)Applies to entire listnone
border-topstring (border)Applies to entire listnone
border-rightstring (border)Applies to entire listnone
border-bottomstring (border)Applies to entire listnone
border-leftstring (border)Applies to entire listnone
border-radiuspixelsApplies to entire listnone
directionltr, rtlLanguage directionltr
inner-background-colorcolorApplies to entire listnone
paddingpixelsApplies to entire listnone
padding-toppixelsApplies to entire listnone
padding-rightpixelsApplies to entire listnone
padding-bottompixelsApplies to entire listnone
padding-leftpixelsApplies to entire list25px (note that if you set this to 0, the bullet icons in the list may overflow their container)
vertical-aligntop, middle, bottomApplies to entire listtop
widthpixelsApplies to entire listnone (full width of container)

Available options for <mj-li>

optionunitdetailsdefault value
colorcolorApplies to both bullet marker and textnone (inherited from parent text style)
bullet-colorcolorApplies to bullet marker onlynone (inherited from color)
text-colorcolorApplies to text onlynone (inherited from color)
background-colorcolorApplies to list itemnone
font-familystringApplies to list itemUbuntu, Helvetica, Arial, sans-serif (from <mj-text>)
font-sizepixelsApplies to list item13px (from <mj-text>)
font-stylestringApplies to list itemnone
font-weightstringApplies to list itemnone
gutterpixelsDistance between bullet marker and text3px
letter-spacingpixels (negative allowed)Applies to list itemnone
line-heightnumber, pixels or percentageApplies to list itemnone
padding-rightpixelsApplies to list itemnone
padding-leftpixelsApplies to list itemnone
text-alignleft, center, right, justifyApplies to list itemleft
text-decorationstringApplies to list itemnone
text-transformstringApplies to list itemnone
vertical-aligntop, middle, bottomApplies to list itemtop

Adding this to your emails

In your MJML project directory, install this package via npm:

npm install mjml-bullet-list

In your build process script (such as gulp), require the package:

const mjmlBulletList = require('mjml-bullet-list')

or

import mjmlBulletList from mjml-bullet-list

Finally, add the package to your .mjmlconfig:

{
  "packages": ["mjml-bullet-list/lib/MjList", "mjml-bullet-list/lib/MjLi"]
}

You can now use <mj-list> and <mj-li> in your MJML emails.

Fork or contribute to this component

If you want to edit this component, first grab it via git:

git clone https://github.com/premail/mjml-bullet-list.git

Navigate to the folder and install:

cd mjml-bullet-list
npm install

Edit the component script file in ./components/, then run gulp build or gulp watch to compile. We include sheerun/modern-node, which formats and lints code automatically on commits using Prettier and ESLint. You can use npm run format and npm run lint on their own as well.

To run tests, use npm run test

If you want to use a forked version of this component in your emails without having to publish it to npm, see premail/mjml-custom-component for a guide.

Security

Legalese: This component is provided "as is" without any warranty. Use at your own risk.

For more information and to report security issues, please refer to our security documentation.

License

mjml-bullet-list is licensed under the GNU Affero General Public License v3.0 or later. To be clear: This license only covers the component's code, not any content you generate using it.

For the legal details of the AGPL, see the complete LICENSE.

1.2.0

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.1.7

2 years ago

1.1.1

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago