-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(angular/toast): add framework integration for custom toast message
- Loading branch information
1 parent
606f2e4
commit 7f31f9b
Showing
25 changed files
with
425 additions
and
16 deletions.
There are no files selected for viewing
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
37 changes: 37 additions & 0 deletions
37
packages/angular-test-app/src/preview-examples/toast-custom.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,37 @@ | ||
/* | ||
* COPYRIGHT (c) Siemens AG 2018-2022 ALL RIGHTS RESERVED. | ||
*/ | ||
import { Component, TemplateRef, ViewChild } from '@angular/core'; | ||
import { ToastService } from '@siemens/ix-angular'; | ||
|
||
@Component({ | ||
selector: 'app-toast', | ||
template: ` | ||
<div> | ||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy | ||
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam | ||
voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet | ||
clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit | ||
amet. | ||
</div> | ||
<ix-button (click)="showToastMessage()">Show Toast</ix-button> | ||
<ng-template #customToast let-toast> | ||
<div> | ||
<div>Custom toast message</div> | ||
<ix-button (click)="toast.close('Action')">Action</ix-button> | ||
</div> | ||
</ng-template> | ||
`, | ||
}) | ||
export class ToastCustom { | ||
@ViewChild('customToast', { read: TemplateRef }) | ||
customToastRef!: TemplateRef<any>; | ||
|
||
constructor(private readonly toastService: ToastService) {} | ||
|
||
async showToastMessage() { | ||
this.toastService.show({ | ||
message: this.customToastRef, | ||
}); | ||
} | ||
} |
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,31 @@ | ||
/* | ||
* COPYRIGHT (c) Siemens AG 2018-2022 ALL RIGHTS RESERVED. | ||
*/ | ||
import { Component, TemplateRef, ViewChild } from '@angular/core'; | ||
import { ToastService } from '@siemens/ix-angular'; | ||
|
||
@Component({ | ||
selector: 'app-toast', | ||
template: ` | ||
<div> | ||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy | ||
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam | ||
voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet | ||
clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit | ||
amet. | ||
</div> | ||
<ix-button (click)="showToastMessage()">Show Toast</ix-button> | ||
`, | ||
}) | ||
export class Toast { | ||
@ViewChild('customToast', { read: TemplateRef }) | ||
customModalRef!: TemplateRef<any>; | ||
|
||
constructor(private readonly toastService: ToastService) {} | ||
|
||
async showToastMessage() { | ||
this.toastService.show({ | ||
message: 'Hello World!', | ||
}); | ||
} | ||
} |
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
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,4 @@ | ||
/* | ||
* COPYRIGHT (c) Siemens AG 2018-2022 ALL RIGHTS RESERVED. | ||
*/ | ||
export * from './toast.service'; |
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,9 @@ | ||
/* | ||
* COPYRIGHT (c) Siemens AG 2018-2022 ALL RIGHTS RESERVED. | ||
*/ | ||
import { TemplateRef } from '@angular/core'; | ||
import { ToastConfig as IxToastConfig } from '@siemens/ix'; | ||
|
||
export type ToastConfig = Omit<IxToastConfig, 'message'> & { | ||
message: string | TemplateRef<any>; | ||
}; |
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,45 @@ | ||
/* | ||
* COPYRIGHT (c) Siemens AG 2018-2022 ALL RIGHTS RESERVED. | ||
*/ | ||
import { Injectable } from '@angular/core'; | ||
import { toast, ToastConfig as IxToastConfig } from '@siemens/ix'; | ||
import { ToastConfig } from './toast.config'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class ToastService { | ||
public async show(config: ToastConfig) { | ||
if (typeof config.message === 'string') { | ||
return toast(config as IxToastConfig); | ||
} | ||
|
||
const context: { | ||
close: (() => void) | null; | ||
} = { | ||
close: null, | ||
}; | ||
|
||
const embeddedView = config.message.createEmbeddedView({ | ||
$implicit: context, | ||
}); | ||
|
||
const node: HTMLElement = embeddedView.rootNodes[0]; | ||
const instance = await toast({ | ||
...config, | ||
message: node, | ||
}); | ||
|
||
context.close = () => { | ||
instance.close(); | ||
}; | ||
|
||
embeddedView.detectChanges(); | ||
|
||
instance.onClose.once(() => { | ||
embeddedView.destroy(); | ||
}); | ||
|
||
return instance; | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
packages/documentation/docs/auto-generated/previews/angular/toast-custom.md
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,40 @@ | ||
<!-- Auto generated! Please edit here: siemens-ix/packages/angular-test-app/src/preview-examples/toast-custom.ts --> | ||
```typescript | ||
/* | ||
* COPYRIGHT (c) Siemens AG 2018-2022 ALL RIGHTS RESERVED. | ||
*/ | ||
import { Component, TemplateRef, ViewChild } from '@angular/core'; | ||
import { ToastService } from '@siemens/ix-angular'; | ||
|
||
@Component({ | ||
selector: 'app-toast', | ||
template: ` | ||
<div> | ||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy | ||
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam | ||
voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet | ||
clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit | ||
amet. | ||
</div> | ||
<ix-button (click)="showToastMessage()">Show Toast</ix-button> | ||
<ng-template #customToast let-toast> | ||
<div> | ||
<div>Custom toast message</div> | ||
<ix-button (click)="toast.close('Action')">Action</ix-button> | ||
</div> | ||
</ng-template> | ||
`, | ||
}) | ||
export class ToastCustom { | ||
@ViewChild('customToast', { read: TemplateRef }) | ||
customToastRef!: TemplateRef<any>; | ||
|
||
constructor(private readonly toastService: ToastService) {} | ||
|
||
async showToastMessage() { | ||
this.toastService.show({ | ||
message: this.customToastRef, | ||
}); | ||
} | ||
} | ||
``` |
34 changes: 34 additions & 0 deletions
34
packages/documentation/docs/auto-generated/previews/angular/toast.md
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,34 @@ | ||
<!-- Auto generated! Please edit here: siemens-ix/packages/angular-test-app/src/preview-examples/toast.ts --> | ||
```typescript | ||
/* | ||
* COPYRIGHT (c) Siemens AG 2018-2022 ALL RIGHTS RESERVED. | ||
*/ | ||
import { Component, TemplateRef, ViewChild } from '@angular/core'; | ||
import { ToastService } from '@siemens/ix-angular'; | ||
|
||
@Component({ | ||
selector: 'app-toast', | ||
template: ` | ||
<div> | ||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy | ||
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam | ||
voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet | ||
clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit | ||
amet. | ||
</div> | ||
<ix-button (click)="showToastMessage()">Show Toast</ix-button> | ||
`, | ||
}) | ||
export class Toast { | ||
@ViewChild('customToast', { read: TemplateRef }) | ||
customModalRef!: TemplateRef<any>; | ||
|
||
constructor(private readonly toastService: ToastService) {} | ||
|
||
async showToastMessage() { | ||
this.toastService.show({ | ||
message: 'Hello World!', | ||
}); | ||
} | ||
} | ||
``` |
Oops, something went wrong.