Skip to content
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

feat(icon): allow SVG icons to be registered from strings #10757

Merged
merged 1 commit into from
Apr 11, 2018

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Apr 8, 2018

Expands the icon registry to allow for icons and icon sets to be registered using a trusted HTML string.

Fixes #3132.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Apr 8, 2018
* @param iconName Name under which the icon should be registered.
* @param template SVG source of the icon.
*/
addSvgIconTemplateInNamespace(namespace: string, iconName: string, template: SafeHtml): this {
Copy link
Member Author

Choose a reason for hiding this comment

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

@jelbourn I'm not a fan of having to have two sets of methods. Ideally the signature of addSvgIconInNamespace would be something like addSvgIconInNamespace(namespace: string, iconName: string, data: SafeResourceUrl | SafeHtml), however there's no clean way of detecting which type of resource was used, because SafeResourceUrl and SafeHtml are interfaces.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, would be better, but ultimately doesn't bother me that much.

@crisbeto crisbeto force-pushed the 3132/icon-from-svg-string branch 2 times, most recently from b27933b to eb5bb3f Compare April 8, 2018 09:53
@jelbourn jelbourn added the target: minor This PR is targeted for the next minor release label Apr 9, 2018
constructor(url: SafeResourceUrl);
constructor(svgElement: SVGElement);
constructor(data: SafeResourceUrl | SVGElement) {
if (data instanceof SVGElement) {
Copy link
Member

Choose a reason for hiding this comment

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

Will referencing SVGElement cause any issues on platform-server?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, looks like it does. I've switched it to a hackier approach that should work everywhere.

* @param iconName Name under which the icon should be registered.
* @param template SVG source of the icon.
*/
addSvgIconTemplate(iconName: string, template: SafeHtml): this {
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about addSvgIconLiteral or addSvgIconFromHtmlString? Template isn't really the right term because the string is totally static / non-templated

Copy link
Member Author

Choose a reason for hiding this comment

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

I like "literal", I wanted to avoid having having HTML in there because SVG is an XML dialect rather an HTML one.

Copy link
Member

Choose a reason for hiding this comment

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

"Literal" sounds good to me

* @param iconName Name under which the icon should be registered.
* @param template SVG source of the icon.
*/
addSvgIconTemplateInNamespace(namespace: string, iconName: string, template: SafeHtml): this {
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, would be better, but ultimately doesn't bother me that much.

Expands the icon registry to allow for icons and icon sets to be registered using a trusted HTML string.

Fixes angular#3132.
@crisbeto
Copy link
Member Author

crisbeto commented Apr 9, 2018

Addressed the feedback @jelbourn.

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Apr 9, 2018
@tinayuangao tinayuangao merged commit 57efa13 into angular:master Apr 11, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extending of mdIcon source definition (for strings)
4 participants