-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Icons] Transpile icon SVGs with display name #9871
Conversation
5d12732
to
4a119d9
Compare
polaris-icons/icon-template.js
Outdated
plugins.push('typescript'); | ||
} | ||
const typeScriptTpl = template.smart({plugins}); | ||
return typeScriptTpl.ast`${imports} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have context on these kinds of things but this file seems confusing to me. With this unguarded return here is anything below even getting run?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use the default template, so I don't want to change it more than we have to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"I don't want to change it more than we have to." - Every Design System Engineer ever.
Wise words. +1000
@fortmarek 😂
4a119d9
to
776d031
Compare
776d031
to
48fbd87
Compare
/snapit |
🫰✨ Thanks @kyledurand! Your snapshots have been published to npm. Test the snapshots by updating your yarn add @shopify/polaris-cli@0.0.0-snapshot-release-20230802160056 yarn add @shopify/polaris-icons@0.0.0-snapshot-release-20230802160056 yarn add @shopify/polaris@0.0.0-snapshot-release-20230802160056 |
@kyledurand I think we are removing the displayName for production builds in web? If consumers have that in their bundler, I think we shouldn't be too concerned. |
Edit I think this will stay in production since we are using displayName as a static variable |
I don't see how they'd be removed in prod. They get bundled as react components So this:'use strict';
var React = require('react');
var SvgAbandonedCartMajor = function SvgAbandonedCartMajor(props) {
return /*#__PURE__*/React.createElement("svg", Object.assign({
viewBox: "0 0 20 20"
}, props), /*#__PURE__*/React.createElement("path", {
d: "M3.25 3a.75.75 0 0 0 0 1.5h1.612a.25.25 0 0 1 .248.22l1.04 8.737a1.75 1.75 0 0 0 1.738 1.543h6.362a.75.75 0 0 0 0-1.5h-6.362a.25.25 0 0 1-.248-.22l-.093-.78h6.35a2.75 2.75 0 0 0 2.743-2.54l.358-4.652a.75.75 0 0 0-1.496-.116l-.358 4.654a1.25 1.25 0 0 1-1.246 1.154h-6.53l-.768-6.457a1.75 1.75 0 0 0-1.738-1.543h-1.612Z"
}), /*#__PURE__*/React.createElement("path", {
d: "M8.87 5.12a.75.75 0 0 0 0 1.06l1.32 1.32-1.32 1.32a.75.75 0 1 0 1.06 1.06l1.32-1.32 1.32 1.32a.75.75 0 0 0 1.06-1.06l-1.32-1.32 1.32-1.32a.75.75 0 0 0-1.06-1.06l-1.32 1.32-1.32-1.32a.75.75 0 0 0-1.06 0Z"
}), /*#__PURE__*/React.createElement("path", {
d: "M10 17a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"
}), /*#__PURE__*/React.createElement("path", {
d: "M15 17a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"
}));
};
exports.SvgAbandonedCartMajor = SvgAbandonedCartMajor; Becomes this'use strict';
var React = require('react');
var SvgAbandonedCartMajor = function SvgAbandonedCartMajor(props) {
return /*#__PURE__*/React.createElement("svg", Object.assign({
viewBox: "0 0 20 20"
}, props), /*#__PURE__*/React.createElement("path", {
d: "M3.25 3a.75.75 0 0 0 0 1.5h1.612a.25.25 0 0 1 .248.22l1.04 8.737a1.75 1.75 0 0 0 1.738 1.543h6.362a.75.75 0 0 0 0-1.5h-6.362a.25.25 0 0 1-.248-.22l-.093-.78h6.35a2.75 2.75 0 0 0 2.743-2.54l.358-4.652a.75.75 0 0 0-1.496-.116l-.358 4.654a1.25 1.25 0 0 1-1.246 1.154h-6.53l-.768-6.457a1.75 1.75 0 0 0-1.738-1.543h-1.612Z"
}), /*#__PURE__*/React.createElement("path", {
d: "M8.87 5.12a.75.75 0 0 0 0 1.06l1.32 1.32-1.32 1.32a.75.75 0 1 0 1.06 1.06l1.32-1.32 1.32 1.32a.75.75 0 0 0 1.06-1.06l-1.32-1.32 1.32-1.32a.75.75 0 0 0-1.06-1.06l-1.32 1.32-1.32-1.32a.75.75 0 0 0-1.06 0Z"
}), /*#__PURE__*/React.createElement("path", {
d: "M10 17a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"
}), /*#__PURE__*/React.createElement("path", {
d: "M15 17a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"
}));
};
SvgAbandonedCartMajor.displayName = "AbandonedCartMajor";
exports.SvgAbandonedCartMajor = SvgAbandonedCartMajor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with increasing the bundle size if this is necessary. It's definitely a nice to have anyway
Thanks for the reviews! The increase in bundle size (3 %) is unfortunate but we highly need this feature. |
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @shopify/polaris-icons@7.8.0 ### Minor Changes - [#9858](#9858) [`3fc3d5923`](3fc3d59) Thanks [@ardakaracizmeli](https://github.com/ardakaracizmeli)! - Added SidekickMajor - [#9871](#9871) [`bac86a621`](bac86a6) Thanks [@fortmarek](https://github.com/fortmarek)! - Added displayName to transpiled icons - [#9854](#9854) [`5dabf0fe0`](5dabf0f) Thanks [@heyjoethomas](https://github.com/heyjoethomas)! - Updated CancelMajor and CancelMinor icons ## @shopify/polaris@11.11.0 ### Minor Changes - [#9697](#9697) [`c078d5d85`](c078d5d) Thanks [@nat-king](https://github.com/nat-king)! - Added optional prop `TextDecorationLine` to `Text` to include a line-through decoration ### Patch Changes - [#9847](#9847) [`85b68a358`](85b68a3) Thanks [@qt314](https://github.com/qt314)! - Added `role` prop to `VerticalStack` - [#9863](#9863) [`4061fd04d`](4061fd0) Thanks [@zakwarsame](https://github.com/zakwarsame)! - Fixed ActionList item overflow and tooltip zIndex - Updated dependencies \[[`3fc3d5923`](3fc3d59), [`bac86a621`](bac86a6), [`5dabf0fe0`](5dabf0f)]: - @shopify/polaris-icons@7.8.0 ## @shopify/polaris-cli@0.2.29 ## polaris.shopify.com@0.56.7 ### Patch Changes - Updated dependencies \[[`3fc3d5923`](3fc3d59), [`85b68a358`](85b68a3), [`bac86a621`](bac86a6), [`4061fd04d`](4061fd0), [`5dabf0fe0`](5dabf0f), [`c078d5d85`](c078d5d)]: - @shopify/polaris-icons@7.8.0 - @shopify/polaris@11.11.0 Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
<!-- ☝️How to write a good PR title: - Prefix it with [ComponentName] (if applicable), for example: [Button] - Start with a verb, for example: Add, Delete, Improve, Fix… - Give as much context as necessary and as little as possible - Prefix it with [WIP] while it’s a work in progress --> ### WHY are these changes introduced? For full context, read [here](https://github.com/Shopify/web/pull/100163). We are introducing a `displayName` prop to be able to dynamically read the icon name when we have access only to the Polaris icon component function: ```tsx import {AbandondedCartMajor} from '@shopify/polaris-icons'; const iconName = AbandondedCartMajor.displayName; /* Do something with displayName */ // This wouldn't work as the `name` gets minified // const iconName = AbandonedCartMajor.name; ``` React components generally use the convention of `displayName` already and we use this convention in [Polaris as well](https://github.com/search?q=repo%3AShopify%2Fpolaris%20displayname&type=code). <!-- Context about the problem that’s being addressed. --> ### WHAT is this pull request doing? For transpiling the SVG files, we use the [svgr](https://github.com/gregberge/svgr) library. Ideally, this library would by default add the `displayName` but this was [rejected by the author](gregberge/svgr#328). Instead, we can provide our [own template](https://react-svgr.com/docs/migrate/#template) to be used by the `svgr` library. The only difference from the default template is the following file: ``` ${componentName}.displayName = "${componentName.name.replace(/^Svg/g, '')}"; ``` You can check the before and after of `dist/icons/AbandondedCartMajor.svg.js` here: <details> <summary>Before</summary> ```tsx 'use strict'; var React = require('react'); var SvgAbandonedCartMajor = function SvgAbandonedCartMajor(props) { return /*#__PURE__*/React.createElement("svg", Object.assign({ viewBox: "0 0 20 20" }, props), /*#__PURE__*/React.createElement("path", { d: "M3.25 3a.75.75 0 0 0 0 1.5h1.612a.25.25 0 0 1 .248.22l1.04 8.737a1.75 1.75 0 0 0 1.738 1.543h6.362a.75.75 0 0 0 0-1.5h-6.362a.25.25 0 0 1-.248-.22l-.093-.78h6.35a2.75 2.75 0 0 0 2.743-2.54l.358-4.652a.75.75 0 0 0-1.496-.116l-.358 4.654a1.25 1.25 0 0 1-1.246 1.154h-6.53l-.768-6.457a1.75 1.75 0 0 0-1.738-1.543h-1.612Z" }), /*#__PURE__*/React.createElement("path", { d: "M8.87 5.12a.75.75 0 0 0 0 1.06l1.32 1.32-1.32 1.32a.75.75 0 1 0 1.06 1.06l1.32-1.32 1.32 1.32a.75.75 0 0 0 1.06-1.06l-1.32-1.32 1.32-1.32a.75.75 0 0 0-1.06-1.06l-1.32 1.32-1.32-1.32a.75.75 0 0 0-1.06 0Z" }), /*#__PURE__*/React.createElement("path", { d: "M10 17a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z" }), /*#__PURE__*/React.createElement("path", { d: "M15 17a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z" })); }; exports.SvgAbandonedCartMajor = SvgAbandonedCartMajor; ``` </details> <details> <summary>After</summary> ```tsx 'use strict'; var React = require('react'); var SvgAbandonedCartMajor = function SvgAbandonedCartMajor(props) { return /*#__PURE__*/React.createElement("svg", Object.assign({ viewBox: "0 0 20 20" }, props), /*#__PURE__*/React.createElement("path", { d: "M3.25 3a.75.75 0 0 0 0 1.5h1.612a.25.25 0 0 1 .248.22l1.04 8.737a1.75 1.75 0 0 0 1.738 1.543h6.362a.75.75 0 0 0 0-1.5h-6.362a.25.25 0 0 1-.248-.22l-.093-.78h6.35a2.75 2.75 0 0 0 2.743-2.54l.358-4.652a.75.75 0 0 0-1.496-.116l-.358 4.654a1.25 1.25 0 0 1-1.246 1.154h-6.53l-.768-6.457a1.75 1.75 0 0 0-1.738-1.543h-1.612Z" }), /*#__PURE__*/React.createElement("path", { d: "M8.87 5.12a.75.75 0 0 0 0 1.06l1.32 1.32-1.32 1.32a.75.75 0 1 0 1.06 1.06l1.32-1.32 1.32 1.32a.75.75 0 0 0 1.06-1.06l-1.32-1.32 1.32-1.32a.75.75 0 0 0-1.06-1.06l-1.32 1.32-1.32-1.32a.75.75 0 0 0-1.06 0Z" }), /*#__PURE__*/React.createElement("path", { d: "M10 17a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z" }), /*#__PURE__*/React.createElement("path", { d: "M15 17a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z" })); }; SvgAbandonedCartMajor.displayName = "AbandonedCartMajor"; exports.SvgAbandonedCartMajor = SvgAbandonedCartMajor; ``` </details> <!-- Summary of the changes committed. Before / after screenshots are appreciated for UI changes. Make sure to include alt text that describes the screenshot. If you include an animated gif showing your change, wrapping it in a details tag is recommended. Gifs usually autoplay, which can cause accessibility issues for people reviewing your PR: <details> <summary>Summary of your gif(s)</summary> <img src="..." alt="Description of what the gif shows"> </details> --> <!-- ℹ️ Delete the following for small / trivial changes --> ### How to 🎩 🖥 [Local development instructions](https://github.com/Shopify/polaris/blob/main/README.md#local-development) 🗒 [General tophatting guidelines](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md) 📄 [Changelog guidelines](https://github.com/Shopify/polaris/blob/main/.github/CONTRIBUTING.md#changelog) <!-- Give as much information as needed to experiment with the component in the playground. --> Add the following line to `Icon.stories.tsx`: ``` console.log(CirclePlusMinor.displayName); ``` When you open the story, the `displayName` should be printed. ### 🎩 checklist - [x] Tested on [mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing) - [x] Tested on [multiple browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers) - [x] ~Tested for [accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md)~ - [x] ~Updated the component's `README.md` with documentation changes~ - [x] ~[Tophatted documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md) changes in the style guide~
WHY are these changes introduced?
For full context, read here.
We are introducing a
displayName
prop to be able to dynamically read the icon name when we have access only to the Polaris icon component function:React components generally use the convention of
displayName
already and we use this convention in Polaris as well.WHAT is this pull request doing?
For transpiling the SVG files, we use the svgr library. Ideally, this library would by default add the
displayName
but this was rejected by the author.Instead, we can provide our own template to be used by the
svgr
library.The only difference from the default template is the following file:
You can check the before and after of
dist/icons/AbandondedCartMajor.svg.js
here:Before
After
How to 🎩
🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines
Add the following line to
Icon.stories.tsx
:When you open the story, the
displayName
should be printed.🎩 checklist
Tested for accessibilityUpdated the component'sREADME.md
with documentation changesTophatted documentation changes in the style guide