Skip to content
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

Deny flex-item rules in components #43

Open
ascrazy opened this issue Mar 18, 2016 · 4 comments
Open

Deny flex-item rules in components #43

ascrazy opened this issue Mar 18, 2016 · 4 comments

Comments

@ascrazy
Copy link

ascrazy commented Mar 18, 2016

I want to raise a question about flex-item rules.

I think that it's better not to use flex-item rules at least in default component state because component itself can't know if it will be used in flex-container or not, and even inside flex-container flex-item rules will have different behavior with different flex-container rules on component's parent (flex-direction, flex-wrap, ...)

I guess we should start recommending for flex-item rules the same approach as for positioning.

First, I want to discuss this question with community, maybe other solutions will be found. And then I can try to implement PR (or maybe someone with better English).

@whaaaley
Copy link

I'd say maybe. I think this might fall under the same thing as what's described in variants.

"A component may need to appear a certain way when nested in another component. Avoid modifying the nested component by reaching into it from the containing component."

"Instead, prefer to add a variant to the nested component and apply it from the containing component."

http://rscss.io/nested-components.html#variants

So, "by default" it's already sort of recommended to only use flex-item rules in modifiers anyway, because they have to be initiated by the parent, but maybe clarification or elaboration is needed.

@ascrazy
Copy link
Author

ascrazy commented Mar 19, 2016

@dustindowell22,

We already have an exception for positioning rules.

If you need to define these, try to define them in whatever context they will be in. In this example below, notice that the widths and floats are applied on the list component, not the component itself.

.article-list {
  & {
    @include clearfix;
  }
  .article-card {
    width: 33.3%;
    float: left;
  }
}
.article-card {
  & { /* ... */ }
  .image { /* ... */ }
  .title { /* ... */ }
  .category { /* ... */ }
}

I think that flex-grow, flex-shink or align-self mustn't be properties of component itself, because it's properties of certain context where component is placed (properties of parent component).

I my current project we decided to define variants for this, but it still looking quite abnormal, because you must provide very specific set of rules on parent component if you want to use such variant on its child.

@rstacruz
Copy link
Owner

I guess we should start recommending for flex-item rules the same approach as for positioning.

Makes sense.

@rstacruz
Copy link
Owner

On this note, some people have raised the question: what delineates a component and a layout? In practice, I find that most layouts are components too.

Just wondering if anyone has any opinions on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants