Skip to content

Commit a6bb1df

Browse files
smnandreKocal
authored andcommitted
Add UPGRADE-3.0.md file
1 parent d07eef3 commit a6bb1df

File tree

4 files changed

+158
-117
lines changed

4 files changed

+158
-117
lines changed

UPGRADE-3.0.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# UPGRADE FROM `2.x` TO `3.0`
2+
3+
Symfony UX follows Symfony's release process, 2.x and 3.0 have the same
4+
features, but Symfony UX 3.0 doesn't include any deprecated features. To
5+
upgrade, make sure to resolve all deprecation notices. Read more about this in
6+
the [Symfony documentation](https://symfony.com/doc/6.4/setup/upgrade_major.html#upgrade-major-symfony-deprecations).
7+
8+
> [!NOTE]
9+
> Requires PHP `8.2` or higher.
10+
>
11+
> Requires Symfony `6.4` or higher.
12+
13+
## LazyImage
14+
15+
* The package has been removed, see the [previous README](https://raw.githubusercontent.com/symfony/ux/refs/heads/2.x/src/LazyImage/README.md)
16+
for migration steps
17+
18+
## LiveComponent
19+
20+
* Remove `csrf` argument from `AsLiveComponent` in favor of same-origin/CORS:
21+
```diff
22+
- #[AsLiveComponent(csrf: true)]
23+
+ #[AsLiveComponent]
24+
class MyLiveComponent {
25+
// ...
26+
}
27+
```
28+
29+
## Map
30+
31+
* The Twig function `render_map()` has been removed, use `ux_map()` instead
32+
* The option `title` from `Polygon`, `Polyline`, `Rectangle` and `Circle`, has been removed, use option `infoWindow` instead
33+
* The property `rawOptions` from `ux:map:*:before-create` events has been removed, use `bridgeOptions` instead
34+
35+
## Swup
36+
37+
* The package has been removed, see the [previous README](https://raw.githubusercontent.com/symfony/ux/refs/heads/2.x/src/Turbo/README.md)
38+
for migration steps
39+
40+
## TogglePassword
41+
42+
* The package has been removed, see the [previous README](https://raw.githubusercontent.com/symfony/ux/refs/heads/2.x/src/TogglePassword/README.md)
43+
for migration steps
44+
45+
## TwigComponent
46+
47+
* The configuration `twig_component.defaults` is now mandatory and must contain at least one namespace/directory pair:
48+
```diff
49+
# config/packages/twig_component.yaml
50+
twig_component:
51+
anonymous_template_directory: 'components/'
52+
+ defaults:
53+
+ # Namespace & directory for components
54+
+ App\Twig\Components\: 'components/'
55+
```
56+
57+
* Remove method `PreCreateForRenderEvent::getProps()` in favor of `PreCreateForRenderEvent::getInputProps()`
58+
```diff
59+
class HookIntoTwigPreCreateForRenderSubscriber implements EventSubscriberInterface
60+
{
61+
public function onPreCreateForRender(PreCreateForRenderEvent $event): void
62+
{
63+
- $event->getProps();
64+
+ $event->getInputProps();
65+
}
66+
67+
public static function getSubscribedEvents(): array
68+
{
69+
return [PreCreateForRenderEvent::class => 'onPreCreateForRender'];
70+
}
71+
}
72+
```
73+
74+
* Remove `cva` Twig function in favor of [`html_cva` Twig function from `twig/html-extra:^3.12`](https://twig.symfony.com/html_cva)
75+
76+
**Before:**
77+
```twig
78+
{% set alert = cva({
79+
base: 'alert',
80+
variants: {
81+
color: { blue: 'bg-blue', red: 'bg-red', green: 'bg-green' },
82+
size: { sm: 'text-sm', md: 'text-md', lg: 'text-lg' }
83+
},
84+
defaultVariants: { size: 'md', color: 'blue' },
85+
compoundVariants: [{
86+
color: ['red'],
87+
size: ['lg'],
88+
class: 'font-bold'
89+
}],
90+
defaultVariants: {
91+
rounded: 'md'
92+
}
93+
}) %}
94+
95+
<div class="{{ alert.apply({color, size}, attributes.render('class')) }}">
96+
{% block content %}{% endblock %}
97+
</div>
98+
```
99+
**After:**
100+
```twig
101+
{% set alert = html_cva(
102+
base: 'alert',
103+
variants: {
104+
color: { blue: 'bg-blue', red: 'bg-red', green: 'bg-green' },
105+
size: { sm: 'text-sm', md: 'text-md', lg: 'text-lg' }
106+
},
107+
compound_variants: [{
108+
color: ['red'],
109+
size: ['lg'],
110+
class: 'font-bold'
111+
}],
112+
default_variants: {
113+
rounded: 'md'
114+
}
115+
) %}
116+
117+
<div class="{{ alert.apply({color, size}, attributes.render('class')) }}">
118+
{% block content %}{% endblock %}
119+
</div>
120+
```
121+
122+
## Typed
123+
124+
* The package has been removed, see the [previous README](https://raw.githubusercontent.com/symfony/ux/refs/heads/2.x/src/Typed/README.md)
125+
for migration steps

src/LiveComponent/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Minimum required Symfony version is now 6.4
66
- Minimum required PHP version is now 8.2
7+
- Remove `csrf` argument from `AsLiveComponent` in favor of same-origin/CORS
78

89
## 2.30
910

src/TwigComponent/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
- Minimum required Symfony version is now 6.4
66
- Minimum required PHP version is now 8.2
7+
- The configuration `twig_component.defaults` could not be nullable anymore
8+
- Remove method `PreCreateForRenderEvent::getProps()` in favor of `PreCreateForRenderEvent::getInputProps()`
9+
- Remove `cva` Twig function in favor of [`html_cva` Twig function from `twig/html-extra`](https://twig.symfony.com/html_cva)
10+
- Passing `null` as an attribute value when using `ComponentAttributes` (or `attributes` Twig variable) will now throw an exception, use `remove()` instead
11+
- Remove method `ComponentAttributes::add()`, use `{{ attributes.defaults(stimulus_controller('...')) }}` instead
12+
- The `ComponentTemplateFinder` does not accept `Twig\Environment` as first argument anymore, pass a `LoaderInterface` instead
13+
- The `ComponentTemplateFinder` does not accept a nullable `directory` argument anymore, pass a string instead
714

815
## 2.30
916

src/TwigComponent/doc/index.rst

Lines changed: 25 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,58 +1216,41 @@ The nesting is recursive so you could potentially do something like this:
12161216
row:widget:class="ui-form-widget"
12171217
/>
12181218

1219-
Component with Complex Variants (CVA)
1220-
-------------------------------------
1221-
1222-
.. deprecated:: 2.20
1219+
Class Variant Authority
1220+
-----------------------
12231221

1224-
The ``cva`` function was deprecated in TwigComponents 2.20, and will be
1225-
removed in 3.0. The function is now provided by the ``twig/html-extra:^3.12``
1226-
package under the name `html_cva`_.
1227-
1228-
`CVA (Class Variant Authority)`_ originates from the JavaScript ecosystem. It
1229-
enables reusable, customizable components by managing variants (e.g., color, size).
1230-
The ``cva()`` Twig function defines ``base`` classes (always applied) and variant-specific
1231-
classes:
1222+
`CVA (Class Variant Authority)`_ originates from the JavaScript ecosystem.
1223+
It enables reusable, customizable components by managing variants (e.g., color, size).
1224+
The `html_cva()`_ Twig function from ``twig/html-extra:^3.12`` defines ``base`` classes (always applied)
1225+
and variant-specific classes:
12321226

12331227
.. code-block:: html+twig
12341228

1235-
{# templates/components/Alert.html.twig #}
1236-
{% props color = 'blue', size = 'md' %}
1237-
1238-
{% set alert = cva({
1239-
base: 'alert',
1229+
{% set button = html_cva(
1230+
base: 'btn',
12401231
variants: {
1241-
color: {
1242-
blue: 'bg-blue',
1243-
red: 'bg-red',
1244-
green: 'bg-green',
1245-
},
1246-
size: {
1247-
sm: 'text-sm',
1248-
md: 'text-md',
1249-
lg: 'text-lg',
1250-
}
1251-
}
1252-
}) %}
1232+
color: { primary: 'btn-primary', secondary: 'btn-secondary' },
1233+
size: { sm: 'btn-sm', md: 'btn-md', lg: 'btn-lg' }
1234+
},
1235+
default_variant: { color: 'primary', size: 'md' }
1236+
) %}
12531237

1254-
<div class="{{ alert.apply({color, size}, attributes.render('class')) }}">
1255-
{% block content %}{% endblock %}
1256-
</div>
1238+
<button class="{{ button.apply({color, size}, attributes.render('class')) }}">
1239+
{% block content %}{% endblock %}
1240+
</button>
12571241

1258-
Then use the ``color`` and ``size`` variants to select the classes needed:
1242+
When rendering the component, pass the desired variants:
12591243

12601244
.. code-block:: html+twig
12611245

1262-
<twig:Alert color="green" size="sm">
1263-
...
1264-
</twig:Alert>
1246+
{# renders as: <button class="btn btn-primary btn-md">... #}
1247+
<twig:Button>Click Me!</twig:Button>
12651248

1266-
{# will render as: #}
1249+
{# renders as: <button class="btn btn-secondary btn-lg">... #}
1250+
<twig:Button color="secondary" size="lg">Click Me!</twig:Button>
12671251

1268-
<div class="alert bg-green text-sm">
1269-
...
1270-
</div>
1252+
{# renders as: <button class="btn btn-primary btn-sm custom-class">... #}
1253+
<twig:Button size="sm" class="custom-class">Click Me!</twig:Button>
12711254

12721255
CVA and Tailwind CSS
12731256
~~~~~~~~~~~~~~~~~~~~
@@ -1278,85 +1261,10 @@ to resolve conflicts:
12781261

12791262
.. code-block:: html+twig
12801263

1281-
<div class="{{ alert.apply({color, size}, attributes.render('class'))|tailwind_merge }}">
1264+
<div class="{{ button.apply({color, size}, attributes.render('class'))|tailwind_merge }}">
12821265
{% block content %}{% endblock %}
12831266
</div>
12841267

1285-
Compound Variants
1286-
~~~~~~~~~~~~~~~~~
1287-
1288-
Define compound variants for conditions involving multiple variants:
1289-
1290-
.. code-block:: html+twig
1291-
1292-
{# templates/components/Alert.html.twig #}
1293-
{% props color = 'blue', size = 'md' %}
1294-
1295-
{% set alert = cva({
1296-
base: 'alert',
1297-
variants: {
1298-
color: { red: 'bg-red' },
1299-
size: { lg: 'text-lg' }
1300-
},
1301-
compoundVariants: [{
1302-
color: ['red'],
1303-
size: ['lg'],
1304-
class: 'font-bold'
1305-
}]
1306-
}) %}
1307-
1308-
<div class="{{ alert.apply({color, size}) }}">
1309-
{% block content %}{% endblock %}
1310-
</div>
1311-
1312-
{# index.html.twig #}
1313-
1314-
<twig:Alert color="red" size="lg">
1315-
...
1316-
</twig:Alert>
1317-
1318-
{# will render as: #}
1319-
1320-
<div class="alert bg-red text-lg font-bold">
1321-
...
1322-
</div>
1323-
1324-
Default Variants
1325-
~~~~~~~~~~~~~~~~
1326-
1327-
If no variants match, you can define a default set of classes to apply:
1328-
1329-
.. code-block:: html+twig
1330-
1331-
{# templates/components/Alert.html.twig #}
1332-
{% set alert = cva({
1333-
base: 'alert',
1334-
variants: {
1335-
color: {
1336-
red: 'bg-red'
1337-
},
1338-
rounded: {
1339-
sm: 'rounded-sm',
1340-
md: 'rounded-md'
1341-
}
1342-
},
1343-
defaultVariants: {
1344-
rounded: 'md'
1345-
}
1346-
}) %}
1347-
1348-
{# index.html.twig #}
1349-
1350-
<twig:Alert color="red">
1351-
...
1352-
</twig:Alert>
1353-
1354-
{# will render as: #}
1355-
1356-
<div class="alert bg-red rounded-md">
1357-
...
1358-
</div>
1359-
13601268
Test Helpers
13611269
------------
13621270

@@ -1809,7 +1717,7 @@ https://symfony.com/doc/current/contributing/code/bc.html
18091717
.. _`Passing Blocks to Live Components`: https://symfony.com/bundles/ux-live-component/current/index.html#passing-blocks
18101718
.. _`Stimulus controller`: https://symfony.com/bundles/StimulusBundle/current/index.html
18111719
.. _`CVA (Class Variant Authority)`: https://cva.style/docs/getting-started/variants
1812-
.. _`html_cva`: https://twig.symfony.com/doc/3.x/functions/html_cva.html
1720+
.. _`html_cva()`: https://twig.symfony.com/doc/3.x/functions/html_cva.html
18131721
.. _`tales-from-a-dev/twig-tailwind-extra`: https://github.com/tales-from-a-dev/twig-tailwind-extra
18141722
.. _`ignore not defined options`: https://symfony.com/doc/current/components/options_resolver.html#ignore-not-defined-options
18151723
.. _`Symfony MakerBundle`: https://symfony.com/bundles/SymfonyMakerBundle/current/index.html

0 commit comments

Comments
 (0)