@ducor/react
Version:
admin template ui interface
60 lines (59 loc) • 3.05 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;
};
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
import React, { createElement, Fragment, useEffect, useState } from "react";
import { twMerge } from "tailwind-merge";
var Icon = function (_a) {
var name = _a.name, _b = _a.height, height = _b === void 0 ? 24 : _b, _c = _a.width, width = _c === void 0 ? 24 : _c, className = _a.className, props = __rest(_a, ["name", "height", "width", "className"]);
var rootAttributes = __assign({ xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", className: twMerge(className) }, props);
var _d = useState(null), svgObject = _d[0], setSvgObject = _d[1];
useEffect(function () {
var url = "https://raw.githubusercontent.com/feathericons/feather/refs/heads/main/icons/".concat(name, ".svg");
// fetch(url)
// .then((response) => response.text())
// .then((textSvg: any) => {
// setSvgObject(parse(textSvg));
// });
}, [name]);
var makeComponent = function (tagName, attributes, children) {
var childrenComponent = undefined;
if (typeof children === "string" || typeof children === "undefined") {
childrenComponent = children;
}
else if (Array.isArray(children) && children.length) {
childrenComponent = children.map(function (child, key) {
return makeComponent(child.tagName, __assign(__assign({}, child.attributes), { key: key }), child.children);
});
}
if (tagName === null) {
return createElement(Fragment, {}, childrenComponent);
}
return createElement(tagName, attributes, childrenComponent);
};
if (svgObject) {
var jsxSvgComponent = makeComponent(svgObject.tagName, __assign(__assign({}, rootAttributes), svgObject.attributes), svgObject.children);
console.log("abc", React.Children.toArray(jsxSvgComponent));
}
return _jsx(_Fragment, {}); // return jsxSvgComponent; // Comment out for now to avoid console.log
};
export default Icon;