-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat(icon): Add support to svg symbol icon set #11162
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
|
CLAs look good, thanks! |
Thank you for your contribution. Please squash your commits and update the commit message to follow the commit message guidelines. This is important for your changes to properly show up in the changelog. |
The description of the current behavior here and the related fix in this PR don't seem to map directly to #8689. It does seem related, but it doesn't seem to be the same exact issue. Can you please provide a CodePen that demonstrates the issue being solved here? The code seems to make sense, but it's not clear that there is an issue without a demo that reproduces the issue. |
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 you please add a test that verifies this fix? We would hate to have a regression to this functionality in the future due to a missing test.
This PR is not direct fix for #8689 issue, but related to it. It is directly related to this closed issue #1514 (I didn't wont to do PR against closed ticket, but can change if you think it is better). |
OK, thank you for the link to #1514. That's good to know. We'll certainly need a unit test to cover this behavior. It might be worth looking into adding a demo for this in the icon demos as well. If the demo gets too complicated or you have issues with it, please let me know. |
@Splaktar I added unit tests and demo with 2 additional icons to |
@cobisimo thanks for adding the tests and demos. I'll take a look. It looks like the commits didn't get squashed properly. You'll need to force push your branch to GitHub after squashing in order for things to work properly. |
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.
Thanks for adding the tests, they look good. The demo is very useful as well. I had a question about the spinner icon and a couple minor comments.
<md-icon md-svg-icon="social:cake" style="color: #f00;width:60px;height:60px;" aria-label="Cake Icon"></md-icon> | ||
<md-icon md-svg-icon="social:people" style="color: #00F;" class="s48" aria-label="People Icon"></md-icon> | ||
<md-icon md-svg-icon="symbol:spinner" style="color: #f00;width:60px;height:60px;" aria-label="Spinner Icon"></md-icon> | ||
<md-icon md-svg-icon="symbol:angular" class="s48" aria-label="Angular Icon"></md-icon> |
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.
Minor nit, but it looks like the white space isn't lined up for aria-label
in this last icon.
if (viewbox) el.setAttribute('viewBox', viewbox); | ||
} | ||
|
||
if (el && el.tagName.toLowerCase() != 'svg') { |
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.
Please use !==
here.
@@ -0,0 +1,4 @@ | |||
<svg> | |||
<symbol id="spinner" viewBox="0 0 44 44"><path d="M5.386 19.817c-.584 4.44.595 8.84 3.32 12.39 5.628 7.333 16.172 8.722 23.504 3.095 7.332-5.628 8.72-16.173 3.093-23.504-3.57-4.65-9.406-7.12-15.238-6.447-.264.028-.51-.16-.54-.428-.03-.267.16-.51.43-.54 6.166-.707 12.345 1.902 16.12 6.822 5.956 7.76 4.488 18.917-3.27 24.87-3.215 2.467-7.01 3.66-10.78 3.66-5.33 0-10.604-2.385-14.092-6.932C5.048 29.042 3.8 24.386 4.42 19.69c.595-4.532 2.86-8.578 6.392-11.447H5.57c-.27 0-.488-.22-.488-.488 0-.27.218-.488.487-.488h6.678c.27 0 .488.218.488.488v6.68c0 .27-.218.487-.488.487s-.488-.217-.488-.488V8.737c-3.53 2.724-5.792 6.657-6.374 11.08z"><animateTransform attributeName="transform" type="rotate" from="0 22 22" to="360 22 22" dur="3s" repeatCount="indefinite"/></path></symbol> |
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 like the AngularJS logo SVG! Where does this spinner come from? Did you create it or do you have a link to the related license?
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 was using icon from webpack-svgstore-plugin. I change it now to material sync icon: https://material.io/icons/#ic_sync to not guess about licence.
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.
Excellent, thank you.
Oh, one more thing, in your squashed commit, please use |
Add support for SVG icon sets with symbol elements. SVG icon sprite with symbols is most commonly produced by: svg-sprite-loader, webpack-svgstore-plugin, gulp-svg-sprites ... This may consider also as backport, as angular material2 project support this kind of sets. This change is related to angular#8689 issue and directly related to closed issue angular#1514
f2c6d50
to
d85f596
Compare
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.
LGTM
Add support for SVG icon sets with symbol elements. SVG icon sprite with symbols is most commonly produced by: svg-sprite-loader, webpack-svgstore-plugin, gulp-svg-sprites ... This may consider also as backport, as angular material2 project support this kind of sets. This change is related to angular#8689 issue and directly related to closed issue angular#1514
Add support for SVG icon sets with symbol elements. SVG icon sprite with symbols is most commonly produced by: svg-sprite-loader, webpack-svgstore-plugin, gulp-svg-sprites ... This may consider also as backport, as angular material2 project support this kind of sets. This change is related to #8689 issue and directly related to closed issue #1514
// If the node is a <symbol>, it won't be rendered so we have to convert it into <svg>. | ||
if (el && el.tagName.toLowerCase() === 'symbol') { | ||
var viewbox = el.getAttribute('viewBox'); | ||
el = angular.element('<svg xmlns="http://www.w3.org/2000/svg">').html(el.innerHTML)[0]; |
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 just wanted to give a heads up that this caused a regression / exception as innerHTML
is not supported for SVG elements in IE11. Investigation happening here.
PR Checklist
Please check that your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Currently icon sets with symbols are not supported. Icon don't display as symbols are not rendered.
Issue Number: #8689
What is the new behavior?
This is kind of backport from material2 (angular 2 material design) project. You can check this:
https://github.com/angular/material2/blob/54252d5c1be882e6ffaec0f72516363f66b9de58/src/lib/icon/icon-registry.ts#L410
If detect symbol element iinstead svg within icon set convert it to svg.
Does this PR introduce a breaking change?
Other information