@@ -3,7 +3,7 @@ Stimulus & Symfony UX
33
44.. tip ::
55
6- Check out live demos of Symfony UX at ` https://ux.symfony.com `_ !
6+ Check out live demos of Symfony UX at https://ux.symfony.com!
77
88Symfony UX is an initiative and set of libraries to seamlessly
99integrate JavaScript tools into your application. For example,
@@ -17,41 +17,14 @@ your page.
1717Installing Symfony UX
1818---------------------
1919
20- To install Symfony UX, either install :doc: `Webpack Encore </frontend/encore/installation >`
21- or :doc: `Asset Mapper </frontend/asset-mapper >` - see
22- :doc: `Encore vs AssetMapper </frontend >` to
23- learn which is best for your project.
20+ Installing Symfony UX actually means installing StimulusBundle: a bundle that
21+ offers helper functions for the `Stimulus `_ JavaScript library and helps
22+ integrate extra Stimulus controllers from the UX packages.
2423
25- Once that's set up, run:
24+ Read: ` Installing StimulusBundle `_.
2625
27- .. code-block :: terminal
28-
29- $ composer require symfony/stimulus-bundle
30-
31- The last steps depend on which asset management tool you chose:
32-
33- .. tabs ::
34-
35- .. group-tab :: Webpack Encore
36-
37- Webpack Encore stuff!
38-
39- .. group-tab :: AssetMapper
40-
41- AssetMapper stuff!
42-
43- Then, install any of the UX packages listed below. For example, to install
44-
45- Before you install any specific UX library, make sure you've installed
46-
47-
48- If you already have it installed, make sure you have an
49- ``assets/bootstrap.js `` file (this initializes Stimulus & the UX packages),
50- an ``assets/controllers.json `` file (this controls the 3rd party UX packages that
51- you've installed) and ``.enableStimulusBridge('./assets/controllers.json') `` in
52- your ``webpack.config.js `` file. If these are missing, try upgrading the
53- ``symfony/webpack-encore-bundle `` Flex recipe. See
54- :ref: `Upgrading Flex Recipes <updating-flex-recipes >`.
26+ Then, `create your own Stimulus controllers `_ or install one of the
27+ Symfony UX packages below.
5528
5629.. _ux-packages-list :
5730
@@ -72,106 +45,10 @@ exist beyond the UX packages:
7245* `stimulus-components `_ A large number of pre-made Stimulus controllers, like for
7346 Copying to clipboard, Sortable, Popover (similar to tooltips) and much more.
7447
75- How does Symfony UX Work?
76- -------------------------
77-
78- When you install a UX PHP package, Symfony Flex will automatically update your
79- ``package.json `` file to point to a "virtual package" that lives inside the
80- PHP package. For example:
81-
82- .. code-block :: json
83-
84- {
85- "devDependencies" : {
86- "..." : " " ,
87- "@symfony/ux-chartjs" : " file:vendor/symfony/ux-chartjs/assets"
88- }
89- }
90-
91- This gives you a *real * Node package (e.g. ``@symfony/ux-chartjs ``) that, instead
92- of being downloaded, points directly to files that already live in your ``vendor/ ``
93- directory.
94-
95- The Flex recipe will usually also update your ``assets/controllers.json `` file
96- to add a new Stimulus controller to your app. For example:
97-
98- .. code-block :: json
99-
100- {
101- "controllers" : {
102- "@symfony/ux-chartjs" : {
103- "chart" : {
104- "enabled" : true ,
105- "fetch" : " eager"
106- }
107- }
108- },
109- "entrypoints" : []
110- }
111-
112- Finally, your ``assets/bootstrap.js `` file - working with the `@symfony/stimulus-bridge `_ -
113- package will automatically register:
114-
115- * All files in ``assets/controllers/ `` as Stimulus controllers;
116- * And all controllers described in ``assets/controllers.json `` as Stimulus controllers.
117-
118- The end result: you install a package, and you instantly have a Stimulus
119- controller available! In this example, it's called
120- ``@symfony/ux-chartjs/chart ``. Well, technically, it will be called
121- ``symfony--ux-chartjs--chart ``. However, you can pass the original name
122- into the ``{{ stimulus_controller() }} `` function from WebpackEncoreBundle, and
123- it will normalize it:
124-
125- .. code-block :: html+twig
126-
127- <div {{ stimulus_controller('@symfony/ux-chartjs/chart') }}>
128-
129- <!-- will render as: -->
130- <div data-controller="symfony--ux-chartjs--chart">
131-
132- Lazy Controllers
133- ----------------
134-
135- By default, all of your controllers (i.e. files in ``assets/controllers/ `` +
136- controllers in ``assets/controllers.json ``) will be downloaded and loaded on
137- every page.
138-
139- Sometimes you may have a controller that is only used on some pages, or maybe
140- only in your admin area. In that case, you can make the controller "lazy". When
141- a controller is lazy, it is *not * downloaded on initial page load. Instead, as
142- soon as an element appears on the page matching the controller (e.g.
143- ``<div data-controller="hello"> ``), the controller - and anything else it imports -
144- will be lazyily-loaded via Ajax.
145-
146- To make one of your custom controllers lazy, add a special comment on top:
147-
148- .. code-block :: javascript
149-
150- import { Controller } from ' @hotwired/stimulus' ;
151-
152- /* stimulusFetch: 'lazy' */
153- export default class extends Controller {
154- // ...
155- }
156-
157- To make a third-party controller lazy, in ``assets/controllers.json ``, set
158- ``fetch `` to ``lazy ``.
159-
160- .. note ::
161-
162- If you write your controllers using TypeScript, make sure
163- ``removeComments `` is not set to ``true `` in your TypeScript config.
164-
165- More Advanced Setup
166- -------------------
167-
168- To learn about more advanced options, read about `@symfony/stimulus-bridge `_,
169- the Node package that is responsible for a lot of the magic.
170-
17148.. _`Chart.js` : https://www.chartjs.org/
17249.. _`UX Chart.js` : https://symfony.com/bundles/ux-chartjs/current/index.html
17350.. _`Stimulus` : https://stimulus.hotwired.dev/
174- .. _`@symfony/stimulus-bridge` : https://github.com/symfony/stimulus-bridge
17551.. _`stimulus-use` : https://stimulus-use.github.io/stimulus-use
17652.. _`stimulus-components` : https://stimulus-components.netlify.app/
177- .. _`https://ux.symfony.com` : https://ux.symfony.com
53+ .. _Installing StimulusBundle : https://symfony.com/bundles/StimulusBundle/current/index.html#installation
54+ .. _create your own Stimulus controllers : https://symfony.com/bundles/StimulusBundle/current/index.html#usage
0 commit comments