-
Notifications
You must be signed in to change notification settings - Fork 167
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: add Svg component #15540
feat: add Svg component #15540
Conversation
A very trivial implementation capable only do display static SVG at this point.
If any of @vaadin/flow team member or other core hackers would have good idea how to quickly implement a way to create to root element with createElementNS or another hack how to get rid of the wrapper div, it would be cleaner and good for forward compatibility (in case we ever get SVG support to Element API). Otherwise I believe this component would already help people as such. |
Thanks @mstahv for the contribution. Just a question, why isn't using the
What kind of styling you have in mind that cannot be done with |
@taefi : "Compared to using SVG as Image source, the SVG content displayed using this component can be styled with CSS." With CSS you can for example change colors of icons without actually touching the SVG itself. @anezthes Can provide you more details. I don't think dynamic creation of SVG itself has nothing to do with this case, that can be done with Image already if needed. This is more about styling and discoverability/documentation. |
flow-server/src/test/java/com/vaadin/flow/component/SvgTest.java
Outdated
Show resolved
Hide resolved
flow-server/src/test/java/com/vaadin/flow/component/SvgTest.java
Outdated
Show resolved
Hide resolved
flow-server/src/test/java/com/vaadin/flow/component/SvgTest.java
Outdated
Show resolved
Hide resolved
* @param svg | ||
* the SVG string | ||
*/ | ||
public void setSvg(String 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.
I suggest to rename the setters for the content of the Svg component to setContent
, since having a svg
variable and calling a setSvg
method on it is verbose and even a little confusing.
public void setSvg(String svg) { | |
public void setContent(String svgContent) { |
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 don't agree. That method name would confuse people to pass in only content of the top level svg element.
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.
In Image we have setSrc. Don't like that either, especially in that shorthand form.
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 get your concern about a situation that someone might pass children contents of a svg
instead of including the <svg ...> </svg>
itself as well, but we can address that issue by a good documentation. Also, given the fact that the implementation of the validateAndSet
is taking care of the presence of additional contents such as <?xml ...>
or <!DOCTYPE svg... >
, or not having the <svg ...>
in the input, I don't see a reason to add the verbosity.
Btw, imagining myself reading/reviewing a code/documentation/tutorial (having a Svg svg = new Svg();
in the context), I still prefer:
svg.setContent("<svg ...></svg>");
over
svg.setSvg("<svg ...></svg>");
Maybe this is only my personal taste.
@taefi This is because Vaadin is creating the svg element on the client side with createElement, should use createElmentNS (or something to create it with the different namespace). |
Do I remember wrong or was there some "virtual child" concept? That with some JS hack maybe (if we don't want to touch the client side code and add an actual framework feature)? |
I'm not sure if this is somehow related as well, but there seems to be an open issue for rendering |
@mstahv please Another issue for omitting the wrapper This PR is good to be merged IMO. |
Formatted✅ Enhancement issue: #15601 |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
A very trivial implementation capable only do display static SVG at this point.
Compared to using Html, this component don't need any hacks to wrap svg into some html element.
Compared to using SVG as Image source, the SVG content displayed using this component can be styled with CSS.
Type of change
Checklist
Additional for
Feature
type of change