UNPKG

@eccenca/gui-elements

Version:

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

38 lines 2.23 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 constants_1 = require("../../configuration/constants"); const Tooltip_1 = __importDefault(require("./../Tooltip/Tooltip")); /** * The base icon provides the basic functionality that is necessary to wrap the Carbon icon component. */ function BaseIcon(_a) { var { iconComponent, className = "", large = false, small = false, tooltipText, tooltipProps, intent, tabIndex } = _a, restProps = __rest(_a, ["iconComponent", "className", "large", "small", "tooltipText", "tooltipProps", "intent", "tabIndex"]); let sizeConfig = { height: 20, width: 20, size: 20 }; if (small) sizeConfig = { height: 16, width: 16, size: 16 }; if (large) sizeConfig = { height: 32, width: 32, size: 32 }; const CarbonIconNamed = iconComponent; const icon = (react_1.default.createElement(CarbonIconNamed, Object.assign({}, restProps, sizeConfig, { className: `${constants_1.CLASSPREFIX}-icon` + (intent ? ` ${constants_1.CLASSPREFIX}-intent--${intent}` : "") + (className ? ` ${className}` : ""), // @ts-ignore tabIndex is number but internally Carbon defined it as string propType. tabIndex: typeof tabIndex !== "undefined" ? tabIndex.toString() : undefined }))); return tooltipText ? (react_1.default.createElement(Tooltip_1.default, Object.assign({ content: tooltipText }, tooltipProps), react_1.default.createElement("span", null, icon))) : (icon); } exports.default = BaseIcon; //# sourceMappingURL=BaseIcon.js.map