UNPKG

@universal-material/web

Version:
42 lines 1.28 kB
import './dialog.js'; export class DialogBuilder { #headline; constructor(message) { this.message = message; } headline(headline) { this.#headline = headline; return this; } show() { const dialog = document.createElement('u-dialog'); dialog.innerText = this.message; this.addHeadline(dialog); this.addButtons(dialog); return this.innerShow(dialog); } innerShow(dialog) { dialog.addEventListener('closed', () => dialog.remove()); document.body.appendChild(dialog); dialog.show(); return; } addHeadline(dialog) { if (!this.#headline) { return; } const headlineElement = document.createElement('span'); headlineElement.slot = 'headline'; headlineElement.textContent = this.#headline; dialog.appendChild(headlineElement); } addButton(dialog, buttonDef, click) { const button = document.createElement('u-button'); button.variant = buttonDef.variant; button.textContent = buttonDef.label; button.slot = 'actions'; button.addEventListener('click', click); dialog.appendChild(button); } } //# sourceMappingURL=dialog-builder.js.map