-
Notifications
You must be signed in to change notification settings - Fork 837
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
Custom icon rendering to support SVG icons #1860
Comments
Hi @osre77, I like the idea in general but I am not sure why this is a feature of RadzenIcon. To be honest it doesn't use anything from it and seems to just complicate things. |
I just used RadzenIcon for my prototype. The idea is to use IRadzenIcon everywhere where icons are currently used, like RadzenButton, ... If it were just for standalone SVG icons a SvgIcon component would be the easier solution. |
How would this be used in RadzenButton for example? Wouldn't it require a new property? The diff doesn't show such usage at the moment. |
If implemented as a braking change then the And you would use it like that:
where
Would cause a compilation error. As a non-breaking change a new property like
Using both |
The thing is a lot of the components are not using RadzenIcon but simply render the
|
I know that all components with icons would have to be touched: I would offer to do that, either as a breaking change or with the alternative property for the icon. And I'm also aware that the SVG icon could simply be put into the content. But I would prefer if the icons would just work as is with the property but is not locked to font icons. |
Honestly I think this is too much of an effort and quite a big of a change. The workaround is simple enough - to use the content of the component. So let's not do that but use the child content instead. |
OK, thank you for your input. |
Hi,
i was looking into a solution to support SVG icons along with the font icons used by Radzen.
I made a rapid prototype that uses an interface for icons that offers one method to return a
RenderFragment
for the icon.CustomIconRendererPrototypeDiff
The idea is to replace all the
string Icon
properties withIRadzenIcon Icon
.Instead of having the hardcoded
<i>
element, the interface implementation provides theRenderFragment
to render.My goal was to make it code compatible by implementing an implicit cast operator from
string
toIRadzenIcon
, but that failed because the razor files do not recognize the icon names as string anymore once the property type is not string.This is why for the prototype I added the
IconX
property to theRadzenIcon
. If it is set it will be rendered instead of the<i>
element.I made an implementation for the
FontIcon
. TheMaterialIcons
class offers all known standard icons (just a subset in the prototype). This class would best be generated with a source generator. Using this class instead of just the string for the icon name has the advantage to offer auto completion in the editor.I also added a
SvgIcon
implementation that loads the SVG content from an embedded resource and makes some adjustments to it for sizing and tinting.This solution supports sizing and coloring of the icon just like the font icons. Using the
<img>
element and load the file from wwwroot would not allow coloring and probably would have sizing issues as well.The only downside I can see here is that if the
string Icon
in all components is replaced withIRadzenIcon Icon
, all existing code out there would break. My solution in the prototype with the additional property would make it a non-breaking change but might be a bit confusing to use. It also requires more changes to all components with icons.This prototype is by no means something to merge into the Radzen codebase. It is just a prototype/prove of concept.
If you say you would like to have this in Radzen, and maybe have some more ideas as well, I would happily continue development to a releasable state.
The text was updated successfully, but these errors were encountered: