Skip to content
Snippets Groups Projects
Select Git revision
  • d24130d02eb38b6901e8e5089f6f64083876a7b3
  • main default protected
  • renovate/lock-file-maintenance
  • demo protected
  • person-select-custom
  • dbp-translation-component
  • icon-set-mapping
  • port-i18next-parser
  • remove-sentry
  • favorites-and-recent-files
  • revert-6c632dc6
  • lit2
  • advertisement
  • wc-part
  • automagic
  • publish
  • wip-cleanup
  • demo-file-handling
18 results

vpu-button.js

Blame
    • Reiter, Christoph's avatar
      d27ed11c
      Add getAssetURL() to common · d27ed11c
      Reiter, Christoph authored
      This splits things into two phases, initAssetBaseURL() will try to set
      a module wide base url for all assets.
      
      The first code to use it successfully will define the asset base url for
      all future getAssetURL() calls.
      d27ed11c
      History
      Add getAssetURL() to common
      Reiter, Christoph authored
      This splits things into two phases, initAssetBaseURL() will try to set
      a module wide base url for all assets.
      
      The first code to use it successfully will define the asset base url for
      all future getAssetURL() calls.
    vpu-button.js 2.42 KiB
    import {html, LitElement, css} from 'lit-element';
    import * as commonUtils from './utils.js';
    import bulmaCSSPath from 'bulma/css/bulma.min.css';
    import VPULitElement from './vpu-lit-element.js';
    import * as utils from '../../src/utils';
    
    /**
     * vpu-button implements a button with Bulma styles and automatic spinner and
     * disabling if button is clicked
     *
     * Use the attribute "no-spinner-on-click" to disable the spinner, then you can
     * start it with start() and stop it with stop()
     *
     * Use the attribute "type" to set Bulma styles like "is-info"
     * See https://bulma.io/documentation/elements/button/#colors for a list of all styles
     */
    class Button extends VPULitElement {
        constructor() {
            super();
            this.value = "";
            // see: https://bulma.io/documentation/elements/button/#colors
            this.type = "is-primary";
            this.spinner = false;
            this.noSpinnerOnClick = false;
            this.disabled = false;
            this.button = null;
        }
    
        connectedCallback() {
            super.connectedCallback();
            const that = this;
    
            this.updateComplete.then(()=> {
                this.button = this._("button");
            });
        }
    
        static get properties() {
            return {
                value: { type: String },
                type: { type: String },
                spinner: { type: Boolean },
                noSpinnerOnClick: { type: Boolean, attribute: 'no-spinner-on-click' },
                disabled: { type: Boolean },
            };
        }
    
        static get styles() {
            return css`vpu-mini-spinner { margin-left: 0.5em; }`;
        }
    
        clickHandler() {
            if (!this.noSpinnerOnClick) {
                this.start();
            }
        }
    
        start() {
            this.spinner = true;
            this.disabled = true;
            this.setAttribute("disabled", "disabled");
        }
    
        stop() {
            this.spinner = false;
            this.disabled = false;
            this.removeAttribute("disabled");
        }
    
        isDisabled() {