UNPKG

codogo-react-widgets

Version:

Provides a unified way to access the styling of commonly used widgets across different apps

112 lines (100 loc) 3.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /* eslint no-use-before-define: 0 */ var hexToColor = function hexToColor(hex) { var regex = new RegExp(); if (hex.length === 7) { regex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i; } else if (hex.length === 4) { regex = /^#?([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})$/i; } else { return "MIXIN_ERROR"; } var result = regex.exec(hex); if (result) { return result.filter(function (s, i) { return i > 0; }).map(function (hexnum) { return parseInt(hexnum, 16) * (hexnum.length < 2 ? 17 : 1); }).concat(1); } else { return getColor(); } }; // returns [ r, g, b, a, ] var getColor = function getColor(color) { var fallback = [255, 255, 255, 1]; //white if (!color) { return fallback; } else if (color.constructor === Array) { return color.length === 4 ? color : color.concat(1); } else if (color.indexOf("#") > -1) { return hexToColor(color); } else if (color.indexOf("rgb") > -1 || color.indexOf("rgba") > -1) { return color.replace(/ /g, "").replace("rgb(", "").replace("rgba(", "").replace(")", "").split(","); } else { return fallback; } }; var rgba = function rgba() { for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } var r = ""; if (args.length === 1) { r = args[0].join(","); } else if (args.length === 2) { r = getColor(args[0]).slice(0, 3).concat(args[1]); } else if (args.length === 3) { r = args.concat(1).join(","); } else if (args.length === 4) { r = args.join(","); } else { r = getColor().join(","); } return "rgba(" + r + ")"; }; var mix = function mix(c1, c2) { var num = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.5; return rgba(getColor(c1).map(function (h, i) { return Math.round(num * h + (1 - num) * getColor(c2)[i]); })); }; exports.default = { tr: function tr(num) { return "\n\t\trgba(0,0,0," + num + ")\n\t"; }, truncate: function truncate() { return "\n\t\twhite-space: nowrap;\n\t\toverflow: hidden;\n\t\ttext-overflow: ellipsis;\n\t"; }, rgba: rgba, stretch: function stretch() { return "\n\t\t\tposition: absolute;\n\t\t\ttop: 0;\n\t\t\tright: 0;\n\t\t\tbottom: 0;\n\t\t\tleft: 0;\n\t\t"; }, mix: mix, darken: function darken(color) { var num = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.1; return mix("#000", color, num); }, wh: function wh(size) { return "\n\t\twidth: " + size + ";\n\t\theight: " + size + ";\n\t"; }, shadow: function shadow() { var elevation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; return { "1": "box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);", "2": "box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);", "3": "box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);", "4": "box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);", "5": "box-shadow: 0 19px 38px rgba(0,0,0,0.30), 0 15px 12px rgba(0,0,0,0.22);", "-1": "box-shadow: inset 0 -1px 3px rgba(0,0,0,0.12), inset 0 -1px 2px rgba(0,0,0,0.24);" }[elevation]; }, contained: function contained() { var offset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; return "\n\t\tposition: absolute;\n\t\ttop: " + offset + ";\n\t\tright: " + offset + ";\n\t\tbottom: " + offset + ";\n\t\tleft: " + offset + ";\n\t"; } }; //# sourceMappingURL=mixins.js.map