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

[Foundation 7] BEMIT - AppFramework level compiler. Edit: Foundation level Compiler also! #10430

Closed
IamManchanda opened this issue Jul 18, 2017 · 62 comments

Comments

@IamManchanda
Copy link
Contributor

IamManchanda commented Jul 18, 2017

Hey Community,

Internally there has been a very deep discussion going on these days b/w yetinauts about the sass architecture and namespacing!
Yes the first and foremost goal is to make the CSS Environment Agnostic
But also concerned about lot of other goals
and thus yeti's think that BEM (or BEMIT) is the solution for it.

BEM is applicable to all projects, whether its big or small, avoids the nestings/specificity issues, helps you encapsulates your code for reuse, Arguably a quick way to deliver prototypes and helps you make good decision (ensures that you plan) and most importantly is semantic
But again we can't hide the stuff that its really a very long html
Thus we yeti's are looking very deep on minimizing the effort of the end user

So last night @ncoden came up with the plan of compiling

Frankly what he said is this

<div bem="myBlock:myModifier as b">
    <div bem="b.myChild:myChildModifier">...</div>
</div>

By this, we can compile and achive the desired result!
Not saying that this is the wrong approach but its not that semantic

So i thinked long today and here is what I think
Why not create an AppFramework level compiler instead of Foundation level?
What that mean is while starting out, we can create App Framework level compiler in three popular frameworks of today (Vue, React, Angular) and also let the community to contribute more compiler for the other framework

As i know bit of Vue.js,
Here is the semantic Vue.js based example for the same

<accordion :modifier="{primary, large}">
  <item :parent="accordion" :objects="{bordered, rounded}">
    <heading :parent="{accordion, item}">
      Accordion Heading
    </heading>
    <content :parent="{accordion, item}">
      Lorem ipsum dolor
    </content>
  </item>
</accordion>

which will automatically convert the code into a BEMIT code like this into the DOM

<div class="c-accordion c-accordion--primary c-accordion--large">
  <div class="c-accordion__item o-bordered o-rounded">
    <div class="c-accordion__item__heading">
      Accordion Heading
    </div>
    <div class="c-accordion__item__content">
      Lorem ipsum dolor
    </div>
  </div>
</div>
@IamManchanda
Copy link
Contributor Author

cc @kball @ncoden @DaSchTour @brettsmason @SassNinja @codetheorist & everyone
What do you guys think ?

@kball
Copy link
Contributor

kball commented Jul 18, 2017

I'm currently dubious... this seems like a pretty large amount of tooling requirement at the usage level, which makes it a lot harder to integrate across a range of environments. It should be straightforward to use Foundation in a rails environment, php environment, wordpress environment, etc without depending on a particular tooling stack at the app side.

I think more advanced tooling in the framework generation side makes a ton of sense, and we should explore that road,

@IamManchanda
Copy link
Contributor Author

Foundation in a rails environment, php environment, wordpress environment, etc without depending on a particular tooling stack at the app side.

Only the compilation code is dependent ... Those guys can still use BEM or BEMIT
Again we should make it easy for others to contribute there environment compilation if want to get easy i guess!

@IamManchanda
Copy link
Contributor Author

This below code is very semantic

<accordion :modifier="{primary, large}">
  <item :parent="accordion" :objects="{bordered, rounded}">
    <heading :parent="{accordion, item}">
      Accordion Heading
    </heading>
    <content :parent="{accordion, item}">
      Lorem ipsum dolor
    </content>
  </item>
</accordion>

@IamManchanda
Copy link
Contributor Author

IamManchanda commented Jul 19, 2017

Hey so I thinked about it, Advanced tooling in the framework generation side!
What we can do for (rails, php, wordpress etc) environments is to create a global compiler

The Global (Vanilla JS) Compiler with html 5 data attributes may look like this
(Based on @ncoden suggestion)

<div data-bem="myBlock:myModifier as b">
    <div data-bem="b.myChild:myChildModifier">...</div>
</div>

But still create atleast 3 ( Vue, Angular, React) App Level compiler so that users of these app frameworks can use the code like my above comment instead of these data-bem.

