import styles from "./xio-op.css.js" import {Op, ops} from "../../../framework/ops.js" import svgWarning from "../../../framework/icons/warning.svg.js" import svgSpinner from "../../../framework/icons/spinner.svg.js" import {Component, html, mixinStyles, property} from "../../../framework/component.js" @mixinStyles(styles) export class XioOp extends Component { @property({type: String, reflect: true}) mode: string = "none" private _op: Op = ops.none() get op() { return this._op } @property({type: Object}) set op(op: Op) { const old = this._op this._op = op this.mode = ops.mode(op) this.requestUpdate("op", old) } @property() errorIcon = svgWarning @property() loadingIcon = svgSpinner @property({type: String}) ["loading-message"] = "" @property({type: String}) ["error-message"] = "error" @property({type: Boolean}) ["hide-error-text"]: boolean = false @property({type: Boolean}) ["start-loading"]: boolean firstUpdated() { if (this["start-loading"]) { this.op = ops.loading() } } render() { return ops.select(this.op, { none: () => html` `, loading: () => html` ${this.loadingIcon} ${this["loading-message"] ? html`${this["loading-message"]}` : null} `, error: reason => html` ${this.errorIcon} ${this["hide-error-text"] ? null : html`${reason ?? this["error-message"]}`} `, ready: () => html` `, }) } }