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 f8a2a8c commit 88c7f6a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/Map/src/Twig/MapExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\UX\Map\Twig;

use Symfony\UX\Map\Renderer\Renderers;
use Twig\DeprecatedCallableInfo;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

Expand All @@ -27,9 +28,9 @@ public function getFunctions(): array
return [
new TwigFunction('render_map', [Renderers::class, 'renderMap'], [
'is_safe' => ['html'],
'deprecated' => '2.20',
'deprecating_package' => 'symfony/ux-map',
'alternative' => 'ux_map',
...(class_exists(DeprecatedCallableInfo::class)
? ['deprecation_info' => new DeprecatedCallableInfo('symfony/ux-map', '2.20', 'ux_map')]
: ['deprecated' => '2.20', 'deprecating_package' => 'symfony/ux-map', 'alternative' => 'ux_map']),
]),
new TwigFunction('ux_map', [Renderers::class, 'renderMap'], ['is_safe' => ['html']]),
];
Expand Down
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 provided by the ``twig/html-extra:^3.12`` package under the name `html_cva`_.

`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 TwigComponent 2.20, use CVA from the "twig/html-extra:^3.12.0" package instead.
*/
final class CVA
{
Expand Down
8 changes: 7 additions & 1 deletion src/TwigComponent/src/Twig/ComponentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ public function getFunctions(): array
{
return [
new TwigFunction('component', [$this, 'render'], ['is_safe' => ['all']]),
new TwigFunction('cva', [$this, 'cva']),
new TwigFunction('cva', [$this, 'cva'], [
...(class_exists(DeprecatedCallableInfo::class)
? ['deprecation_info' => new DeprecatedCallableInfo('symfony/ux-twig-component', '2.20', 'html_cva', 'twig/html-extra')]
: ['deprecated' => '2.20', 'deprecating_package' => 'symfony/ux-twig-component', 'alternative' => 'html_cva']),
]),
];
}

Expand Down Expand Up @@ -105,6 +109,8 @@ public function finishEmbeddedComponentRender(): void
*/
public function cva(array $cva): CVA
{
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.');

return new CVA(
$cva['base'] ?? '',
$cva['variants'] ?? [],
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 88c7f6a

Please sign in to comment.