1: <?php
2:
3: declare(strict_types=1);
4:
5: namespace Atk4\Ui;
6:
7: /**
8: * Set size to 1, 2, 3, 4 or 5 if you are looking for Page Header. The size is not affected by
9: * header placement on the page. Specify number to constructor like this:.
10: *
11: * $h = new Header(['size' => 1]); // creates <h1>..</h1> header
12: *
13: * Alternatively set content headers. Those will emphasize the text in the context of the section.
14: *
15: * $h = new Header(['size' => 'large']); // make large header <div class="ui large header">..</div>
16: */
17: class Header extends View
18: {
19: /** @var int|string Set to 1, 2, .. 5 for page-headers or small/medium/large for content headers. */
20: public $size;
21:
22: /** @var string Specify icon that will be included in a header. */
23: public $icon;
24:
25: /** @var string Include image with a specified source. */
26: public $image;
27:
28: /** @var string Will include sub-header. */
29: public $subHeader;
30:
31: /** @var string Specify alignment of the header. */
32: public $aligned;
33:
34: public $ui = 'header';
35:
36: public $defaultTemplate = 'header.html';
37:
38: #[\Override]
39: protected function renderView(): void
40: {
41: if ($this->size) {
42: if (is_int($this->size)) {
43: $this->setElement('h' . $this->size);
44: } else {
45: $this->addClass($this->size);
46: }
47: }
48:
49: if ($this->icon) {
50: $this->icon = Icon::addTo($this, [$this->icon], ['Icon']);
51: }
52:
53: if ($this->image) {
54: $this->image = Image::addTo($this, [$this->image], ['Icon']);
55: }
56:
57: if ($this->subHeader) {
58: $this->subHeader = View::addTo($this, [$this->subHeader], ['SubHeader'])->addClass('sub header');
59: }
60:
61: if ($this->aligned) {
62: $this->addClass($this->aligned . ' aligned');
63: }
64:
65: if ($this->aligned && ($this->icon || $this->image)) {
66: $this->addClass('icon');
67: }
68:
69: if (!$this->icon && !$this->elements) {
70: $this->template->del('hasContent');
71: $this->template->set('title', $this->content);
72: $this->content = null;
73: }
74:
75: parent::renderView();
76: }
77: }
78: