/* * Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { BaseElement, element } from '../BaseElement'; @element('lit-button') export class LitButton extends BaseElement { private slotHtml: HTMLElement | undefined; private button: HTMLButtonElement | null | undefined; private litIcon: LitButton | null | undefined; static get observedAttributes(): string[] { return [ 'text', 'back', 'icon', 'height', 'width', 'color', 'font_size', 'border', 'padding', 'justify_content', 'border_radius', 'margin_icon', 'opacity', ]; } get text(): string { return this.getAttribute('text') || ''; } set text(text: string) { this.setAttribute('text', text); } get back(): string { return this.getAttribute('back') || ''; } set back(backColor: string) { this.button!.style.backgroundColor = backColor; this.setAttribute('back', backColor); } get icon(): string { return this.getAttribute('icon') || ''; } set icon(icon: string) { this.litIcon?.setAttribute('name', icon); this.setAttribute('icon', icon); if (icon) { this.litIcon!.style.display = 'block'; } } get height(): string { return this.getAttribute('height') || ''; } set height(height: string) { this.setAttribute('height', height); } get width(): string { return this.getAttribute('width') || ''; } set width(width: string) { this.setAttribute('width', width); } set color(color: string) { this.setAttribute('color', color); } set font_size(fontSize: string) { this.setAttribute('font_size', fontSize); } set border(border: string) { this.setAttribute('border', border); } set padding(padding: string) { this.setAttribute('padding', padding); } set justify_content(justifyContent: string) { this.setAttribute('justify_content', justifyContent); } set border_radius(borderRadius: string) { this.setAttribute('border_radius', borderRadius); } set margin_icon(value: string) { this.litIcon?.setAttribute('margin_icon', value); } set opacity(value: string) { this.litIcon?.setAttribute('opacity', value); } set hidden(hidden: boolean) { if (hidden) { this.setAttribute('hidden', 'true'); this.style.display = 'none'; } else { this.removeAttribute('hidden'); this.style.display = 'block'; } } initHtml(): string { return ` ${this.initHtmlStyle()}