UNPKG

@eccenca/gui-elements

Version:

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

57 lines 3.22 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; 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; }; import React from "react"; import { Tag as BlueprintTag } from "@blueprintjs/core"; import Color from "color"; import { intentClassName } from "../../common/Intent/index.js"; import { CLASSPREFIX as eccgui } from "../../configuration/constants.js"; import Icon from "../Icon/Icon.js"; import decideContrastColorValue from "./../../common/utils/colorDecideContrastvalue.js"; function Tag(_a) { var _b, _c; var children = _a.children, _d = _a.className, className = _d === void 0 ? "" : _d, intent = _a.intent, icon = _a.icon, _e = _a.emphasis, emphasis = _e === void 0 ? "normal" : _e, _f = _a.minimal, minimal = _f === void 0 ? true : _f, _g = _a.small, small = _g === void 0 ? false : _g, _h = _a.large, large = _h === void 0 ? false : _h, backgroundColor = _a.backgroundColor, 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) { var additionalStyles = (_c = otherProps.style) !== null && _c !== void 0 ? _c : {}; var color = Color("#ffffff"); try { color = Color(backgroundColor); } catch (ex) { // eslint-disable-next-line no-console console.warn("Received invalid background color for tag: " + backgroundColor); } otherProps["style"] = __assign(__assign({}, additionalStyles), { backgroundColor: color.rgb().toString(), color: decideContrastColorValue({ testColor: color }), }); } var leftIcon = !!icon && typeof icon === "string" ? React.createElement(Icon, { name: icon }) : icon; return (React.createElement(BlueprintTag, __assign({}, otherProps, { className: "".concat(eccgui, "-tag__item ").concat(eccgui, "-tag--").concat(emphasis, "emphasis") + (intent ? " ".concat(intentClassName(intent)) : "") + (small ? " ".concat(eccgui, "-tag--small") : "") + (large ? " ".concat(eccgui, "-tag--large") : "") + (className ? " " + className : ""), minimal: minimal, icon: leftIcon ? React.cloneElement(leftIcon, { small: !large }) : undefined }), children)); } export default Tag; //# sourceMappingURL=Tag.js.map