Skip to content

Commit 1f58821

Browse files
committed
[TwigComponent] Deprecate cva twig function
1 parent 907eb05 commit 1f58821

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

src/TwigComponent/doc/index.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,11 @@ Component with Complex Variants (CVA)
11581158

11591159
The ``cva`` function was added in TwigComponents 2.16.
11601160

1161+
.. deprecated:: 2.20
1162+
1163+
The ``cva`` function was deprecated in TwigComponents 2.20, and will be removed in 3.0.
1164+
The function is now provided by the ``twig/html-extra:^3.12`` package under the name `html_cva`_.
1165+
11611166
`CVA (Class Variant Authority)`_ is a concept from the JavaScript world and used
11621167
by the well-known `shadcn/ui`_.
11631168
CVA allows you to display a component with different variants (color, size, etc.),
@@ -1763,6 +1768,7 @@ https://symfony.com/doc/current/contributing/code/bc.html
17631768
.. _`Passing Blocks to Live Components`: https://symfony.com/bundles/ux-live-component/current/index.html#passing-blocks
17641769
.. _`Stimulus controller`: https://symfony.com/bundles/StimulusBundle/current/index.html
17651770
.. _`CVA (Class Variant Authority)`: https://cva.style/docs/getting-started/variants
1771+
.. _`html_cva`: https://twig.symfony.com/doc/3.x/functions/html_cva.html
17661772
.. _`shadcn/ui`: https://ui.shadcn.com
17671773
.. _`tales-from-a-dev/twig-tailwind-extra`: https://github.com/tales-from-a-dev/twig-tailwind-extra
1768-
.. _`ignore not defined options`: https://symfony.com/doc/current/components/options_resolver.html#ignore-not-defined-options
1774+
.. _`ignore not defined options`: https://symfony.com/doc/current/components/options_resolver.html#ignore-not-defined-options

src/TwigComponent/src/CVA.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
* @author Mathéo Daninos <matheo.daninos@gmail.com>
2525
*
2626
* @experimental
27+
*
28+
* @deprecated since TwigComponent 2.20, use CVA from the "twig/html-extra:^3.12.0" package instead.
2729
*/
2830
final class CVA
2931
{

src/TwigComponent/src/Twig/ComponentExtension.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ public function getFunctions(): array
4242
{
4343
return [
4444
new TwigFunction('component', [$this, 'render'], ['is_safe' => ['all']]),
45-
new TwigFunction('cva', [$this, 'cva']),
45+
new TwigFunction('cva', [$this, 'cva'], [
46+
'deprecated' => '2.20',
47+
'deprecating_package' => 'symfony/ux-twig-component',
48+
'alternative' => 'html_cva',
49+
]),
4650
];
4751
}
4852

@@ -105,6 +109,8 @@ public function finishEmbeddedComponentRender(): void
105109
*/
106110
public function cva(array $cva): CVA
107111
{
112+
trigger_deprecation('symfony/ux-twig-component', '2.20', 'Twig Function "cva" is deprecated; use "html_cva" from the "twig/html-extra" package (available since version 3.12) instead.');
113+
108114
return new CVA(
109115
$cva['base'] ?? '',
110116
$cva['variants'] ?? [],

src/TwigComponent/tests/Unit/CVATest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
use Symfony\UX\TwigComponent\CVA;
1616

1717
/**
18+
* To remove in TwigComponent 3.0.
19+
*
1820
* @author Mathéo Daninos <matheo.daninos@gmail.com>
21+
*
22+
* @group legacy
1923
*/
2024
class CVATest extends TestCase
2125
{

0 commit comments

Comments
 (0)