What is the equivalent of mixin? #258
Answered
by
daryawood
HeartSquared
asked this question in
Q&A
-
@namliw and I have been experimenting and we can't seem to figure out what the equivalent of a mixin would be. The use case we have is something like this, where we have shared styles between different selectors ( export const navItem = style({
selectors: {
'&:hover::after': {
backgroundColor: tokens.colour.bulbasaur,
top: '50%',
bottom: `calc(${HIGHLIGHT_OVERFLOW} * -1)`,
},
},
});
export const navItemActive = style({
'::after': {
backgroundColor: tokens.colour.pikachu,
top: '50%',
bottom: `calc(${HIGHLIGHT_OVERFLOW} * -1)`,
},
},
}); How would we achieve something equivalent to this pattern? @mixin highlight($bg-color) {
backgroundColor: $bg-color,
top: 50%,
bottom: `calc(${HIGHLIGHT_OVERFLOW} * -1)`,
}
.navItem {
&:hover::after {
@extend highlight(tokens.colour.bulbasaur);
}
};
.navItemActive {
&::after {
@extend highlight(tokens.colour.pikachu);
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
daryawood
Jul 29, 2021
Replies: 1 comment 1 reply
-
I'd suggest using functions :) const HIGHLIGHT_OVERFLOW = '';
const highlight = (bgColor) => {
return {
backgroundColor: bgColor,
top: '50%',
bottom: `calc(${HIGHLIGHT_OVERFLOW} * -1)`,
}
}
const navItem = style({
selectors: {
'&:hover::after': {
...highlight(tokens.colour.bulbasaur),
// other rules
},
},
});
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
HeartSquared
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd suggest using functions :)