-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transpile icon SVGs with display name
- Loading branch information
Marek Fořt
committed
Aug 2, 2023
1 parent
f28f7de
commit 4a119d9
Showing
3 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@shopify/polaris-icons': patch | ||
--- | ||
|
||
Add displayName to transpiled icons |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
template: require('./icon-template.js'), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |