Skip to content

Commit 023437f

Browse files
committed
Introduce UX React component
1 parent 040e75d commit 023437f

34 files changed

+876
-8
lines changed

.github/workflows/test.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ jobs:
101101
run: php vendor/bin/simple-phpunit
102102
working-directory: src/LazyImage
103103

104+
- name: React Dependencies
105+
uses: ramsey/composer-install@v2
106+
with:
107+
working-directory: src/React
108+
dependency-versions: lowest
109+
- name: React Tests
110+
run: php vendor/bin/simple-phpunit
111+
working-directory: src/React
112+
104113
tests-php8-low-deps:
105114
runs-on: ubuntu-latest
106115
steps:
@@ -184,6 +193,14 @@ jobs:
184193
working-directory: src/LiveComponent
185194
run: php vendor/bin/simple-phpunit
186195

196+
- name: React Dependencies
197+
uses: ramsey/composer-install@v2
198+
with:
199+
working-directory: src/React
200+
- name: React Tests
201+
working-directory: src/React
202+
run: php vendor/bin/simple-phpunit
203+
187204
tests-php81-high-deps:
188205
runs-on: ubuntu-latest
189206
steps:

babel.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
22
presets: [
33
['@babel/preset-env', {targets: {node: 'current'}}],
4+
'@babel/react',
45
'@babel/preset-typescript',
56
],
67
};

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ module.exports = {
77
path.join(__dirname, 'test/setup.js'),
88
],
99
transform: {
10-
'\\.(j|t)s$': ['babel-jest', { configFile: path.join(__dirname, './babel.config.js') }]
10+
'\\.(j|t)s': ['babel-jest', { configFile: path.join(__dirname, './babel.config.js') }]
1111
},
1212
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"devDependencies": {
1616
"@babel/core": "^7.15.8",
1717
"@babel/preset-env": "^7.15.8",
18-
"@babel/preset-typescript": "^7.15.0",
18+
"@babel/preset-react": "^7.15.8",
19+
"@babel/preset-typescript": "^7.15.8",
1920
"@rollup/plugin-node-resolve": "^13.0.0",
2021
"@rollup/plugin-typescript": "^8.3.0",
2122
"@symfony/stimulus-testing": "^2.0.1",

src/LiveComponent/assets/dist/live_controller.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -971,11 +971,14 @@ function haveRenderedValuesChanged(originalDataJson, currentDataJson, newDataJso
971971
}
972972

973973
function normalizeAttributesForComparison(element) {
974-
if (element.value) {
975-
element.setAttribute('value', element.value);
976-
}
977-
else if (element.hasAttribute('value')) {
978-
element.setAttribute('value', '');
974+
const isFileInput = element instanceof HTMLInputElement && element.type === 'file';
975+
if (!isFileInput) {
976+
if (element.value) {
977+
element.setAttribute('value', element.value);
978+
}
979+
else if (element.hasAttribute('value')) {
980+
element.setAttribute('value', '');
981+
}
979982
}
980983
Array.from(element.children).forEach((child) => {
981984
normalizeAttributesForComparison(child);

src/React/.gitattributes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/.gitattributes export-ignore
2+
/.gitignore export-ignore
3+
/phpunit.xml.dist export-ignore
4+
/Resources/assets/test export-ignore
5+
/Tests export-ignore

src/React/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
vendor
2+
composer.lock
3+
.php_cs.cache
4+
.phpunit.result.cache

src/React/.symfony.bundle.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
branches: ["2.x"]
2+
maintained_branches: ["2.x"]
3+
doc_dir: "Resources/doc"

src/React/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# CHANGELOG
2+
3+
## 2.2
4+
5+
- Component added
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\UX\React\DependencyInjection;
13+
14+
use Symfony\Component\DependencyInjection\ContainerBuilder;
15+
use Symfony\Component\DependencyInjection\Definition;
16+
use Symfony\Component\DependencyInjection\Reference;
17+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
18+
use Symfony\UX\React\Twig\ReactComponentExtension;
19+
20+
/**
21+
* @author Titouan Galopin <galopintitouan@gm ail.com>
22+
*
23+
* @internal
24+
*/
25+
class ReactExtension extends Extension
26+
{
27+
public function load(array $configs, ContainerBuilder $container)
28+
{
29+
$container
30+
->setDefinition('twig.extension.react', new Definition(ReactComponentExtension::class))
31+
->setArgument(0, new Reference('webpack_encore.twig_stimulus_extension'))
32+
->addTag('twig.extension')
33+
->setPublic(false)
34+
;
35+
}
36+
}

0 commit comments

Comments
 (0)