-
Notifications
You must be signed in to change notification settings - Fork 843
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
Use inline SVGs for icons #160
Conversation
Anything that simplifies the build for consumers is a +1 in my ledger |
@pugnascotia This is awesome man! I tested it with Kibana the icons show up now, though it looks like the majority of them contain errors. I wonder if the format of the SVGs themselves could be the cause? @snide What do you think? Here are the icons side by side in Kibana and in the EUI docs: There are errors in both, but not always the same kinds of errors. For example, faceHappy and faceSad are fine in EUI but broken in Kibana. I'm not sure what to make of this discrepancy. |
Face Happy and Sad use strokes. They need to be cleaned up in EUI as well (notice that they'll fail in the dark theme). The rest of our icons though should be pretty clean and only use shapes so I don't know why you'd run into errors. Likely they aren't being translated properly. |
I've changed approach and generated React components via script and versioned them. It occurred to me that if someone wanted to consume the components as ES6, without any Babel stuff, they'd be stuffed. In an ideal world the transform would probably still be a Babel transform of some kind, but my Babel-fu is lacking. Thoughts? |
To me it sounds like what we need to be doing, instead of this PR, is fix our build process. Can't we get rid of |
How would that resolve the need for the SVG sprite plugin stuff? |
We'd have a bundle at our interface that's already compiled, so things like SVG sprites would've been inlined into that bundle already at the boundary. |
I did try that, in Berlin I think it was, but it meant having React available as a global library - as in, on Also, if we ditch the sprites method, we still need a way of being able to dynamically set the |
Right. I'm saying there should be a better way of compiling than what we're doing. Isn't there a way to tell webpack not to follow import links and thus just run the plugins without bundling? |
We are already using webpack externals to exclude React and PropTypes from our bundle in /* 0 */
/***/ (function(module, exports) {
module.exports = window.React;
/***/ }), We can make Cloud UI import React from |
What I'm saying is doing something like this for the https://www.npmjs.com/package/webpack-node-externals So that just like with const React = require('react')
const inlineSvg = '...'
const anotherInlineSvg = '...'
/* ... */
module.exports = Eui Then any consumer can just import this and it'll just work, no |
The files in the The first commit on this PR added |
Maybe we can just fork the Babel plugin? |
I would happily, if I knew how to do it. I literally do not currently know enough about Babel and transforms (specifically to JSX ASTs) to be able to do the work. Conceptually it's not difficult. You first, @bevacqua :-) |
Why don't we just add those |
If the // For an icon-only button
<EuiButton aria-label="Copy document">
<EuiIcon type="copy" aria-hidden="true" />
</EuiButton>
// Or for an icon that represents status in a table row
<EuiIcon type="check" aria-label="Successfully saved" /> I can't think of any situation where we'll be using an icon without some wrapping element or some supplementary element which we can use to provide information in this manner. |
Oh for real? Man, I wish I'd known that earlier. |
Sorry 😞 |
Actually in my opinion, @cjcenizal suggestion is even better than providing a As he said, we most often have the icon in buttons/links. If it's the only content, you can easily replace as shown above with an So if the image is the only content within a button/link, better use @cjcenizal approach, then SVG In cases where we use the Icon as a real image to identify something, |
Thanks @timroes! I was the one who introduced the |
af96d87
to
59e8362
Compare
Right, armed with new information from @cjcenizal and @timroes, we're back to the Babel plugin implementation, and it's pretty simple. Some eyes please? |
searchProfilerApp, | ||
securityApp, | ||
shard, | ||
share, |
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.
This line was duplicated.
package.json
Outdated
@@ -44,6 +44,7 @@ | |||
"babel-jest": "21.0.0", | |||
"babel-loader": "7.1.2", | |||
"babel-plugin-add-module-exports": "0.2.1", | |||
"babel-plugin-inline-react-svg": "^0.5.2", |
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.
Can we pin this?
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.
src/components/icon/icon.js
Outdated
{svgReference} | ||
</svg> | ||
); | ||
return <Svg className={classes} aria-label={titleText} {...rest} />; |
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 think we can delete aria-label={titleText}
here and just expect consumers to pass in a arial-label
prop directly. We'd just have to document this as a breaking change.
I've pinned the plugin version and remove the default title. @cjcenizal The difference in Kibana is weird. Is the rendered SVG different? Is there extra CSS being applied in Kibana? Ping me when you come online and we'll try to get to the bottom of it. If there's an easy way to get it running locally, let me know. |
d8cf9d5
to
522c410
Compare
@snide @bevacqua what do you think about merging this change as-is? I'm happy to work with @cjcenizal to resolve any Kibana issues if they arise. |
SGTM @pugnascotia! |
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.
Did a visual check and some tests of usage. Seems to still work as intended. Looks good to me.
This is an experiment in rendering icons through inline SVGs. This removes the need for consumers of EUI to also support automatic SVG sprite handling. A Babel plugin transforms the SVGs into React components automatically. Class names are still propagated, but
<title>
is missing. More work would be needed to make this a complete swap.CC @cjcenizal for feedback.