Files
lucide/packages/lucide-angular/src/create-element.ts

27 lines
644 B
TypeScript
Raw Normal View History

2021-04-11 19:04:24 +02:00
import { IconData } from './icons/types'
/**
* Creates a new SVGElement from icon node
* @param {string} tag
* @param {object} attrs
* @param {array} children
* @returns {SVGElement}
*/
export const createElement = ([tag, attrs, children = []]: IconData): SVGElement => {
const element = document.createElementNS('http://www.w3.org/2000/svg', tag);
Object.keys(attrs).forEach(name => {
element.setAttribute(name, attrs[name]);
});
if (children.length) {
children.forEach((child: IconData) => {
const childElement = createElement(child);
element.appendChild(childElement);
});
}
return element;
};