Skip to content

Commit

Permalink
Feat(email-components): ImageLink component
Browse files Browse the repository at this point in the history
  • Loading branch information
chadimaOndrej committed Nov 8, 2023
1 parent 87c9d02 commit 4c4f466
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 23 deletions.
1 change: 1 addition & 0 deletions packages/email-components/.mjmlconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"./dist/components/Content/Content.js",
"./dist/components/Header/Header.js",
"./dist/components/Heading/Heading.js",
"./dist/components/ImageLink/ImageLink.js",
"./dist/components/Link/Link.js",
"./dist/components/Rating/Rating.js",
"./dist/components/RatingItem/RatingItem.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
<tr>
<td>data-msys-linkname</td>
<td><code>string</code></td>
<td></td>
<td>no</td>
<td>-</td>
<td>Data analytics attribute</td>
</tr>
<tr>
Expand Down
19 changes: 10 additions & 9 deletions packages/email-components/src/components/Button/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ The `mjc-button` component is button for e-mail template.

## Available props

| Prop name | Type | Default | Required | Description |
| ---------------- | ------------------------- | --------- | -------- | --------------- |
| `align` | `left \| right \| center` | `left` | no | Button position |
| `color` | `primary \| secondary` | `primary` | yes | Button color |
| `href` | `string` | - | no | Link to url |
| `padding-bottom` | `unit(px,%)` | `32px` | no | Bottom spacing |
| `padding-top` | `unit(px,%)` | `32px` | no | Top spacing |
| `rel` | `string` | - | no | |
| `vertical-align` | `top \| bottom \| middle` | `middle` | no | Bottom position |
| Prop name | Type | Default | Required | Description |
| -------------------- | ------------------------- | --------- | -------- | ------------------------ |
| `align` | `left \| right \| center` | `left` | no | Button position |
| `color` | `primary \| secondary` | `primary` | yes | Button color |
| `data-msys-linkname` | `string` | - | no | Data analytics attribute |
| `href` | `string` | - | no | Link to url |
| `padding-bottom` | `unit(px,%)` | `32px` | no | Bottom spacing |
| `padding-top` | `unit(px,%)` | `32px` | no | Top spacing |
| `rel` | `string` | - | no | |
| `vertical-align` | `top \| bottom \| middle` | `middle` | no | Bottom position |
20 changes: 12 additions & 8 deletions packages/email-components/src/components/Header/Header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default class Header extends BodyComponent {

static allowedAttributes = {
alight: 'enum(left,right,center)',
'data-msys-linkname': 'string',
externalLink: 'string',
height: 'unit(px,%)',
imageAlt: 'string',
Expand All @@ -63,14 +64,17 @@ export default class Header extends BodyComponent {
return this.renderMJML(`
<mj-section padding="0">
<mj-column css-class="Header" padding="22px">
<mj-image
align="${this.align}"
alt="${this.imageAlt}"
height="${this.height}"
href="${this.externalLink}"
padding="0"
src="${this.imageUrl}"
width="${this.width}"
<mjc-image-link
${this.htmlAttributes({
align: this.align,
alt: this.imageAlt,
'data-msys-linkname': this.getAttribute('data-msys-linkname'),
height: this.height,
href: this.externalLink,
padding: 0,
src: this.imageUrl,
width: this.width,
})}
/>
</mj-column>
</mj-section>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<mjc-content>
<mj-column>
<mj-divider border-width="2px" border-color="#000000" />
<mj-text><strong>COMPONENT: ImageLink</strong> - mjc-image-link</mj-text>
<mjc-image-link
src="https://ijobs.cz/static/images/email/logo-jobs.png?1"
alt="jobs.cz logo"
href="https://jobs.cz"
data-msys-linkname="header"
/>
</mj-column>
</mjc-content>
78 changes: 78 additions & 0 deletions packages/email-components/src/components/ImageLink/ImageLink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { BodyComponent } from 'mjml-core';
const { registerDependencies } = require('mjml-validator');

registerDependencies({
'mj-wraper': ['mjc-image-link'],
'mj-section': ['mjc-image-link'],
'mj-column': ['mjc-image-link'],
'mjc-image-link': [''],
});

export default class ImageLink extends BodyComponent {
constructor(initialData = {}) {
super(initialData);
}

static componentName = 'mjc-image-link';
static endingTag = true;
static dependencies = {
'mj-column': ['mjc-image-link'],
'mj-section': ['mjc-image-link'],
'mj-wraper': ['mjc-image-link'],
'mjc-image-link': [],
};

static allowedAttributes = {
alt: 'string',
'data-msys-linkname': 'string',
href: 'string',
name: 'string',
src: 'string',
srcset: 'string',
sizes: 'string',
title: 'string',
rel: 'string',
align: 'enum(left,center,right)',
border: 'string',
'border-bottom': 'string',
'border-left': 'string',
'border-right': 'string',
'border-top': 'string',
'border-radius': 'unit(px,%){1,4}',
'container-background-color': 'color',
'fluid-on-mobile': 'boolean',
padding: 'unit(px,%){1,4}',
'padding-bottom': 'unit(px,%)',
'padding-left': 'unit(px,%)',
'padding-right': 'unit(px,%)',
'padding-top': 'unit(px,%)',
target: 'string',
width: 'unit(px)',
height: 'unit(px,auto)',
'max-height': 'unit(px,%)',
'font-size': 'unit(px)',
usemap: 'string',
};

render() {
const { href, rel, target, name, ['data-msys-linkname']: dataMsysLinkname, ...restAttributes } = this.attributes;

return `
<a
${this.htmlAttributes({
href,
target,
rel,
name,
'data-msys-linkname': dataMsysLinkname,
})}
>
${this.renderMJML(`
<mj-image
${this.htmlAttributes(restAttributes)}
/>
`)}
</a>
`;
}
}
22 changes: 22 additions & 0 deletions packages/email-components/src/components/ImageLink/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# IMAGELINK

The `mjc-image-link` is extend of the `mj-image` component and add some custom attributes.

```mjml
<mjc-image-link
src="https://ijobs.cz/static/images/email/logo-jobs.png?1"
alt="jobs.cz logo"
href="https://jobs.cz"
data-msys-linkname="header"
/>
```

## Available props

| Prop name | Type | Default | Required | Description |
| -------------------- | -------- | ------- | -------- | ------------------------ |
| `data-msys-linkname` | `string` | - | no | Data analytics attribute |

You can add all attributes as to `mj-image` component look at the [mj-image][image-doc] documentation in MJML README.

[image-doc]: https://documentation.mjml.io/#mj-image
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ export default class ResultCard extends BodyComponent {
<mjc-spacer />
${this.generateSubtitle()}
<mjc-link
data-msys-linkname="${this.getAttribute('data-msys-linkname')}"
href="${this.link}"
size="large"
underline="none"
${this.htmlAttributes({
'data-msys-linkname': this.getAttribute('data-msys-linkname'),
href: this.link,
size: 'large',
underline: 'none',
})}
>
${this.title}
</mjc-link>
Expand Down
2 changes: 2 additions & 0 deletions packages/email-components/src/templates/styleGuide.mjml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

<mj-include path="../components/Heading/Heading.stories.mjml" />

<mj-include path="../components/ImageLink/ImageLink.stories.mjml" />

<mj-include path="../components/Link/Link.stories.mjml" />

<mj-include path="../components/RatingItem/RatingItem.stories.mjml" />
Expand Down

0 comments on commit 4c4f466

Please sign in to comment.