-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Methodology, questions] Loose coupling, soft encapsulation #134
Comments
The docs do go into some detail on the situation you describe - Styling dependencies. There is also this great post by Philip Walton - Extending Styles. I've had success with option 4 when using postcss-extend. |
Regarding your first question, yep wrapping (b) is in my opinion the best way to go. <style>
.Button {
margin: 0;
width: 100%;
}
.Header-button {
width: 20%;
float: right;
}
</style>
<header class="Header">
<h1 class="Header-title">Hey bud</h1>
<span class="Header-button">
<button type="button" class="Button">Do Something</button>
</span>
</header> I wrote a little thing around this topic with focus on margins. Regarding question no. 2, I don't think that one should avoid components nesting (in html): a component's HTML should not be directly included in the HTML for another component. Things that one usually wants to control from the parent are Otherwise maybe postcss-apply is preferable to extend. |
Hey guys, thanks for your thoughts!
So, SUIT basically allows 2) and 3) ?
My opinion on extending: from lots of code I've seen I concluded that
Oh, that one is a good read as well, thanks.
I agree. The thing is, SUIT docs state that clearly and firmly: don't place components' HTML into other components' HTML, i.e. no nesting. Our team decides on the codestyle (and ideally a methodology) to adopt, so explaining every person new to SUIT that "yeah, they say it but they don't mean it" would be a strange and confusing. Maybe the docs need an update on this? |
The documentation says:
That means that a There are two examples in the docs that show this: <article class="Excerpt u-cf">
{{! other implementation details }}
<read-button class="Excerpt-button">Read more</read-button>
<div class="Excerpt-wrapButton">
<read-button>Read more</read-button>
</div>
</article> In both cases the If the documentation is not clear enough then we could definitely improve it. |
If possible, I think that would be great. I'd also propose to make In fact, it's not just my personal vision; all these are things my teammates pointed at as issues/contradictions (and I'd really love our team to adopt SUIT). |
By expanding the Your example of the naming is covered elsewhere in the documentation:
|
Ah, thanks, I read that part too long ago so totally missed it now. As for the |
Hey everyone, I came across a case I'm unsure how to deal with according to SUIT (and whoa! - there is a convenient thread still not shot in the head :) ). Let's say, there is a component inside another component; and we need to be able to control the looks of the child component's elements with the parent component's modifiers/class states. For example: <form class="Form">
...
<button class="Button"><i class="Button-icon"></i> some text </button>
</form> here we might want to make the
.Form.is-loading .Button-icon is simpler and easier to implement (for a person building the markup, as he won't omit necessary details by mistake). But it introduces undesired cross-component dependencies.
So what would be the correct way of doing that with SUIT, assuming we have control over how these components are built? How do you deal with such situations? |
There is a section in the docs https://github.com/suitcss/suit/blob/master/doc/components.md#styling-dependencies and an interesting blog post on this topic http://simurai.com/blog/2015/05/11/nesting-components Tbh I don't know the answer yet though :) If you are only targeting evergreen browsers and can use custom properties then maybe you have better options |
Hey @giuseppeg Yep, I have read the docs. More than once actually :) Still, there's no clear answer to the question above there. As for the blog post - It basically goes into more detail on the options from the first message here, which is not what I'm scratching my head at now :) I'd be ok with a modifier for |
It feels like the cleanest seperation is to add |
I would not start with the You can also make utilities that can be applied to the component later when you are done prototyping out the design, as I have done here: This way you can prototype out your component design using utilities and just apply them when you are done. This also allows you to change the core component design which is helpful when you don't need a modifier like |
Yeah, it is. Just hoped there is a simpler way. Because passing props might be not that trivial in non-react environments. But, oh well, will have to stick to that option. Thanks for discussing that. @oleersoy thanks for your thoughts. A legit pattern, surely, but only for part of cases. That simply won't work if one already has a page design and needs to implement it. Or if Header just has to be a component, which it usually is. In any case, both questions were about things different from what you were describing. |
@dryoma you are much better of leaving cross component state in the javascript domain. |
Whilie thinking over and discussing SUIT design principles I found that I might not understand some moments fully.
Say we have a Header, whose children must be styled in some way (like, be floated or flexed, etc.). Some of those children are components themselves. There are three approaches one could think of:
a) apply the needed styles to
.Header-inner
and add this class to inner components:b) apply the needed styles to
.Header-inner
, but place the inner components inside them:c) Apply the needed styles to
.Header-inner
and to the other components' modifiers And place those on the same level:a) seems the worst as it breaches the "your component should not leak styles into the HTML tree fragments of other components" principle. So I would pick b) or c).
This can be confusing. I really doubt that the principle discourages from having some components for minor or major layouts (like
.Header
,.Menu
), while the others for simple building bricks (.Button
). So this could mean that its ok to place components inside other components, but a component should not rely on that some other components would be inside its HTML? Like, not having such rules as:Could the authors please elaborate on these moments?
The text was updated successfully, but these errors were encountered: