Button.js 1.4 KB
import template from "./Button.html";
import style from "antd/lib/button/style/index.css";

class Button {
    
    useModules = ["esNgAntd"];

    props = {
        type: String,
        size: String,
        ghost: Boolean,
        loading: Boolean,
        htmlType: String,
    };

    state = {
        disabled: null,
        className: "",
    };

    template = template;

    watch = {
        loading:  (newVal)=> {
            if (newVal !== undefined) {
                if (newVal === "true") {
                    this.state.className += " ant-btn-loading";
                } else {
                    this.state.className = this.state.className.replace(
                        " ant-btn-loading",
                        ""
                    );
                }
            }
        },
    };

    constructor() {
        esNgAntd.createStyle("ant-btn", style);

        let className = ["ant-btn"];
        if (this.props.type) {
            className.push("ant-btn-" + this.props.type);
        }
        if (this.props.size && ["lg", "sm", "xs"].includes(this.props.size)) {
            className.push("ant-btn-" + this.props.size);
        }
        if (this.props.ghost) {
            className.push("ant-btn-background-ghost");
        }
        this.state.className = className.join(" ");

        if (this.props.htmlType) {
            $element[0].setAttribute("type", this.props.htmlType)
        }
    }
}