Skip to content

Commit 8ebf469

Browse files
committed
CVA apply function accept null arguments
1 parent 2ddc47b commit 8ebf469

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/TwigComponent/src/CVA.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public function __construct(
3939
) {
4040
}
4141

42-
public function apply(array $recipes, string ...$classes): string
42+
public function apply(array $recipes, ?string ...$classes): string
4343
{
44-
return trim($this->resolve($recipes).' '.implode(' ', $classes));
44+
return trim($this->resolve($recipes).' '.implode(' ', array_filter($classes)));
4545
}
4646

4747
public function resolve(array $recipes): string

src/TwigComponent/tests/Unit/CVATest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,29 @@ public function testApply(): void
5252
$this->assertEquals('font-semibold border rounded text-primary text-sm text-red-500', $recipe->apply(['colors' => 'primary', 'sizes' => 'sm']));
5353
}
5454

55+
public function testApplyWithNullString(): void
56+
{
57+
$recipe = new CVA('font-semibold border rounded', [
58+
'colors' => [
59+
'primary' => 'text-primary',
60+
'secondary' => 'text-secondary',
61+
],
62+
'sizes' => [
63+
'sm' => 'text-sm',
64+
'md' => 'text-md',
65+
'lg' => 'text-lg',
66+
],
67+
], [
68+
[
69+
'colors' => ['primary'],
70+
'sizes' => ['sm'],
71+
'class' => 'text-red-500',
72+
],
73+
]);
74+
75+
$this->assertEquals('font-semibold border rounded text-primary text-sm text-red-500 flex justify-center', $recipe->apply(['colors' => 'primary', 'sizes' => 'sm'], 'flex', null, 'justify-center'));
76+
}
77+
5578
public static function recipeProvider(): iterable
5679
{
5780
yield 'base null' => [

0 commit comments

Comments
 (0)