diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/property-editors/property-editor-content-picker.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/property-editors/property-editor-content-picker.element.ts index 2ce22c1c48..5793e3ca23 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/property-editors/property-editor-content-picker.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/property-editors/property-editor-content-picker.element.ts @@ -43,14 +43,22 @@ class UmbPropertyEditorContentPicker extends UmbContextConsumerMixin(LitElement) } private _open() { - const modalHandler = this._modalService?.openSidebar('umb-modal-content-picker'); + const modalHandler = this._modalService?.openSidebar('umb-modal-content-picker', { size: 'small' }); modalHandler?.onClose.then(() => { console.log('Closed the modal for:', this); }); } + private _tempOpenDialog() { + //TODO: remove this + this._modalService?.openDialog('umb-modal-content-picker'); + } + render() { - return html` Open `; + return html` + Open sidebar + Open dialog + `; } } diff --git a/src/Umbraco.Web.UI.Client/src/core/services/modal.service.ts b/src/Umbraco.Web.UI.Client/src/core/services/modal.service.ts index cc8f7dff33..a382b271e3 100644 --- a/src/Umbraco.Web.UI.Client/src/core/services/modal.service.ts +++ b/src/Umbraco.Web.UI.Client/src/core/services/modal.service.ts @@ -5,16 +5,16 @@ export class UmbModalService { private _modals: BehaviorSubject> = new BehaviorSubject(>[]); public readonly modals: Observable> = this._modals.asObservable(); - public openSidebar(elementName: string): UmbModalHandler { - return this._open(elementName, 'uui-modal-sidebar'); + public openSidebar(elementName: string, modalOptions?: any): UmbModalHandler { + return this._open(elementName, 'uui-modal-sidebar', modalOptions); } - public openDialog(elementName: string): UmbModalHandler { - return this._open(elementName, 'uui-modal-dialog'); + public openDialog(elementName: string, modalOptions?: any): UmbModalHandler { + return this._open(elementName, 'uui-modal-dialog', modalOptions); } - private _open(elementName: string, modalElementName: string): UmbModalHandler { - const modalHandler = new UmbModalHandler(elementName, modalElementName); + private _open(elementName: string, modalElementName: string, modalOptions?: any): UmbModalHandler { + const modalHandler = new UmbModalHandler(elementName, modalElementName, modalOptions); modalHandler.onClose.then(() => this._close(modalHandler)); this._modals.next([...this._modals.getValue(), modalHandler]); return modalHandler; diff --git a/src/Umbraco.Web.UI.Client/src/core/services/modalHandler.ts b/src/Umbraco.Web.UI.Client/src/core/services/modalHandler.ts index 028d3f1d5a..75e268ef13 100644 --- a/src/Umbraco.Web.UI.Client/src/core/services/modalHandler.ts +++ b/src/Umbraco.Web.UI.Client/src/core/services/modalHandler.ts @@ -1,5 +1,7 @@ +import { html, render } from 'lit'; + +//TODO consider splitting this into two separate handlers export default class UmbModalHandler { - private _elementName; private _closeResolver: any; private _closePromise: any; @@ -7,22 +9,28 @@ export default class UmbModalHandler { public key: string; public modal: any; - constructor(elementName: string, modalElementName: string) { + constructor(elementName: string, modalElementName: string, modalOptions?: any) { this.key = Date.now().toString(); //TODO better key - this._elementName = elementName; - this._createLayoutElement(modalElementName); + this._createLayoutElement(elementName, modalElementName, modalOptions); this._closePromise = new Promise((resolve) => { this._closeResolver = resolve; }); } - private _createLayoutElement(modalElementName: string) { + private _createLayoutElement(elementName: string, modalElementName: string, modalOptions?: any) { this.modal = document.createElement(modalElementName); this.modal.addEventListener('close-end', () => { this._closeResolver(); }); - this.modal.size = 'small'; //TODO make meta object for settings - this.element = document.createElement(this._elementName); + + if (modalOptions) { + // Apply modal options as attributes on the modal + Object.keys(modalOptions).forEach((option) => { + this.modal.setAttribute(option, modalOptions[option]); + }); + } + + this.element = document.createElement(elementName); this.modal.appendChild(this.element); this.element.modalHandler = this; }