Skip to content

Commit

Permalink
Transpile icon SVGs with display name
Browse files Browse the repository at this point in the history
  • Loading branch information
Marek Fořt committed Aug 2, 2023
1 parent f28f7de commit 776d031
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-rats-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris-icons': patch
---

Add displayName to transpiled icons
3 changes: 3 additions & 0 deletions polaris-icons/.svgrrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
template: require('./icon-template.js'),
};
15 changes: 15 additions & 0 deletions polaris-icons/icon-template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function defaultTemplate(
{template},
opts,
{imports, componentName, props, jsx, exports},
) {
return template.ast`${imports}
const ${componentName} = (${props}) => ${jsx}
${componentName}.displayName = "${componentName.name.replace(/^Svg/g, '')}";
${exports}
`;
}

module.exports = defaultTemplate;

0 comments on commit 776d031

Please sign in to comment.