Skip to content

Commit afe8f2d

Browse files
committed
minor #930 Asset mapper: Further docs updates (weaverryan)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- Asset mapper: Further docs updates | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Tickets | None | License | MIT Further updates for smooth documentation now that the AssetMapper component exists. The biggest change is that the docs for installing UX (which really just means installing StimulusBundle at this point) have moved into that bundle. Cheers! Commits ------- 62b8c76 Asset mapper: Further docs updates
2 parents e780fa7 + 62b8c76 commit afe8f2d

File tree

17 files changed

+391
-106
lines changed

17 files changed

+391
-106
lines changed

src/Autocomplete/doc/index.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,19 @@ into an Ajax-powered autocomplete smart UI control (leveraging `Tom Select`_):
1212
Installation
1313
------------
1414

15-
Before you start, make sure you have `Symfony UX configured in your app`_.
15+
Before you start, make sure you have `StimulusBundle configured in your app`_.
1616

1717
Then install the bundle using Composer and Symfony Flex:
1818

1919
.. code-block:: terminal
2020
2121
$ composer require symfony/ux-autocomplete
2222
23-
If you're using WebpackEncore, install your assets and restart Encore. This is
24-
not needed if you're using AssetMapper:
23+
If you're using WebpackEncore, install your assets and restart Encore (not
24+
needed if you're using AssetMapper):
2525

2626
.. code-block:: terminal
2727
28-
# Don't forget to install the JavaScript dependencies as well and compile
2928
$ npm install --force
3029
$ npm run watch
3130
@@ -585,7 +584,7 @@ This bundle aims at following the same Backward Compatibility promise as
585584
the Symfony framework: https://symfony.com/doc/current/contributing/code/bc.html
586585

587586
.. _`Tom Select`: https://tom-select.js.org/
588-
.. _`Symfony UX configured in your app`: https://symfony.com/doc/current/frontend/ux.html
587+
.. _StimulusBundle configured in your app: https://symfony.com/bundles/StimulusBundle/current/index.html
589588
.. _`Tom Select Options`: https://tom-select.js.org/docs/#general-configuration
590589
.. _`controller.ts`: https://github.com/symfony/ux/blob/2.x/src/Autocomplete/assets/src/controller.ts
591590
.. _`Tom Select Render Templates`: https://tom-select.js.org/docs/#render-templates

src/Chartjs/doc/index.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,19 @@ It is part of `the Symfony UX initiative`_.
88
Installation
99
------------
1010

11-
Before you start, make sure you have `Symfony UX configured in your app`_.
11+
Before you start, make sure you have `StimulusBundle configured in your app`_.
1212

13-
Then, install this bundle using Composer and Symfony Flex:
13+
Then install the bundle using Composer and Symfony Flex:
1414

1515
.. code-block:: terminal
1616
1717
$ composer require symfony/ux-chartjs
1818
19-
If you're using WebpackEncore, install your assets and restart Encore. This is
20-
not needed if you're using AssetMapper:
19+
If you're using WebpackEncore, install your assets and restart Encore (not
20+
needed if you're using AssetMapper):
2121

2222
.. code-block:: terminal
2323
24-
# Don't forget to install the JavaScript dependencies as well and compile
2524
$ npm install --force
2625
$ npm run watch
2726
@@ -244,7 +243,7 @@ the Symfony framework: https://symfony.com/doc/current/contributing/code/bc.html
244243
.. _`Chart.js`: https://www.chartjs.org
245244
.. _`the Symfony UX initiative`: https://symfony.com/ux
246245
.. _`Chart.js documentation`: https://www.chartjs.org/docs/latest/
247-
.. _`Symfony UX configured in your app`: https://symfony.com/doc/current/frontend/ux.html
246+
.. _StimulusBundle configured in your app: https://symfony.com/bundles/StimulusBundle/current/index.html
248247
.. _`a lot of plugins`: https://github.com/chartjs/awesome#plugins
249248
.. _`zoom plugin`: https://www.chartjs.org/chartjs-plugin-zoom/latest/
250249
.. _`zoom plugin documentation`: https://www.chartjs.org/chartjs-plugin-zoom/latest/guide/integration.html

src/Cropperjs/doc/index.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,19 @@ Symfony UX Cropper.js is a Symfony bundle integrating the
88
Installation
99
------------
1010

11-
Before you start, make sure you have `Symfony UX configured in your app`_.
11+
Before you start, make sure you have `StimulusBundle configured in your app`_.
1212

1313
Then, install this bundle using Composer and Symfony Flex:
1414

1515
.. code-block:: terminal
1616
1717
$ composer require symfony/ux-cropperjs
1818
19-
If you're using WebpackEncore, install your assets and restart Encore. This is
20-
not needed if you're using AssetMapper:
19+
If you're using WebpackEncore, install your assets and restart Encore (not
20+
needed if you're using AssetMapper):
2121

2222
.. code-block:: terminal
2323
24-
# Don't forget to install the JavaScript dependencies as well and compile
2524
$ npm install --force
2625
$ npm run watch
2726
@@ -151,4 +150,4 @@ https://symfony.com/doc/current/contributing/code/bc.html
151150
.. _`Cropper.js`: https://fengyuanchen.github.io/cropperjs/
152151
.. _`the Symfony UX initiative`: https://symfony.com/ux
153152
.. _`the Cropper.js options`: https://github.com/fengyuanchen/cropperjs/blob/main/README.md#options
154-
.. _`Symfony UX configured in your app`: https://symfony.com/doc/current/frontend/ux.html
153+
.. _StimulusBundle configured in your app: https://symfony.com/bundles/StimulusBundle/current/index.html

src/Dropzone/doc/index.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@ having to browse their computer for a file.
1010
Installation
1111
------------
1212

13-
Before you start, make sure you have `Symfony UX configured in your app`_.
13+
Before you start, make sure you have `StimulusBundle configured in your app`_.
1414

1515
Then, install this bundle using Composer and Symfony Flex:
1616

1717
.. code-block:: terminal
1818
1919
$ composer require symfony/ux-dropzone
2020
21-
If you're using WebpackEncore, install your assets and restart Encore. This is
22-
not needed if you're using AssetMapper:
21+
If you're using WebpackEncore, install your assets and restart Encore (not
22+
needed if you're using AssetMapper):
2323

2424
.. code-block:: terminal
2525
26-
# Don't forget to install the JavaScript dependencies as well and compile
2726
$ npm install --force
2827
$ npm run watch
2928
@@ -157,4 +156,4 @@ the Symfony framework:
157156
https://symfony.com/doc/current/contributing/code/bc.html
158157

159158
.. _`the Symfony UX initiative`: https://symfony.com/ux
160-
.. _`Symfony UX configured in your app`: https://symfony.com/doc/current/frontend/ux.html
159+
.. _StimulusBundle configured in your app: https://symfony.com/bundles/StimulusBundle/current/index.html

src/LazyImage/doc/index.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,19 @@ It provides two key features:
1212
Installation
1313
------------
1414

15-
Before you start, make sure you have `Symfony UX configured in your app`_.
15+
Before you start, make sure you have `StimulusBundle configured in your app`_.
1616

1717
Then install this bundle using Composer and Symfony Flex:
1818

1919
.. code-block:: terminal
2020
2121
$ composer require symfony/ux-lazy-image
2222
23-
If you're using WebpackEncore, install your assets and restart Encore. This is
24-
not needed if you're using AssetMapper:
23+
If you're using WebpackEncore, install your assets and restart Encore (not
24+
needed if you're using AssetMapper):
2525

2626
.. code-block:: terminal
2727
28-
# Don't forget to install the JavaScript dependencies as well and compile
2928
$ npm install --force
3029
$ npm run watch
3130
@@ -174,4 +173,4 @@ https://symfony.com/doc/current/contributing/code/bc.html
174173
.. _`the Symfony UX initiative`: https://symfony.com/ux
175174
.. _`BlurHash implementation`: https://blurha.sh
176175
.. _`StimulusBundle`: https://symfony.com/bundles/StimulusBundle/current/index.html
177-
.. _`Symfony UX configured in your app`: https://symfony.com/doc/current/frontend/ux.html
176+
.. _StimulusBundle configured in your app: https://symfony.com/bundles/StimulusBundle/current/index.html

src/LiveComponent/doc/index.rst

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ Live Components
44
**EXPERIMENTAL** This component is currently experimental and is likely
55
to change, or even change drastically.
66

7-
Live components work with the `TwigComponent`_ library
7+
Live components builds on top of the `TwigComponent`_ library
88
to give you the power to automatically update your Twig components on
99
the frontend as the user interacts with them. Inspired by
1010
`Livewire`_ and `Phoenix LiveView`_.
1111

12+
If you're not familiar with Twig components yet, it's worth taking a few minutes
13+
to familiarize yourself in the `TwigComponent documentation`_.
14+
1215
A real-time product search component might look like this::
1316

1417
// src/Components/ProductSearch.php
@@ -55,16 +58,6 @@ A real-time product search component might look like this::
5558
</ul>
5659
</div>
5760

58-
.. versionadded:: 2.1
59-
60-
The ability to reference local variables in the template (e.g. ``query``) was added in TwigComponents 2.1.
61-
Previously, all data needed to be referenced through ``this`` (e.g. ``this.query``).
62-
63-
.. versionadded:: 2.1
64-
65-
The ability to initialize live component with the ``attributes`` twig variable was added in LiveComponents
66-
2.1. Previously, the ``init_live_component()`` function was required (this function was removed in 2.1).
67-
6861
Done! Now render it wherever you want:
6962

7063
.. code-block:: twig
@@ -79,20 +72,19 @@ Want some demos? Check out https://ux.symfony.com/live-component#demo
7972
Installation
8073
------------
8174

82-
Before you start, make sure you have `Symfony UX configured in your app`_.
75+
Before you start, make sure you have `StimulusBundle configured in your app`_.
8376

8477
Now install the library with:
8578

8679
.. code-block:: terminal
8780
8881
$ composer require symfony/ux-live-component
8982
90-
If you're using WebpackEncore, install your assets and restart Encore. This is
91-
not needed if you're using AssetMapper:
83+
If you're using WebpackEncore, install your assets and restart Encore (not
84+
needed if you're using AssetMapper):
9285

9386
.. code-block:: terminal
9487
95-
# Don't forget to install the JavaScript dependencies as well and compile
9688
$ npm install --force
9789
$ npm run watch
9890
@@ -411,7 +403,8 @@ In this case, the model (e.g. ``publishAt``) will probably *not*
411403
update correctly because JavaScript doesn't trigger the normal
412404
``change`` event. To fix this, you'll need to "hook" into the
413405
JavaScript library and set the model directly (or trigger a
414-
``change`` event on the ``data-model`` field). See :ref:`working-in-javascript`.
406+
``change`` event on the ``data-model`` field). See
407+
:ref:`manually trigger an element change <javascript-manual-element-change>`.
415408

416409
.. _hydration:
417410

@@ -789,6 +782,8 @@ initialized:
789782
const component = document.getElementById('id-of-your-element').__component;
790783
component.mode = 'editing';
791784
785+
.. _javascript-manual-element-change:
786+
792787
Finally, you can also set the value of a model field directly. However,
793788
be sure to *also* trigger a ``change`` event so that live components is notified
794789
of the change:
@@ -2949,14 +2944,15 @@ However it is currently considered `experimental`_, meaning it is not
29492944
bound to Symfony's BC policy for the moment.
29502945

29512946
.. _`TwigComponent`: https://symfony.com/bundles/ux-twig-component/current/index.html
2947+
.. _TwigComponent documentation: https://symfony.com/bundles/ux-twig-component/current/index.html
29522948
.. _`Livewire`: https://laravel-livewire.com
29532949
.. _`Phoenix LiveView`: https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html
29542950
.. _`Twig Component`: https://symfony.com/bundles/ux-twig-component/current/index.html
29552951
.. _`Twig Component mount documentation`: https://symfony.com/bundles/ux-twig-component/current/index.html#the-mount-method
29562952
.. _`Symfony form`: https://symfony.com/doc/current/forms.html
29572953
.. _`experimental`: https://symfony.com/doc/current/contributing/code/experimental.html
29582954
.. _`dependent form fields`: https://ux.symfony.com/live-component/demos/dependent-form-fields
2959-
.. _`Symfony UX configured in your app`: https://symfony.com/doc/current/frontend/ux.html
2955+
.. _StimulusBundle configured in your app: https://symfony.com/bundles/StimulusBundle/current/index.html
29602956
.. _`localizes its URLs`: https://symfony.com/doc/current/translation/locale.html#translation-locale-url
29612957
.. _`attributes variable`: https://symfony.com/bundles/ux-twig-component/current/index.html#component-attributes
29622958
.. _`CollectionType`: https://symfony.com/doc/current/form/form_collections.html

