Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
Tabs | |
0.00% |
0 / 8 |
|
0.00% |
0 / 5 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTabs | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAttributes | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getHtml | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Tabs.php |
4 | * |
5 | * This file is part of the Codex design system, the official design system for Wikimedia projects. |
6 | * It contains the definition and implementation of the `Tabs` class, responsible for managing |
7 | * the behavior and properties of the corresponding component. |
8 | * |
9 | * @category Component |
10 | * @package Codex\Component |
11 | * @since 0.1.0 |
12 | * @author Doğu Abaris <abaris@null.net> |
13 | * @license https://www.gnu.org/copyleft/gpl.html GPL-2.0-or-later |
14 | * @link https://doc.wikimedia.org/codex/main/ Codex Documentation |
15 | */ |
16 | |
17 | namespace Wikimedia\Codex\Component; |
18 | |
19 | use Wikimedia\Codex\Renderer\TabsRenderer; |
20 | |
21 | /** |
22 | * Tabs |
23 | * |
24 | * This class is part of the Codex PHP library and is responsible for |
25 | * representing an immutable object. It is primarily intended for use |
26 | * with a builder class to construct its instances. |
27 | * |
28 | * @category Component |
29 | * @package Codex\Component |
30 | * @since 0.1.0 |
31 | * @author Doğu Abaris <abaris@null.net> |
32 | * @license https://www.gnu.org/copyleft/gpl.html GPL-2.0-or-later |
33 | * @link https://doc.wikimedia.org/codex/main/ Codex Documentation |
34 | */ |
35 | class Tabs { |
36 | |
37 | /** |
38 | * The ID for the tabs component. |
39 | */ |
40 | private string $id; |
41 | |
42 | /** |
43 | * An array of Tab component objects representing each tab in the component. |
44 | */ |
45 | private array $tabs; |
46 | |
47 | /** |
48 | * Additional HTML attributes for the `<form>` element. |
49 | */ |
50 | private array $attributes; |
51 | |
52 | /** |
53 | * The renderer instance used to render the tabs. |
54 | */ |
55 | private TabsRenderer $renderer; |
56 | |
57 | /** |
58 | * Constructor for the Tabs component. |
59 | * |
60 | * Initializes a Tabs instance with the specified properties. |
61 | * |
62 | * @param string $id The ID for the tabs component. |
63 | * @param array $tabs An array of Tab component objects. |
64 | * @param array $attributes Additional HTML attributes for the tabs component. |
65 | * @param TabsRenderer $renderer The renderer to use for rendering the tabs. |
66 | */ |
67 | public function __construct( |
68 | string $id, |
69 | array $tabs, |
70 | array $attributes, |
71 | TabsRenderer $renderer |
72 | ) { |
73 | $this->id = $id; |
74 | $this->tabs = $tabs; |
75 | $this->attributes = $attributes; |
76 | $this->renderer = $renderer; |
77 | } |
78 | |
79 | /** |
80 | * Get the HTML ID for the tabs. |
81 | * |
82 | * This method returns the HTML `id` attribute value for the tabs element. |
83 | * |
84 | * @since 0.1.0 |
85 | * @return string The ID for the tabs. |
86 | */ |
87 | public function getId(): string { |
88 | return $this->id; |
89 | } |
90 | |
91 | /** |
92 | * Get the array of tabs in the component. |
93 | * |
94 | * This method returns an array of `Tab` objects that represent each tab in the component. |
95 | * Each tab contains properties such as label, content, selected state, and disabled state. |
96 | * |
97 | * @since 0.1.0 |
98 | * @return array The array of `Tab` objects representing the tabs in the component. |
99 | */ |
100 | public function getTabs(): array { |
101 | return $this->tabs; |
102 | } |
103 | |
104 | /** |
105 | * Get the additional HTML attributes for the `<form>` element. |
106 | * |
107 | * This method returns an associative array of custom HTML attributes applied to the `<form>` element |
108 | * that wraps the tabs. These attributes can be used to enhance accessibility or integrate with JavaScript. |
109 | * |
110 | * @since 0.1.0 |
111 | * @return array The additional attributes as an array. |
112 | */ |
113 | public function getAttributes(): array { |
114 | return $this->attributes; |
115 | } |
116 | |
117 | /** |
118 | * Get the component's HTML representation. |
119 | * |
120 | * This method generates the HTML markup for the component, incorporating relevant properties |
121 | * and any additional attributes. The component is structured using appropriate HTML elements |
122 | * as defined by the implementation. |
123 | * |
124 | * @since 0.1.0 |
125 | * @return string The generated HTML string for the component. |
126 | */ |
127 | public function getHtml(): string { |
128 | return $this->renderer->render( $this ); |
129 | } |
130 | } |