This repository has been archived on 2021-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
postcss/mixins.js

28 lines
790 B
JavaScript
Raw Normal View History

2021-01-05 10:52:05 +00:00
// eslint-disable-next-line import/no-extraneous-dependencies
const toHSL = require('hex-to-hsl');
// untested TODO - test
function defineHSL(mixin, name, hue, sat, light) {
2021-01-05 10:52:05 +00:00
const 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;
2021-01-05 10:52:05 +00:00
}
// defines a custom property with identifier name, along with individual hue,
// saturation and lightness components
function defineHex(mixin, name, hex) {
const [hue, sat, light] = toHSL(hex);
return defineHSL(name, hue, sat, light)
2021-01-05 10:52:05 +00:00
}
const postcssMixins = {
defineHSL,
defineHex,
2021-01-05 10:52:05 +00:00
};
module.exports = postcssMixins;