@devchristian1337/dev-icons
Version:
A library to serve development-related icons
53 lines (52 loc) • 2.29 kB
JavaScript
;
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 __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DevIcon = void 0;
var react_1 = __importDefault(require("react"));
var index_1 = __importDefault(require("../index"));
var DevIcon = function (_a) {
var name = _a.name, _b = _a.size, size = _b === void 0 ? 24 : _b, _c = _a.className, className = _c === void 0 ? "" : _c, props = __rest(_a, ["name", "size", "className"]);
var icon = index_1.default.getIcon(name);
if (!icon) {
console.warn("Icon \"".concat(name, "\" not found"));
return null;
}
// Parse the SVG string to get its attributes
var parser = new DOMParser();
var doc = parser.parseFromString(icon.icon, "image/svg+xml");
var svg = doc.querySelector("svg");
if (!svg) {
console.warn("Invalid SVG content for icon \"".concat(name, "\""));
return null;
}
// Create props object with merged attributes
var svgProps = __assign(__assign({}, props), { width: size, height: size, className: "dev-icon ".concat(className).trim(), dangerouslySetInnerHTML: { __html: svg.innerHTML } });
// Return the SVG element with the merged props
return react_1.default.createElement("svg", svgProps);
};
exports.DevIcon = DevIcon;
exports.default = exports.DevIcon;