I'm making a view that displays transactions on an account, and I want to colour-code the transaction type/state. I also want to show a legend explaining the colour codes.
I want an end result that's structured like this:
HTML
<table id="transactions">
<thead>
<tr>
<th colspan="2">
Transactions
</th>
</tr>
</thead>
<tbody>
<tr class="credit">
<td>A credit</td>
<td>$1.00</td>
</tr>
<tr class="debit paid">
<td>A paid debit</td>
<td>($2.00)</td>
</tr>
<tr class="debit unpaid">
<td>An unpaid debit</td>
<td>($3.00)</td>
</tr>
</tbody>
</table>
<hr/>
<table id="legend">
<thead>
<tr>
<th colspan="3">
Legend
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="credit">Credit</td>
<td class="debit paid">Paid</td>
<td class="debit unpaid">Unpaid</td>
</tr>
</tbody>
</table>
CSS
table#transactions > tbody > tr.credit {
color: limegreen;
}
table#legend > tbody > tr > td.credit {
color: limegreen;
}
table#transactions > tbody > tr.debit.paid {
color: goldenrod;
}
table#legend > tbody > tr > td.debit.paid {
color: goldenrod;
}
table#transactions > tbody > tr.debit.unpaid {
color: crimson;
}
table#legend > tbody > tr > td.debit.unpaid {
color: crimson;
}
Note that the "debits" use two class names, to tell them apart from the credits.
Clearly there's a bit of redundancy there, which I tried to refactor into this (invalid) LESS code:
.transaction-status(@class, @color) {
table#transactions > tbody > tr@{class} {
color: @color;
}
table#legend > tbody > tr > td@{class} {
color: @color;
}
}
.transaction-status(.credit, limegreen);
.transaction-status(.debit.paid, goldenrod);
.transaction-status(.debit.unpaid, crimson);
A possible workaround would be to rejigger things so the different transaction types have a single unique class name but that feels like time travelling to the time of IE6. I.e. I'm aware of, but would like to avoid this valid LESS, which seems so close, and yet so far:
.transaction-status(@class, @color) {
table#transactions > tbody > tr.@{class} {
color: @color;
}
table#legend > tbody > tr > td.@{class} {
color: @color;
}
}
.transaction-status(credit, limegreen);
.transaction-status(debit-paid, goldenrod);
.transaction-status(debit-unpaid, crimson);
I tried quoting the class names, but even though that makes the first LESS sample compile, the quotes are passed to the output CSS. So, is there a way to pass something else than an "identifier" as a parameter to a LESS mixin, and have it work in selector interpolation correctly?