Work on badge logic

This commit is contained in:
2024-08-08 14:35:07 +01:00
parent 36f3267fc6
commit ff8f7b9f79

View File

@@ -10,15 +10,19 @@ use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
#[AsTwigComponent(name: 'Pcm:Badge', template: "@PcmBadge/components/Badge.html.twig")] #[AsTwigComponent(name: 'Pcm:Badge', template: "@PcmBadge/components/Badge.html.twig")]
final class Badge final class Badge
{ {
public string $baseClasses = 'rounded text-xs px-2 py-1 border min-w-max'; public string $baseClasses = 'rounded max-w-max text-xs px-2 py-1 border min-w-max';
public string $finalClasses = ''; public string $finalClasses = '';
public function mount(BadgeableInterface $object): void /**
* @param BadgeableInterface $object The object to be converted into a badge
* @param string $class Extra classes you want to add to the badge template
*/
public function mount(BadgeableInterface $object, string $class = ''): void
{ {
$palette = $object->getBadgeColour()->getPalette(); $palette = $object->getBadgeColour()->getPalette();
$this->finalClasses = sprintf('text-white %s %s %s', $palette->borderColourClass, $palette->backgroundColourClass, $this->baseClasses); $this->finalClasses = sprintf('text-white %s %s %s %s', $palette->borderColourClass, $palette->backgroundColourClass, $this->baseClasses, $class);
} }
} }