I have the following LESS code:
.favourite-action-link {
&:after {
color:@grey;
content: '\e836';
}
&.is-favourite:after {
color:@red;
content: '\e811';
}
&:hover {
&:after {
color:@red;
content: '\e811';
}
&.is-favourite:after {
color:@grey;
content: '\e836';
}
}
}
With the essential goal being that there is a normal state and a hover state, that are reversed when another class is present. I'll be repeating this for other actions (eg .share-action-link
, .review-action-link
etc) and this just seems messy the way I have it. Is there a way to create a mixin such that I could provide this like so:
.favourite-action-link {
&:after {
color:@grey;
content: '\e836';
&:hover {
color:@red;
content: '\e811';
}
.reverseOnClass(is-favourite);
}
}
Or something like that? The only way I can think of so far would be to do:
.favourite-action-link {
&:after {
color:@grey;
content: '\e836';
}
&.active:after {
color:@red;
content: '\e811';
}
}
and then to use jQuery instead to do the hover - toggling .active
on (isHovering XOR hasClass(is-favourite))
- but turning LESS into LESS + jQuery is the opposite of fixing a mess/maintainability issue.