1 | <?php namespace Arcanesoft\Core\Helpers\UI; |
||
12 | class Link implements Htmlable |
||
13 | { |
||
14 | /* ----------------------------------------------------------------- |
||
15 | | Traits |
||
16 | | ----------------------------------------------------------------- |
||
17 | */ |
||
18 | use LinkTraits\ActivateLinks, |
||
19 | LinkTraits\AddLinks, |
||
20 | LinkTraits\DeleteLinks, |
||
21 | LinkTraits\DetachLinks, |
||
22 | LinkTraits\EditLinks, |
||
23 | LinkTraits\RestoreLinks, |
||
24 | LinkTraits\ShowLinks; |
||
25 | |||
26 | /* ----------------------------------------------------------------- |
||
27 | | Properties |
||
28 | | ----------------------------------------------------------------- |
||
29 | */ |
||
30 | /** @var string */ |
||
31 | protected $action; |
||
32 | |||
33 | /** @var string */ |
||
34 | protected $url; |
||
35 | |||
36 | /** @var \Illuminate\Support\Collection */ |
||
37 | protected $attributes; |
||
38 | |||
39 | /** @var bool */ |
||
40 | protected $disabled; |
||
41 | |||
42 | /** @var string */ |
||
43 | protected $size = 'md'; |
||
44 | |||
45 | /** @var bool */ |
||
46 | public $withTitle = true; |
||
47 | |||
48 | /** @var bool */ |
||
49 | protected $withIcon = true; |
||
50 | |||
51 | /** @var bool */ |
||
52 | protected $withTooltip = true; |
||
53 | |||
54 | /* ----------------------------------------------------------------- |
||
55 | | Constructor |
||
56 | | ----------------------------------------------------------------- |
||
57 | */ |
||
58 | /** |
||
59 | * LinkElement constructor. |
||
60 | * |
||
61 | * @param string $action |
||
62 | * @param string $url |
||
63 | * @param array $attributes |
||
64 | * @param bool $disabled |
||
65 | */ |
||
66 | 75 | public function __construct($action, $url, array $attributes = [], $disabled = false) |
|
74 | |||
75 | /* ----------------------------------------------------------------- |
||
76 | | Getters & Setters |
||
77 | | ----------------------------------------------------------------- |
||
78 | */ |
||
79 | /** |
||
80 | * Get the action title. |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | 63 | protected function getActionTitle() |
|
88 | |||
89 | /** |
||
90 | * Set the attributes. |
||
91 | * |
||
92 | * @param array $attributes |
||
93 | * |
||
94 | * @return self |
||
95 | */ |
||
96 | 75 | public function setAttributes(array $attributes) |
|
108 | |||
109 | /** |
||
110 | * Set an attribute. |
||
111 | * |
||
112 | * @param string $key |
||
113 | * @param mixed $value |
||
114 | * |
||
115 | * @return self |
||
116 | */ |
||
117 | 6 | public function setAttribute($key, $value) |
|
123 | |||
124 | /** |
||
125 | * Set the size. |
||
126 | * |
||
127 | * @param string $size |
||
128 | * |
||
129 | * @return self |
||
130 | */ |
||
131 | 75 | public function size($size) |
|
137 | |||
138 | /** |
||
139 | * @param bool $withTitle |
||
140 | * |
||
141 | * @return self |
||
142 | */ |
||
143 | 72 | public function withTitle($withTitle) |
|
149 | |||
150 | /** |
||
151 | * Show/Hide the icon. |
||
152 | * |
||
153 | * @var bool $icon |
||
154 | * |
||
155 | * @return self |
||
156 | */ |
||
157 | 18 | public function icon($withIcon) |
|
163 | |||
164 | /** |
||
165 | * Enable the tooltip. |
||
166 | * |
||
167 | * @param bool $withTooltip |
||
168 | * |
||
169 | * @return self |
||
170 | */ |
||
171 | 24 | public function tooltip($withTooltip) |
|
177 | |||
178 | /** |
||
179 | * Show only the icon and the title as tooltip. |
||
180 | * |
||
181 | * @return self |
||
182 | */ |
||
183 | public function onlyIcon() |
||
187 | |||
188 | /* ----------------------------------------------------------------- |
||
189 | | Main Methods |
||
190 | | ----------------------------------------------------------------- |
||
191 | */ |
||
192 | /** |
||
193 | * Make link instance. |
||
194 | * |
||
195 | * @param string $action |
||
196 | * @param string $url |
||
197 | * @param array $attributes |
||
198 | * @param bool $disabled |
||
199 | * |
||
200 | * @return self |
||
201 | */ |
||
202 | 75 | public static function make($action, $url, array $attributes = [], $disabled = false) |
|
206 | |||
207 | /* ----------------------------------------------------------------- |
||
208 | | Other Functions |
||
209 | | ----------------------------------------------------------------- |
||
210 | */ |
||
211 | /** |
||
212 | * Get content as a string of HTML. |
||
213 | * |
||
214 | * @return string |
||
215 | */ |
||
216 | 75 | public function toHtml() |
|
220 | |||
221 | /** |
||
222 | * Render the link value. |
||
223 | * |
||
224 | * @return string |
||
225 | */ |
||
226 | 75 | protected function renderValue() |
|
232 | |||
233 | /** |
||
234 | * Render the icon. |
||
235 | * |
||
236 | * @return string |
||
237 | */ |
||
238 | 75 | protected function renderIcon() |
|
242 | |||
243 | /** |
||
244 | * Render the attributes. |
||
245 | * |
||
246 | * @return string |
||
247 | */ |
||
248 | 75 | protected function renderAttributes() |
|
265 | |||
266 | /** |
||
267 | * Get the link class. |
||
268 | * |
||
269 | * @return string |
||
270 | */ |
||
271 | 75 | protected function getLinkClass() |
|
275 | |||
276 | /** |
||
277 | * Get the link color. |
||
278 | * |
||
279 | * @return string |
||
280 | */ |
||
281 | 75 | protected function getLinkColor() |
|
287 | |||
288 | /** |
||
289 | * Get the link size. |
||
290 | * |
||
291 | * @return string|null |
||
292 | */ |
||
293 | 75 | protected function getLinkSize() |
|
297 | |||
298 | /** |
||
299 | * Get the icon. |
||
300 | * |
||
301 | * @return string|null |
||
302 | */ |
||
303 | 75 | protected function getLinkIcon() |
|
307 | } |
||
308 |