-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Request for "rule replacement" feature #1372
Comments
@jonschlinkert I'll try to explain more what i want reach. I want to work with bootstrap with folowing workflow: css/bootstrap/*.less <- will never touch them Now for example I want to change
Result css should be:
I'm not sure about syntax, we can discuss this. But this is should be something like:
|
What keeps coming to mind as I think about this request is minimatch patterns. Imagine how much more powerful this concept would be if we modified the syntax of this feature in a way that (elegantly) allowed the usage of globbing patterns for selectors lol! My point is that |
I think its really great idea. Can you show some examples how it can be integrated? |
Sure, so the way it would work is that instead of just using |
I'm saying "excluded", but I also consider "replacement" to be implicit. |
So we can do for example:
Doing |
Yes, but you would also exclude any other selector that starts with "h", such as This is completely fine though IMO, anyone who uses globbing knows this, so you use patterns that are intended to be specific enough to target what you need, but not so general that will accidentally target something else. |
@jonschlinkert Seems its very powerfull. Its can also work this way:
Mean not exclude all |
Well, you would probably do something like:
But what I didn't mention is that minimatch also allows for inclusion patterns. What that means is that when combined with the With your concept (and minimatch), we could do this: @import (reference) "bootstrap.less";
.alert* {}
.nav* {}
.modal* {
max-width: 720px;
}
// etc. Here, we're using "inclusion" patterns, which IMO is more powerful than exclusion. |
Did that example makes sense? I mean are you familiar with the "reference" feature? |
@jonschlinkert Yes, i totally got idea. |
As usual, I'm going to interject and suggest possibly more appropriate terminology. I think that |
Override is correct, I got hung up on "replace" as well. But actually the original request was for both overriding and exclusion. So replacement probably seemed convenient as a catchall. I would now probably describe this as a request for "the ability to use inclusion and exclusion patterns for greater control over which selectors are rendered when importing external libs". Agreed? |
Agreed. I could see people asking "how can I override styles from an external library?" so I think the term is more likely to make sense and get hits when people are searching for help. |
This is the inverse of using reference and extend.. which is something I would probably suggest over rule replacement.. e.g. pick out the things you need and leave the rest rather than taking it all and then over-riding the bits that don't make sense. I'd like to see how people use reference and extend and how libraries adapt before implementing more features to help using them. |
I think with the fact you can reference styles in a root library (without outputting), and that you can name your classes something different and import what you want means that this doesn't seem necessary. The fact that you can't name your own classes to begin with is a problem created by the LESS library, not the parser, so I don't think it's our business necessarily to solve problems created by libraries (since they can be solved by re-architecting the library). |
@lukeapage agreed. I think that's important. I also think this request may be useful in the future so it will be fun to see how the dialog evolves here. @matthew-dean, yeah I was afraid folks wouldn't completely get this request. It has nothing to do with "other" libraries or solving anyone's problems. The lib could by yours intentionally created for this purpose... ;-) Just give this one the benefit of the doubt, I think there is more to this than will be immediately understood, not because it's "complex" or anything like that, but that there is no easily explained frame of reference from which to explain the feature. It will make more sense after |
@jonschlinkert What I mean is that the "rules" could be defined as mixins or variables, which was what was in my head. So, you could do this: .error-box-definition() {
background: red;
color: yellow;
}
// some other selectors.less file would have maps
.error-box {
.error-box-definition;
} Or, alternatively: // selectors.less
@errorBox: ~".error-box";
// definitions.less
@{errorBox} {
background: red;
color: yellow;
} |
I also didn't get what he was asking for initially (to the degree that I actually asked if I could delete my comments lol, which was a first, but I didn't want to take away from the request), I suggest reading back through. It's not even close to what you're suggesting. |
Including particular selectors from a library? I've looked through it; it still doesn't seem necessary. Rather than having inclusion patterns like .alerts* {}, a library could be grouping selectors by mixin and switching by variable. Or with reference, grouping such selectors by feature (less file), and allowing an author to include or simply reference. I think there's more coverage than we may realize by existing or upcoming features, but the patterns have not emerged yet from usage. So, in general, I'm in agreement with Luke:
|
In other words, the assumption may be that this is needed based on how libraries are structured now, but they may restructure around use of reference, extend, and variable interopolation in selectors. |
I'm sorry, but I'm using reference a lot with both individual components and "manifests" that refer to libraries of components, and this request would be amazing to see implemented at some point. I'm quite familiar with our existing features and nothing can do anything like this. Reference, mixins and extend all require you to target specific selectors for inclusion, this request on the other hand would allow you to exclude selectors. And with the introduction of the minimatch, you could include or exclude any given pattern of selectors at once. |
Guys. Cant got one thing. For example there is no that issue. But 1.5 released. For example we have
And
? |
But, Jon, how is a typical user going to know what exclusion patterns to use on, say, a library like Bootstrap, that won't have knock-on effects when they start applying some of the classes? Would it not be better to funnel library makers into creating a type of API architecture where those exclusions are predefined using mixin wrappers? So that people don't end up excluding things accidentally that break the library? In the end, I don't disagree that we don't necessarily cover exactly what you're saying. I'm just wondering if that isn't, in fact, a good thing. But, devil's advocate, I suppose class overriding is no less disruptive to code or dangerous than overriding properties (Issue #1342). So, I suppose it may be hypocritical to say that powerful features that are potentially destructive or confusing in some cases shouldn't exist. If the author is willing to take the risk, I guess it's somewhat on them. But, just to bring it back to Luke's point, I think it's sound judgment to just slow a bit while people start building extend, reference, and variable interpolation in selectors into their projects and libraries. That way they may choose simpler, less destructive features first before using something more destructive in case they need it. |
The way I'm interpreting this rule is basically to have "cascading LESS". Where LESS files are aware of their structure and cascade rules in much the same way CSS does already. I see this as a natural extension, but one that must be planned carefully given the extensions that already exist (mixins, especially). I think that namespaced variables are probably the first step in this direction, allowing libraries to both isolate and allow variable overriding without having to pollute a global scope. This takes care of many of the margin and colour issues one faces with Bootstrap, without the need for structure awareness; As long as Bootstrap is being imported in its LESS form. However, namespaces and variables do not address the possibility of needing to import raw CSS and perform overrides when there are no variables or mixins to contend with. |
I was suggesting that minimatch is a much more powerful tool for inclusion. But there is still a need for selective exclusion. |
|
I just wanted to revisit this after working on a project where I really could have used it. I just used Going even further, IMO it would make more sense to use minimatch than // Extend Bootstrap's .dropdown-menu
.dropdown-inverse {
&:extend(.dropdown-menu *);
} and with exclusion patterns .notification {
&:extend(.alert *, !.alert-foo);
} |
@jonschlinkert The problem is that these symbols conflict with existing CSS selectors, e.g.:
|
+1 Would love to see a way to exclude declarations, too. E.g. Bootstrap has many declarations which may not be used by many but are compiled by all of the billion bootstrap users. As a consequence, all visitors of all bootstrap-built websites have to load this .css bloat over and over again. If we can exclude stuff from e.g. bootstrap, we get a slick css which can trimmed down to the core without ever touching the sources. Smaller css size would make websites load faster, thus saves on computer power, thus reduces CO2 emission, thus saves lives. In other words, you guys would kill people if you ignore this request. :-) |
@bartelsmedia That's really more of a build step using something like https://github.com/addyosmani/grunt-uncss |
Problem is that we would need to uncss all the LESS rendered css output instead of just the LESS declarations themselve. Besides, we use Crunch on a client. |
@bartelsmedia Crunch is an editor, you can have Grunt or Gulp running in the background, listening for file changes and running a build process. Typically this would include compiling your LESS to CSS, then autoprefixing, then uncss, then perhaps minification with source maps. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
For example we have
bootstrap/typo.less
:and
typo.less
:and
site.less
:Overall css result will be:
My suggestion is to add new feature
replace previous
. For examplebootstrap/typo.less
:and
typo.less
:and site.less:
Overall css result should be:
This will be very useful for customizing css frameworks like twitter bootstrap without modifing its code.
The text was updated successfully, but these errors were encountered: