100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Added or-mwc-dialog.ts UI component
Rich Turnerfc9e512c2a32
diff --git a/ui/component/or-mwc-components/package.json b/ui/component/or-mwc-components/package.jsonindex aa82e67e7..37f03fb64 100644--- a/ui/component/or-mwc-components/package.json+++ b/ui/component/or-mwc-components/package.json@@ -12,6 +12,7 @@"dependencies": {"@material/menu": "^4.0.0","@material/drawer": "^4.0.0",+ "@material/dialog": "^4.0.0","lit-element": "^2.2.1"},"devDependencies": {diff --git a/ui/component/or-mwc-components/src/or-mwc-dialog.ts b/ui/component/or-mwc-components/src/or-mwc-dialog.tsnew file mode 100644index 000000000..c77f90318--- /dev/null+++ b/ui/component/or-mwc-components/src/or-mwc-dialog.ts@@ -0,0 +1,157 @@+import {+ css,+ customElement,+ html,+ LitElement,+ property,+ PropertyValues,+ query,+ TemplateResult,+ unsafeCSS+} from "lit-element";+import {MDCDialog, MDCDialogCloseEventDetail} from "@material/dialog";+import "@openremote/or-translate";++const dialogStyle = require("!!raw-loader!@material/dialog/dist/mdc.dialog.css");++export interface DialogAction {+ default?: boolean;+ content: TemplateResult;+ actionName: string;+ action?: () => void;+}++export class OrMwcDialogOpenedEvent extends CustomEvent<void> {++ public static readonly NAME = "or-mwc-dialog-opened";++ constructor() {+ super(OrMwcDialogOpenedEvent.NAME, {+ bubbles: true,+ composed: true+ });+ }+}++export class OrMwcDialogClosedEvent extends CustomEvent<string | undefined> {++ public static readonly NAME = "or-mwc-dialog-closed";++ constructor(action?: string) {+ super(OrMwcDialogClosedEvent.NAME, {+ detail: action,+ bubbles: true,+ composed: true+ });+ }+}++declare global {+ export interface HTMLElementEventMap {+ [OrMwcDialogOpenedEvent.NAME]: OrMwcDialogOpenedEvent;+ [OrMwcDialogClosedEvent.NAME]: OrMwcDialogClosedEvent;+ }+}++// language=CSS+const style = css`+ :host {+ position: relative;+ }+`;++@customElement("or-mwc-dialog")+export class OrMwcDialog extends LitElement {++ static get styles() {+ return [+ css`${unsafeCSS(dialogStyle)}`,+ style+ ];+ }++ @property({type: String})+ public dialogTitle?: string;++ @property({type: Object, attribute: false})+ public dialogContent?: TemplateResult;++ @property({type: Array, attribute: false})+ public dialogActions?: DialogAction[];++ @query("#dialog")+ protected _mdcElem!: HTMLElement;++ protected _mdcComponent?: MDCDialog;++ public open() {+ if (this._mdcComponent) {+ this._mdcComponent.open();+ }+ }++ public close(action?: string) {+ if (this._mdcComponent) {+ this._mdcComponent.close(action);+ }+ }++ disconnectedCallback(): void {+ super.disconnectedCallback();+ if (this._mdcComponent) {+ this._mdcComponent.destroy();+ this._mdcComponent = undefined;+ }+ }++ protected render() {++ return html`+ <div id="dialog"+ class="mdc-dialog"+ role="alertdialog"+ aria-modal="true"+ aria-labelledby="dialog-title"+ aria-describedby="dialog-content"+ @MDCDialog:opened="${() => this._onDialogOpened()}"+ @MDCDialog:closed="${(evt: any) => this._onDialogClosed(evt.detail.action)}">+ <div class="mdc-dialog__container">+ <div class="mdc-dialog__surface">+ <h2 class="mdc-dialog__title" id="dialog-title"><or-translate value="${this.dialogTitle}"></or-translate></h2>+ <div class="dialog-container mdc-dialog__content" id="dialog-content">+ ${this.dialogContent ? this.dialogContent : html`<div></div>`}+ </div>+ <footer class="mdc-dialog__actions">+ ${this.dialogActions ? this.dialogActions.map((action) => {+ return html`<div class="mdc-button mdc-dialog__button" ?data-mdc-dialog-button-default="${action.default}" data-mdc-dialog-action="${action.actionName}">${action.content}</div>`+ }) : ``}+ </footer>+ </div>+ </div>+ <div class="mdc-dialog__scrim"></div>+ </div>+ `;+ }++ protected firstUpdated(_changedProperties: PropertyValues): void {+ super.firstUpdated(_changedProperties);+ if (this._mdcElem) {+ this._mdcComponent = new MDCDialog(this._mdcElem);+ }+ }++ protected _onDialogOpened() {+ this.dispatchEvent(new OrMwcDialogOpenedEvent());+ }++ protected _onDialogClosed(action?: string) {+ this.dispatchEvent(new OrMwcDialogClosedEvent(action));++ if (action && this.dialogActions) {+ const matchedAction = this.dialogActions.find((dialogAction) => dialogAction.actionName === action);+ if (matchedAction && matchedAction.action) {+ matchedAction.action();+ }+ }+ }+}diff --git a/ui/component/or-mwc-components/tsconfig.json b/ui/component/or-mwc-components/tsconfig.jsonindex acb1a2837..8e37015eb 100644--- a/ui/component/or-mwc-components/tsconfig.json+++ b/ui/component/or-mwc-components/tsconfig.json@@ -10,6 +10,7 @@],"references": [{ "path": "../core" },- { "path": "../or-select" }+ { "path": "../or-select" },+ { "path": "../or-translate" }]}\ No newline at end of file