-
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
Variable property #36
Comments
Hey, you can do that with pattern matching, let me illustrate:
Output
So in essence, you can match an arbitrary mixin depending on a variable, instead of creating an arbitrary property name. |
Gidon, this is in dotless so you could use it as cloudhead suggests. One issue with this it takes a lot of setting up. instead of potentially having 4 mixins, one each for padding-top, -left, -bottom and -right. you would just have 1. as an aside. I like the sass sub property syntax...
this outputs as the usual perhaps it would be possible to store that in a variable?
(I'm just thinking out loud, it's probably not very elegant but looks interesting.) |
Looks also nice, though it doesn't look very "lessy", does it? LESS also doesn't support conditions, or does it? .mypadding { |
the best solution is the one I proposed imo. Cascading stylesheets shouldn't have logic in them, so if/then/else is not an option. |
:) I love it when people say things like that. surely, when i write there is logic in less. It just doesn't feel like logic because it doesn't include the word "if". i still like the |
there's logic in the implementation of course, but not in the stylesheet. It's declarative. Yea, attribute interpolation is powerful, but I don't think we need it. |
Yep, I got your point. I can work with the solution provided in less.js |
How would you recommend doing a CSS3 mixin? right now I can do this: But that only allows for one cross-browser compatible call per selector. :\ |
How would you prefer to use it? |
I am not entirely sure what an elegant way would be to pull this off, not without iterating through arguments and having logic of some sort to modify the strings. :P As it stands there are only a few properties that you would need to do for this sort of thing, but I am spoiled and dont want to do them all by hand. :P |
Gradients are another thing that logic would help with generation. Especially considering the differences in browser syntax at the moment. Right now I have to make different gradient mixins, ones that accept 3 arguments, and ones that accept 2. :D |
Hmm, could you show me the desired CSS output, maybe in a Gist, and I'll see if I can think of anything. |
Here's my LTR/RTL variable solution: http://stackoverflow.com/questions/5121584/less-how-to-insert-an-variable-into-property-as-opposed-to-the-value/5162599#5162599 |
nice! |
First, I would like to thank @cloudhead for his awesome work. Being an open source author, I know how thankless it can feel sometimes. Specific to this project, I have worked on two ruby gems less-rails and less-rails-bootstrap to help promote LESS CSS. Both of these gems build on top of @cowboyd's wonderful less.rb. With that out of the way, about this issue. I think it is important to note that there are always going to be "workarounds". Hell, we can just write raw CSS right? Some of the workarounds I have seen may be pragmatic for some but fail to address the core concern. To me this ticket's subject says it all. It would be really nice to have variable or string substitution for CSS properties, not just their values. I can provide my own use case for said feature and I simply ask you do not turn my contrived code examples around with said workarounds that debase this feature request. Given that I may have my CSS setup like this, imagine that my color pallet has around 24 colors. I would like to (1) create a mixin that helps define descendant selectors on a given CSS property. In my case I have the contrived @myWhite: rgb(240,240,240);
@myGray: rgb(140,140,140);
@myBlack: rgb(30,30,30);
.myColorClasses(@property) {
&.white { @property: @myWhite !important; }
&.gray { @property: @myGray !important; }
&.black { @property: @myBlack !important; }
}
.box {
.myColorClasses("background-color");
} Could possibly generate this CSS. .box.white {
background-color: #f0f0f0 !important;
}
.box.gray {
background-color: #8c8c8c !important;
}
.box.black {
background-color: #1e1e1e !important;
} The list of the usages of this would be numerous and allow a form of meta prgramming within the LESS CSS framework. I understand that @cloudhead is a busy person and that being a good OSS participant, I should generate a patch which would hopefully include tests. To that end, can I get some feedback on my comments, accepted syntax, comments on if this may be possible, where might I head in the code, etc?
|
Am I to understand that 93b23d2 is the closer for this issue? |
@metaskills As I understand it, that trick only works for selectors, not for properties (at least I can't make it work). My problem is that I'm building a grid generator, which uses the same calculation for push, pull and column width, but because I can't give it a property as a parameter, I have to have three different mix-ins for the exact same thing. And further more, if I wanted to fork out my IE hack from that, I'd have to put that in three further mix-ins. That's six vs. two. |
Just a through: Since selectors already accept Used for whole declaration:
Used only for property:
Values use different escape syntax |
have a look at #698 some property hacks are already supported and there is an argument that because some prefixing requires different values, having a generic prefix mixin has limited use. Since it adds limited value, I'm not sure on the future of this feature request. also note that the syntax above is being deprecated and replaced by |
Thank you, I did not knew that |
Deprecated means "will be removed from 1.4"? It seems like the new @{variable} is not fully equivalent to the old (~"@{variable}"). The same code with different syntaxes produces different results. Input:
Output:
New syntax generates additional quotes around the value. However, it is impossible to assign the .something value to the variable, because Is this ok? It looks suspicious, but I do not want to open a new issue for "as intended" behavior nor for bugs in deprecated features. |
Thank you again, I should have seen that solution. |
I like @metaskills proposal, and I would like to share the simple solution I created and that I am using while variable interpolation isn't supported. I call it vendorify.less and it has already been submitted as a solution to issue 698. @cloudhead, see the comments below the Gist for more information, test cases and sample output. |
The primary usefulness of this isn't to solve problems that otherwise can't be solved, but to (sometimes drastically) reduce the amount of coding needed to do similar tasks. For example:
|
@extemporalgenome another example using prefixes. We have other issues attempting to make prefixes easier, but also prefixes are in the long term going away |
@lukeapage true enough, though the above example would still get some usefulness out of this hypothetical feature, even without prefixes, not to mention it's a consistency issue (considering that unquoted interpolation works in mixin names but not attribute names). |
thats a different issue and happens to be fixed in 1.4.0
what use is that? |
@lukeapage regarding the fix for that, running lessc on the commit titled "1.4.0 release" with the following input:
I still get an "ParseError: Unrecognised input" error. Usefulness-wise, attribute variable interpolation can be used to make attribute values (and patterns/groups of attributes) reusable. For example, padding, margins, border widths, etc. have identical value grammars in CSS, yet without this kind of interpolation, separate mixins sets would be needed for each attribute type, as opposed to a single set of generic mixins. |
Is this really still not possible? Why the resistance for an obvious piece of functionality? |
@thelucid This feature is being added. There is no longer any resistance to it. :-) |
@matthew-dean Excellent, any idea when? |
Probably when 1.5 comes out and no, there is no definitive timeline for that. There has never been any resistance to this feature, only discussion. Being a library that others rely upon, the developers have be very sure-footed and as forward-looking as possible when they make implementation decisions. |
Agreed with @matthew-dean, there isn't resistance to it, but there is limited time. I don't recall seeing @lukeapage mention this as being planned for 1.5, he's super busy atm. @thelucid are you interested in implementing the code for this? |
@jonschlinkert Possibly, I'm not completely familiar with the code but will take a look over the next couple of weeks. I though I recalled seeing a pull request back-along that was refused as @cloudhead didn't want it, I may be wrong. |
Link the pull request if you can. I'm sure if it was rejected that there was a good reason for it. |
@Soviut I can't find the pull request I was thinking of but this is similar: #698 Also this comment suggests that @cloudhead doesn't see the need: #36 (comment) ...I understand not wanting to include too much conditional stuff but I see variable properties as quite an elegant solution and necessary for things like rem mixins. |
For the specific case of bidirectional sites, I'd like to suggest a more-scoped alternative: Create |
@TedDriggs what are you referring to? This is a discussion about allowing attributes/properties to have variables in their names. Any references to "left" or "right" are just examples one might use for wanting to add left float and left margin using a mixin. |
Given that we've introduced variable interpolation in selectors since then, I'd say it's OK (if not expected) to have it in property names too now. |
👍 |
👍 agreed |
👍 |
Above. I did not create a pull-request to the master repo yet as I guess it would probably be too dramatic change for 1.5.0-beta at the last moment. |
👍 |
In 1.6.0 |
See: http://groups.google.com/group/dotless/browse_thread/thread/9d580e75248b3250
Hi,
SHORT VERSION:
Is the following doable:
.bla {
padding-@variable: 5px; //where @variable could be left, right, top, bottom.
}
INTRO:
I'm working on a website that supports both LTR and RTL. So far I made
two stylesheets, one for LTR and one for RTL. The RTL stylesheet
imports the LTR stylesheet and "overrides" those items that are RTL
specific. (padding-right vs padding-left etc).
float: right/left I manage by having a variable called @SIDE (and
@side-opposite) and setting it to the correct side in both stylesheets
(in RTL it is "right", and in LTR it is "left"). In my LTR stylesheet
I write : float : @SIDE
That was the intro....
QUESTION:
I would also like to eliminate the "overriding" issue, to keep my code
more DRY.
The ultimate thing would be if I could make the property variable:
.bla {
padding-@SIDE: 20px;
}
Can this be done?
Thanks a lot.
Gidon
The text was updated successfully, but these errors were encountered: