from this link in javascript, customs element extending button is made as:
var MegaButton = document.registerElement('mega-button', {
prototype: Object.create(HTMLButtonElement.prototype),
extends: 'button'
});
<button is="mega-button">
I tried making the same using dart, by this code:
class MegaButton extends ButtonElement {
static final tag = 'mega-button';
factory MegaButton()=>new Element.tag('button', tag);
MegaButton.created() : super.created() {
var shadow = this.createShadowRoot();
shadow.text='save';
}
}
document.registerElement(MegaButton.tag, MegaButton);
in the html file
<button is="mega-button"></button>
<mega-button>click me</mega-button>
but got this error:
Exception: Unsupported operation: Class must provide extendsTag if base native class is not HTMLElement
any help pls. thanks
document.registerElement should look like:
document.registerElement(MegaButton.tag, MegaButton, extendsTag: 'button');
=> new Element.tag('button', tag);
see also Custom Polymer element extending AElement in Dart
The below code worked perfectly with me:
class SaveBtn extends HtmlElement {
static final tag = 'save-button';
factory SaveBtn()=>new Element.tag(tag);
SaveBtn.created() : super.created() {
// Create a Shadow Root
var shadow = this.createShadowRoot();
// Create a standard element and set it's attributes.
var btn = new ButtonElement()
..style.height= '20px'
..style.width= '50px'
..style.color= '#FF8F66'
..style.border='1px solid #BCC1C8'
..style.background='#F1F4FB'
..style.borderRadius='5px'
..style.fontFamily='openSansItalic'
..style.fontSize='12px'
..style.padding='0px 6px'
..style.marginLeft='0.1em'
..style.borderBeforeStyle='solid'
..style.borderWidth='1px'
..style.borderColor='transparent'
..style.marginBottom='2px'
..style.borderBottom='1px solid #D1DBE9';
btn.text= this.getAttribute('data-name');
btn.onMouseDown.listen((e){
btn..style.color="#333"
..style.background='#FF8F66';
});
btn.onMouseUp.listen((e){
btn..style.color="#FF8F66"
..style.background='#F1F4FB'
..style.outline='none'; // remove the focus outline/glur
});
btn.onMouseEnter.listen((e)=> btn..style.boxShadow='0px 0px 5px #888888');
btn.onMouseLeave.listen((e)=> btn..style.boxShadow='0px 0px 0px');
if(btn.disabled==true){
btn..style.color="gray";
}
shadow.nodes.add(btn);
Element launchElement(){
return (shadow);
}
}
}
the custom element registration:
document.registerElement(SaveBtn.tag, SaveBtn);
and in the html file, I used:
<save-button data-name='save orders'></save-button>