@ducor/react
Version:
admin template ui interface
47 lines (46 loc) • 2.52 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;
};
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
import React, { createElement, Fragment, useEffect, useState } from "react";
import { twMerge } from "tailwind-merge";
const Icon = (_a) => {
var { name, height = 24, width = 24, className } = _a, props = __rest(_a, ["name", "height", "width", "className"]);
const rootAttributes = Object.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);
const [svgObject, setSvgObject] = useState(null);
useEffect(() => {
const url = `https://raw.githubusercontent.com/feathericons/feather/refs/heads/main/icons/${name}.svg`;
// fetch(url)
// .then((response) => response.text())
// .then((textSvg: any) => {
// setSvgObject(parse(textSvg));
// });
}, [name]);
const makeComponent = (tagName, attributes, children) => {
let childrenComponent = undefined;
if (typeof children === "string" || typeof children === "undefined") {
childrenComponent = children;
}
else if (Array.isArray(children) && children.length) {
childrenComponent = children.map((child, key) => makeComponent(child.tagName, Object.assign(Object.assign({}, child.attributes), { key }), child.children));
}
if (tagName === null) {
return createElement(Fragment, {}, childrenComponent);
}
return createElement(tagName, attributes, childrenComponent);
};
if (svgObject) {
const jsxSvgComponent = makeComponent(svgObject.tagName, Object.assign(Object.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;