1 import {Component} from "./component.js";
2 import {showLoading} from "../services/dom";
3 import {el} from "../wysiwyg/utils/dom";
7 * Shows a loading indicator and disables the button when the button is clicked,
8 * or when the form attached to the button is submitted.
10 export class LoadingButton extends Component {
12 protected button!: HTMLButtonElement;
13 protected loadingEl: HTMLDivElement|null = null;
16 this.button = this.$el as HTMLButtonElement;
17 const form = this.button.form;
19 const action = () => {
20 setTimeout(() => this.showLoadingState(), 10)
23 this.button.addEventListener('click', action);
25 form.addEventListener('submit', action);
30 this.button.disabled = true;
32 if (!this.loadingEl) {
33 this.loadingEl = el('div', {class: 'inline block'}) as HTMLDivElement;
34 showLoading(this.loadingEl);
35 this.button.after(this.loadingEl);