Skip to content

Commit

Permalink
Merge pull request #6 from slavik990/feature/update-navigation-block
Browse files Browse the repository at this point in the history
update navigation block
  • Loading branch information
wanoo21 authored Mar 27, 2024
2 parents 092df3f + d7eb9c9 commit 09c176c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
3 changes: 3 additions & 0 deletions mjml-output/Section.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {IpBlocks, IStructure, IStructureColumnOptions, RenderingClass} from './interfaces';
import {Button, Divider, Image, Social, Spacer, Text} from './blocks';
import {createBorder, createPadding, createWidthHeight, defaultStructureColumnsWidth} from './utils';
import { Navigation } from './blocks/Navigation';

const defaultColumnsOptions: IStructureColumnOptions = {
background: {
Expand All @@ -21,6 +22,8 @@ export class Section implements RenderingClass {

private static getBlock(block: IpBlocks) {
switch (block.type) {
case 'navigation':
return new Navigation(block.options).render();
case 'text':
return new Text(block.innerText, block.options).render();
case 'image':
Expand Down
29 changes: 15 additions & 14 deletions mjml-output/blocks/Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import {
INavigationBlockOptions,
NavigationBlock,
RenderingClass,
} from "@mjml-output/interfaces";

export class Navigation implements NavigationBlock, RenderingClass {

constructor(public innerText: string, public options: INavigationBlockOptions) {
} from "@mjml-output/interfaces";
export class Navigation implements NavigationBlock, RenderingClass {
constructor(public options: INavigationBlockOptions) {
}

render(): string {
const {
color,
Expand All @@ -22,7 +22,7 @@ export class Navigation implements NavigationBlock, RenderingClass {
textDecoration,
hamburger
} = this.options

return `
<mj-navbar align="${align}" hamburger="${hamburger ? 'hamburger' : ''}">
${elements.map((el) => {
Expand All @@ -31,18 +31,19 @@ export class Navigation implements NavigationBlock, RenderingClass {
color="${color}"
target="${target}"
font-family="${font.family}"
font-size="${font.size}"
font-size="${font.size}px"
font-style="${font.style}"
font-weight="${font.weight}"
letter-spacing="${letterSpacing}px"
text-decoration="${textDecoration}"
line-height="${lineHeight}"
padding-top="${padding.top}"
padding-right="${padding.right}"
padding-left="${padding.left}"
padding-bottom="${padding.bottom}"></mj-navbar-link>`
text-transform="none"
line-height="${lineHeight.value}${lineHeight.unit}"
padding-top="${padding.top}px"
padding-right="${padding.right}px"
padding-left="${padding.left}px"
padding-bottom="${padding.bottom}px">${el.label}</mj-navbar-link>`
})}
</mj-navbar>
`;
}
}
}
3 changes: 2 additions & 1 deletion mjml-output/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface RenderingClass {

export abstract class NavigationBlock {
readonly type?: 'navigation';
protected constructor(public innerText: string, public options: INavigationBlockOptions) {
protected constructor(public options: INavigationBlockOptions) {
}
}

Expand Down Expand Up @@ -54,6 +54,7 @@ export type IpBlocks =
| ButtonBlock
| DividerBlock
| SpacerBlock
| NavigationBlock
| SocialBlock;

export interface IForRootConf {
Expand Down

0 comments on commit 09c176c

Please sign in to comment.