From f6003aa26a27e47f92db48fee9514c5d7bcfb81c Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Mon, 11 Mar 2024 13:17:34 -0400 Subject: [PATCH] [Twig] allow compound variant value to be string --- src/TwigComponent/src/CVA.php | 4 ++++ src/TwigComponent/tests/Unit/CVATest.php | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/TwigComponent/src/CVA.php b/src/TwigComponent/src/CVA.php index b61188c8feb..23709b3216f 100644 --- a/src/TwigComponent/src/CVA.php +++ b/src/TwigComponent/src/CVA.php @@ -77,6 +77,10 @@ public function resolve(array $recipes): string break; } + if (!\is_array($compoundValues)) { + $compoundValues = [$compoundValues]; + } + if (!\in_array($recipes[$compoundName], $compoundValues)) { $isCompound = false; break; diff --git a/src/TwigComponent/tests/Unit/CVATest.php b/src/TwigComponent/tests/Unit/CVATest.php index e3b5e1652b4..46b602daa22 100644 --- a/src/TwigComponent/tests/Unit/CVATest.php +++ b/src/TwigComponent/tests/Unit/CVATest.php @@ -221,7 +221,7 @@ public static function recipeProvider(): iterable ], 'compounds' => [ [ - 'colors' => ['primary'], + 'colors' => 'primary', 'sizes' => ['sm'], 'class' => 'text-red-500', ], @@ -361,7 +361,7 @@ public static function recipeProvider(): iterable 'compounds' => [ [ 'colors' => ['danger', 'secondary'], - 'sizes' => ['sm'], + 'sizes' => 'sm', 'class' => 'text-red-500', ], ],