-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
feat(icon): allow SVG icons to be registered from strings #10757
Conversation
src/lib/icon/icon-registry.ts
Outdated
* @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 { |
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.
@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.
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.
Yeah, would be better, but ultimately doesn't bother me that much.
b27933b
to
eb5bb3f
Compare
src/lib/icon/icon-registry.ts
Outdated
constructor(url: SafeResourceUrl); | ||
constructor(svgElement: SVGElement); | ||
constructor(data: SafeResourceUrl | SVGElement) { | ||
if (data instanceof SVGElement) { |
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.
Will referencing SVGElement
cause any issues on platform-server?
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.
Yep, looks like it does. I've switched it to a hackier approach that should work everywhere.
src/lib/icon/icon-registry.ts
Outdated
* @param iconName Name under which the icon should be registered. | ||
* @param template SVG source of the icon. | ||
*/ | ||
addSvgIconTemplate(iconName: string, template: SafeHtml): 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.
What do you think about addSvgIconLiteral
or addSvgIconFromHtmlString
? Template isn't really the right term because the string is totally static / non-templated
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 "literal", I wanted to avoid having having HTML in there because SVG is an XML dialect rather an HTML one.
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.
"Literal" sounds good to me
src/lib/icon/icon-registry.ts
Outdated
* @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 { |
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.
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.
eb5bb3f
to
bad81e5
Compare
Addressed the feedback @jelbourn. |
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
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Expands the icon registry to allow for icons and icon sets to be registered using a trusted HTML string.
Fixes #3132.