Bcoz as a Vue (or Angular or React) developer, we would be looking for custom semantic elements! No?

@SassNinja
Copy link
Contributor

SassNinja commented Jul 19, 2017

We're using BEMIT in my company so I'm not averse to bringing it into foundation.
BEM is definitely a great thing and helps me a lot to read other developers' code.
But I won't be able to use a JS compiler for BEM because we internally use twig for templating.

So just to make sure I've understood you correctly:
All of these compilers you mentioned are optional and I would still be able to write vanilla BEM conform HTML, wouldn't I?

And secondly:
Your suggested changes will result in working over the whole SASS & JS code, won't they?
Meaning there will be things as for example $elem.addClass('c-button--hover') instead of $elem.addClass('hover')?

@IamManchanda
Copy link
Contributor Author

I can confirm for sure we will still be able to use normal BEM coding aka normal html... Ofcoursew

@IamManchanda
Copy link
Contributor Author

IamManchanda commented Jul 19, 2017

@SassNinja first of all sorry for very short comment above but that time was unavailable


We're using BEMIT in my company so I'm not averse to bringing it into foundation.
BEM is definitely a great thing and helps me a lot to read other developers' code.

That sounds good. Infact you are not alone, see => https://www.webdesignerdepot.com/2017/04/the-state-of-front-end-tooling/

So just to make sure I've understood you correctly:
All of these compilers you mentioned are optional and I would still be able to write vanilla BEM conform HTML, wouldn't I?

Ofcourse you would... here we are talking about easing the user with easy and understandable coding by compiling code into bem code without writting these long html. Normal BEM coding would just work fine

But I won't be able to use a JS compiler for BEM because we internally use twig for templating.

