UNPKG

@eccenca/gui-elements

Version:

GUI elements based on other libraries, usable in React application, written in Typescript.

51 lines 3 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const react_1 = __importDefault(require("react")); const core_1 = require("@blueprintjs/core"); const color_1 = __importDefault(require("color")); const Intent_1 = require("../../common/Intent"); const constants_1 = require("../../configuration/constants"); const Icon_1 = __importDefault(require("../Icon/Icon")); const colorDecideContrastvalue_1 = __importDefault(require("./../../common/utils/colorDecideContrastvalue")); function Tag(_a) { var _b, _c; var { children, className = "", intent, icon, emphasis = "normal", minimal = true, small = false, large = false, backgroundColor } = _a, otherProps = __rest(_a, ["children", "className", "intent", "icon", "emphasis", "minimal", "small", "large", "backgroundColor"]); otherProps["interactive"] = ((_b = otherProps.interactive) !== null && _b !== void 0 ? _b : !!otherProps.onClick) ? true : false; if (backgroundColor) { const additionalStyles = (_c = otherProps.style) !== null && _c !== void 0 ? _c : {}; let color = (0, color_1.default)("#ffffff"); try { color = (0, color_1.default)(backgroundColor); } catch (ex) { // eslint-disable-next-line no-console console.warn("Received invalid background color for tag: " + backgroundColor); } otherProps["style"] = Object.assign(Object.assign({}, additionalStyles), { backgroundColor: color.rgb().toString(), color: (0, colorDecideContrastvalue_1.default)({ testColor: color }), }); } const leftIcon = !!icon && typeof icon === "string" ? react_1.default.createElement(Icon_1.default, { name: icon }) : icon; return (react_1.default.createElement(core_1.Tag, Object.assign({}, otherProps, { className: `${constants_1.CLASSPREFIX}-tag__item ${constants_1.CLASSPREFIX}-tag--${emphasis}emphasis` + (intent ? ` ${(0, Intent_1.intentClassName)(intent)}` : "") + (small ? ` ${constants_1.CLASSPREFIX}-tag--small` : "") + (large ? ` ${constants_1.CLASSPREFIX}-tag--large` : "") + (className ? " " + className : ""), minimal: minimal, icon: leftIcon ? react_1.default.cloneElement(leftIcon, { small: !large }) : undefined }), children)); } exports.default = Tag; //# sourceMappingURL=Tag.js.map