Skip to content
This repository has been archived by the owner on Dec 24, 2020. It is now read-only.

Generated Classes Can't Be Extended #95

Closed
dzoba opened this issue Sep 27, 2013 · 2 comments
Closed

Generated Classes Can't Be Extended #95

dzoba opened this issue Sep 27, 2013 · 2 comments

Comments

@dzoba
Copy link

dzoba commented Sep 27, 2013

I've got some Less to create a bunch of default padding classes. However, I can't use those classes in other CSS classes after they are generated.

An example input:

.layout(5px, small);
.layout(10px, large);

.layout(@n, @size) {
  .pad-@{size} {padding: @n}
}

.test {
    &:extend(.pad-small);
}

I would expect to see this as output:

.pad-small,
.test {
  padding: 5px;
}
.pad-large {
  padding: 10px;
}

However, this is what I'm getting:

.pad-small {
  padding: 5px;
}
.pad-large {
  padding: 10px;
}

This is unexpected behavior. As a work around, I tried not using extend, like this:

.layout(5px, small);
.layout(10px, large);

.layout(@n, @size) {
  .pad-@{size} {padding: @n}
}

.test {
    .pad-small;
}

However, the output I got was:

Name error: .pad-small is undefined
.test { .pad-small;}

I'd greatly appreciate any advice. Right now I'm going to have to generate the CSS with less, and then copy and paste the generated CSS into my less files, which is a pain because I'd rather be using Less in my files, not CSS!

@SomMeri
Copy link
Member

SomMeri commented Sep 27, 2013

Generated classes can not be extended and can not be used as mixins.

I tried to come up with another solution:

.layout(@n, @size) {
  .pad-general(@padSize) when (@padSize=@size) {
    padding: @n
  }
}

.layout(5px, small);
.layout(10px, large);

.test-small {
    .pad-general(small);
}
.test-large {
    .pad-general(large);
}

but that one does not work due to this: less/less.js#1291 .

So, my question is, what are you trying to achieve? Maybe there is yet another possibility that would work.

@lukeapage
Copy link
Member

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

No branches or pull requests

3 participants