| @@ -9,10 +9,19 @@ | ||
| 9 | 9 | */ |
| 10 | 10 | public function render($attributes) { |
| 11 | 11 | $attrs = TextAttrs::from_array($attributes); |
| 12 | 12 | |
| 13 | - $styleValues = ['margin:0']; | |
| 13 | + $marginShorthand = $this->sides_shorthand($attrs->styles->margin); | |
| 14 | + $paddingShorthand = $this->sides_shorthand($attrs->styles->padding); | |
| 14 | 15 | |
| 16 | + $styleValues = []; | |
| 17 | + $styleValues[] = 'margin:' . ($marginShorthand !== '' ? $marginShorthand : '0'); | |
| 18 | + if ($paddingShorthand !== '') { | |
| 19 | + $styleValues[] = 'padding:' . $paddingShorthand; | |
| 20 | + } | |
| 21 | + | |
| 22 | + $styleValues[] = 'text-align:' . $attrs->align->asAttr(); | |
| 23 | + | |
| 15 | 24 | if ($attrs->styles->textColor->isNotEmpty()) { |
| 16 | 25 | $styleValues[] = 'color:' . $attrs->styles->textColor->asAttr(); |
| 17 | 26 | } |
| 18 | 27 | |
| @@ -29,10 +38,37 @@ | ||
| 29 | 38 | } |
| 30 | 39 | |
| 31 | 40 | $styleAttr = implode(';', $styleValues); |
| 32 | 41 | |
| 42 | + // Only paint the links when a colour was picked; otherwise the | |
| 43 | + // theme's own link colour applies. | |
| 44 | + $className = 'tableberg-text-element'; | |
| 45 | + if ($attrs->styles->linkColor->isNotEmpty()) { | |
| 46 | + $className .= ' tableberg-has-link-color'; | |
| 47 | + } | |
| 48 | + | |
| 33 | 49 | return |
| 34 | - "<p class='tableberg-text-element' style='{$styleAttr}'> | |
| 50 | + "<p class='{$className}' style='{$styleAttr}'> | |
| 35 | 51 | {$attrs->content->asHtml()} |
| 36 | 52 | </p>"; |
| 53 | + } | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * Build a CSS shorthand from a 4-side value; returns '' when all sides | |
| 57 | + * are empty so the property can be skipped. | |
| 58 | + * | |
| 59 | + * @param Sides $sides | |
| 60 | + * @return string | |
| 61 | + */ | |
| 62 | + private function sides_shorthand($sides) { | |
| 63 | + $top = $sides->top->isNotEmpty() ? $sides->top->asAttr() : '0'; | |
| 64 | + $right = $sides->right->isNotEmpty() ? $sides->right->asAttr() : '0'; | |
| 65 | + $bottom = $sides->bottom->isNotEmpty() ? $sides->bottom->asAttr() : '0'; | |
| 66 | + $left = $sides->left->isNotEmpty() ? $sides->left->asAttr() : '0'; | |
| 67 | + | |
| 68 | + if ($top === '0' && $right === '0' && $bottom === '0' && $left === '0') { | |
| 69 | + return ''; | |
| 70 | + } | |
| 71 | + | |
| 72 | + return "{$top} {$right} {$bottom} {$left}"; | |
| 37 | 73 | } |
| 38 | 74 | } |