For CustomElements I can do this:
class MyElement extends HTMLElement {}
Can I do the same for SVG Elements? like
class MyOwnRectangle extends SVGRectElement {}
If it works, can I trouble someone for a jsbin?
If not, why not?
This has some very good use cases like being able to store model data in the element itself. SVG manipulation is basically used in 2 major areas:
A library like JointJS has its own abstractions in the form of classes (which extends a Backbone View) to store model data associated with the view (SVG diagrams on screen).
Like WebComponents can eventually replace jQuery Plugins, Framework X's components in a standard way, why not do the same for SVG?
Finally,
How is Polymer 0.5 able to do this?
Does Polymer.js support inner SVG elements?
How is this patch able to do this in Polymer 1.0?
https://github.com/Polymer/polymer/pull/3372
What is the alternative for now?
I guess we can extend HTMLElement
. In our ShadowDOM use an <svg>
element and then attach all the SVG tags we actually want to extend like <rect>
, <polyline>
etc! Perhaps a much cleaner way out of this?
Will this be implemented in the future?
We can create custom HTML elements, described by our class, with its own methods and properties, events and so on. Once a custom element is defined, we can use it on par with built-in HTML elements. That's great, as HTML dictionary is rich, but not infinite.
Custom elements allow web developers to define new HTML tags, extend existing ones, and create reusable web components.
The benefits of the Web Components. Web Components allow you to create reusable components based on HTML, JavaScript and CSS, separating their functionality and layout from the rest of the code, so it's a good encapsulation tool.
I think the answer is "yes" - Web Components will replace UI frameworks like React.
According to the specification
If result’s namespace is not the HTML namespace, then throw a NotSupportedError.
All SVG elements are in the SVG namespace. So the speification precludes support.
Ways to store data in SVG include the the <metadata> tag and data- attributes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With