1 | <?php namespace Arcanesoft\Core\Helpers\UI; |
||
12 | abstract class AbstractClickable implements Htmlable |
||
13 | { |
||
14 | /* ----------------------------------------------------------------- |
||
15 | | Properties |
||
16 | | ----------------------------------------------------------------- |
||
17 | */ |
||
18 | /** @var string */ |
||
19 | protected $action; |
||
20 | |||
21 | /** @var \Illuminate\Support\Collection */ |
||
22 | protected $attributes; |
||
23 | |||
24 | /** @var bool */ |
||
25 | protected $disabled = false; |
||
26 | |||
27 | /** @var string */ |
||
28 | protected $size = 'md'; |
||
29 | |||
30 | /** @var bool */ |
||
31 | protected $withTitle = true; |
||
32 | |||
33 | /** @var bool */ |
||
34 | protected $withIcon = true; |
||
35 | |||
36 | /** @var bool */ |
||
37 | protected $withTooltip = false; |
||
38 | |||
39 | /** @var array */ |
||
40 | protected $extraClass = []; |
||
41 | |||
42 | /* ----------------------------------------------------------------- |
||
43 | | Getters & Setters |
||
44 | | ----------------------------------------------------------------- |
||
45 | */ |
||
46 | /** |
||
47 | * Set the action. |
||
48 | * |
||
49 | * @param string $action |
||
50 | * |
||
51 | * @return \Arcanesoft\Core\Helpers\UI\AbstractClickable |
||
52 | */ |
||
53 | 108 | public function setAction($action) |
|
59 | |||
60 | /** |
||
61 | * Set the attributes. |
||
62 | * |
||
63 | * @param array $attributes |
||
64 | * |
||
65 | * @return \Arcanesoft\Core\Helpers\UI\AbstractClickable |
||
66 | */ |
||
67 | 108 | public function setAttributes(array $attributes) |
|
73 | |||
74 | /** |
||
75 | * Set an attribute. |
||
76 | * |
||
77 | * @param string $key |
||
78 | * @param mixed $value |
||
79 | * |
||
80 | * @return \Arcanesoft\Core\Helpers\UI\AbstractClickable |
||
81 | */ |
||
82 | 12 | public function setAttribute($key, $value) |
|
88 | |||
89 | /** |
||
90 | * Append a style class. |
||
91 | * |
||
92 | * @param string $class |
||
93 | * |
||
94 | * @return \Arcanesoft\Core\Helpers\UI\AbstractClickable |
||
95 | */ |
||
96 | 12 | public function appendClass($class) |
|
102 | |||
103 | /** |
||
104 | * Set disabled state. |
||
105 | * |
||
106 | * @param bool $disabled |
||
107 | * |
||
108 | * @return \Arcanesoft\Core\Helpers\UI\AbstractClickable |
||
109 | */ |
||
110 | 108 | public function setDisabled($disabled) |
|
122 | |||
123 | /** |
||
124 | * Forget attribute(s). |
||
125 | * |
||
126 | * @param string|array $attributes |
||
127 | * |
||
128 | * @return \Arcanesoft\Core\Helpers\UI\AbstractClickable |
||
129 | */ |
||
130 | 12 | public function forgetAttribute($attributes) |
|
136 | |||
137 | /** |
||
138 | * Set the size. |
||
139 | * |
||
140 | * @param string $size |
||
141 | * |
||
142 | * @return \Arcanesoft\Core\Helpers\UI\AbstractClickable |
||
143 | */ |
||
144 | 12 | public function size($size) |
|
150 | |||
151 | /** |
||
152 | * Show/Hide the title. |
||
153 | * |
||
154 | * @param bool $withTitle |
||
155 | * |
||
156 | * @return \Arcanesoft\Core\Helpers\UI\AbstractClickable |
||
157 | */ |
||
158 | 6 | public function withTitle($withTitle) |
|
164 | |||
165 | /** |
||
166 | * Show/Hide the icon. |
||
167 | * |
||
168 | * @var bool $withIcon |
||
169 | * |
||
170 | * @return \Arcanesoft\Core\Helpers\UI\AbstractClickable |
||
171 | */ |
||
172 | 18 | public function withIcon($withIcon) |
|
178 | |||
179 | /** |
||
180 | * Enable/Disable the tooltip. |
||
181 | * |
||
182 | * @param bool $withTooltip |
||
183 | * |
||
184 | * @return \Arcanesoft\Core\Helpers\UI\AbstractClickable |
||
185 | */ |
||
186 | 12 | public function withTooltip($withTooltip) |
|
192 | |||
193 | /** |
||
194 | * Show only the icon and the title as tooltip. |
||
195 | * |
||
196 | * @return \Arcanesoft\Core\Helpers\UI\AbstractClickable |
||
197 | */ |
||
198 | 6 | public function onlyIcon() |
|
202 | |||
203 | /** |
||
204 | * Add loading text attribute. |
||
205 | * |
||
206 | * @return \Arcanesoft\Core\Helpers\UI\AbstractClickable |
||
207 | */ |
||
208 | 6 | public function withLoadingText() |
|
212 | |||
213 | /* ----------------------------------------------------------------- |
||
214 | | Main Methods |
||
215 | | ----------------------------------------------------------------- |
||
216 | */ |
||
217 | /** |
||
218 | * Get the string content for the link instance. |
||
219 | * |
||
220 | * @return string |
||
221 | */ |
||
222 | 6 | public function __toString() |
|
226 | |||
227 | /* ----------------------------------------------------------------- |
||
228 | | Other Methods |
||
229 | | ----------------------------------------------------------------- |
||
230 | */ |
||
231 | /** |
||
232 | * Render the value. |
||
233 | * |
||
234 | * @return string |
||
235 | */ |
||
236 | 108 | protected function renderValue() |
|
245 | |||
246 | /** |
||
247 | * Render the icon. |
||
248 | * |
||
249 | * @return string |
||
250 | */ |
||
251 | 96 | protected function renderIcon() |
|
255 | |||
256 | /** |
||
257 | * Get the action title. |
||
258 | * |
||
259 | * @return string |
||
260 | */ |
||
261 | 102 | protected function getTitle() |
|
265 | |||
266 | /** |
||
267 | * Get the icon. |
||
268 | * |
||
269 | * @return string|null |
||
270 | */ |
||
271 | 96 | protected function getIcon() |
|
275 | |||
276 | /** |
||
277 | * Get the button class. |
||
278 | * |
||
279 | * @return string |
||
280 | */ |
||
281 | 108 | protected function getStyleClass() |
|
291 | |||
292 | /** |
||
293 | * Get the base style class. |
||
294 | * |
||
295 | * @return string |
||
296 | */ |
||
297 | 108 | protected function getBaseStyleClass() |
|
301 | |||
302 | /** |
||
303 | * Get the link size. |
||
304 | * |
||
305 | * @return string|null |
||
306 | */ |
||
307 | 108 | protected function getSize() |
|
311 | |||
312 | /** |
||
313 | * Get the link color. |
||
314 | * |
||
315 | * @return string |
||
316 | */ |
||
317 | 108 | protected function getColor() |
|
323 | |||
324 | /** |
||
325 | * Get the value from config. |
||
326 | * |
||
327 | * @param string $key |
||
328 | * |
||
329 | * @return mixed |
||
330 | */ |
||
331 | abstract protected function getConfig($key); |
||
332 | } |
||
333 |