|
| 1 | +<?php |
| 2 | +namespace Spipu\Html2Pdf\Tag\Html; |
| 3 | + |
| 4 | +use Spipu\Html2Pdf\Tag\AbstractTag; |
| 5 | + |
| 6 | +/** |
| 7 | + * Button Tag class |
| 8 | + */ |
| 9 | +class Button extends AbstractTag |
| 10 | +{ |
| 11 | + /** |
| 12 | + * @inheritdoc |
| 13 | + */ |
| 14 | + public function getName() |
| 15 | + { |
| 16 | + return 'button'; |
| 17 | + } |
| 18 | + |
| 19 | + /** |
| 20 | + * @inheritdoc |
| 21 | + */ |
| 22 | + public function open($properties) |
| 23 | + { |
| 24 | + $styles = $this->getStyleFromProperties($properties); |
| 25 | + |
| 26 | + // Set default button styling if not specified |
| 27 | + if (!isset($styles['background'])) { |
| 28 | + $styles['background'] = '#f0f0f0'; |
| 29 | + } |
| 30 | + if (!isset($styles['border'])) { |
| 31 | + $styles['border'] = '1px solid #ccc'; |
| 32 | + } |
| 33 | + if (!isset($styles['padding'])) { |
| 34 | + $styles['padding'] = '5px 10px'; |
| 35 | + } |
| 36 | + |
| 37 | + // Add custom class if provided |
| 38 | + if (isset($properties['class'])) { |
| 39 | + $this->parsingCss->analyse('button.' . $properties['class']); |
| 40 | + } |
| 41 | + |
| 42 | + // Handle button type |
| 43 | + $type = isset($properties['type']) ? $properties['type'] : 'button'; |
| 44 | + |
| 45 | + // Create button container with proper styling |
| 46 | + $this->pdf->setStyle($styles); |
| 47 | + return true; |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * @inheritdoc |
| 52 | + */ |
| 53 | + public function close($properties) |
| 54 | + { |
| 55 | + // Reset styles after button closure |
| 56 | + $this->pdf->resetStyle(); |
| 57 | + return true; |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * @inheritdoc |
| 62 | + */ |
| 63 | + protected function getStyleFromProperties($properties) |
| 64 | + { |
| 65 | + $styles = []; |
| 66 | + |
| 67 | + // Handle standard CSS properties |
| 68 | + $cssProperties = ['width', 'height', 'background', 'color', 'border', 'padding', 'margin', 'font-size']; |
| 69 | + foreach ($cssProperties as $prop) { |
| 70 | + if (isset($properties[$prop])) { |
| 71 | + $styles[$prop] = $properties[$prop]; |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + return $styles; |
| 76 | + } |
| 77 | +} |
0 commit comments