@@ -10,6 +10,7 @@ class Button
1010 protected string $ icon = '' ;
1111 protected string $ label = '' ;
1212 protected array $ attributes = [];
13+ protected string $ tooltip = '' ;
1314
1415 /**
1516 * Instanciate a new button.
@@ -32,6 +33,28 @@ 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 mixed $args
41+ * @param string $icon
42+ * @param string $tooltip
43+ * @param string $color
44+ * @param array $attributes
45+ * @return string
46+ */
47+ public static function custom (string $ route , mixed $ args = [], string $ icon = '' , string $ tooltip = '' , string $ color = 'default ' , array $ attributes = []): string
48+ {
49+ $ button = self ::add ()->route ($ route , $ args )->tooltip ($ tooltip );
50+
51+ if (! empty ($ icon )) {
52+ $ button ->icon ($ icon );
53+ }
54+
55+ return $ button ->color ($ color )->attributes ($ attributes )->make ();
56+ }
57+
3558 /**
3659 * Returns an edit button.
3760 *
@@ -41,7 +64,7 @@ public static function add(string $label = ''): self
4164 */
4265 public static function show (string $ route , $ args = []): string
4366 {
44- return self ::add ()->attributes (['data-action ' => 'dt-show-element ' ])->route ($ route , $ args )->icon ('eye ' )->make ();
67+ return self ::add ()->attributes (['data-action ' => 'dt-show-element ' ])->route ($ route , $ args )->tooltip ( __ ( ' boilerplate::datatable.show ' ))-> icon ('eye ' )->make ();
4568 }
4669
4770 /**
@@ -53,7 +76,7 @@ public static function show(string $route, $args = []): string
5376 */
5477 public static function edit (string $ route , $ args = []): string
5578 {
56- return self ::add ()->attributes (['data-action ' => 'dt-edit-element ' ])->route ($ route , $ args )->color ('primary ' )->icon ('pencil-alt ' )->make ();
79+ return self ::add ()->attributes (['data-action ' => 'dt-edit-element ' ])->route ($ route , $ args )->tooltip ( __ ( ' boilerplate::datatable.edit ' ))-> color ('primary ' )->icon ('pencil-alt ' )->make ();
5780 }
5881
5982 /**
@@ -68,6 +91,7 @@ public static function delete(string $route, $args = []): string
6891 return self ::add ()
6992 ->route ($ route , $ args )
7093 ->attributes (['data-action ' => 'dt-delete-element ' ])
94+ ->tooltip (__ ('boilerplate::datatable.delete ' ))
7195 ->color ('danger ' )
7296 ->icon ('trash ' )
7397 ->make ();
@@ -161,15 +185,26 @@ public function link(string $href): self
161185 return $ this ;
162186 }
163187
188+ /**
189+ * Sets tooltip of button.
190+ *
191+ * @param string $tooltip
192+ * @return $this
193+ */
194+ public function tooltip (string $ tooltip ): self
195+ {
196+ $ this ->tooltip = $ tooltip ;
197+
198+ return $ this ;
199+ }
200+
164201 /**
165202 * Renders the button.
166203 *
167204 * @return string
168205 */
169206 public function make (): string
170207 {
171- $ str = '<a href="%s" class="btn btn-sm btn-%s ml-1%s" %s>%s%s</a> ' ;
172-
173208 if (! empty ($ this ->label ) && ! empty ($ this ->icon )) {
174209 $ this ->label = $ this ->label .' ' ;
175210 }
@@ -182,6 +217,9 @@ public function make(): string
182217 return sprintf ('%s="%s" ' , $ k , $ this ->attributes [$ k ]);
183218 }, array_keys ($ this ->attributes )));
184219
185- return sprintf ($ str , $ this ->href , $ this ->color , $ this ->class , $ attributes , $ this ->label , $ this ->icon );
220+ $ tooltip = ! empty ($ this ->tooltip ) ? sprintf (' data-toggle="tooltip" title="%s" ' , e ($ this ->tooltip )) : '' ;
221+ $ str = '<a href="%s"%s class="btn btn-sm btn-%s ml-1%s" %s>%s%s</a> ' ;
222+
223+ return sprintf ($ str , $ this ->href , $ tooltip , $ this ->color , $ this ->class , $ attributes , $ this ->label , $ this ->icon );
186224 }
187225}
0 commit comments