Update badge logic
This commit is contained in:
@@ -6,6 +6,7 @@ namespace Pcm\BadgeBundle\Twig\Component;
|
|||||||
|
|
||||||
use Pcm\BadgeBundle\Enum\BadgeColour;
|
use Pcm\BadgeBundle\Enum\BadgeColour;
|
||||||
use Pcm\BadgeBundle\Interface\BadgeableInterface;
|
use Pcm\BadgeBundle\Interface\BadgeableInterface;
|
||||||
|
use Symfony\UX\Icons\Registry\IconifyOnDemandRegistry;
|
||||||
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
|
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
|
||||||
use TailwindMerge\TailwindMerge;
|
use TailwindMerge\TailwindMerge;
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ final class Badge
|
|||||||
public ?string $label = null;
|
public ?string $label = null;
|
||||||
public ?string $icon = null;
|
public ?string $icon = null;
|
||||||
|
|
||||||
public function __construct(private string $baseClasses)
|
public function __construct(private string $baseClasses, private IconifyOnDemandRegistry $reg)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,9 +36,14 @@ final class Badge
|
|||||||
if (!$icon) {
|
if (!$icon) {
|
||||||
$this->icon = null;
|
$this->icon = null;
|
||||||
} else if ("1" === $icon) {
|
} else if ("1" === $icon) {
|
||||||
|
if (null === $obj) {
|
||||||
|
throw new \RuntimeException("Missing icon name.");
|
||||||
|
}
|
||||||
|
|
||||||
$this->icon = $obj->getBadgeIcon();
|
$this->icon = $obj->getBadgeIcon();
|
||||||
|
|
||||||
if (null === $this->icon) {
|
if (null === $this->icon) {
|
||||||
throw new \RuntimeException("Missing an icon name.");
|
throw new \RuntimeException("Missing icon name.");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->icon = $icon;
|
$this->icon = $icon;
|
||||||
@@ -72,15 +78,17 @@ final class Badge
|
|||||||
$merger = TailwindMerge::instance();
|
$merger = TailwindMerge::instance();
|
||||||
|
|
||||||
if (true === $outline) {
|
if (true === $outline) {
|
||||||
$classes = sprintf('bg-white %s/30 %s %s %s', $palette->borderColourClass, $palette->textColourClass, $this->baseClasses, $class);
|
$glossyClass = $glossy
|
||||||
} else {
|
? 'bg-[image:radial-gradient(ellipse_at_top_left,color-mix(in_srgb,currentColor_5%,transparent),transparent_65%),linear-gradient(to_bottom,transparent,color-mix(in_srgb,currentColor_4%,transparent))]'
|
||||||
if ($glossy) {
|
: '';
|
||||||
$glossy = 'bg-[image:radial-gradient(ellipse_at_top_left,rgba(255,255,255,0.25),transparent_65%),linear-gradient(to_bottom,rgba(255,255,255,0.05),rgba(0,0,0,0.12))]';
|
|
||||||
} else {
|
|
||||||
$glossy = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$classes = sprintf('text-white border-transparent %s %s %s %s', $palette->backgroundColourClass, $glossy, $this->baseClasses, $class);
|
$classes = sprintf('bg-white %s/50 %s %s %s %s', $palette->borderColourClass, $palette->textColourClass, $glossyClass, $this->baseClasses, $class);
|
||||||
|
} else {
|
||||||
|
$glossyClass = $glossy
|
||||||
|
? 'bg-[image:radial-gradient(ellipse_at_top_left,rgba(255,255,255,0.25),transparent_65%),linear-gradient(to_bottom,rgba(255,255,255,0.05),rgba(0,0,0,0.12))]'
|
||||||
|
: '';
|
||||||
|
|
||||||
|
$classes = sprintf('text-white border-transparent %s %s %s %s', $palette->backgroundColourClass, $glossyClass, $this->baseClasses, $class);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->icon !== null) {
|
if ($this->icon !== null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user