Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can use hsl instead of rgb for scss global declaration javascript api

that's how my next.config.js look like

// next.config.js

const env = require('./site.config').env;
const Colour = require('sass').types.Color;
const {r, g, b} = require('./site.config').customProperties;

const withBundleAnalyzer = require('@next/bundle-analyzer')({enabled: !!process.env.ANALYZE});

const config = {
  env: {
    ...env,
  },
  sassOptions: {
    functions: {
      'primaryOpacityColour()': function(){
        return new Colour(r, g,b)
        // here I want to return Colour in hsl form
      },
    },
  },
};

module.exports = withBundleAnalyzer(config);

I'm not able to return Colour in hsl form, can anyone please help me how to resolve this issue?

like image 333
Pavan Tank Avatar asked Jan 06 '21 08:01

Pavan Tank


People also ask

What is HSL color in CSS?

In CSS, a color can be specified using hue, saturation, and lightness (HSL) in the form: hsl (hue, saturation, lightness) Hue is a degree on the color wheel from 0 to 360. 0 is red, 120 is green, and 240 is blue. Saturation is a percentage value, 0% means a shade of gray, and 100% is the full color.

What does HSL mean on the color wheel?

hsl ( hue, saturation, lightness) Hue is a degree on the color wheel from 0 to 360. 0 is red, 120 is green, and 240 is blue. Saturation is a percentage value, 0% means a shade of gray, and 100% is the full color. Lightness is also a percentage, 0% is black, 50% is neither light or dark, 100% is white. Experiment by mixing the HSL values below:

What is the HSL () function used for?

The hsl () function define colors using the Hue-saturation-lightness model (HSL). HSL stands for hue, saturation, and lightness - and represents a cylindrical-coordinate representation of colors. The numbers in the table specify the first browser version that fully supports the function.

Why can’t I Pass $blue or $alpha to RGB in Sass?

Sass’s special parsing rules for slash-separated values make it difficult to pass variables for $blue or $alpha when using the rgb ($red $green $blue / $alpha) signature. Consider using rgb ($red, $green, $blue, $alpha) instead.


1 Answers

according to https://github.com/sass/sass/issues/2988 you cannot do this with the javascript api. dart-sass has it in the dart api, but not in the javascript api (yet).

your best bet is to convert from hsl to rgb and return Colour, as you are doing now.

like image 181
Jayen Avatar answered Oct 07 '22 00:10

Jayen