Skip to content

Commit 2562a6c

Browse files
committed
bug #1610 [Twig] allow compound variant value to be string (kbond)
This PR was merged into the 2.x branch. Discussion ---------- [Twig] allow compound variant value to be string | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Issues | n/a | License | MIT According to https://cva.style/docs/getting-started/variants#compound-variants, the compound variant values can be strings. /cc `@WebMamba` Commits ------- f6003aa [Twig] allow compound variant value to be string
2 parents 272d17e + f6003aa commit 2562a6c

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/TwigComponent/src/CVA.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ public function resolve(array $recipes): string
7777
break;
7878
}
7979

80+
if (!\is_array($compoundValues)) {
81+
$compoundValues = [$compoundValues];
82+
}
83+
8084
if (!\in_array($recipes[$compoundName], $compoundValues)) {
8185
$isCompound = false;
8286
break;

src/TwigComponent/tests/Unit/CVATest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public static function recipeProvider(): iterable
221221
],
222222
'compounds' => [
223223
[
224-
'colors' => ['primary'],
224+
'colors' => 'primary',
225225
'sizes' => ['sm'],
226226
'class' => 'text-red-500',
227227
],
@@ -361,7 +361,7 @@ public static function recipeProvider(): iterable
361361
'compounds' => [
362362
[
363363
'colors' => ['danger', 'secondary'],
364-
'sizes' => ['sm'],
364+
'sizes' => 'sm',
365365
'class' => 'text-red-500',
366366
],
367367
],

0 commit comments

Comments
 (0)