Skip to content

Commit

Permalink
feat: add additional default properties to root svg element
Browse files Browse the repository at this point in the history
Co-authored-by: chris <[email protected]>
  • Loading branch information
joschka and chohner committed Jan 5, 2024
1 parent d7e396e commit 1b7140c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ do
mv "$file" "${file/_24px/}"
done

npx @svgr/cli --typescript --no-svgo --out-dir $react_tmp_path -- $original_svg_path
npx @svgr/cli --typescript --no-svgo --svg-props role=img --svg-props focusable=false --svg-props aria-hidden=true --template "template.js" --out-dir $react_tmp_path -- $original_svg_path

ls $react_tmp_path > files.txt

Expand Down
27 changes: 27 additions & 0 deletions template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const template = (variables, { tpl }) => {
variables.jsx.openingElement.attributes.push({
"type": "JSXAttribute",
"name": {
"type": "JSXIdentifier",
"name": "data-testid"
},
"value": {
"type": "StringLiteral",
"value": `${variables.componentName.replace("Svg", "")}Icon`
}
})

return tpl`
${variables.imports};
${variables.interfaces};
const ${variables.componentName} = (${variables.props}) => (
${variables.jsx}
);
${variables.exports};
`
}

module.exports = template

0 comments on commit 1b7140c

Please sign in to comment.