From ce272e0b80f98353d8a2e57930bdfac27143f3fa Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Wed, 10 Aug 2022 13:53:09 +0200 Subject: [PATCH] fix dialog stories and add options for each layout --- .../src/core/services/modal/modal.stories.ts | 121 ++++-------------- 1 file changed, 24 insertions(+), 97 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/core/services/modal/modal.stories.ts b/src/Umbraco.Web.UI.Client/src/core/services/modal/modal.stories.ts index 38ebf60216..27244e4ea7 100644 --- a/src/Umbraco.Web.UI.Client/src/core/services/modal/modal.stories.ts +++ b/src/Umbraco.Web.UI.Client/src/core/services/modal/modal.stories.ts @@ -1,5 +1,7 @@ import '../../../backoffice/components/backoffice-modal-container.element'; import '../../../core/services/modal/layouts/content-picker/modal-layout-content-picker.element'; +import '../../context/context-provider.element'; +import '../../../backoffice/components/editor-layout.element'; import '@umbraco-ui/uui-modal'; import '@umbraco-ui/uui-modal-container'; @@ -11,7 +13,7 @@ import { html } from 'lit-html'; import { customElement, property, state } from 'lit/decorators.js'; import { UmbContextConsumerMixin } from '../../context'; import { LitElement } from 'lit'; -import { UmbModalHandler, UmbModalOptions, UmbModalService } from './'; +import { UmbModalHandler, UmbModalService } from './'; export default { title: 'API/Modals', @@ -27,89 +29,20 @@ export default { ], id: 'installer-page', argTypes: { - modalType: { control: 'select', options: ['sidebar', 'dialog'] }, + modalLayout: { control: 'select', options: ['Confirm', 'Content Picker'] }, }, } as Meta; -@customElement('story-modal-service-dialog-example') -class DialogExampleElement extends UmbContextConsumerMixin(LitElement) { - @property({ attribute: false }) - modalHandler?: UmbModalHandler; - - private _close() { - this.modalHandler?.close(); - } - - private _submit(value: any) { - this.modalHandler?.close(value); - } - - render() { - return html` - - -

By clicking the close button, the modal is closed

-

- By clicking the submit button, the modal is closed and the value I am the value is returned to the - component that opened this modal -

- this._close()} label="close"> - this._submit('I am the value')} - label="submit"> -
-
- `; - } -} - -@customElement('story-modal-service-sidebar-example') -class SidebarExampleElement extends UmbContextConsumerMixin(LitElement) { - @property({ attribute: false }) - modalHandler?: UmbModalHandler; - - private _close() { - this.modalHandler?.close(); - } - - private _submit(value: any) { - this.modalHandler?.close(value); - } - - render() { - return html`
-

Sidebar

-

By clicking the close button, the modal is closed

-

- By clicking the submit button, the modal is closed and the value I am the value is returned to the - component that opened this modal -

- this._close()} label="close"> - this._submit('I am the value')} - label="submit"> -
`; - } -} - @customElement('story-modal-service-example') class StoryModalServiceExampleElement extends UmbContextConsumerMixin(LitElement) { - private _modalService?: UmbModalService; - @property() - modalType: 'dialog' | 'sidebar' = 'dialog'; - - @property() - modalOptions: UmbModalOptions = { type: 'sidebar', size: 'small' }; + modalLayout = 'confirm'; @state() value = ''; + private _modalService?: UmbModalService; + constructor() { super(); this.consumeContext('umbModalService', (modalService: UmbModalService) => { @@ -118,23 +51,26 @@ class StoryModalServiceExampleElement extends UmbContextConsumerMixin(LitElement } private _open() { - let modalHandler = null; - if (this.modalType === 'dialog') { - modalHandler = this._modalService?.open('story-modal-service-dialog-example'); + let modalHandler: UmbModalHandler | undefined; + + switch (this.modalLayout) { + case 'Content Picker': + modalHandler = this._modalService?.contentPicker(); + break; + default: + modalHandler = this._modalService?.confirm({ + headline: 'Headline', + content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit', + }); + break; } - if (this.modalType === 'sidebar') { - modalHandler = this._modalService?.open('story-modal-service-sidebar-example', this.modalOptions); - } - modalHandler?.onClose.then((result) => { - this.value = result ?? this.value; - }); } render() { return html` - this._open()}>Open modal -

The value is: ${this.value}

- (this.value = '')}> + this._open()} style="margin-right: 9px;" + >Open modal `; } } @@ -142,17 +78,8 @@ class StoryModalServiceExampleElement extends UmbContextConsumerMixin(LitElement const Template: Story = (props) => { return html` - + `; }; -export const Dialog = Template.bind({}); -Dialog.args = { - modalType: 'dialog', -}; - -export const Sidebar = Template.bind({}); -Sidebar.args = { - modalType: 'sidebar', - modalOptions: { size: 'small' }, -}; +export const Overview = Template.bind({});