css-framework/src/postcss/mixins.js

36 lines
986 B
JavaScript

// eslint-disable-next-line import/no-extraneous-dependencies
const toHSL = require('hex-to-hsl');
const postcssMixins = {
// TODO - untest
defineHSL(mixin, name, hue, sat, light) {
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;
},
// defines a custom property with identifier name, along with individual hue,
// saturation and lightness components
defineHex(mixin, name, hex) {
const [hue, sat, light] = toHSL(hex);
return defineHSL(name, hue, sat, light);
},
// TODO - untested
// // font rendering -> useful for light text on dark backgrounds
fontSmooth() {
return {
'-webkit-font-smoothing': 'antialiased',
'-moz-osx-font-smoothing': 'grayscale',
};
},
};
module.exports = postcssMixins;