From 30f18de0397b6b780e6ee1c585271bb2af14c29a Mon Sep 17 00:00:00 2001 From: Ray Elliott Date: Wed, 17 Feb 2021 17:44:17 +0200 Subject: [PATCH] add defineHS()L, remove defineColorAlpha() --- mixins.js | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/mixins.js b/mixins.js index a95e9a0..ecffdcc 100644 --- a/mixins.js +++ b/mixins.js @@ -1,31 +1,28 @@ // eslint-disable-next-line import/no-extraneous-dependencies const toHSL = require('hex-to-hsl'); -// defines a custom property with identifier name, along with individual hue, -// saturation and lightness components -function defineColor(mixin, name, hex) { - const [hue, sat, light] = toHSL(hex); +// untested TODO - test +function defineHSL(mixin, name, hue, sat, light) { const obj = {}; - obj[name] = hex; - // need to convert hue to string otherwise postcss (is it postcss?) appends - // 'px' to the property's value. - obj[`${name}__h`] = hue.toString(); - obj[`${name}__s`] = `${sat}%`; - obj[`${name}__l`] = `${light}%`; - return obj; + obj[name] = name; + // need to ensure hue is a string otherwise postcss (is it postcss?) appends + // 'px' to the property's value. + obj[`${name}__h`] = hue.toString(); + obj[`${name}__s`] = `${sat}%`; + obj[`${name}__l`] = `${light}%`; + return obj; } // defines a custom property with identifier name, along with individual hue, -// saturation, lightness and alpha components -function defineColorAlpha(mixin, name, hex, alpha) { - const obj = defineColor(mixin, name, hex); - obj[`${name}-a`] = alpha; - return obj; +// saturation and lightness components +function defineHex(mixin, name, hex) { + const [hue, sat, light] = toHSL(hex); + return defineHSL(name, hue, sat, light) } const postcssMixins = { - defineColor, - defineColorAlpha, + defineHSL, + defineHex, }; -module.exports = postcssMixins; +module.exports = postcssMixins; \ No newline at end of file