import { $el, getStrTypeAttr, removeAttrs, setHtml } from '../../dom-utils'; import { moreThanOneNode } from '../../mixins'; import PREFIX from '../prefix'; class Jumbotron { readonly VERSION: string; readonly COMPONENTS: NodeListOf; constructor() { this.VERSION = 'v1.0'; this.COMPONENTS = $el('r-jumbotron', { all: true }); this._create(this.COMPONENTS); } private _create(COMPONENTS: NodeListOf) { COMPONENTS.forEach((node) => { if (moreThanOneNode(node)) return; const placeholderNode = node.firstElementChild; const { title, subTitle } = this._attrs(node); this._setMainTemplate(node, title, subTitle); this._setExtraContent(node, placeholderNode); removeAttrs(node, ['title', 'sub-title']); }); } private _setMainTemplate(node: Element, title: string, subTitle: string): void { const template = `

${title}

${subTitle}
`; setHtml(node, template); } private _setExtraContent(node: Element, placeholderNode: Element | null): void { if (!placeholderNode) return; const JumbotronContainer = node.querySelector(`.${PREFIX.jumbotron}-container`); JumbotronContainer?.appendChild(placeholderNode); } private _attrs(node: Element) { return { title: getStrTypeAttr(node, 'title', ''), subTitle: getStrTypeAttr(node, 'sub-title', '') }; } } export default Jumbotron;