src/Notify/doc/index.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@ in Symfony applications using `Mercure`_. It is part of `the Symfony UX initiati
77
Installation
88
------------
99

10-
Before you start, make sure you have `Symfony UX configured in your app`_.
10+
Before you start, make sure you have `StimulusBundle configured in your app`_.
1111

1212
Then, install this bundle using Composer and Symfony Flex:
1313

1414
.. code-block:: terminal
1515
1616
$ composer require symfony/ux-notify
1717
18-
If you're using WebpackEncore, install your assets and restart Encore. This is
19-
not needed if you're using AssetMapper:
18+
If you're using WebpackEncore, install your assets and restart Encore (not
19+
needed if you're using AssetMapper):
2020

2121
.. code-block:: terminal
2222
23-
# Don't forget to install the JavaScript dependencies as well and compile
2423
$ npm install --force
2524
$ npm run watch
2625
@@ -153,7 +152,7 @@ the Symfony framework:
153152
https://symfony.com/doc/current/contributing/code/bc.html
154153

155154
.. _`the Symfony UX initiative`: https://symfony.com/ux
156-
.. _`Symfony UX configured in your app`: https://symfony.com/doc/current/frontend/ux.html
155+
.. _StimulusBundle configured in your app: https://symfony.com/bundles/StimulusBundle/current/index.html
157156
.. _`Mercure`: https://mercure.rocks
158157
.. _`running Mercure server`: https://symfony.com/doc/current/mercure.html#running-a-mercure-hub
159158
.. _`native notifications`: https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API

src/React/doc/index.rst

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ Symfony UX React supports React 18+.
1313
Installation
1414
------------
1515

16-
Before you start, make sure you have `Symfony UX configured in your app`_.
16+
.. note::
17+
18+
This package works best with WebpackEncore. To use it with AssetMapper, see
19+
:ref:`Using with AssetMapper <using-with-asset-mapper>`.
20+
21+
Before you start, make sure you have `StimulusBundle configured in your app`_.
1722
Then install the bundle using Composer and Symfony Flex:
1823

1924
.. code-block:: terminal
@@ -40,7 +45,6 @@ Install a package to help React:
4045
$ npm run watch
4146
4247
# or use yarn
43-
4448
$ yarn add @babel/preset-react --dev --force
4549
$ yarn watch
4650
@@ -98,11 +102,40 @@ For example:
98102
<div {{ react_component('MyComponent', { 'fullName': number }) }}>
99103
Loading... <i class="fas fa-cog fa-spin fa-3x"></i>
100104
</div>
101-
105+
102106
{# Component living in a subdirectory: "assets/react/controllers/Admin/OtherComponent" #}
103107
<div {{ react_component('Admin/OtherComponent') }}></div>
104108
{% endblock %}
105109

110+
.. _using-with-asset-mapper:
111+
112+
Using with AssetMapper
113+
----------------------
114+
115+
Because the JSX format isn't pure JavaScript, using this library with AssetMapper
116+
requires some extra steps.
117+
118+
#. Compile your ``.jsx`` files to pure JavaScript files. This can be done by
119+
installing Babel and the ``@babel/preset-react`` preset. Example:
120+
https://github.com/symfony/ux/blob/2.x/ux.symfony.com/package.json
121+
122+
#. Point this library at the "built" controllers directory that contains the final
123+
JavaScript files:
124+
125+
.. code-block:: yaml
126+
127+
# config/packages/react.yaml
128+
react:
129+
controllers_path: '%kernel.project_dir%/assets/build/react/controllers'
130+
131+
Also, inside of your ``.jsx`` files, when importing another component, use the
132+
``.js`` extension:
133+
134+
.. code-block:: javascript
135+
136+
// use PackageList.js even though the file is named PackageList.jsx
137+
import PackageList from '../components/PackageList.js';
138+
106139
Backward Compatibility promise
107140
------------------------------
108141

@@ -112,4 +145,4 @@ https://symfony.com/doc/current/contributing/code/bc.html
112145

113146
.. _`React`: https://reactjs.org/
114147
.. _`the Symfony UX initiative`: https://symfony.com/ux
115-
.. _`Symfony UX configured in your app`: https://symfony.com/doc/current/frontend/ux.html
148+
.. _StimulusBundle configured in your app: https://symfony.com/bundles/StimulusBundle/current/index.html

0 commit comments

Comments
 (0)