-
Notifications
You must be signed in to change notification settings - Fork 65
Toastr service and component #1614
Changes from 32 commits
3f4222e
a450054
4b809aa
d55f351
833bcc7
b553659
ab82ba3
db21c76
a282a86
995f024
f4c10f0
c8994ae
d210c2b
11ab289
a49ebf3
28c09b6
3b5d5cb
35de170
ce8ba62
bc37187
82c286d
52f7983
692cbf0
803a205
ed4558f
35e789d
8c8f6c2
a4f23b3
7d3458f
03c63ae
a37b829
99696ac
874ef58
636c5dd
0158250
f57ffc0
e548824
c6c847b
bdc97a6
ff5093c
83e7d04
6104aaf
01c38d6
2fa1e41
57bfe9c
6e766de
d576545
15103e0
37f50ec
ac1e7bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<toast-visual></toast-visual> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<b class="sky-custom-toast">Toast component</b> | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Component } from '@angular/core'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs barrel import format. |
||
import { SkyToastService, SkyToastCustomComponent, SkyToastMessage } from '@blackbaud/skyux/dist/core'; | ||
|
||
@Component({ | ||
selector: 'sky-test-cmp-toast', | ||
templateUrl: './toast-demo.component.html', | ||
providers: [SkyToastService] | ||
}) | ||
export class ToastDemoComponent implements SkyToastCustomComponent { | ||
public message: SkyToastMessage; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div id="screenshot-toast" style="height: 500px;"> | ||
<button | ||
type="button" | ||
class="sky-btn sky-btn-primary" | ||
(click)="openToast()"> | ||
Open toast | ||
</button> | ||
<button | ||
type="button" | ||
class="sky-btn sky-btn-secondary" | ||
(click)="openTemplatedToast()"> | ||
Open custom toast | ||
</button> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Component } from '@angular/core'; | ||
import { SkyToastService } from '@blackbaud/skyux/dist/core'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs barrel import format. |
||
|
||
import { ToastDemoComponent } from './toast-demo.component'; | ||
|
||
@Component({ | ||
selector: 'toast-visual', | ||
templateUrl: './toast-visual.component.html' | ||
}) | ||
export class ToastVisualComponent { | ||
constructor( | ||
private toastService: SkyToastService | ||
) { } | ||
|
||
public openToast() { | ||
this.toastService.openMessage('Toast message'); | ||
} | ||
|
||
public openTemplatedToast() { | ||
this.toastService.openTemplatedMessage(ToastDemoComponent, {}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { SkyVisualTest } from '../../../config/utils/visual-test-commands'; | ||
import { element, by } from 'protractor'; | ||
|
||
describe('Toast', () => { | ||
it('should match previous toast screenshot', () => { | ||
return SkyVisualTest.setupTest('toast') | ||
.then(() => { | ||
element(by.css('.sky-btn-primary')).click(); | ||
SkyVisualTest.moveCursorOffScreen(); | ||
return SkyVisualTest.compareScreenshot({ | ||
screenshotName: 'toast', | ||
selector: 'body' | ||
}).then(() => { | ||
expect(by.css('.sky-toast')).toBeTruthy(); | ||
element(by.css('.sky-toast')).click(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should match previous templated toast screenshot', () => { | ||
return SkyVisualTest.setupTest('toast') | ||
.then(() => { | ||
element(by.css('.sky-btn-secondary')).click(); | ||
SkyVisualTest.moveCursorOffScreen(); | ||
return SkyVisualTest.compareScreenshot({ | ||
screenshotName: 'toast', | ||
selector: 'body' | ||
}).then(() => { | ||
expect(by.css('.sky-custom-toast')).toBeTruthy(); | ||
element(by.css('.sky-toast')).click(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should match previous toast screenshot on tiny screens', () => { | ||
return SkyVisualTest.setupTest('toast', 480) | ||
.then(() => { | ||
element(by.css('.sky-btn-primary')).click(); | ||
SkyVisualTest.moveCursorOffScreen(); | ||
return SkyVisualTest.compareScreenshot({ | ||
screenshotName: 'toast', | ||
selector: 'body' | ||
}).then(() => { | ||
expect(by.css('.sky-toast')).toBeTruthy(); | ||
element(by.css('.sky-toast')).click(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should match previous templated toast screenshot on tiny screens', () => { | ||
return SkyVisualTest.setupTest('toast', 480) | ||
.then(() => { | ||
element(by.css('.sky-btn-secondary')).click(); | ||
SkyVisualTest.moveCursorOffScreen(); | ||
return SkyVisualTest.compareScreenshot({ | ||
screenshotName: 'toast', | ||
selector: 'body' | ||
}).then(() => { | ||
expect(by.css('.sky-custom-toast')).toBeTruthy(); | ||
element(by.css('.sky-toast')).click(); | ||
}); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ import { | |
SkyTextHighlightDemoComponent, | ||
SkyTileDemoComponent, | ||
SkyTimepickerDemoComponent, | ||
SkyToastDemoComponent, | ||
SkyTokensDemoComponent, | ||
SkyToolbarDemoComponent, | ||
SkyUrlValidationDemoComponent, | ||
|
@@ -996,6 +997,22 @@ export class SkyDemoService { | |
} | ||
] | ||
}, | ||
{ | ||
name: 'Toast', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you missing the "custom" toast component here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
component: SkyToastDemoComponent, | ||
files: [ | ||
{ | ||
name: 'toast-demo.component.html', | ||
fileContents: require('!!raw-loader!./toast/toast-demo.component.html') | ||
}, | ||
{ | ||
name: 'toast-demo.component.ts', | ||
fileContents: require('!!raw-loader!./toast/toast-demo.component.ts'), | ||
componentName: 'SkyToastDemoComponent', | ||
bootstrapSelector: 'sky-toast-demo' | ||
} | ||
] | ||
}, | ||
{ | ||
name: 'Tokens', | ||
component: SkyTokensDemoComponent, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './toast-demo.component'; | ||
export * from './toast-custom-demo.component'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { SkyToastCustomComponent, SkyToastMessage } from '../../core'; | ||
|
||
@Component({ | ||
selector: 'sky-toast-custom-demo', | ||
template: "<p>{{text}}<a *ngIf='!(message.isClosing | async)' href='http://example.com'>example.com</a></p>" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separate file for your template, please. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
export class SkyToastCustomDemoComponent implements OnInit, SkyToastCustomComponent { | ||
public message: SkyToastMessage; | ||
public text: string = 'This is a templated message. It can even link you to '; | ||
|
||
constructor() {} | ||
|
||
public ngOnInit() { | ||
this.message.isClosing.subscribe((value: boolean) => { | ||
if (value) { | ||
this.text = 'Bye bye :D'; | ||
} | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<div> | ||
<table> | ||
<thead> | ||
<td>Toast type</td> | ||
<td></td> | ||
</thead> | ||
<tbody> | ||
<tr *ngFor="let type of types"> | ||
<td>{{ typeTranslator[type] }}</td> | ||
<td> | ||
<input type="radio" name="radiogroup" [checked]="type === selectedType" (change)="selectedType = type" /> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<button class="sky-btn sky-btn-primary" (click)="openMessage()">Open toast</button> | ||
<button class="sky-btn sky-btn-primary" (click)="openTemplatedMessage()">Open templated toast</button> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Component } from '@angular/core'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs barrel import format. |
||
import { | ||
SkyToastService, | ||
SkyToastType | ||
} from '../../core'; | ||
import { SkyToastCustomDemoComponent } from './toast-custom-demo.component'; | ||
|
||
@Component({ | ||
selector: 'sky-toast-demo', | ||
templateUrl: './toast-demo.component.html' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs |
||
}) | ||
export class SkyToastDemoComponent { | ||
public typeTranslator = SkyToastType; | ||
public types: SkyToastType[] = [SkyToastType.Info, SkyToastType.Success, SkyToastType.Warning, SkyToastType.Danger]; | ||
public selectedType: SkyToastType = SkyToastType.Info; | ||
|
||
constructor(private toastSvc: SkyToastService) { } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All constructor injections should be on a single line. #1647 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
public openMessage() { | ||
this.toastSvc.openMessage('This is a ' + SkyToastType[this.selectedType] + ' toast.', {toastType: this.selectedType}); | ||
} | ||
|
||
public openTemplatedMessage() { | ||
this.toastSvc.openTemplatedMessage(SkyToastCustomDemoComponent, {toastType: this.selectedType}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -819,6 +819,10 @@ | |
"_description": "The close button for the timepicker modal", | ||
"message": "Done" | ||
}, | ||
"toast_close": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's text for a button, I usually suffix the key with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. Sorry missed that after applying the inf scroll changes from before |
||
"_description": "Screen reader text for the close button on toasts", | ||
"message": "Close the toast" | ||
}, | ||
"token_dismiss_button_title": { | ||
"_description": "The default text for the token dismiss button title.", | ||
"message": "Remove item" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { SkyToastContainerComponent } from './toast-container.component'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use "blind" exports so that the file itself can determine what is publicly exported.
|
||
export { SkyToastService } from './services/toast.service'; | ||
export { SkyToastModule } from './toast.module'; | ||
export * from './types'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { | ||
Injectable, | ||
Renderer2, | ||
RendererFactory2 | ||
} from '@angular/core'; | ||
import { SkyWindowRefService } from '../../window'; | ||
|
||
@Injectable() | ||
export class SkyToastAdapterService { | ||
private renderer: Renderer2; | ||
|
||
constructor( | ||
private rendererFactory: RendererFactory2, | ||
private windowRef: SkyWindowRefService | ||
) { | ||
this.renderer = this.rendererFactory.createRenderer(undefined, undefined); | ||
} | ||
|
||
public appendToBody(element: any): void { | ||
const body = this.windowRef.getWindow().document.body; | ||
this.renderer.appendChild(body, element); | ||
} | ||
|
||
public removeHostElement(): void { | ||
const document = this.windowRef.getWindow().document; | ||
const hostElement = document.querySelector('sky-toast'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this selector be |
||
this.renderer.removeChild(document.body, hostElement); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer
strong
overb
. https://davidzych.com/why-use-strong-and-em-over-b-and-i/There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done