@eccenca/gui-elements
Version:
GUI elements based on other libraries, usable in React application, written in Typescript.
58 lines • 2.51 kB
JavaScript
;
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 });
exports.Icon = exports.iconUtils = void 0;
const react_1 = __importDefault(require("react"));
const BaseIcon_1 = __importDefault(require("./BaseIcon"));
const canonicalIconNames_1 = __importDefault(require("./canonicalIconNames"));
/** Returns the first icon that exists or the fallback icon. */
const findExistingIcon = (iconName, fallbackItem = canonicalIconNames_1.default["undefined"]) => {
var _a;
if (typeof iconName === "string") {
return (_a = canonicalIconNames_1.default[iconName]) !== null && _a !== void 0 ? _a : fallbackItem;
}
else {
return canonicalIconNames_1.default[findExistingIconName(iconName)];
}
};
/**
* Returns the first icon name that exists or the fallback icon name.
*/
const findExistingIconName = (iconNames, fallbackIconName = "undefined") => {
let foundIconName = fallbackIconName;
const iconNameStack = [...iconNames];
while (foundIconName === fallbackIconName && iconNameStack.length > 0) {
const iconNameToTest = iconNameStack.shift();
if (iconNameToTest && canonicalIconNames_1.default[iconNameToTest] != null) {
foundIconName = iconNameToTest;
}
}
return foundIconName;
};
exports.iconUtils = {
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).
*/
const Icon = (_a) => {
var { name } = _a, otherBaseIconProps = __rest(_a, ["name"]);
return react_1.default.createElement(BaseIcon_1.default, Object.assign({ iconComponent: findExistingIcon(name) }, otherBaseIconProps));
};
exports.Icon = Icon;
exports.default = exports.Icon;
//# sourceMappingURL=Icon.js.map