-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1507 from enkelmedia/1506-custom-modal
Feature/Proposal: Added support for element factory for modal manager context
- Loading branch information
Showing
11 changed files
with
244 additions
and
45 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
examples/custom-modal/example-custom-modal-dashboard.element.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { EXAMPLE_MODAL_TOKEN, type ExampleModalData, type ExampleModalResult } from './example-modal-token.js'; | ||
import { css, html, customElement } from '@umbraco-cms/backoffice/external/lit'; | ||
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; | ||
import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal'; | ||
import './example-custom-modal-element.element.js'; | ||
|
||
@customElement('example-custom-modal-dashboard') | ||
export class UmbExampleCustomModalDashboardElement extends UmbLitElement { | ||
|
||
#modalManagerContext? : typeof UMB_MODAL_MANAGER_CONTEXT.TYPE; | ||
|
||
constructor() { | ||
super(); | ||
this.consumeContext(UMB_MODAL_MANAGER_CONTEXT,(instance)=>{ | ||
this.#modalManagerContext = instance; | ||
}) | ||
} | ||
|
||
#onOpenModal(){ | ||
this.#modalManagerContext?.open(this,EXAMPLE_MODAL_TOKEN,{}) | ||
} | ||
|
||
override render() { | ||
return html` | ||
<uui-box> | ||
<p>Open the custom modal</p> | ||
<uui-button look="primary" @click=${this.#onOpenModal}>Open Modal</uui-button> | ||
</uui-box> | ||
`; | ||
} | ||
|
||
static override styles = [css` | ||
:host{ | ||
display:block; | ||
padding:20px; | ||
} | ||
`]; | ||
} | ||
|
||
export default UmbExampleCustomModalDashboardElement | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'example-custom-modal-dashboard': UmbExampleCustomModalDashboardElement; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
examples/custom-modal/example-custom-modal-element.element.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { css, html } from "@umbraco-cms/backoffice/external/lit"; | ||
import { defineElement, UUIModalElement } from "@umbraco-cms/backoffice/external/uui"; | ||
|
||
/** | ||
* This class defines a custom design for the modal it self, in the same was as | ||
* UUIModalSidebarElement and UUIModalDialogElement. | ||
*/ | ||
@defineElement('example-modal-element') | ||
export class UmbExampleCustomModalElement extends UUIModalElement { | ||
override render() { | ||
return html` | ||
<dialog> | ||
<h2>Custom Modal-wrapper</h2> | ||
<slot></slot> | ||
</dialog> | ||
`; | ||
} | ||
|
||
static override styles = [ | ||
...UUIModalElement.styles, | ||
css` | ||
dialog { | ||
width:100%; | ||
height:100%; | ||
max-width: 100%; | ||
max-height: 100%; | ||
top:0; | ||
left:0; | ||
right:0; | ||
bottom:0; | ||
background:#fff; | ||
} | ||
:host([index='0']) dialog { | ||
box-shadow: var(--uui-shadow-depth-5); | ||
} | ||
:host(:not([index='0'])) dialog { | ||
outline: 1px solid rgba(0, 0, 0, 0.1); | ||
} | ||
`, | ||
]; | ||
} | ||
|
||
export default UmbExampleCustomModalElement; | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'example-modal-element': UmbExampleCustomModalElement; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { UmbModalToken } from "@umbraco-cms/backoffice/modal"; | ||
|
||
export interface ExampleModalData { | ||
unique: string | null; | ||
} | ||
|
||
export interface ExampleModalResult { | ||
text : string; | ||
} | ||
|
||
export const EXAMPLE_MODAL_TOKEN = new UmbModalToken< | ||
ExampleModalData, | ||
ExampleModalResult | ||
>('example.modal.custom.element', { | ||
modal : { | ||
type : 'custom', | ||
element: () => import('./example-custom-modal-element.element.js'), | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { ExampleModalData, ExampleModalResult } from './example-modal-token.js'; | ||
import { css, html, customElement, property } from '@umbraco-cms/backoffice/external/lit'; | ||
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; | ||
import type { UmbModalContext } from '@umbraco-cms/backoffice/modal'; | ||
import './example-custom-modal-element.element.js'; | ||
|
||
@customElement('example-modal-view') | ||
export class UmbExampleModalViewElement extends UmbLitElement { | ||
|
||
@property({ attribute: false }) | ||
public modalContext?: UmbModalContext<ExampleModalData, ExampleModalResult>; | ||
|
||
onClickDone(){ | ||
this.modalContext?.submit(); | ||
} | ||
|
||
override render() { | ||
return html` | ||
<div id="modal"> | ||
<p>Example content of custom modal element</p> | ||
<uui-button look="primary" label="Submit modal" @click=${() => this.onClickDone()}></uui-button> | ||
</div> | ||
`; | ||
} | ||
|
||
static override styles = [css` | ||
:host { | ||
background: #eaeaea; | ||
display: block; | ||
box-sizing:border-box; | ||
} | ||
#modal { | ||
box-sizing:border-box; | ||
} | ||
p { | ||
margin:0; | ||
padding:0; | ||
} | ||
`]; | ||
} | ||
|
||
export default UmbExampleModalViewElement | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'example-modal-view': UmbExampleModalViewElement; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { ManifestDashboard } from '@umbraco-cms/backoffice/dashboard'; | ||
import type { ManifestModal } from '@umbraco-cms/backoffice/modal'; | ||
|
||
const demoModal : ManifestModal = { | ||
type: 'modal', | ||
name: 'Example Custom Modal Element', | ||
alias: 'example.modal.custom.element', | ||
js: () => import('./example-modal-view.element.js'), | ||
} | ||
|
||
const demoModalsDashboard : ManifestDashboard = { | ||
type: 'dashboard', | ||
name: 'Example Custom Modal Dashboard', | ||
alias: 'example.dashboard.custom.modal.element', | ||
element: () => import('./example-custom-modal-dashboard.element.js'), | ||
weight: 900, | ||
meta: { | ||
label: 'Custom Modal', | ||
pathname: 'custom-modal', | ||
}, | ||
conditions : [ | ||
{ | ||
alias: 'Umb.Condition.SectionAlias', | ||
match: 'Umb.Section.Content' | ||
} | ||
] | ||
} | ||
|
||
export default [demoModal,demoModalsDashboard]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.