-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new
@ng-web-apis/notification
package (Notification API)
- Loading branch information
1 parent
c6f19db
commit b90a2b5
Showing
35 changed files
with
983 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ jobs: | |
storage, | ||
workers, | ||
view-transition, | ||
notification, | ||
] | ||
name: ${{ matrix.project }} | ||
steps: | ||
|
@@ -134,6 +135,11 @@ jobs: | |
directory: ./coverage/view-transition/ | ||
flags: summary,view-transition | ||
name: view-transition | ||
- uses: codecov/[email protected] | ||
with: | ||
directory: ./coverage/notification/ | ||
flags: summary,notification | ||
name: notification | ||
|
||
concurrency: | ||
group: test-${{ github.workflow }}-${{ github.ref }} | ||
|
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 |
---|---|---|
|
@@ -44,3 +44,4 @@ testem.log | |
Thumbs.db | ||
|
||
apps/demo/routesFile.txt | ||
.ssl |
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
17 changes: 17 additions & 0 deletions
17
apps/demo/src/app/pages/notification/examples/01-getting-permission/index.html
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,17 @@ | ||
<ng-container [ngSwitch]="notificationPermissionState$ | async"> | ||
<tui-badge | ||
*ngSwitchCase="'granted'" | ||
status="success" | ||
value="Permission is granted" | ||
></tui-badge> | ||
|
||
<tui-badge | ||
*ngSwitchCase="'denied'" | ||
status="error" | ||
value="Permission is denied" | ||
></tui-badge> | ||
|
||
<button *ngSwitchDefault tuiButton (click)="requestPermission()"> | ||
Request permission | ||
</button> | ||
</ng-container> |
31 changes: 31 additions & 0 deletions
31
apps/demo/src/app/pages/notification/examples/01-getting-permission/index.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,31 @@ | ||
import {ChangeDetectionStrategy, Component} from '@angular/core'; | ||
import {NotificationService} from '@ng-web-apis/notification'; | ||
import {PermissionsService} from '@ng-web-apis/permissions'; | ||
|
||
@Component({ | ||
selector: 'notification-page-example-1', | ||
templateUrl: './index.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class NotificationPageExample1 { | ||
readonly notificationPermissionState$ = | ||
this.permissionsService.state('notifications'); | ||
|
||
constructor( | ||
private readonly notificationService: NotificationService, | ||
private readonly permissionsService: PermissionsService, | ||
) {} | ||
|
||
requestPermission(): void { | ||
this.notificationService.requestPermission().subscribe({ | ||
next: permission => | ||
console.info( | ||
'Permission status:', | ||
permission, // 'denied' | 'granted' | ||
), | ||
error: err => | ||
// e.g. 'Notification API is not supported in your browser' | ||
console.error(err), | ||
}); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
apps/demo/src/app/pages/notification/examples/02-create-notification/index.html
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 @@ | ||
<button tuiButton (click)="sendNotification()">Send notification</button> |
27 changes: 27 additions & 0 deletions
27
apps/demo/src/app/pages/notification/examples/02-create-notification/index.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,27 @@ | ||
import {ChangeDetectionStrategy, Component} from '@angular/core'; | ||
import {NotificationService} from '@ng-web-apis/notification'; | ||
import {filter, switchMap} from 'rxjs/operators'; | ||
|
||
@Component({ | ||
selector: 'notification-page-example-2', | ||
templateUrl: './index.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class NotificationPageExample2 { | ||
constructor(private readonly notificationService: NotificationService) {} | ||
|
||
sendNotification(): void { | ||
this.notificationService | ||
.requestPermission() | ||
.pipe( | ||
filter(permission => permission === 'granted'), | ||
switchMap(() => | ||
this.notificationService.open('Web APIs for Angular', { | ||
body: 'High quality lightweight wrappers for native Web APIs for idiomatic use with Angular', | ||
icon: 'assets/images/web-api.svg', | ||
}), | ||
), | ||
) | ||
.subscribe(); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
apps/demo/src/app/pages/notification/examples/03-close-notification/index.html
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 @@ | ||
<button tuiButton (click)="sendNotification()">Send notification</button> |
30 changes: 30 additions & 0 deletions
30
apps/demo/src/app/pages/notification/examples/03-close-notification/index.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,30 @@ | ||
import {ChangeDetectionStrategy, Component} from '@angular/core'; | ||
import {NotificationService} from '@ng-web-apis/notification'; | ||
import {timer} from 'rxjs'; | ||
import {filter, switchMap, takeUntil} from 'rxjs/operators'; | ||
|
||
@Component({ | ||
selector: 'notification-page-example-3', | ||
templateUrl: './index.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class NotificationPageExample3 { | ||
constructor(private readonly notificationService: NotificationService) {} | ||
|
||
sendNotification(): void { | ||
this.notificationService | ||
.requestPermission() | ||
.pipe( | ||
filter(permission => permission === 'granted'), | ||
switchMap(() => | ||
this.notificationService.open('Close me, please!', { | ||
requireInteraction: true, | ||
}), | ||
), | ||
takeUntil(timer(5_000)), // close stream after 5 seconds | ||
) | ||
.subscribe({ | ||
complete: () => console.info('Notification closed!'), | ||
}); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
apps/demo/src/app/pages/notification/examples/04-listen-notification-events/index.html
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 @@ | ||
<button tuiButton (click)="sendNotification()">Send notification</button> |
30 changes: 30 additions & 0 deletions
30
apps/demo/src/app/pages/notification/examples/04-listen-notification-events/index.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,30 @@ | ||
import {ChangeDetectionStrategy, Component} from '@angular/core'; | ||
import {NotificationService} from '@ng-web-apis/notification'; | ||
import {fromEvent} from 'rxjs'; | ||
import {filter, switchMap} from 'rxjs/operators'; | ||
|
||
@Component({ | ||
selector: 'notification-page-example-4', | ||
templateUrl: './index.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class NotificationPageExample4 { | ||
constructor(private readonly notificationService: NotificationService) {} | ||
|
||
sendNotification(): void { | ||
this.notificationService | ||
.requestPermission() | ||
.pipe( | ||
filter(permission => permission === 'granted'), | ||
switchMap(() => | ||
this.notificationService.open(`Click me, please`, { | ||
body: `Then open console and investigate property "target"`, | ||
requireInteraction: true, | ||
data: `Randomly generate number: ${Math.random().toFixed(2)}`, | ||
}), | ||
), | ||
switchMap(notification => fromEvent(notification, 'click')), | ||
) | ||
.subscribe(console.info); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
apps/demo/src/app/pages/notification/notification-page.component.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,30 @@ | ||
import {ChangeDetectionStrategy, Component} from '@angular/core'; | ||
import {TuiDocExample} from '@taiga-ui/addon-doc'; | ||
|
||
@Component({ | ||
selector: 'notification-page', | ||
templateUrl: './notification-page.template.html', | ||
styleUrls: ['./notification-page.style.less'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class NotificationPageComponent { | ||
readonly gettingPermissionExample: TuiDocExample = { | ||
'index.ts': import('./examples/01-getting-permission/index.ts?raw'), | ||
'index.html': import('./examples/01-getting-permission/index.html?raw'), | ||
}; | ||
|
||
readonly createNotificationExample: TuiDocExample = { | ||
'index.ts': import('./examples/02-create-notification/index.ts?raw'), | ||
'index.html': import('./examples/02-create-notification/index.html?raw'), | ||
}; | ||
|
||
readonly closeNotificationExample: TuiDocExample = { | ||
'index.ts': import('./examples/03-close-notification/index.ts?raw'), | ||
'index.html': import('./examples/03-close-notification/index.html?raw'), | ||
}; | ||
|
||
readonly listenNotificationEventsExample: TuiDocExample = { | ||
'index.ts': import('./examples/04-listen-notification-events/index.ts?raw'), | ||
'index.html': import('./examples/04-listen-notification-events/index.html?raw'), | ||
}; | ||
} |
30 changes: 30 additions & 0 deletions
30
apps/demo/src/app/pages/notification/notification-page.module.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,30 @@ | ||
import {CommonModule} from '@angular/common'; | ||
import {NgModule} from '@angular/core'; | ||
import {RouterModule} from '@angular/router'; | ||
import {TuiAddonDocModule} from '@taiga-ui/addon-doc'; | ||
import {TuiButtonModule, TuiNotificationModule} from '@taiga-ui/core'; | ||
import {TuiBadgeModule} from '@taiga-ui/kit'; | ||
import {NotificationPageExample1} from './examples/01-getting-permission'; | ||
import {NotificationPageExample2} from './examples/02-create-notification'; | ||
import {NotificationPageExample3} from './examples/03-close-notification'; | ||
import {NotificationPageExample4} from './examples/04-listen-notification-events'; | ||
import {NotificationPageComponent} from './notification-page.component'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
TuiAddonDocModule, | ||
TuiBadgeModule, | ||
TuiButtonModule, | ||
TuiNotificationModule, | ||
RouterModule.forChild([{path: '', component: NotificationPageComponent}]), | ||
], | ||
declarations: [ | ||
NotificationPageComponent, | ||
NotificationPageExample1, | ||
NotificationPageExample2, | ||
NotificationPageExample3, | ||
NotificationPageExample4, | ||
], | ||
}) | ||
export class NotificationPageModule {} |
21 changes: 21 additions & 0 deletions
21
apps/demo/src/app/pages/notification/notification-page.style.less
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,21 @@ | ||
:host { | ||
display: block; | ||
max-width: 900px; | ||
margin: 0 auto; | ||
font: var(--tui-font-text-m); | ||
} | ||
|
||
tui-notification { | ||
margin-bottom: 1rem; | ||
} | ||
|
||
.header { | ||
font: var(--tui-font-heading-4); | ||
display: flex; | ||
align-items: center; | ||
gap: 1rem; | ||
} | ||
|
||
.description { | ||
margin-bottom: 2rem; | ||
} |
Oops, something went wrong.