New setup for new NPM package

This commit is contained in:
Eric Fennis
2020-07-17 23:07:51 +02:00
parent d051a09232
commit de6906e242
19 changed files with 21787 additions and 9 deletions
+17
View File
@@ -0,0 +1,17 @@
const createElement = (tag, attrs, children = []) => {
const element = document.createElement(tag);
Object.keys(attrs).forEach(name => {
element.setAttribute(name, attrs[name]);
})
if (children.length) {
children = children.forEach(child => {
const childElement = createElement(child);
element.appendChild(childElement);
});
}
}
export default (iconVnode) => createElement(iconVnode);
+33
View File
@@ -0,0 +1,33 @@
import { forwardRef, createElement } from "react";
export default (iconName, [tag, attrs, children]) => {
const Component = forwardRef(
(
{ color = "currentColor", size = 24, width = 2, ...rest },
ref
) =>
createElement(
tag,
{
ref,
...attrs,
width: size,
height: size,
color,
strokeWidth: width,
...rest
},
children.map(([childTag, childAttrs]) =>
createElement(childTag, childAttrs)
)
)
);
Component.propTypes = {
color: PropTypes.string,
size: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
};
Component.displayName = `${iconName}`;
}
+31
View File
@@ -0,0 +1,31 @@
export default (iconName, [tag, attrs, children]) => ({
name: iconName,
functional: true,
render(
createElement,
{
props: {
color = "currentColor",
size = 48,
width = 2,
strokeWidth = 2,
...rest
}
}
) {
return createElement(
tag,
{
attrs: {
...attrs,
width: size,
height: size,
color,
strokeWidth,
...rest
}
},
children.map(([tag, attrs]) => createElement(tag, { attrs }))
);
}
});
View File