1 | <?php namespace Arcanesoft\Core\Helpers\UI; |
||
12 | abstract class AbstractClickable implements Htmlable |
||
13 | { |
||
14 | /* ----------------------------------------------------------------- |
||
15 | | Properties |
||
16 | | ----------------------------------------------------------------- |
||
17 | */ |
||
18 | |||
19 | /** @var string */ |
||
20 | protected $action; |
||
21 | |||
22 | /** @var \Illuminate\Support\Collection */ |
||
23 | protected $attributes; |
||
24 | |||
25 | /** @var bool */ |
||
26 | protected $disabled = false; |
||
27 | |||
28 | /** @var string */ |
||
29 | protected $size = 'md'; |
||
30 | |||
31 | /** @var bool */ |
||
32 | protected $withTitle = true; |
||
33 | |||
34 | /** @var bool */ |
||
35 | protected $withIcon = true; |
||
36 | |||
37 | /** @var bool */ |
||
38 | protected $withTooltip = false; |
||
39 | |||
40 | /** @var array */ |
||
41 | protected $extraClass = []; |
||
42 | |||
43 | /* ----------------------------------------------------------------- |
||
44 | | Getters & Setters |
||
45 | | ----------------------------------------------------------------- |
||
46 | */ |
||
47 | |||
48 | /** |
||
49 | * Set the action. |
||
50 | * |
||
51 | * @param string $action |
||
52 | * |
||
53 | * @return $this |
||
54 | */ |
||
55 | 72 | public function setAction($action) |
|
61 | |||
62 | /** |
||
63 | * Set the attributes. |
||
64 | * |
||
65 | * @param array $attributes |
||
66 | * |
||
67 | * @return $this |
||
68 | */ |
||
69 | 72 | public function setAttributes(array $attributes) |
|
75 | |||
76 | /** |
||
77 | * Set an attribute. |
||
78 | * |
||
79 | * @param string $key |
||
80 | * @param mixed $value |
||
81 | * |
||
82 | * @return $this |
||
83 | */ |
||
84 | 8 | public function setAttribute($key, $value) |
|
90 | |||
91 | /** |
||
92 | * Append a style class. |
||
93 | * |
||
94 | * @param string $class |
||
95 | * |
||
96 | * @return $this |
||
97 | */ |
||
98 | 8 | public function appendClass($class) |
|
104 | |||
105 | /** |
||
106 | * Set disabled state. |
||
107 | * |
||
108 | * @param bool $disabled |
||
109 | * |
||
110 | * @return $this |
||
111 | */ |
||
112 | 72 | public function setDisabled($disabled) |
|
113 | { |
||
114 | 72 | $this->disabled = (bool) $disabled; |
|
115 | |||
116 | 72 | if ($this->disabled) { |
|
117 | 4 | $this->attributes = $this->attributes->reject(function ($value, $key) { |
|
118 | return Str::startsWith($key, ['data-']); |
||
119 | 4 | }); |
|
120 | } |
||
121 | |||
122 | 72 | return $this; |
|
123 | } |
||
124 | |||
125 | /** |
||
126 | * Forget attribute(s). |
||
127 | * |
||
128 | * @param string|array $attributes |
||
129 | * |
||
130 | * @return $this |
||
131 | */ |
||
132 | 8 | public function forgetAttribute($attributes) |
|
138 | |||
139 | /** |
||
140 | * Set the size. |
||
141 | * |
||
142 | * @param string $size |
||
143 | * |
||
144 | * @return $this |
||
145 | */ |
||
146 | 8 | public function size($size) |
|
152 | |||
153 | /** |
||
154 | * Show/Hide the title. |
||
155 | * |
||
156 | * @param bool $withTitle |
||
157 | * |
||
158 | * @return $this |
||
159 | */ |
||
160 | 4 | public function withTitle($withTitle) |
|
166 | |||
167 | /** |
||
168 | * Show/Hide the icon. |
||
169 | * |
||
170 | * @var bool $withIcon |
||
171 | * |
||
172 | * @return $this |
||
173 | */ |
||
174 | 12 | public function withIcon($withIcon) |
|
180 | |||
181 | /** |
||
182 | * Enable/Disable the tooltip. |
||
183 | * |
||
184 | * @param bool $withTooltip |
||
185 | * |
||
186 | * @return $this |
||
187 | */ |
||
188 | 8 | public function withTooltip($withTooltip) |
|
194 | |||
195 | /** |
||
196 | * Show only the icon and the title as tooltip. |
||
197 | * |
||
198 | * @return $this |
||
199 | */ |
||
200 | 4 | public function onlyIcon() |
|
204 | |||
205 | /** |
||
206 | * Add loading text attribute. |
||
207 | * |
||
208 | * @return $this |
||
209 | */ |
||
210 | 4 | public function withLoadingText() |
|
214 | |||
215 | /* ----------------------------------------------------------------- |
||
216 | | Main Methods |
||
217 | | ----------------------------------------------------------------- |
||
218 | */ |
||
219 | |||
220 | /** |
||
221 | * Get the string content for the link instance. |
||
222 | * |
||
223 | * @return string |
||
224 | */ |
||
225 | 4 | public function __toString() |
|
229 | |||
230 | /* ----------------------------------------------------------------- |
||
231 | | Other Methods |
||
232 | | ----------------------------------------------------------------- |
||
233 | */ |
||
234 | |||
235 | /** |
||
236 | * Render the value. |
||
237 | * |
||
238 | * @return string |
||
239 | */ |
||
240 | 72 | protected function renderValue() |
|
249 | |||
250 | /** |
||
251 | * Render the icon. |
||
252 | * |
||
253 | * @return string |
||
254 | */ |
||
255 | 64 | protected function renderIcon() |
|
259 | |||
260 | /** |
||
261 | * Get the action title. |
||
262 | * |
||
263 | * @return string |
||
264 | */ |
||
265 | 68 | protected function getTitle() |
|
269 | |||
270 | /** |
||
271 | * Get the icon. |
||
272 | * |
||
273 | * @return string|null |
||
274 | */ |
||
275 | 64 | protected function getIcon() |
|
279 | |||
280 | /** |
||
281 | * Get the button class. |
||
282 | * |
||
283 | * @return string |
||
284 | */ |
||
285 | 72 | protected function getStyleClass() |
|
295 | |||
296 | /** |
||
297 | * Get the base style class. |
||
298 | * |
||
299 | * @return string |
||
300 | */ |
||
301 | 72 | protected function getBaseStyleClass() |
|
305 | |||
306 | /** |
||
307 | * Get the link size. |
||
308 | * |
||
309 | * @return string|null |
||
310 | */ |
||
311 | 72 | protected function getSize() |
|
315 | |||
316 | /** |
||
317 | * Get the link color. |
||
318 | * |
||
319 | * @return string |
||
320 | */ |
||
321 | 72 | protected function getColor() |
|
327 | |||
328 | /** |
||
329 | * Get the value from config. |
||
330 | * |
||
331 | * @param string $key |
||
332 | * |
||
333 | * @return mixed |
||
334 | */ |
||
335 | abstract protected function getConfig($key); |
||
336 | } |
||
337 |