44
55class Button
66{
7- protected $ class = '' ;
8- protected $ color = 'default ' ;
9- protected $ href = '# ' ;
10- protected $ icon = '' ;
11- protected $ label = '' ;
12- protected $ attributes = [];
7+ protected string $ class = '' ;
8+ protected string $ color = 'default ' ;
9+ protected string $ href = '# ' ;
10+ protected string $ icon = '' ;
11+ protected string $ label = '' ;
12+ protected array $ attributes = [];
13+ protected string $ tooltip = '' ;
1314
1415 /**
1516 * Instanciate a new button.
@@ -32,6 +33,23 @@ public static function add(string $label = ''): self
3233 return new static ($ label );
3334 }
3435
36+ /**
37+ * Returns a custom button.
38+ *
39+ * @param string $route
40+ * @param array|string $args
41+ * @param string $tooltip
42+ * @param string $color
43+ * @param string $icon
44+ * @param array $attributes
45+ * @return string
46+ */
47+ public static function custom (string $ route , array |string $ args = [], string $ tooltip = '' , string $ color = 'default ' , string $ icon = '' , array $ attributes = []): string
48+ {
49+ return self ::add ()->route ($ route , $ args )->tooltip ($ tooltip )->color ($ color )->icon ($ icon )->attributes ($ attributes )->make ();
50+ }
51+
52+
3553 /**
3654 * Returns an edit button.
3755 *
@@ -168,7 +186,7 @@ public function link(string $href): self
168186 */
169187 public function make (): string
170188 {
171- $ str = '<a href="%s" class="btn btn-sm btn-%s ml-1%s" %s>%s%s</a> ' ;
189+ $ str = '<a href="%s" title="%s" class="btn btn-sm btn-%s ml-1%s" %s>%s%s</a> ' ;
172190
173191 if (! empty ($ this ->label ) && ! empty ($ this ->icon )) {
174192 $ this ->label = $ this ->label .' ' ;
@@ -182,6 +200,19 @@ public function make(): string
182200 return sprintf ('%s="%s" ' , $ k , $ this ->attributes [$ k ]);
183201 }, array_keys ($ this ->attributes )));
184202
185- return sprintf ($ str , $ this ->href , $ this ->color , $ this ->class , $ attributes , $ this ->label , $ this ->icon );
203+ return sprintf ($ str , $ this ->href , $ this ->tooltip , $ this ->color , $ this ->class , $ attributes , $ this ->label , $ this ->icon );
204+ }
205+
206+ /**
207+ * Sets tooltip of button.
208+ *
209+ * @param string $tooltip
210+ * @return $this
211+ */
212+ public function tooltip (string $ tooltip ): self
213+ {
214+ $ this ->tooltip = $ tooltip ;
215+
216+ return $ this ;
186217 }
187218}
0 commit comments