Skip to content

Commit ea80287

Browse files
committed
minor #63 using stimulus_controller() everywhere (weaverryan)
This PR was merged into the main branch. Discussion ---------- using stimulus_controller() everywhere | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Tickets | None | License | MIT I think we should embrace `stimulus_controller()`. The controller name normalization is especially important. Also, it looks like we should also update many of the options (e.g. `data-hd-url`) to values (in a BC way, obviously). That would make things even nicer with the `stimulus_controller()` function. Cheers! Commits ------- 5fd2045 using stimulus_controller() everywhere
2 parents 3c2c411 + 5fd2045 commit ea80287

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/LazyImage/README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ page has been rendered:
3434
```twig
3535
<img
3636
src="{{ asset('image/small.png') }}"
37-
data-controller="symfony--ux-lazy-image--lazy-image"
37+
{{ stimulus_controller('symfony/ux-lazy-image/lazy-image') }}
3838
data-hd-src="{{ asset('image/large.png') }}"
3939
4040
{# Optional but avoids having a page jump when the image is loaded #}
@@ -43,13 +43,16 @@ page has been rendered:
4343
/>
4444
```
4545

46+
**Note** The `stimulus_controller()` function comes from
47+
[WebpackEncoreBundle v1.10](https://github.com/symfony/webpack-encore-bundle).
48+
4649
Instead of using a generated thumbnail that would exist on your filesystem, you can use
4750
the BlurHash algorithm to create a light, blurred, data-uri thumbnail of the image:
4851

4952
```twig
5053
<img
5154
src="{{ data_uri_thumbnail('public/image/large.png', 100, 75) }}"
52-
data-controller="symfony--ux-lazy-image--lazy-image"
55+
{{ stimulus_controller('symfony/ux-lazy-image/lazy-image') }}
5356
data-hd-src="{{ asset('image/large.png') }}"
5457
5558
{# Using BlurHash, the size is required #}
@@ -104,7 +107,10 @@ Then in your template, add your controller to the HTML attribute:
104107
```twig
105108
<img
106109
src="{{ data_uri_thumbnail('public/image/large.png', 100, 75) }}"
107-
data-controller="mylazyimage symfony--ux-lazy-image--lazy-image"
110+
{{ stimulus_controller({
111+
mylazyimage: {},
112+
'symfony/ux-lazy-image/lazy-image: {}
113+
}) }}
108114
data-hd-src="{{ asset('image/large.png') }}"
109115
110116
{# Using BlurHash, the size is required #}

src/Swup/README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The main usage of Symfony UX Swup is to use its Stimulus controller to initializ
4343
{{ encore_entry_script_tags('app') }}
4444
{% endblock %}
4545
</head>
46-
<body data-controller="symfony--ux-swup--swup">
46+
<body {{ stimulus_controller('symfony/ux-swup/swup') }}>
4747
{# ... #}
4848
4949
<main id="swup">
@@ -53,6 +53,9 @@ The main usage of Symfony UX Swup is to use its Stimulus controller to initializ
5353
</html>
5454
```
5555

56+
**Note** The `stimulus_controller()` function comes from
57+
[WebpackEncoreBundle v1.10](https://github.com/symfony/webpack-encore-bundle).
58+
5659
That's it! Swup now reacts to a link click and run the default fade-in transition.
5760

5861
By default, Swup will use the `#swup` selector as a container, meaning it will only swap
@@ -69,7 +72,7 @@ additional containers, for instance to have a navigation menu that updates when
6972
{% endblock %}
7073
</head>
7174
<body
72-
data-controller="symfony--ux-swup--swup"
75+
{{ stimulus_controller('symfony/ux-swup/swup') }}
7376
data-containers="#swup #nav" {# list of selectors separated by spaces #}
7477
>
7578
{# ... #}
@@ -93,7 +96,7 @@ You can configure several other options using data-attributes on the `body` tag:
9396
<title>Swup</title>
9497
</head>
9598
<body
96-
data-controller="symfony--ux-swup--swup"
99+
{{ stimulus_controller('symfony/ux-swup/swup') }}
97100
data-containers="#swup #nav"
98101
data-theme="slide" {# or "fade", the default #}
99102
data-debug="data-debug" {# add this attribute to enable debug #}
@@ -140,7 +143,10 @@ Then in your template, add your controller to the HTML attribute:
140143
<title>Swup</title>
141144
{# ... #}
142145
</head>
143-
<body data-controller="myswup symfony--ux-swup--swup">
146+
<body {{ stimulus_controller({
147+
myswup: {},
148+
'symfony/ux-swup/swup: {}
149+
})>
144150
{# ... #}
145151
</body>
146152
</html>

0 commit comments

Comments
 (0)