Skip to content

Commit

Permalink
[TwigComponent] Deprecate cva twig function
Browse files Browse the repository at this point in the history
  • Loading branch information
Kocal committed Sep 10, 2024
1 parent 907eb05 commit 9fc807d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/TwigComponent/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,11 @@ Component with Complex Variants (CVA)

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

.. deprecated:: 2.20

The ``cva`` function was deprecated in TwigComponents 2.20, and will be removed in 3.0.
The function is now called `html_cva`_ and is now part of ``twig/html-extra:^3.12`` package.

`CVA (Class Variant Authority)`_ is a concept from the JavaScript world and used
by the well-known `shadcn/ui`_.
CVA allows you to display a component with different variants (color, size, etc.),
Expand Down Expand Up @@ -1763,6 +1768,7 @@ https://symfony.com/doc/current/contributing/code/bc.html
.. _`Passing Blocks to Live Components`: https://symfony.com/bundles/ux-live-component/current/index.html#passing-blocks
.. _`Stimulus controller`: https://symfony.com/bundles/StimulusBundle/current/index.html
.. _`CVA (Class Variant Authority)`: https://cva.style/docs/getting-started/variants
.. _`html_cva`: https://twig.symfony.com/doc/3.x/functions/html_cva.html
.. _`shadcn/ui`: https://ui.shadcn.com
.. _`tales-from-a-dev/twig-tailwind-extra`: https://github.com/tales-from-a-dev/twig-tailwind-extra
.. _`ignore not defined options`: https://symfony.com/doc/current/components/options_resolver.html#ignore-not-defined-options
.. _`ignore not defined options`: https://symfony.com/doc/current/components/options_resolver.html#ignore-not-defined-options
2 changes: 2 additions & 0 deletions src/TwigComponent/src/CVA.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* @author Mathéo Daninos <[email protected]>
*
* @experimental
*
* @deprecated since 2.20, use CVA from the "twig/html-extra:^3.12.0" package instead.
*/
final class CVA
{
Expand Down
11 changes: 10 additions & 1 deletion src/TwigComponent/src/Twig/ComponentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\UX\TwigComponent\ComponentRenderer;
use Symfony\UX\TwigComponent\CVA;
use Symfony\UX\TwigComponent\Event\PreRenderEvent;
use Twig\DeprecatedCallableInfo;
use Twig\Error\RuntimeError;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
Expand All @@ -42,7 +43,15 @@ public function getFunctions(): array
{
return [
new TwigFunction('component', [$this, 'render'], ['is_safe' => ['all']]),
new TwigFunction('cva', [$this, 'cva']),
new TwigFunction('cva', [$this, 'cva'], [
'deprecation_info' => new DeprecatedCallableInfo(
package: 'symfony/ux-twig-component',
version: '2.20',
altName: 'html_cva',
altPackage: 'twig/html-extra',
altVersion: '3.12.0',
),
]),
];
}

Expand Down
4 changes: 4 additions & 0 deletions src/TwigComponent/tests/Unit/CVATest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
use Symfony\UX\TwigComponent\CVA;

/**
* To remove in TwigComponent 3.0.
*
* @author Mathéo Daninos <[email protected]>
*
* @group legacy
*/
class CVATest extends TestCase
{
Expand Down

0 comments on commit 9fc807d

Please sign in to comment.