No issue, You can keep using normal BEM coding but hey you can contribute the compiler for the same i guess (if that makes sense with other Yeti's like @kball)

Your suggested changes will result in working over the whole SASS & JS code, won't they?
Meaning there will be things as for example $elem.addClass('c-button--hover') instead of $elem.addClass('hover')?

Not at all, hover is a state and state is not a modifier
See https://csswizardry.com/2015/03/more-transparent-ui-code-with-namespaces/
and visit Stateful Namespaces section ( is-/has- )

For BEMIT, its frankly a SMACSS Approach for state

.is-active {}
.has-dropdown {}

On the question about changing code, yes because you have to move from active to is-active
That being this is already been implemented a bit in v6.4 and i dont think this will be a big trouble
See => http://foundation.zurb.com/sites/docs/menu.html#active-state


I hope i was able to answer on your questions
If not let me know!

@IamManchanda IamManchanda changed the title [Foundation 7] BEMIT - AppFramework level compiler instead of Foundation level [Foundation 7] BEMIT - AppFramework level compiler. Edit: Foundation level Compiler also! Jul 19, 2017
@SassNinja
Copy link
Contributor

@IamManchanda thank you for the detailed response!

Since normal coding is still supported I won't argue against a BEMIT structure.
The idea of providing several compilers to save code & time during templating is great.
However I think before creating any compiler there must be well-thought-out concept with plenty of 'realistic' code examples (instead of only abstract ones).
No matter what the syntax is going to look, it should have a clear benefit compared to vanilla HTML.

At the moment I'm using a custom emmet filter in SublimeText to save some time while creating the templates, but it's definitely far away from perfect.
It will be awesome if there's a twig extension for BEM in the future 😄

@IamManchanda
Copy link
Contributor Author

The code input and output is another part of the story... This is just a rough code @SassNinja

Had a talk with @kball last night about compiler's... We are thinking about using compilers as an add-on (maybe as a separate repo) instead of including in the core!

@IamManchanda
Copy link
Contributor Author

@brettsmason What do you think about it ??
I would want to know your thoughts on this buddy ??

{ PS: Yes i know you are not sold on BEMIT yet but still 😉 )

@marnen
Copy link

marnen commented Jul 22, 2017

As a longtime Foundation user, let me explicitly register my strong dislike of BEM, and my desire to not have Foundation infected with it. If Foundation's BEM support is limited to being compatible with an optional postprocessor such as BEMIT, I have no problem with that. However, I don't want a BEM naming scheme to become part of Foundation's core, because I don't want my own sites using Foundation to be forced into using BEM.

I know BEM is popular in the CSS community today, but I think it's a big step in the wrong direction, and it's getting harder and harder to find a Sass framework that doesn't force me into using BEM when I don't want to...

@IamManchanda
Copy link
Contributor Author

No issue @marnen... Thanks for expressing your dislike... we will surely look into it

As a longtime Foundation user, let me explicitly register my strong dislike of BEM, and my desire to not have Foundation infected with it. I know BEM is popular in the CSS community today, but I think it's a big step in the wrong direction, and it's getting harder and harder to find a Sass framework that doesn't force me into using BEM when I don't want to...

cc @ncoden

@ncoden
Copy link
Contributor

ncoden commented Jul 23, 2017

@marnen Please give your reasons for not using BEM in a project / why you dislike BEM / why you do not want BEM to be integrated into Foundation.

@SassNinja
Copy link
Contributor

@marnen I'm also interested in your reasons that argue against BEM.

It helps to understand the code structure and dependencies easier. Besides it forces you to think more object orientated and modularly. The only disadvantage imo is the increased amount of HTML and JS (e.g. when toggling classes). But with the help of the mentioned custom compilers (and hopefully some JS utilities) this probably won't be a problem either. The SASS part won't be a big deal because it's out of the box suitable with a syntax as &__element and &--modifier.

@ncoden
Copy link
Contributor

ncoden commented Jul 23, 2017

@marnen @SassNinja Beyond the way you build your components and the maintainability, BEM allow you to (almost) freely use your components by forcing a total separation between your structure (HTML) and your style (CSS), through the "1-everywhere" CSS specificity.

You are not limited to use the components the only way the framework would allow you to :

  1. No arbitrary CSS Specificity.
  2. Less dependencies between parents/children.
  3. No assumption in CSS of your HTML structure.
  4. No assumption in CSS of the others components.
  5. No properties applied "automatically" (on all children tags / classes).
  6. No shared global namespace.

So you can declare, inherit, apply, combine and nest your CSS components way more easily, without having your custom properties being overridden by a vendor component's one (1), without being artificially restricted on the way you place a components children (2) and (3), without complex, arbitrary and inconsistent particular cases in component combination (4), without unexpected, unwanted and hardly resolvable properties applied globally or to all the children of a component (5), without naming collision between components, components' children, states and utilities (6).

And BEM is only a start, a fundamental way to declare your CSS components inspired by OOCSS. There is other CSS methodologies on top of BEM (SMACSS, ITCSS, ITBEM) that give you a lot of others advantages.

CSS is broken by design, we're only trying to push the community to a solution.

@marnen
Copy link

marnen commented Jul 23, 2017

Ack, didn't want to derail this topic, but I feel like I need to answer the questions asked. I'll go into more detail if wanted, but I don't want to lose the topic of this thread.

@SassNinja:

Besides it forces you to think more object orientated and modularly.

I already structure my CSS this way. I don't need to rely on ugly redundant class names to make me do so.

@ncoden:

For the most part, I think that the arguments that you advance for BEM (to the extent that I understand them: some of your language is unclear) represent no actual advantages of BEM, but simply a failure to use the cascade and basic CSS selector logic properly. The cascade, along with properly chosen non-BEM selectors, will do everything BEM does (with the possible exception of preventing "inward leaks") if you let it, and won't leak ugly, repetitive class names into your markup.

For example, if you don't want dependencies or assumption of your HTML structure in your CSS, just target your selectors so they don't assume what you don't want them to assume. You don't need BEM to do that. Also, because of the way selectors work, the "shared global namespace" isn't really a shared global namespace: every selector can in principle act as a namespace for its child objects if wanted.

There is other CSS methodologies on top of BEM (SMACSS, ITCSS, ITBEM)

SMACSS is separate from BEM, and predates it AFAIK. Unless something has changed (possible: I'm only passingly familiar with SMACSS), it is not "on top of BEM".

I'll admit, though, that I don't find any of these methodologies terribly helpful except as inspiration. I've had much better luck simply understanding how selectors and the cascade work at a fundamental level, and using those features to get my CSS to behave in the way I want it to, which is always possible without much trouble. That is, I would rather work from first principles than from a methodology in this case.

CSS in broken by design, we're only trying to push the community to a solution.

CSS has some broken aspects (e.g. lack of functions and named constants until very recently), which is why we need Sass/Less/..., but selector specificity is not one of them IMHO. If you don't like the way CSS selectors work, fine, that's your prerogative. But please don't claim that they're not adequate for their intended purpose, when in fact they are.

@IamManchanda
Copy link
Contributor Author

I strongly dislike @marnen thoughts!

@ncoden
Copy link
Contributor

ncoden commented Jul 23, 2017

@IamManchanda Please give reasons.

@IamManchanda
Copy link
Contributor Author

Short and simple reasons

  1. Selector Specificity is a big pain and BEM solves it.
  2. ClassNames are not ugly... Its just the wrong thinking... They are very semantic classname specially if bundled up with compilers mentioned above
  3. Its many times that you need to pull out a component and its sub components from templates... and BEM makes that very easy!
  4. I find all of these methodologies (BEM, SMACSS, ITCSS, BEMIT) very helpful to organize your code in a better way.
  5. If i have to think like an app framework developer and the way these frameworks divides components... I will think my best bet would be to choose BEMIT or BEM... If that wont be possible... I would have no choice but writting the CSS within the JS component (Angular, Vue example)

@ncoden
Copy link
Contributor

ncoden commented Jul 23, 2017

@IamManchanda

  1. Selector Specificity is a big pain and BEM solves it.

As @marnen said, I think, Selector Specificity is not the problem, but the way we use it with arbitrary selectors, aka selectors mapping the HTML structure rather than declaring a component with its contexts and child objects. BEM solves it only by forcing the user to declare selectors properly and to increase the specificity only when needed.

  1. ClassNames are not ugly.

ClassNames are ugly. .menu__item__link is ugly. This thing have to be repeated across all the HTML. You have a better solution I take it (the compiler could be one, but it mainly depends on how it would be usable with different tools and stacks). But for now it's not really the question.

  1. Its many times that you need to pull out a component and its sub components from templates... and BEM makes that very easy!

I don't understand what that means.

  1. I find all of these methodologies (BEM, SMACSS, ITCSS, BEMIT) very helpful to organize your code in a better way.

Even if this is true, this is is not their main advantage. If we're talking about component encapsulation and organization with layers (utilitities / generic components / semantic sections / ...), well there is nothing specific to these methodologies. You can have a more or less clean CSS in your project without them.

  1. (...) If that wont be possible... I would have no choice but writting the CSS within the JS component.

It's the bad solution to a deeper problem. Like @marnen said, the main problems in CSS come from the lake of knowledge of how specificity and cascading works and how to take advantage of it. Local CSS does not resolve the problem, it destroy to create a bigger one: code duplication.

@marnen
Copy link

marnen commented Jul 23, 2017

While I'll happily debate the merits of BEM, I'm starting to feel that doing so here misses the point. The point is that a general-purpose Sass framework should not impose too much on the structure of user code. If @IamManchanda would like to use BEM with Foundation, I think he should be able to do so (even if I don't think it's a great idea). Likewise, if I want to not use BEM with Foundation, I should be able to continue to do so without going against the nature of the framework.

Foundation has been great in this regard, and all I'm really saying here is that I hope future versions will continue this practice.

@brettsmason
Copy link
Contributor

@IamManchanda sorry I haven't replied yet on purpose as I think it's important to let the discussion grow. I will reply fully though this week, but this sort of sums up concern too:

The point is that a general-purpose Sass framework should not impose too much on the structure of user code

@ncoden
Copy link
Contributor

ncoden commented Jul 25, 2017

@marnen Right, we will not use BEM, because no framework should enforce a methodology with no reasons and enclose the user in it. I totally agree with you.

However.

We will take advantage of the specificity and cascading to keep control on the property order, so use the same specificity for all the standard context of our components, and incread the specificity according to the context if CSS doesn't do it natively to ensure context priorities.

We will avoid declaring selectors with artificial dependencies between components and their children when it is not required by the CSS rules themselves, to allow a free use in our components in a complex markup. For the same reason, we will declare style components only, as separated as we can from the markup.

We will split our components into different categories when we know we always expect a priority from some of them over the others because of their semantic particularity.

We will avoid applying properties automatically from the parents because more than preventing the control of the specificity, this lead to unwanted properties in a lot of cases that cannot be resolved without breaking the specificity again, and it goes on...

And all that require a Single Class API.

So we will not use BEM, because you're asking us not to. But we will use what is making BEM BEM, because we have good reasons for it, the same you are defending when you're telling us how BEM is not necessary, and because we know these reasons as explicit rules and simplified principles will benefits to all our users.

@marnen
Copy link

marnen commented Jul 25, 2017

@ncoden What do you mean by a single class API?

Also:

But we will use what is making BEM BEM, because we have good reasons for it, the same you are defending when you're telling us how BEM is not necessary

I suspect you're not understanding what I'm arguing for or against, then. But I will defer further discussion of this until I make sure I understand what "single class API" means.

@IamManchanda
Copy link
Contributor Author

@ncoden
Copy link
Contributor

ncoden commented Jul 26, 2017

@marnen A single-class API is a CSS API composed with "one-class" selectors, to ensure an equal specificity of 0.1.0. This mean that instead of

.menu
.menu li
.menu > .link

You have (for example)

.menu
.menu-li
.menu-link

@IamManchanda
Copy link
Contributor Author

Yes and for that Bem is the right area to move ahead

@ncoden
Copy link
Contributor

ncoden commented Jul 27, 2017

This is not possible!

@IamManchanda This is totally possible. Since I am at Foundation, I push for we have a complete Sass API that provide at least all the components and modifiers of the CSS API. So we can try to make Foundation "Sass first", and still provide a CSS API from that for prototyping or user comfort.

@marnen I wanted to use Bourbon at first for a project I worked on, but finally used Foundation because Bourbon did not have components as I expected. I like the "Semantic classes" approach with everything built in Sass (creating tons of classes in CSS to do everything is not scalable for now), but it lead to a lot of code duplication. It would be great if you have a solution to this problem.

@IamManchanda
Copy link
Contributor Author

You guys mean to remove all css by default... sorry but ...I am strongly against it
cc @kball @rafibomb ??

@brettsmason
Copy link
Contributor

@IamManchanda that's not what @ncoden and @marnen were saying. Nicolas was saying create the framework as primarily a Sass mixin library (like Bourbon) but also have the ability to output classes as we do now.

I think thats a great suggestion and would be a good step forward in my opinion.

We could have a global selector map, then all CSS generating mixins could get their selectors from that. So the suggestion by @marnen could be output with a class child selector or an element. Maybe even an option to set to nested or single class... Just brain dumping now 😄

@ncoden
Copy link
Contributor

ncoden commented Jul 27, 2017

Nicolas was saying create the framework as primarily a Sass mixin library (like Bourbon) but also have the ability to output classes as we do now. (@brettsmason )

Exactly. CSS is limited. No variables (for now), functions, reusable code, logics in general or inheritance without a dedicated architecture. People should understand that building their components from atomic classes directly in the HTML is limited. We cannot generate an infinite number of classes for all possibilities.

They have to write custom CSS one time or an other. And at this point there would be no difficulty to move to Sass and create their own classes by inheriting the Foundation Sass components. This is definitely better than having to ask Foundation to add this or that very specific feature.

But I still want Foundation to provide a standard CSS library, and a very simple way in Sass to generate all the default components, like we are doing now.

Maybe even an option to set to nested or single class

@marnen About what I said before:

But as explained before, SCA is not really a "naming convention" but a fundamental architecture principle. We cannot change it based on an user option, because the whole framework architecture is based on it.

I thought about it and changed my mind. Components need to be built a particular way in Sass to make SCA possible (all properties in their respective elements, strict component organization), but then it cost nothing to use a selector or an other (like .menu > li instead of .menu-item). It's sad, it's too bad for the user and will probably cause problems, but at this point we don't care. We have what we want, a SCA framework, we'll try to teach our users about it, but if they still want to code "à la Bootstrap" we should not artificially limit them.

@ncoden
Copy link
Contributor

ncoden commented Jul 27, 2017

And:

You guys mean to remove all css by default... sorry but ...I am strongly against it

Please. Give. Reasons. ;)

@IamManchanda
Copy link
Contributor Author

IamManchanda commented Jul 27, 2017

If thats the case we should be creating separate repo Foundation Sass or Sass Activate or F7 Sass Activate (Just like Bourbon)
and then use that same code mixins for Foundation 7 css ??

If people want different implementation unlike what foundation 7 gonna have... then simply they can install that lightweight repo only and create there own code ??

@ncoden
Copy link
Contributor

ncoden commented Jul 27, 2017

we should be creating separate repo for [ similar product with some little differences ]

It's never a good idea (maintenance division, bugs/fix/features duplication...).

If people want different implementation

We're talking about different CSS implementation. Our CSS is currently generated by Sass mixins. Nothing prevent us from making mixins that can be used to generate our current CSS and a SCA.

So people can install the same repo, import or not the Sass mixins in their Sass project and import or not the CSS files in their HTML/build process.

@IamManchanda
Copy link
Contributor Author

build process

👍 I would say build process @ncoden

# For only sass mixins
foundation new --framework sites --styling sass-mixins-only

# Sass mixins and CSS
foundation new --framework sites --styling full-box

@ncoden
Copy link
Contributor

ncoden commented Jul 27, 2017

This is not a build process. foundation new is a generator. It create a basic project structure, but do not create your distribution files (like we are with gulp).

@rafibomb
Copy link
Member

Yes - it would be a global variable to turn off the class output. There will still need to be suggestions for markup structure.

@IamManchanda
Copy link
Contributor Author

I wanted to add this in so adding it.

Even Google/Alphabet have started using BEM
See https://deepmind.com/

@marnen
Copy link

marnen commented Aug 2, 2017

@ncoden:

Components need to be built a particular way in Sass to make SCA possible (all properties in their respective elements, strict component organization), but then it cost nothing to use a selector or an other (like .menu > li instead of .menu-item). It's sad, it's too bad for the user and will probably cause problems, but at this point we don't care. We have what we want, a SCA framework, we'll try to teach our users about it, but if they still want to code "à la Bootstrap" we should not artificially limit them.

I'm trying to understand what you meant by this…and failing. Can you clarify?

When you say that components need to be built a particular way in Sass to make SCA possible, are you referring to a structure such as this

@mixin menu { ... }

@mixin menu-item { ... }

as opposed to

@mixin menu {
  ...
  .item { ... }
}

?

If so, then I agree with your claim. But in that case, what do you mean by

It's sad, it's too bad for the user and will probably cause problems, but at this point we don't care.

?

Are you referring to the fact that you can't include a component with one mixin if you structure your Sass this way?

If that is the case, BTW, what's preventing this?

@mixin menu { ... }
@mixin menu-item { ... }

@mixin menu-complete {
  @include menu;
  .item { @include menu-item }
}

(Perhaps it's not worth it. Just an idea.)

We have what we want, a SCA framework, we'll try to teach our users about it, but if they still want to code "à la Bootstrap" we should not artificially limit them.

I hope you're not meaning to claim that these are the only two options. For myself, I use neither the single-class pattern or the Bootstrap pattern.


On another note, I really appreciate what I'm seeing here of the way the Foundation community seems to function. I was fully expecting my initial post in this thread to be disregarded or considered off-topic, but I'm really pleased that we've wound up in an apparently constructive discussion as a result. Suffice it to say that this gives me a much better feeling than discussions I've with the maintainers of several other similar libraries, and gives me the impression that Foundation has a better chance of remaining viable for my work (though there are certainly things I'd like to see it do differently).

@marnen
Copy link

marnen commented Aug 2, 2017

Also, @ncoden:

I like the "Semantic classes" approach with everything built in Sass (creating tons of classes in CSS to do everything is not scalable for now), but it lead to a lot of code duplication. It would be great if you have a solution to this problem.

If you can describe the problem in more detail, perhaps I can help solve it. :)

@ncoden
Copy link
Contributor

ncoden commented Aug 3, 2017

When you say that components need to be built a particular way in Sass to make SCA possible, are you referring to a structure such as this (...)

Yes.

If so, then I agree with your claim. But in that case, what do you mean by: "It's sad, it's too bad for the user and will probably cause problems, but at this point we don't care."

It's sad in my point of view, because we have a framework that is "SCA-compatible". You are sure it will not apply properties you don't want, fuck up your specificity, etc... And people will use Bootstrap-like selectors "because it's more convenient" then stack dirty fixs over dirty fixs to have the render they want.

But. "at this point we don't care.". We provide a framework, we don't rule the world. Let's create good tools and make people learn why they should use them. But we should not artificially restrict anyone, it's just useless.

Are you referring to the fact that you can't include a component with one mixin if you structure your Sass this way?

No (see above). But this is false too. We can provide (like we are doing sometimes) one mixin for each block/element/modifier AND a component mixin that generate the CSS component with arguments/configuration-based selectors. This is almost what we are doing for ZF grids.

This allows the user to change the generated selectors for all the components through the config, and to inherit a whole components (or a part of it) with one mixin call.

If that is the case, BTW, what's preventing this?

Nothing, that's the point. a SCA framework is compatible with and can be converted to any other architecture. The limitation is in the way you create your components.

I hope you're not meaning to claim that these are the only two options. For myself, I use neither the single-class pattern or the Bootstrap pattern.

I do not :D . I know there is a whole palette between BEM and Bootstrap. I like the "scope"/"scoping modifier" principles (I already talked about it on some issues I think) that are a good compromise in some contexts.

I was fully expecting my initial post in this thread to be disregarded or considered off-topic

I like playing the devil's advocate, it may help :).


If you can describe the problem in more detail, perhaps I can help solve it. :)

The idea behind this is : instead of generating tons of CSS selectors, and making the inheritance when applying them in the HTML (for example <... class="house house--purple house--big my-house">, we could move all that to Sass and generate classes you use directly in the markup (<... class="this-house-for-this-context">).
So you have two things: a markup that is oriented around the structure and semantic with classes applied for everything, and an associated stylesheet when you will create/inherit/customize all components and more or less generic styles.

See: https://designshack.net/articles/css/semantic-grid-class-naming-with-placeholder-selectors-in-sass-3-2/

The problem is: we cannot use @extend because your properties are ordered like your placeholders, and not like the components. So this can't be applied to a whole application because all components/utilities/etc priorities are mixed.
And with @include, well this duplicate every component. Not better.

PS: I did not forgot your post above. I found back some aspects of BEM+compilor I did not liked and I'm looking for solutions.

@marnen
Copy link

marnen commented Aug 4, 2017

[Look at your line-breaking after block quotes—it doesn't do what you think it does. :) ]

I'm still not quite understanding all of your issue, but I will say this: I consider @include to be usually the best way of removing duplication and presentation code in Sass. @extend, though useful, is IMHO a bit of a hack, and I only use it (with real selectors) when I'm depending on framework CSS that I don't control (as is the case with Bootstrap). I hardly ever use it otherwise. I've never actually used %placeholders with @extend as mentioned in the article, because I just don't see the point when @include exists. Maybe I don't understand what they're good for.

@marnen
Copy link

marnen commented Aug 4, 2017

@ncoden Ah...I may have finally understood another piece of the puzzle. Are you objecting to the duplication that @include introduces into the generated CSS? If so, I agree that's slightly messy, but I'm not sure how much I care, since no human has to maintain the duplication.

@ncoden
Copy link
Contributor

ncoden commented Aug 5, 2017

since no human has to maintain the duplication

Maybe, but for example a common grid with 3 columns generate 30+ properties. This is a piece the user should not duplicate to create its own semantical "layout classes". Generated CSS files would be around 10MB instead of 100KB

@marnen
Copy link

marnen commented Aug 5, 2017

Yes, that would be a reason for @extend over @include, if it were actually measured to be a problem (otherwise it's just premature optimization), although @extend puts a lot of unused selectors into the generated CSS. I think your size estimates are inflated, though.

I'll admit that I don't generally worry much about the size of my CSS files (they don't wind up being very large, and they're cached anyway), but I understand that as a framework author you have to. (Of course, if a file is that repetitive, it's a good candidate for gzipped delivery, but we certainly don't want to force that.)

@marnen
Copy link

marnen commented Aug 5, 2017

...and with this realization, I understand now what %placeholders might be good for: removing the unused selectors and having less repetition in the generated code. Hmm.

@HansUXdev
Copy link

HansUXdev commented Sep 21, 2017

@marnen and @ncoden thank you very much for your input. I feel like you guys are preaching to save the heart and soul of the framework lol

@IamManchanda if you disagree its cool but when you are the only one thumbs downing something/someone and not stating the reason(s) it comes across as kinda brash and discourages conversation about a serious issue...

That being said, I fully agree with marnen and ncoden when they talk about keeping it more like bourbon as a library of mixins for component. If the framework enforced BEM or any other type then I and a lot of others would probably stop using.

Personally I would like to see foundation 7 built on what made v6 great which is it's flexibility.
So something like this would be nice to see:

// colors
@import 'theme';     
// framework settings
@import 'settings';

//import all framework mixins, styles html5 core tags and base components
@import 'foundation'; 
// import mixins for building-blocks, community driven components
@import 'building-blocks';

// import your name schema (to make everyone happy)
@include foundation-legacy;
// @include foundation-bem;

More over, I think the focus of Foundation 7 should be a component driven framework rather than a site driven framework like foundation 6 but avoiding the mistakes of foundation for apps.

One of the major (css) mistakes of F4A was the naming/grid. Lets face it, the grid was aweful. It was weirdly named and functioned strange (XY is a MAJOR improvement).

That being said, the original purpose of this topic "AppFramework level compiler" is interesting but I worry it could quickly become another F4A like scenario and that would be devastating to the community which primarily uses sites. I would love to see a working example (demo/proof of concept) for angular, react and vue before any major BEM, etc is implemented.

As for ugly syntax:
I thought the example below was the ugliest css-like selector I have ever seen...

<div bem="myBlock:myModifier as b">
    <div bem="b.myChild:myChildModifier">...</div>
</div>

However the sematic version below is actually really interesting:

<accordion :modifier="{primary, large}">
  <item :parent="accordion" :objects="{bordered, rounded}">
    <heading :parent="{accordion, item}">
      Accordion Heading
    </heading>
    <content :parent="{accordion, item}">
      Lorem ipsum dolor
    </content>
  </item>
</accordion>

@IamManchanda
Copy link
Contributor Author

IamManchanda commented Sep 21, 2017

No issue... thanks for your concern @HansUXdev

{ PS: Please don't use slang's which can be seen as double meant! FWIW I have edited your comment with a synonym! }

@HansUXdev
Copy link

@IamManchanda by the way, again I think a AppFramework level compiler is a great idea.

But being devils advocate, aside from maybe a vanillia-js approach that can be plugined into vue, react, angular, how is it different then advanced css modules?

More importantly why would a tool like this, require changing the entire framework's naming schema?

@IamManchanda
Copy link
Contributor Author

Simple Answer => Because its not #CSSinJS

@phifa
Copy link
Contributor

phifa commented Feb 6, 2018

@IamManchanda how are we doing with the BEM plans? will this be for v7?

@JeremyEnglert
Copy link

Closing this issue out. We can reopen for discussion in V7.

@DanielRuf DanielRuf added this to Planning and Organizing in Foundation V7 Oct 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Foundation V7
Planning and Organizing
Development

No branches or pull requests

10 participants