new: [bootstrap-helper:badge] Added support of ID and icon

develop-unstable
Sami Mokaddem 2022-12-02 09:49:37 +01:00
parent 6e6107dc46
commit c49e3ac508
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 20 additions and 2 deletions

View File

@ -13,6 +13,7 @@ use App\View\Helper\BootstrapGeneric;
* - html: The HTML content of the badge * - html: The HTML content of the badge
* - variant: The Bootstrap variant of the badge * - variant: The Bootstrap variant of the badge
* - pill: Should the badge have a Bootstrap pill style * - pill: Should the badge have a Bootstrap pill style
* - icon: Should the button have an icon right before the text
* - title: The title of the badge * - title: The title of the badge
* - class: Additional class to add to the button * - class: Additional class to add to the button
* *
@ -26,10 +27,12 @@ use App\View\Helper\BootstrapGeneric;
class BootstrapBadge extends BootstrapGeneric class BootstrapBadge extends BootstrapGeneric
{ {
private $defaultOptions = [ private $defaultOptions = [
'id' => '',
'text' => '', 'text' => '',
'html' => null, 'html' => null,
'variant' => 'primary', 'variant' => 'primary',
'pill' => false, 'pill' => false,
'icon' => false,
'title' => '', 'title' => '',
'class' => [], 'class' => [],
]; ];
@ -63,8 +66,23 @@ class BootstrapBadge extends BootstrapGeneric
self::getBGAndTextClassForVariant($this->options['variant']), self::getBGAndTextClassForVariant($this->options['variant']),
$this->options['pill'] ? 'rounded-pill' : '', $this->options['pill'] ? 'rounded-pill' : '',
]), ]),
'title' => $this->options['title'] 'title' => $this->options['title'],
], $this->options['html'] ?? h($this->options['text'])); 'id' => $this->options['id'] ?? '',
], [
$this->genIcon(),
$this->options['html'] ?? h($this->options['text'])
]);
return $html; return $html;
} }
private function genIcon(): string
{
if (!empty($this->options['icon'])) {
$bsIcon = new BootstrapIcon($this->options['icon'], [
'class' => [(!empty($this->options['text']) ? 'me-1' : '')]
]);
return $bsIcon->icon();
}
return '';
}
} }