Skip to content

Commit 408fa5f

Browse files
authored
Merge pull request #30 from dingo-d/feature/mj-navbar
Implement mj-navbar components
2 parents 0916036 + 4c4b8f8 commit 408fa5f

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MadeByDenis\PhpMjmlRenderer\Elements\BodyComponents;
6+
7+
use MadeByDenis\PhpMjmlRenderer\Elements\AbstractElement;
8+
9+
class MjNavbar extends AbstractElement
10+
{
11+
public const string TAG_NAME = 'mj-navbar';
12+
public const bool ENDING_TAG = false;
13+
14+
protected array $allowedAttributes = [
15+
'align' => ['unit' => 'string', 'type' => 'string', 'default_value' => 'center'],
16+
'base-url' => ['unit' => 'string', 'type' => 'string', 'default_value' => ''],
17+
];
18+
19+
protected array $defaultAttributes = ['align' => 'center'];
20+
21+
public function render(): string
22+
{
23+
$children = $this->getChildren() ?? [];
24+
return $this->renderChildren($children, []);
25+
}
26+
27+
public function getStyles(): array
28+
{
29+
return [];
30+
}
31+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MadeByDenis\PhpMjmlRenderer\Elements\BodyComponents;
6+
7+
use MadeByDenis\PhpMjmlRenderer\Elements\AbstractElement;
8+
9+
class MjNavbarLink extends AbstractElement
10+
{
11+
public const string TAG_NAME = 'mj-navbar-link';
12+
public const bool ENDING_TAG = true;
13+
14+
protected array $allowedAttributes = [
15+
'color' => ['unit' => 'color', 'type' => 'color', 'default_value' => '#000000'],
16+
'font-family' => [
17+
'unit' => 'string',
18+
'type' => 'string',
19+
'default_value' => 'Ubuntu, Helvetica, Arial, sans-serif',
20+
],
21+
'font-size' => ['unit' => 'px', 'type' => 'string', 'default_value' => '13px'],
22+
'href' => ['unit' => 'string', 'type' => 'string', 'default_value' => ''],
23+
'padding' => ['unit' => 'px', 'type' => 'string', 'default_value' => '15px 10px'],
24+
'target' => ['unit' => 'string', 'type' => 'string', 'default_value' => '_blank'],
25+
];
26+
27+
protected array $defaultAttributes = [
28+
'color' => '#000000',
29+
'font-size' => '13px',
30+
'padding' => '15px 10px',
31+
'target' => '_blank',
32+
];
33+
34+
public function render(): string
35+
{
36+
$href = $this->getAttribute('href');
37+
$target = $this->getAttribute('target');
38+
$aAttributes = $this->getHtmlAttributes(['style' => 'a']);
39+
$content = $this->getContent();
40+
return "<a href='$href' target='$target' $aAttributes>$content</a>";
41+
}
42+
43+
public function getStyles(): array
44+
{
45+
return ['a' => [
46+
'color' => $this->getAttribute('color'),
47+
'font-family' => $this->getAttribute('font-family'),
48+
'font-size' => $this->getAttribute('font-size'),
49+
'padding' => $this->getAttribute('padding'),
50+
'text-decoration' => 'none',
51+
]];
52+
}
53+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace MadeByDenis\PhpMjmlRenderer\Tests\Unit\Elements\BodyComponents;
4+
5+
use MadeByDenis\PhpMjmlRenderer\Elements\BodyComponents\MjNavbar;
6+
use MadeByDenis\PhpMjmlRenderer\Elements\BodyComponents\MjNavbarLink;
7+
8+
it('MjNavbar has correct tag name', fn() => expect((new MjNavbar())->getTagName())->toBe('mj-navbar'));
9+
it('MjNavbarLink has correct tag name', fn() => expect((new MjNavbarLink())->getTagName())->toBe('mj-navbar-link'));
10+
it('MjNavbarLink renders link', function () {
11+
$element = new MjNavbarLink(['href' => 'test.html'], 'Link Text');
12+
expect($element->render())->toContain('<a')->toContain('test.html')->toContain('Link Text');
13+
});

0 commit comments

Comments
 (0)