import PREFIX from '../prefix'; import { $el, setHtml } from '../../dom-utils'; import { CssTransition, Scrollable } from '../../mixins'; import { destroyElem } from '../../utils'; let spinZIndex = 2010; class Spin { readonly VERSION: string; readonly COMPONENTS: NodeListOf; constructor() { this.VERSION = 'v1.0'; this.COMPONENTS = $el('r-spin', { all: true }); this._create(this.COMPONENTS); } public show({ content = '' } = {}): void { Scrollable({ scroll: false, lock: false }); const template = `
${this._createChildTemplate(content)}
`; const fragment = document.createRange().createContextualFragment(template); document.body.appendChild(fragment); CssTransition($el(`.${PREFIX.spin}-fullscreen`), { inOrOut: 'in', enterCls: 'rab-fade-in' }); } public hide(): void { Scrollable({ scroll: true, lock: true }); const spinElem = $el(`.${PREFIX.spin}-fullscreen`); if (spinElem) destroyElem(spinElem, { fadeOut: true }); } private _create(COMPONENTS: NodeListOf): void { COMPONENTS.forEach((node) => { const customContent = setHtml(node); customContent ? node.classList.add(`${PREFIX.spin}-show-text`) : ''; setHtml(node, this._createChildTemplate(customContent)); }); } private _createChildTemplate(content: string): string { const template = `
${content}
`; return template; } } export default Spin;