mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-11-16 14:18:29 +00:00
React package (#105)
* init new react package project * setup react package * Fix config for build * update package * Fix build * update package * fix package.json * refactor and cleanup * bumb beta version * fix regex * bump version * Add hashing * Add tests * bump version * Add peer dependecies * Add docs * Add readme link
This commit is contained in:
@@ -1,25 +1,47 @@
|
||||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
import { parseDOM } from 'htmlparser2';
|
||||
import DEFAULT_ATTRS from './default-attrs.json';
|
||||
import { toCamelCase, hash } from '../helpers';
|
||||
|
||||
export default iconsObject => {
|
||||
const camelizeAttrs = attrs =>
|
||||
Object.keys(attrs).reduce((newAttrs, attr) => {
|
||||
const attrKey = toCamelCase(attr);
|
||||
|
||||
newAttrs[attrKey] = attrs[attr];
|
||||
return newAttrs;
|
||||
}, {});
|
||||
|
||||
export default (iconsObject, options) => {
|
||||
const iconNodes = {};
|
||||
|
||||
Object.keys(iconsObject).forEach(icon => {
|
||||
const svgString = iconsObject[icon];
|
||||
const dom = parseDOM(svgString);
|
||||
|
||||
const children = dom.map(element => [
|
||||
element.name,
|
||||
{
|
||||
...element.attribs,
|
||||
},
|
||||
]);
|
||||
const children = dom.map(element => {
|
||||
if (options.renderUniqueKey) {
|
||||
const hashSource = {
|
||||
name: element.name,
|
||||
...element.attribs,
|
||||
};
|
||||
|
||||
const uniqueKey = hash(JSON.stringify(hashSource));
|
||||
|
||||
element.attribs.key = uniqueKey;
|
||||
}
|
||||
|
||||
return [
|
||||
element.name,
|
||||
{
|
||||
...(options.camelizeAttrs ? camelizeAttrs(element.attribs) : element.attribs),
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
iconNodes[icon] = [
|
||||
'svg',
|
||||
{
|
||||
...DEFAULT_ATTRS,
|
||||
...(options.camelizeAttrs ? camelizeAttrs(DEFAULT_ATTRS) : DEFAULT_ATTRS),
|
||||
},
|
||||
children,
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user