Repository navigation
Expand file tree
/
Copy pathDisclosure.php
More file actions
69 lines (64 loc) · 2.14 KB
/
Copy pathDisclosure.php
File metadata and controls
69 lines (64 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
declare(strict_types=1);
namespace PHPForge\Debug\Helper;
use PHPForge\Debug\Theme\Css;
use UIAwesome\Html\Flow\Div;
use UIAwesome\Html\Interactive\{Details, Summary};
use UIAwesome\Html\Phrasing\Span;
/**
* Renders the shared collapsible section: a titled `<summary>` with an expand/collapse hint over a `<details>` body.
*/
final class Disclosure
{
/**
* Renders the expand/collapse affordance shown on the right of a summary.
*
* Exposed on its own so sections that build their own `<summary>` (the phpinfo Overview blocks) still share one
* wording and one behaviour.
*
* @return Span Expand/collapse hint element.
*/
public static function hint(): Span
{
return Span::tag()
->addAriaAttribute('hidden', 'true')
->class(Css::DISCLOSURE_HINT)
->html(
Span::tag()
->addDataAttribute('yii-debug-hint', 'collapsed')
->content('click to expand'),
Span::tag()
->addDataAttribute('yii-debug-hint', 'expanded')
->content('click to collapse'),
);
}
/**
* Renders a titled collapsible section.
*
* @param string $title Section heading shown in the summary.
* @param string $body Rendered HTML revealed when the section expands.
* @param bool $open Whether the section is expanded initially.
*
* @return string Collapsible section markup.
*/
public static function render(string $title, string $body, bool $open = false): string
{
return Details::tag()
->open($open)
->class(Css::DISCLOSURE)
->html(
Summary::tag()
->class(Css::DISCLOSURE_SUMMARY)
->html(
Span::tag()
->class(Css::DISCLOSURE_TITLE)
->content($title),
self::hint(),
),
Div::tag()
->class(Css::DISCLOSURE_BODY)
->html($body),
)
->render();
}
}