move label stuff to Et2Button as Et2ButtonIcon does not need it

This commit is contained in:
ralf 2022-08-22 22:00:06 +02:00
parent 1d5467faab
commit ffb8354728
2 changed files with 38 additions and 39 deletions

View File

@ -151,45 +151,6 @@ export const ButtonMixin = <T extends Constructor>(superclass : T) => class exte
}
protected firstUpdated(_changedProperties : PropertyValues)
{
super.firstUpdated(_changedProperties);
if(!this.label && this.__image)
{
/*
Label / no label should get special classes set, but they're missing without this extra requestUpdate()
This is a work-around for button--has-prefix & button--has-label not being set, something to do
with how we're setting them.
*/
this.updateComplete.then(() =>
{
this.requestUpdate();
});
}
}
set label(new_label : string)
{
this.updateComplete.then(() =>
{
if(!this._labelNode)
{
const textNode = document.createTextNode(new_label);
this.appendChild(textNode);
}
else
{
this._labelNode.textContent = new_label;
}
});
}
get label()
{
return this._labelNode?.textContent?.trim();
}
set image(new_image : string)
{
let oldValue = this.__image;

View File

@ -13,11 +13,49 @@ import {Et2InputWidget} from "../Et2InputWidget/Et2InputWidget";
import '../Et2Image/Et2Image';
import {SlButton} from "@shoelace-style/shoelace";
import {ButtonMixin} from "./ButtonMixin";
import {PropertyValues} from "@lion/core";
export class Et2Button extends ButtonMixin(Et2InputWidget(SlButton))
{
protected firstUpdated(_changedProperties : PropertyValues)
{
super.firstUpdated(_changedProperties);
if(!this.label && this.__image)
{
/*
Label / no label should get special classes set, but they're missing without this extra requestUpdate()
This is a work-around for button--has-prefix & button--has-label not being set, something to do
with how we're setting them.
*/
this.updateComplete.then(() =>
{
this.requestUpdate();
});
}
}
set label(new_label : string)
{
this.updateComplete.then(() =>
{
if(!this._labelNode)
{
const textNode = document.createTextNode(new_label);
this.appendChild(textNode);
}
else
{
this._labelNode.textContent = new_label;
}
});
}
get label()
{
return this._labelNode?.textContent?.trim();
}
}
customElements.define("et2-button", Et2Button);