Currently, I am incorporating LESS into one of my projects and I have a requirement to establish different color schemes for various users. The project involves developing a portal where the color scheme should change based on the type of user logging in.
Within my mixins.less file (which is immutable), I have defined the following:
@color-button-bg: #333;
@color-button-txt: #fff;
@color-button-fs: 1.5rem;
@color-button-fw: 500;
@color-button-hover-pct: 10%;
.base-btn-default(@type: button) {
background: ~"@{color-button-bg}";
border: 1px solid ~"@{color-button-bg}";
color: ~"@{color-button-txt}";
font-size: ~"@{color-button-fs}";
font-weight: ~"@{color-button-fw}";
&:hover, &:focus {
@color-btn-hover: ~"color-button-bg";
@color-btn-hover-pct: ~"color-button-hover-pct";
background: darken(@@color-btn-hover,@@color-btn-hover-pct);
border-color: darken(@@color-btn-hover,@@color-btn-hover-pct);
color: ~"@{color-button-txt}";
}
}
In a separate file containing client-specific mixins, I attempted the following approach:
/* Replace default color with theme color */
.theme-styling() {
@color-button-bg: @main-theme-color;
}
Subsequently, my intention was to assign a class to the <body>
tag and implement the color scheme based on that class name:
body.theme-a {
#main-theme-color: teal;
.theme-styling();
}
Regrettably, this method does not appear to be effective. I suspect it may be related to scoping or lazy evaluation, but given my limited experience with LESS, I am struggling to pinpoint the issue.
I have created a Codepen demonstration without utilizing separate files and in a slightly simplified manner: https://codepen.io/jewwy0211/pen/JVNZPv