| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | namespace Atk4\Ui; |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | class Button extends View |
| 11: | { |
| 12: | public $defaultTemplate = 'button.html'; |
| 13: | |
| 14: | public $ui = 'button'; |
| 15: | |
| 16: | |
| 17: | public $icon; |
| 18: | |
| 19: | |
| 20: | public $iconRight; |
| 21: | |
| 22: | #[\Override] |
| 23: | protected function renderView(): void |
| 24: | { |
| 25: | if ($this->icon) { |
| 26: | if (!is_object($this->icon)) { |
| 27: | $this->icon = new Icon($this->icon); |
| 28: | } |
| 29: | |
| 30: | $this->add($this->icon, 'LeftIcon'); |
| 31: | |
| 32: | if ($this->content) { |
| 33: | $this->addClass('labeled'); |
| 34: | } |
| 35: | |
| 36: | $this->addClass('icon'); |
| 37: | } |
| 38: | |
| 39: | if ($this->iconRight) { |
| 40: | if ($this->icon) { |
| 41: | throw (new Exception('Cannot use icon and iconRight simultaneously')) |
| 42: | ->addMoreInfo('icon', $this->icon) |
| 43: | ->addMoreInfo('iconRight', $this->iconRight); |
| 44: | } |
| 45: | |
| 46: | if (!is_object($this->iconRight)) { |
| 47: | $this->iconRight = new Icon($this->iconRight); |
| 48: | } |
| 49: | |
| 50: | $this->add($this->iconRight, 'RightIcon'); |
| 51: | |
| 52: | if ($this->content) { |
| 53: | $this->addClass('right labeled'); |
| 54: | } |
| 55: | |
| 56: | $this->addClass('icon'); |
| 57: | } |
| 58: | |
| 59: | parent::renderView(); |
| 60: | } |
| 61: | } |
| 62: | |