Skip to content

Commit

Permalink
feat: adds direction property to mj-social-element to reverse icon/te…
Browse files Browse the repository at this point in the history
…xt order (#2881)
  • Loading branch information
jamestomasino authored Jul 30, 2024
1 parent 824cd66 commit 5117400
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/mjml-social/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ padding-left | px | left offset | n
padding-right | px | right offset | n/a
padding-top | px | top offset | n/a
icon-padding | px | padding around the icon | 0px
icon-position | string | left/right | right
text-padding | px | padding around the text | 4px 4px 4px 0
sizes | media query & width | set icon width based on query | n/a
src | url | image source | Each social `name` has its own default
Expand Down
25 changes: 19 additions & 6 deletions packages/mjml-social/src/SocialElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export default class MjSocialElement extends BodyComponent {

static allowedAttributes = {
align: 'enum(left,center,right)',
'icon-position': 'enum(left,right)',
'background-color': 'color',
color: 'color',
'border-radius': 'unit(px)',
Expand Down Expand Up @@ -132,6 +133,7 @@ export default class MjSocialElement extends BodyComponent {
static defaultAttributes = {
alt: '',
align: 'left',
'icon-position': 'left',
color: '#000',
'border-radius': '3px',
'font-family': 'Ubuntu, Helvetica, Arial, sans-serif',
Expand Down Expand Up @@ -232,13 +234,9 @@ export default class MjSocialElement extends BodyComponent {
} = this.getSocialAttributes()

const hasLink = !!this.getAttribute('href')
const iconPosition = this.getAttribute('icon-position')

return `
<tr
${this.htmlAttributes({
class: this.getAttribute('css-class'),
})}
>
const makeIcon = () => `
<td ${this.htmlAttributes({ style: 'td' })}>
<table
${this.htmlAttributes({
Expand Down Expand Up @@ -279,6 +277,9 @@ export default class MjSocialElement extends BodyComponent {
</tbody>
</table>
</td>
`

const makeContent = () => `
${
this.getContent()
? `
Expand All @@ -303,6 +304,18 @@ export default class MjSocialElement extends BodyComponent {
`
: ''
}
`

const renderLeft = () => `${makeIcon()} ${makeContent()}`
const renderRight = () => `${makeContent()} ${makeIcon()}`

return `
<tr
${this.htmlAttributes({
class: this.getAttribute('css-class'),
})}
>
${iconPosition === 'left' ? renderLeft() : renderRight() }
</tr>
`
}
Expand Down

0 comments on commit 5117400

Please sign in to comment.