Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

feat(icon): Add support to svg symbol icon set #11162

Merged
merged 1 commit into from
Apr 17, 2018

Conversation

cobisimo
Copy link
Contributor

@cobisimo cobisimo commented Mar 13, 2018

PR Checklist

Please check that your PR fulfills the following requirements:

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Infrastructure changes
[ ] Other... Please describe:

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?

[ ] Yes
[x] No

Other information

@googlebot
Copy link

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. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers
  • Your company has a Point of Contact who decides which employees are authorized to participate. Ask your POC to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • The email used to register you as an authorized contributor must be the email used for the Git commit. Check your existing CLA data and verify that your email is set on your git commits.
  • The email used to register you as an authorized contributor must also be attached to your GitHub account.

@googlebot googlebot added the cla: no PR author needs to sign Google's CLA: https://opensource.google.com/docs/cla/ label Mar 13, 2018
@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes PR author has signed Google's CLA: https://opensource.google.com/docs/cla/ and removed cla: no PR author needs to sign Google's CLA: https://opensource.google.com/docs/cla/ labels Mar 13, 2018
@Splaktar
Copy link
Member

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.

@Splaktar Splaktar self-assigned this Mar 23, 2018
@Splaktar Splaktar added the needs: unit tests This PR needs unit tests to cover the changes being proposed label Mar 23, 2018
@Splaktar
Copy link
Member

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.

@Splaktar Splaktar added the needs: demo A CodePen demo or GitHub repository is needed to demonstrate the reproduction of the issue label Mar 23, 2018
Copy link
Member

@Splaktar Splaktar left a 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.

@cobisimo
Copy link
Contributor Author

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).
The issue here is that md-svg-icon use unique svg sprite <svg> packed within <svg>. There are multiple svg icon sprite generators like svg-sprite-loader, webpack-svgstore-plugin, gulp-svg-sprites ... They all pack icons as <symbol> within <svg>. If we try to use such icon pack it will not work, as <symbol> get embeded in <md-icon> instead <svg> and symbols are not renderable. This fix make addition to present setup to detect if source icon map use symbols and transfer them to svgs on the fly while creating icon cache.
Usual use of symbols to render icons is using <use xlink:href="#icon-name"></use>. This approach is good as it don't require icon cache, but switch to this require more changes to md-icon and have issue working on some browsers. As I said I didn't apply this logical way, I make a mix, using symbol within present setup, the similar way as it is done in material2.

@Splaktar
Copy link
Member

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.

@cobisimo
Copy link
Contributor Author

@Splaktar I added unit tests and demo with 2 additional icons to Demos -> Icons -> Svg Icon Sets block. Also commits should be squashed.

@Splaktar
Copy link
Member

Splaktar commented Apr 5, 2018

@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.

Copy link
Member

@Splaktar Splaktar left a 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>
Copy link
Member

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') {
Copy link
Member

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>
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thank you.

@Splaktar Splaktar added in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs P5: nice to have These issues will not be fixed without community contributions. and removed needs: demo A CodePen demo or GitHub repository is needed to demonstrate the reproduction of the issue needs: unit tests This PR needs unit tests to cover the changes being proposed labels Apr 5, 2018
@Splaktar Splaktar added this to the 1.1.9 milestone Apr 5, 2018
@Splaktar Splaktar changed the title feature(icon): Add support to svg symbol icon set feat(icon): Add support to svg symbol icon set Apr 5, 2018
@Splaktar
Copy link
Member

Splaktar commented Apr 5, 2018

Oh, one more thing, in your squashed commit, please use feat(icon): instead of feature(icon): so that our changelog will pick it up correctly.

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
Copy link
Member

@Splaktar Splaktar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Splaktar Splaktar added pr: merge ready This PR is ready for a caretaker to review pr: lgtm This PR has been approved by the reviewer and removed in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs needs: squash commits labels Apr 10, 2018
@Splaktar Splaktar assigned tinayuangao and mmalerba and unassigned Splaktar and tinayuangao Apr 11, 2018
@mmalerba mmalerba merged commit 5111f9d into angular:master Apr 17, 2018
chmelevskij pushed a commit to chmelevskij/material that referenced this pull request Jun 19, 2018
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
Splaktar pushed a commit that referenced this pull request Jul 31, 2018
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];
Copy link
Member

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.

Splaktar added a commit that referenced this pull request Dec 17, 2018
innerHTML is not supported on svg or symbol elements in IE11
use XMLSerializer instead of innerHTML when innerHTML is not defined

Fixes #11543. Relates to #11342. Relates to #11162.
Splaktar added a commit that referenced this pull request Dec 20, 2018
innerHTML is not supported on svg or symbol elements in IE11
use XMLSerializer instead of innerHTML when innerHTML is not defined

Fixes #11543. Relates to #11342. Relates to #11162.
Splaktar added a commit that referenced this pull request Dec 20, 2018
innerHTML is not supported on svg or symbol elements in IE11
use XMLSerializer instead of innerHTML when innerHTML is not defined
add a test for empty SVGs to match a g3 test

Fixes #11543. Relates to #11342. Relates to #11162.
jelbourn pushed a commit that referenced this pull request Dec 20, 2018
innerHTML is not supported on svg or symbol elements in IE11
use XMLSerializer instead of innerHTML when innerHTML is not defined
add a test for empty SVGs to match a g3 test

Fixes #11543. Relates to #11342. Relates to #11162.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has signed Google's CLA: https://opensource.google.com/docs/cla/ P5: nice to have These issues will not be fixed without community contributions. pr: lgtm This PR has been approved by the reviewer pr: merge ready This PR is ready for a caretaker to review type: enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants