@coko/client
Version:
Client side common code for coko apps
59 lines (51 loc) • 1.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.lighten = exports.darken = void 0;
var _lodash = require("lodash");
var _color = _interopRequireDefault(require("color"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/*
Functions to change the shade of a color.
Valid input for the Color function is defined at https://github.com/Qix-/color.
eg.
darken('#AAAAAA', 0.3)
lighten('#AAA', 0.7)
darken('rgb(255, 255, 255)', 0.2)
It will also accept a valid variable defined in your theme instead.
eg.
darken('colorPrimary', 0.3)
lighten('someProperty.customColor', 0.5)
Percent can be either a decimal point or an integer.
eg. these two functions will evaluate to the same thing
darken('colorPrimary', 0.5)
darken('colorPrimary', 50)
*/
var normalizePercent = function normalizePercent(num) {
return num >= 1 && num <= 100 ? num / 100 : num;
};
var darkenLighten = function darkenLighten(original, percent, props, dark) {
var color = (0, _lodash.get)(props.theme, original) || original;
var thisMuch = normalizePercent(percent);
var converted;
try {
converted = (0, _color["default"])(color);
} catch (_) {
converted = (0, _color["default"])('black');
}
if (dark) return converted.darken(thisMuch).string();
return converted.lighten(thisMuch).string();
};
var darken = function darken(original, percent) {
return function (props) {
return darkenLighten(original, percent, props, true);
};
};
exports.darken = darken;
var lighten = function lighten(original, percent) {
return function (props) {
return darkenLighten(original, percent, props);
};
};
exports.lighten = lighten;