UNPKG

@eccenca/gui-elements

Version:

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

89 lines 3.5 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; }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; import React from "react"; import BaseIcon from "./BaseIcon.js"; import canonicalIcons from "./canonicalIconNames.js"; /** Returns the first icon that exists or the fallback icon. */ var findExistingIcon = function (iconName, fallbackItem) { var _a; if (fallbackItem === void 0) { fallbackItem = canonicalIcons["undefined"]; } if (typeof iconName === "string") { return (_a = canonicalIcons[iconName]) !== null && _a !== void 0 ? _a : fallbackItem; } else { return canonicalIcons[findExistingIconName(iconName)]; } }; /** * Returns the first icon name that exists or the fallback icon name. */ var findExistingIconName = function (iconNames, fallbackIconName) { if (fallbackIconName === void 0) { fallbackIconName = "undefined"; } var foundIconName = fallbackIconName; var iconNameStack = __spreadArray([], __read(iconNames), false); while (foundIconName === fallbackIconName && iconNameStack.length > 0) { var iconNameToTest = iconNameStack.shift(); if (iconNameToTest && canonicalIcons[iconNameToTest] != null) { foundIconName = iconNameToTest; } } return foundIconName; }; export var iconUtils = { findExistingIconName: findExistingIconName, }; /** * The icon provides a graphical symbol that is specified by a canonical name. * This name is hard-coded to force a homegenous usage of the [Carbon icon library](https://carbondesignsystem.com/guidelines/icons/library). */ export var Icon = function (_a) { var name = _a.name, otherBaseIconProps = __rest(_a, ["name"]); return React.createElement(BaseIcon, __assign({ iconComponent: findExistingIcon(name) }, otherBaseIconProps)); }; export default Icon; //# sourceMappingURL=Icon.js.map