|
| 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 | +} |
0 commit comments