Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
InfoChip | |
0.00% |
0 / 12 |
|
0.00% |
0 / 7 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getText | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getStatus | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getIcon | |
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 | * InfoChip.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 `InfoChip` 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\InfoChipRenderer; |
20 | |
21 | /** |
22 | * InfoChip |
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 InfoChip { |
36 | |
37 | /** |
38 | * The ID for the InfoChip. |
39 | */ |
40 | protected string $id; |
41 | |
42 | /** |
43 | * The text displayed inside the InfoChip. |
44 | */ |
45 | protected string $text; |
46 | |
47 | /** |
48 | * The status type, determines chip's visual style. Options include 'notice', 'warning', 'error', and 'success'. |
49 | */ |
50 | protected string $status; |
51 | |
52 | /** |
53 | * The CSS class for a custom icon used in the InfoChip, applicable only for the 'notice' status. |
54 | */ |
55 | protected ?string $icon; |
56 | |
57 | /** |
58 | * Additional HTML attributes for the outer `<div>` element of the InfoChip. |
59 | */ |
60 | protected array $attributes; |
61 | |
62 | /** |
63 | * The renderer instance used to render the infoChip. |
64 | */ |
65 | protected InfoChipRenderer $renderer; |
66 | |
67 | /** |
68 | * Constructor for the InfoChip component. |
69 | * |
70 | * Initializes an InfoChip instance with the specified properties. |
71 | * |
72 | * @param string $id The ID for the InfoChip. |
73 | * @param string $text The text displayed inside the InfoChip. |
74 | * @param string $status The status type of the InfoChip. |
75 | * @param string|null $icon The CSS class for a custom icon, if any. |
76 | * @param array $attributes Additional HTML attributes for the InfoChip element. |
77 | * @param InfoChipRenderer $renderer The renderer to use for rendering the InfoChip. |
78 | */ |
79 | public function __construct( |
80 | string $id, |
81 | string $text, |
82 | string $status, |
83 | ?string $icon, |
84 | array $attributes, |
85 | InfoChipRenderer $renderer |
86 | ) { |
87 | $this->id = $id; |
88 | $this->text = $text; |
89 | $this->status = $status; |
90 | $this->icon = $icon; |
91 | $this->attributes = $attributes; |
92 | $this->renderer = $renderer; |
93 | } |
94 | |
95 | /** |
96 | * Get the InfoChip's HTML ID attribute. |
97 | * |
98 | * This method returns the ID that is assigned to the InfoChip element. |
99 | * The ID can be used for targeting the chip with JavaScript, CSS, or for accessibility purposes. |
100 | * |
101 | * @since 0.1.0 |
102 | * @return string The ID of the InfoChip element. |
103 | */ |
104 | public function getId(): string { |
105 | return $this->id; |
106 | } |
107 | |
108 | /** |
109 | * Get the text content of the info chip. |
110 | * |
111 | * This method returns the text that is displayed inside the info chip. |
112 | * The text provides the primary information that the chip conveys. |
113 | * |
114 | * @since 0.1.0 |
115 | * @return string The text content of the info chip. |
116 | */ |
117 | public function getText(): string { |
118 | return $this->text; |
119 | } |
120 | |
121 | /** |
122 | * Get the status type of the info chip. |
123 | * |
124 | * This method returns the status type of the info chip, which determines its visual style. |
125 | * The status can be one of the following: 'notice', 'warning', 'error', or 'success'. |
126 | * |
127 | * @since 0.1.0 |
128 | * @return string The status type of the info chip. |
129 | */ |
130 | public function getStatus(): string { |
131 | return $this->status; |
132 | } |
133 | |
134 | /** |
135 | * Get the custom icon class for the info chip. |
136 | * |
137 | * This method returns the CSS class for a custom icon used in the info chip, if applicable. |
138 | * This option is only available for chips with the "notice" status. |
139 | * |
140 | * @since 0.1.0 |
141 | * @return string|null The CSS class for the custom icon, or null if no icon is set. |
142 | */ |
143 | public function getIcon(): ?string { |
144 | return $this->icon; |
145 | } |
146 | |
147 | /** |
148 | * Retrieve additional HTML attributes for the outer `<div>` element. |
149 | * |
150 | * This method returns an associative array of additional HTML attributes that will be applied |
151 | * to the outer `<div>` element of the info chip. These attributes can be used to improve |
152 | * accessibility, customization, or to integrate with JavaScript. |
153 | * |
154 | * @since 0.1.0 |
155 | * @return array The additional attributes as an array. |
156 | */ |
157 | public function getAttributes(): array { |
158 | return $this->attributes; |
159 | } |
160 | |
161 | /** |
162 | * Get the component's HTML representation. |
163 | * |
164 | * This method generates the HTML markup for the component, incorporating relevant properties |
165 | * and any additional attributes. The component is structured using appropriate HTML elements |
166 | * as defined by the implementation. |
167 | * |
168 | * @since 0.1.0 |
169 | * @return string The generated HTML string for the component. |
170 | */ |
171 | public function getHtml(): string { |
172 | return $this->renderer->render( $this ); |
173 | } |
174 | } |