simonsmith / stylelint-selector-bem-pattern

Stylelint plugin that incorporates postcss-bem-linter
MIT License
244 stars 13 forks source link

Ability to have themed components #41

Closed maxhartshorn closed 5 years ago

maxhartshorn commented 5 years ago

There is a use case for having multiple versions of a component, built off the same component: see here

A real world example would be a site search form with a full-width variant.

<form class="site-search  site-search--full">
    <input type="text" class="site-search__field">
    <input type="Submit" value ="Search" class="site-search__button">
</form>

It would be great to be able to define a component like: site-search--full, however if we define a component as such, the following selector would be invalid:

.site-search--full .site-search__field {
    color: #000;
}

Since the component is defined as .site-search--full it expects the second selector to be .site-search--full__field. However enforcing this standard would unnecessarily complicate markup:

<form class="site-search  site-search--full">
    <input type="text" class="site-search__field site-search--full__field">
    <input type="Submit" value ="Search" class="site-search__button site-search--full__button">
</form>

I realize this could be fixed with weak mode, but that isn't ideal. What would be great is to be able to have a selector like this appear as valid:

.site-search--full .site-search__field

And a selector like this fail:

.site-search--full .other-component

Is there a way to do this currently with the tool? Do you feel it would be a useful feature?

maxhartshorn commented 5 years ago

Sorry, realizing that this should be posted to the postcss-bem-linter repo: https://github.com/postcss/postcss-bem-linter/issues/142