You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
minor #2025 [Cookbook] - fix component_architecture (WebMamba)
This PR was squashed before being merged into the 2.x branch.
Discussion
----------
[Cookbook] - fix component_architecture
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| Issues | Fix
| License | MIT
Commits
-------
686ab07 [Cookbook] - fix component_architecture
Copy file name to clipboardExpand all lines: ux.symfony.com/cookbook/component_architecture.md
+21-21Lines changed: 21 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -3,20 +3,20 @@ title: Component architecture
3
3
description: Rules and pattern to work with components
4
4
image: images/cookbook/component-architecture.png
5
5
tags:
6
-
- javascript
7
-
- symfony
6
+
- JavaScript
7
+
- Symfony
8
8
author: Mathéo Daninos
9
9
published_at: '2024-08-02'
10
10
---
11
11
12
12
## Introduction
13
13
14
-
In SymfonyUX exist two packages: [TwigComponents](https://symfony.com/bundles/ux-twig-component/current/index.html) and [LiveComponent](https://symfony.com/bundles/ux-live-component/current/index.html).
14
+
In Symfony UX exist two packages: [TwigComponents](https://symfony.com/bundles/ux-twig-component/current/index.html) and [LiveComponent](https://symfony.com/bundles/ux-live-component/current/index.html).
15
15
Those two packages allow you to create reusable components in your Symfony application.
16
-
But the component architecture is not exclusive to Symfony, it is a design pattern that can be applied to any programming language or framework.
17
-
And the js world already implement this architecture for long time, on many different frameworks like React, Vue, or Svelte.
18
-
So, a set of rules and pattern has already be defined to work with components. This is why SymfonyUX try to be as close as possible to those rules.
19
-
So let's see what are those rules!
16
+
But the component architecture is not exclusive to Symfony, it's a design pattern that can be applied to any programming language or framework.
17
+
And the Javascript world already implements this architecture for long time, on many different frameworks like React, Vue, or Svelte.
18
+
So, a set of rules and patterns has already be defined to work with components. This is why Symfony UX tries to be as close as possible to those rules.
19
+
So, let's see what those rules are!
20
20
21
21
## 4 Rules
22
22
@@ -43,27 +43,25 @@ Or you can make composition with the following syntax:
43
43
44
44
```twig
45
45
<twig:Card>
46
-
<twig:CardHeader>
47
-
<h2>My Card</h2>
48
-
</twig:CardHeader>
49
-
<twig:CardBody>
50
-
<p>This is the content of my card.</p>
51
-
</twig:CardBody>
46
+
<twig:Icon name="info"/>
47
+
<twig:Button>
48
+
<twig:Icon name="close" />
49
+
</twig:Button>
52
50
</twig:Card>
53
51
```
54
52
55
-
So here we Card component, and we give to the content of this component mutliple other components.
53
+
So here we have a Card component, and we give to the content of this component two other components.
56
54
57
55
### Independence
58
56
59
-
This is a really important rule, and not obvious. But your component should leave on his own context,
60
-
he should not be aware of the rest of the page. You should to talk one component into a page, to another and it should work exactly the same.
61
-
This rule make your component trully reusable.
57
+
This is a really important rule, and not obvious. But your component should live on his own context,
58
+
it should not be aware of the rest of the page. You should be able to take a component into a page, from another and it should work exactly the same.
59
+
This rule makes your component truly reusable.
62
60
63
61
***How does it work into Symfony?***
64
62
65
-
Symfony keep the context of the page into the context of your component. So this your own responsability to follow this rules.
66
-
But notice that if there are conflic between a variable from the context page and your component, your component context override the page context.
63
+
Symfony keeps the context of the page into the context of your component. So this your own responsibility to follow those rules.
64
+
But notice that if there are conflicts between a variable from the context page and your component, your component context overrides the page context.
67
65
68
66
### Props
69
67
@@ -119,7 +117,7 @@ And when the loading is done, the state `loading` can be set to `false` and the
119
117
120
118
***How does it work into Symfony?***
121
119
122
-
In symfony you 2 different approach to handle state. The first one is to use stimulus directly
120
+
In Symfony you have two different approaches to handle state. The first one is to use stimulus directly
123
121
in to your component. What we recommend to do is to set a controller stimulus at the root of your component.
0 commit comments