|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Leonidas\Library\Admin\Component\Metabox\View; |
|
4
|
|
|
|
|
5
|
|
|
use Leonidas\Contracts\Admin\Component\AdminComponentInterface; |
|
6
|
|
|
use Leonidas\Contracts\Ui\ViewInterface; |
|
7
|
|
|
use WebTheory\Html\Traits\ElementConstructorTrait; |
|
8
|
|
|
|
|
9
|
|
|
class SectionView implements ViewInterface |
|
10
|
|
|
{ |
|
11
|
|
|
use ElementConstructorTrait; |
|
12
|
|
|
|
|
13
|
|
|
public function render(array $context = []): string |
|
14
|
|
|
{ |
|
15
|
|
|
$title = $context['title']; |
|
16
|
|
|
$padding = $context['padding']; |
|
17
|
|
|
$isFieldset = $context['is_fieldset']; |
|
18
|
|
|
$request = $context['request']; |
|
19
|
|
|
|
|
20
|
|
|
/** @var AdminComponentInterface[] $components */ |
|
21
|
|
|
$components = $context['components']; |
|
22
|
|
|
|
|
23
|
|
|
$html = ''; |
|
24
|
|
|
|
|
25
|
|
|
$titleElement = $this->tag('h3', [], $title); |
|
26
|
|
|
$attributes = ['class' => "py-{$padding}"]; |
|
27
|
|
|
$container = $isFieldset ? 'fieldset' : 'div'; |
|
28
|
|
|
|
|
29
|
|
|
$html .= $this->open($container, $attributes); |
|
30
|
|
|
|
|
31
|
|
|
if ($isFieldset && false) { |
|
32
|
|
|
// temporarily disabled because legend elements are absolutely |
|
33
|
|
|
// positioned within their container, making padding not work |
|
34
|
|
|
// as desired |
|
35
|
|
|
$html .= $this->tag('legend', [], $titleElement); |
|
36
|
|
|
} else { |
|
37
|
|
|
$html .= $titleElement; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
foreach ($components as $component) { |
|
41
|
|
|
if ($component->shouldBeRendered($request)) { |
|
42
|
|
|
$html .= $component->renderComponent($request); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$html .= $this->close($container); |
|
47
|
|
|
|
|
48
|
|
|
return $html; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|