You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/TwigComponent/doc/index.rst
+23-29
Original file line number
Diff line number
Diff line change
@@ -1061,11 +1061,15 @@ Exclude specific attributes:
1061
1061
Component with Complex Variants (CVA)
1062
1062
-------------------------------------
1063
1063
1064
-
CVA (Class Variant Authority) is a concept from the JS world (https://cva.style/docs/getting-started/variants).
1065
-
It's a concept used by the famous shadcn/ui library (https://ui.shadcn.com).
1064
+
.. versionadded:: 2.16
1065
+
1066
+
The ``CVA`` function was added in TwigComponents 2.16.
1067
+
1068
+
[CVA (Class Variant Authority)](https://cva.style/docs/getting-started/variants) is a concept from the JavaScript
1069
+
world and used by the well-known [shadcn/ui](https://ui.shadcn.com).
1066
1070
CVA allows you to display a component with different variants (color, size, etc.),
1067
1071
to create highly reusable and customizable components.
1068
-
You can use the cvafunction to define variants for your component.
1072
+
This is powered by a ``cva()`` Twig function where you define ``base`` classes that should always be present and then different ``variants`` and the corresponding classes:
1069
1073
The cva function take as argument an array key-value pairs.
1070
1074
The base key allow you define a set of classes commune to all variants.
1071
1075
In the variants key you define the different variants of your component.
@@ -1095,9 +1099,11 @@ In the variants key you define the different variants of your component.
1095
1099
{% block content %}{% endblock %}
1096
1100
</div>
1097
1101
1102
+
Then use the color and size variants to select the classes needed:
1098
1103
1099
-
{# index.html.twig #}
1104
+
.. code-block:: html+twig
1100
1105
1106
+
{# index.html.twig #}
1101
1107
<twig:Alert color="red" size="lg">
1102
1108
<div>My content</div>
1103
1109
</twig:Alert>
@@ -1108,18 +1114,18 @@ In the variants key you define the different variants of your component.
0 commit comments