question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

use less function && css variable breaks => color2.toHSL

See original GitHub issue
:root{
  --baseColor:pink;
}
@base-color:var(--baseColor, red);
@body-color:shade(var(--baseColor));
body{
  background:@body-color;
}

error: @base-color:var(–baseColor, red); @body-color:shade(@base-color, 15%); ^ Error evaluating function shade: color2.toHSL is not a function in /Users/weiyinpeng/Documents/personal-area/github/mvp/webpack-demo/src/a.less (line 6, column 12) @ ./src/a.less 2:14-111 @ ./src/index.js

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
truefusioncommented, Jul 22, 2020

While I am not familiar with the less source code, it seems to me that less would have CSS variables available to it at compile time, whether we declare them ourselves (like shown in the example) or have less generate code beforehand, and that creating a new function var for less to resolve references would be the simplest way of solving this. Currently, if we want to create dynamic themes for our apps, we have to find really “creative” (i.e. very cumbersome) ways of getting them to work, when we shouldn’t have to because that’s what CSS variables are for. There might be reason to say otherwise, but it is much easier to create apps using web components and then packing everything up with some kind of build tool (e.g. Vue CLI) than to do things the way we did over 5 years ago.

The var function, I would suspect, would work similar to how less property variables and less variables work, at least in regards to scope. I’d be willing to take a crack at it if someone can help me understand how the whole less code works. Would rather not have to spend weeks in trying to figure it out if you guys can take care of it within 24-48 hours.

0reactions
yinsangcommented, Dec 4, 2018

@yinsang You can use modifyVars if you’re compiling Less in browser and injecting from URL params. Use those instead of custom properties. See: http://lesscss.org/usage/#using-less-in-the-browser-modify-variables Thanks a lot. I had considered this solution, but this idea needs to quote a less.js to html. The size of less.min.js is 48kb. It’s not a good idea, either. : (

Read more comments on GitHub >

github_iconTop Results From Across the Web

Color Manipulation With CSS Variables and HSL - Code Salad
Break colors into three variables: hue, saturation, and lightness; Combine HSL ... Use the CSS calc function to manipulate HSL variables.
Read more >
Use CSS variables for controlling colors (#301147) - GitLab
We can reimplement the color functions use CSS variables and calc, or define suffixed-alternate variables, or (most likely) some combination ...
Read more >
Open up new possibilities with custom properties and HSL
Color manipulation with CSS Variables and hsl : ... look at how most people use colors in custom properties 01:35 - Removing the...
Read more >
Sass Color Functions in CSS - Jim Nielsen's Blog
Sass Color Functions in CSS ... tldr; define your colors with individual hsl values using CSS variables, then compose your color declarations ...
Read more >
Calculating Color: Dynamic Color Theming with Pure CSS
With the magic of CSS Custom Properties, HSL colors, and some calc() fun, you too can create custom theming with no dependencies. That...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found