@netdata/netdata-ui
Version:
netdata UI kit
73 lines • 3.16 kB
JavaScript
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
import get from "lodash/get";
export var propOrElse = function propOrElse(pathName, defaultValue) {
return function (props) {
return get(props, pathName, defaultValue);
};
};
export var getOrElse = function getOrElse(pathName, defaultValue) {
return function (_ref) {
var theme = _ref.theme;
return get(theme, pathName, defaultValue);
};
};
export var getSizeUnit = getOrElse(["constants", "SIZE_UNIT"], 8);
export var getColor = function getColor(colorPath) {
var colorPaths = Array.isArray(colorPath) ? colorPath : [colorPath];
return getOrElse(["colors"].concat(_toConsumableArray(colorPaths)), colorPath || "#fff");
};
export var getRgbColor = function getRgbColor(colorPath, opacity) {
if (opacity === void 0) {
opacity = 1;
}
return function (_ref2) {
var theme = _ref2.theme;
var color = getColor(colorPath)({
theme: theme
});
var bigint = parseInt(color.substring(1), 16);
var r = bigint >> 16 & 255;
var g = bigint >> 8 & 255;
var b = bigint & 255;
return "rgba(" + r + ", " + g + ", " + b + ", " + opacity + ")";
};
};
export var getSizeBy = function getSizeBy(multiplier) {
if (multiplier === void 0) {
multiplier = 1;
}
return function (props) {
return isNaN(multiplier) ? multiplier : (getSizeUnit(props) || 0) * multiplier + "px";
};
};
export var getValidatedControlColor = function getValidatedControlColor(defaultColorPath, defaultDisabledPath) {
if (defaultColorPath === void 0) {
defaultColorPath = "border";
}
if (defaultDisabledPath === void 0) {
defaultDisabledPath = "disabled";
}
return function (_ref3) {
var theme = _ref3.theme,
success = _ref3.success,
error = _ref3.error,
disabled = _ref3.disabled;
if (success) return getColor(["success"])({
theme: theme
});
if (error) return getColor(["error"])({
theme: theme
});
if (disabled) return getColor([defaultDisabledPath])({
theme: theme
});
return getColor([defaultColorPath])({
theme: theme
});
};
};