Test adding colour parameter to override object colour
This commit is contained in:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pcm\BadgeBundle\Twig\Component;
|
||||
|
||||
use Pcm\BadgeBundle\Enum\Badge as EnumBadge;
|
||||
use Pcm\BadgeBundle\Interface\BadgeableInterface;
|
||||
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
|
||||
use TailwindMerge\TailwindMerge;
|
||||
@@ -11,7 +12,9 @@ use TailwindMerge\TailwindMerge;
|
||||
#[AsTwigComponent(name: 'Pcm:Badge', template: "@PcmBadge/Badge.html.twig")]
|
||||
final class Badge
|
||||
{
|
||||
public string $finalClasses = '';
|
||||
public string $finalClasses;
|
||||
|
||||
private ?string $colour;
|
||||
|
||||
public function __construct(private string $baseClasses)
|
||||
{
|
||||
@@ -21,9 +24,17 @@ final class Badge
|
||||
* @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
|
||||
public function mount(BadgeableInterface $object, string $class = '', string $colour = null): void
|
||||
{
|
||||
if (null !== $colour) {
|
||||
|
||||
if (!in_array($colour, EnumBadge::cases())) {
|
||||
throw new \RuntimeException(sprintf('"%s" is not a valid Badge colour. Available options are: %s', $colour, implode(", ", EnumBadge::cases())));
|
||||
}
|
||||
|
||||
} else {
|
||||
$palette = $object->getBadgeColour()->getPalette();
|
||||
}
|
||||
|
||||
$merger = TailwindMerge::instance();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user