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