Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds direction property to mj-social-element to reverse icon/text order #2881

Merged
merged 4 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading