Skip to content

Commit 4f21527

Browse files
authored
fix(theme): check real colors to support css variables
This change allows to use CSS variables in custom themes for LESS variables which are basically used in color functions. Although the themes changed variables are imported after the default theme, the LESS logic still tried to apply a css variable to a color function like "darken()" which of course does not work. It makes #737 complete now. So this simple order results into "error evaluating darken()", although the variables are immediatly overridden: @linkColor : #4183C4; @linkHoverColor : darken(saturate(@linkColor, 20), 15, relative); @linkColor: var(--some-link-color); @linkHoverColor: var(--some-link-hover-color); .foo { bar: @linkHoverColor; } By changing every existing color function call inside the default theme to check for a valid color value it is now possible to completely use CSS variables for a custom theme @linkColor : #4183C4; @linkHoverColor : if(iscolor(@linkColor), darken(saturate(@linkColor, 20), 15, relative), @linkColor); @linkColor: var(--some-link-color); @linkHoverColor: var(--some-link-hover-color); .foo { bar: @linkHoverColor; } Succesfully results into .foo { bar: var(--some-link-hover-color); } Simply check the above code via lesscss.org/less-preview The minium LESS Version to support this is 3.12.0, so i had to raise the dependency 3.x version
1 parent 0c3158d commit 4f21527

File tree

13 files changed

+376
-376
lines changed

13 files changed

+376
-376
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"gulp-uglify": "^3.0.1",
6464
"inquirer": "^8.2.0",
6565
"jquery": "^3.4.0",
66-
"less": "^3.7.1 || ^4.0.0",
66+
"less": "^3.12.0 || ^4.0.0",
6767
"map-stream": "^0.1.0",
6868
"merge-stream": "^2.0.0",
6969
"mkdirp": "^1.0.4",

src/definitions/modules/popup.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,8 @@
833833
@color: @value;
834834
@c: @colors[@@color][color];
835835
@l: @colors[@@color][light];
836-
@cl: lighten(@c, @loadingColoredPercent);
837-
@ll: darken(@l, @loadingColoredPercent);
836+
@cl: if(iscolor(@c), lighten(@c, @loadingColoredPercent), @c);
837+
@ll: if(iscolor(@l), darken(@l, @loadingColoredPercent), @l);
838838

839839
& when not (@variationPopupTooltip) {
840840
.ui.ui.ui.@{color}.popup::before,

src/themes/default/collections/table.variables

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,32 +116,32 @@
116116
/* Positive */
117117
@positiveColor: @positiveTextColor;
118118
@positiveBoxShadow: @stateMarkerWidth 0 0 @positiveBorderColor inset;
119-
@positiveBackgroundHover: darken(@positiveBackgroundColor, 3);
120-
@positiveColorHover: darken(@positiveColor, 3);
119+
@positiveBackgroundHover: if(iscolor(@positiveBackgroundColor), darken(@positiveBackgroundColor, 3), @positiveBackgroundColor);
120+
@positiveColorHover: if(iscolor(@positiveColor), darken(@positiveColor, 3), @positiveColor);
121121
@invertedPositiveColor: @positiveTextColor;
122122
@invertedPositiveBackgroundColor: @positiveBorderColor;
123123

124124
/* Negative */
125125
@negativeColor: @negativeTextColor;
126126
@negativeBoxShadow: @stateMarkerWidth 0 0 @negativeBorderColor inset;
127-
@negativeBackgroundHover: darken(@negativeBackgroundColor, 3);
128-
@negativeColorHover: darken(@negativeColor, 3);
127+
@negativeBackgroundHover: if(iscolor(@negativeBackgroundColor), darken(@negativeBackgroundColor, 3), @negativeBackgroundColor);
128+
@negativeColorHover: if(iscolor(@negativeColor), darken(@negativeColor, 3), @negativeColor);
129129
@invertedNegativeColor: @negativeTextColor;
130130
@invertedNegativeBackgroundColor: @negativeBorderColor;
131131

132132
/* Error */
133133
@errorColor: @errorTextColor;
134134
@errorBoxShadow: @stateMarkerWidth 0 0 @errorBorderColor inset;
135-
@errorBackgroundHover: darken(@errorBackgroundColor, 3);
136-
@errorColorHover: darken(@errorColor, 3);
135+
@errorBackgroundHover: if(iscolor(@errorBackgroundColor), darken(@errorBackgroundColor, 3), @errorBackgroundColor);
136+
@errorColorHover: if(iscolor(@errorColor), darken(@errorColor, 3), @errorColor);
137137
@invertedErrorColor: @errorTextColor;
138138
@invertedErrorBackgroundColor: @errorBorderColor;
139139

140140
/* Warning */
141141
@warningColor: @warningTextColor;
142142
@warningBoxShadow: @stateMarkerWidth 0 0 @warningBorderColor inset;
143-
@warningBackgroundHover: darken(@warningBackgroundColor, 3);
144-
@warningColorHover: darken(@warningColor, 3);
143+
@warningBackgroundHover: if(iscolor(@warningBackgroundColor), darken(@warningBackgroundColor, 3), @warningBackgroundColor);
144+
@warningColorHover: if(iscolor(@warningColor), darken(@warningColor, 3), @warningColor);
145145
@invertedWarningColor: @warningTextColor;
146146
@invertedWarningBackgroundColor: #eec97e;
147147

src/themes/default/elements/button.variables

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,28 +247,28 @@
247247
@tertiaryHorizontalPadding: 0.5em;
248248
@tertiaryLineHeight: 0.2em;
249249
@tertiaryTextColor: @textColor;
250-
@tertiaryLineColor: lighten(@tertiaryTextColor, 20%);
250+
@tertiaryLineColor: if(iscolor(@tertiaryTextColor), lighten(@tertiaryTextColor, 20%), @tertiaryTextColor);
251251
@tertiaryWithUnderline: false;
252252
@tertiaryWithOverline: false;
253253
@tertiaryBackgroundColor: none;
254254

255255
/* Tertiary Hover */
256-
@tertiaryHoverColor: lighten(fadein(@tertiaryTextColor, 100%), 20%);
257-
@tertiaryHoverLineColor: lighten(@tertiaryHoverColor, 20%);
256+
@tertiaryHoverColor: if(iscolor(@tertiaryTextColor), lighten(fadein(@tertiaryTextColor, 100%), 20%), @tertiaryTextColor);
257+
@tertiaryHoverLineColor: if(iscolor(@tertiaryHoverColor), lighten(@tertiaryHoverColor, 20%), @tertiaryHoverColor);
258258
@tertiaryHoverWithUnderline: true;
259259
@tertiaryHoverWithOverline: false;
260260
@tertiaryHoverBackgroundColor: none;
261261

262262
/* Tertiary Focus */
263-
@tertiaryFocusColor: lighten(fadein(@tertiaryTextColor, 100%), 20%);
264-
@tertiaryFocusLineColor: lighten(@tertiaryHoverColor, 20%);
263+
@tertiaryFocusColor: if(iscolor(@tertiaryTextColor), lighten(fadein(@tertiaryTextColor, 100%), 20%), @tertiaryTextColor);
264+
@tertiaryFocusLineColor: if(iscolor(@tertiaryHoverColor), lighten(@tertiaryHoverColor, 20%), @tertiaryHoverColor);
265265
@tertiaryFocusWithUnderline: true;
266266
@tertiaryFocusWithOverline: false;
267267
@tertiaryFocusBackgroundColor: none;
268268

269269
/* Tertiary Active */
270-
@tertiaryActiveColor: lighten(@tertiaryHoverColor, 20%);
271-
@tertiaryActiveLineColor: lighten(@tertiaryActiveColor, 20%);
270+
@tertiaryActiveColor: if(iscolor(@tertiaryHoverColor), lighten(@tertiaryHoverColor, 20%), @tertiaryHoverColor);
271+
@tertiaryActiveLineColor: if(iscolor(@tertiaryActiveColor), lighten(@tertiaryActiveColor, 20%), @tertiaryActiveColor);
272272
@tertiaryActiveWithUnderline: true;
273273
@tertiaryActiveWithOverline: false;
274274
@tertiaryActiveBackgroundColor: none;

src/themes/default/elements/label.variables

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
@ribbonZIndex: 1;
159159

160160
/* Inverted */
161-
@invertedBackgroundColor: darken(@backgroundColor, 20);
161+
@invertedBackgroundColor: if(iscolor(@backgroundColor), darken(@backgroundColor, 20), @backgroundColor);
162162
@invertedBackground: @black;
163163
@invertedBoxShadowSize: 2px;
164164
@invertedBorderSize: 1px;

0 commit comments

Comments
 (0)