Skip to content

Commit

Permalink
fix(issue-7): missing validation for tag path (#8)
Browse files Browse the repository at this point in the history
Solve issue #7
  • Loading branch information
r17x committed Nov 16, 2021
1 parent 3d13ee6 commit 458ebf3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions examples/Issue7.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions examples/issue7.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 12 additions & 2 deletions lib/chakra.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,18 @@ const createChakraIcon = (...sources) => {
const isTypescript = sources.some(({ isTypescript }) => isTypescript);
const perFileCode = ({ source: svg, displayName }) => {
const hast = SvgParser.parse(svg);

if (ast.hastChildrenLength(hast) > 1) {
// This for solve issue {https://github.com/kodingdotninja/create-chakra-icons/issues/7}
// In the issue 7, have some example svg file at examples/issue7.svg
// {isNotPathTagName} for know the tag is not <path />
// when not a <path />, so make as icon component (not functional component)
const isNotTagnamePath = (() => {
if (hast.children[0].children) {
const [head] = hast.children[0].children;
return head.tagName && head.tagName !== "path";
}
return false;
})();
if (ast.hastChildrenLength(hast) > 1 || isNotTagnamePath) {
return ast.hastToComponent(hast, { displayName, isTypescript });
}

Expand Down

0 comments on commit 458ebf3

Please sign in to comment.