new: [helper:boostrap-helper] Added support of badge

pull/40/head
mokaddem 2021-03-10 09:28:33 +01:00
parent fb60fd59a2
commit b55c1b813f
1 changed files with 48 additions and 1 deletions

View File

@ -71,6 +71,13 @@ class BootstrapHelper extends Helper
$bsButton = new BoostrapButton($options);
return $bsButton->button();
}
public function badge($options)
{
$bsBadge = new BoostrapBadge($options);
return $bsBadge->badge();
}
}
class BootstrapGeneric
@ -643,4 +650,44 @@ class BoostrapButton extends BootstrapGeneric {
{
return !is_null($this->options['html']) ? $this->options['html'] : $this->options['text'];
}
}
}
class BoostrapBadge extends BootstrapGeneric {
private $defaultOptions = [
'text' => '',
'variant' => 'primary',
'pill' => false,
'title' => ''
];
function __construct($options) {
$this->allowedOptionValues = [
'variant' => BootstrapGeneric::$variants,
];
$this->processOptions($options);
}
private function processOptions($options)
{
$this->options = array_merge($this->defaultOptions, $options);
$this->checkOptionValidity();
}
public function badge()
{
return $this->genBadge();
}
private function genBadge()
{
$html = $this->genNode('span', [
'class' => [
'badge',
"badge-{$this->options['variant']}",
$this->options['pill'] ? 'badge-pill' : '',
],
'title' => $this->options['title']
], h($this->options['text']));
return $html;
}
}