Description
I've created a couple of custom elements in Svelte and it looks really great, but one feature that is missing is that there is no way of extending native HTML elements (eg. link).
One of the use-cases where I want to use these is creating a couple of extended elements, which will have css and some minor JS functionality implemented additionally to the standard ones. I cannot use pure custom elements, as it would be an overkill to integrate them in different frameworks like Vue, React, Angular etc. Not mentioning that it would make the developers to write a lot of boilerplate code just to communicate with custom-elements (getting the value, firing validation and so on).
When trying to build something like the following:
class CustomCbx extends HTMLInputElement {
constructor() {
super();
let shadowRoot = this.attachShadow({mode: 'open'});
this.addStyles(shadowRoot);
}
addStyles(shadowRoot) {
shadowRoot.innerHTML = `
<style>
:host {
color: red;
}
input {
margin: 20px;
}
</style>
`;
}
}
export default CustomCbx;
and running rollup -c
, Svelte throws this error: (svelte plugin) ValidationError: Default export must be an object literal
;
It would be great if Svelte supported something like this.