Skip to content

Commit fc818a7

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

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-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 called `html_cva`_ and is now part of ``twig/html-extra:^3.12`` package.
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 Symfony 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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\UX\TwigComponent\ComponentRenderer;
1717
use Symfony\UX\TwigComponent\CVA;
1818
use Symfony\UX\TwigComponent\Event\PreRenderEvent;
19+
use Twig\DeprecatedCallableInfo;
1920
use Twig\Error\RuntimeError;
2021
use Twig\Extension\AbstractExtension;
2122
use Twig\TwigFunction;
@@ -42,7 +43,15 @@ public function getFunctions(): array
4243
{
4344
return [
4445
new TwigFunction('component', [$this, 'render'], ['is_safe' => ['all']]),
45-
new TwigFunction('cva', [$this, 'cva']),
46+
new TwigFunction('cva', [$this, 'cva'], [
47+
'deprecation_info' => new DeprecatedCallableInfo(
48+
package: 'symfony/ux-twig-component',
49+
version: '2.20',
50+
altName: 'html_cva',
51+
altPackage: 'twig/html-extra',
52+
altVersion: '3.12.0',
53+
),
54+
]),
4655
];
4756
}
4857

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)