| 1 |
<?php |
| 2 |
|
| 3 |
namespace Tableberg\Renderer\Text; |
| 4 |
|
| 5 |
class TextRenderer { |
| 6 |
/** |
| 7 |
* @param array<string, mixed>|null $attributes |
| 8 |
* @return string |
| 9 |
*/ |
| 10 |
public function render($attributes) { |
| 11 |
$attrs = TextAttrs::from_array($attributes); |
| 12 |
|
| 13 |
$styleValues = ['margin:0']; |
| 14 |
|
| 15 |
if ($attrs->styles->textColor->isNotEmpty()) { |
| 16 |
$styleValues[] = 'color:' . $attrs->styles->textColor->asAttr(); |
| 17 |
} |
| 18 |
|
| 19 |
if ($attrs->styles->linkColor->isNotEmpty()) { |
| 20 |
$styleValues[] = '--tableberg-text-link-color:' . $attrs->styles->linkColor->asAttr(); |
| 21 |
} |
| 22 |
|
| 23 |
if ($attrs->styles->backgroundColor->isNotEmpty()) { |
| 24 |
$styleValues[] = 'background-color:' . $attrs->styles->backgroundColor->asAttr(); |
| 25 |
} |
| 26 |
|
| 27 |
if ($attrs->styles->fontSize->isNotEmpty()) { |
| 28 |
$styleValues[] = 'font-size:' . $attrs->styles->fontSize->asAttr(); |
| 29 |
} |
| 30 |
|
| 31 |
$styleAttr = implode(';', $styleValues); |
| 32 |
|
| 33 |
return |
| 34 |
"<p class='tableberg-text-element' style='{$styleAttr}'> |
| 35 |
{$attrs->content->asHtml()} |
| 36 |
</p>"; |
| 37 |
} |
| 38 |
} |
| 39 |
|