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 4a119d9
Show file tree
Hide file tree
Showing 3 changed files with 33 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'),
};
25 changes: 25 additions & 0 deletions polaris-icons/icon-template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const template = (
{template},
opts,
{imports, interfaces, componentName, props, jsx, exports},
) => {
const plugins = ['jsx'];
if (opts.typescript) {
plugins.push('typescript');
}
const typeScriptTpl = template.smart({plugins});
return typeScriptTpl.ast`${imports}
${interfaces}
var ${componentName} = function ${componentName}(${props}) {
return ${jsx};
}
${componentName}.displayName = "${componentName.name.replace(/^Svg/g, '')}";
${exports}
`;
};

module.exports = template;

0 comments on commit 4a119d9

Please sign in to comment.