Skip to content

Commit

Permalink
Remove deprecated toast danger MessageType (#2181)
Browse files Browse the repository at this point in the history
* πŸ”₯ Remove danger-specific messageType tests

* πŸ”₯ Remover danger messageType from Toast

* πŸ”₯ Remove use of danger type for toast in cookbook
  • Loading branch information
RasmusKjeldgaard authored Apr 22, 2022
1 parent 73df668 commit 16e2b6d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ this.modalController.showAlert(config);`;
private onAlertDestructiveClosed(result?: boolean) {
const config: ToastConfig = {
message: result ? 'Message deleted' : 'Nothing happened',
messageType: result ? 'danger' : 'success',
messageType: result ? 'warning' : 'success',
durationInMs: 1500,
};
this.toastController.showToast(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class ListSwipeExampleComponent {
item.deleted = !item.deleted;
const config: ToastConfig = {
message: `Item '${item.title}' has been deleted.`,
messageType: 'danger',
messageType: 'warning',
durationInMs: 1500,
};
this.toastController.showToast(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,4 @@ export interface ToastConfig {
animated?: boolean;
}

/**
* 'danger' is deprecated. Use Kirby Alert for critical events
*/
export type MessageType = 'success' | 'warning' | 'danger';
export type MessageType = 'success' | 'warning';
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,12 @@ describe('ToastHelper', () => {
});

describe('when configured with messageType', () => {
type MessageType = 'success' | 'warning' | 'danger';
type NotificationColor = 'success' | 'warning' | 'danger';
type MessageType = 'success' | 'warning';
type NotificationColor = 'success' | 'warning';

const messageTypeColorMap = new Map<MessageType, NotificationColor>([
['success', 'success'],
['warning', 'warning'],
['danger', 'danger'],
]);

messageTypeColorMap.forEach((notificationColor, messageType) => {
Expand All @@ -79,26 +78,12 @@ describe('ToastHelper', () => {
const ionToast = window.document.getElementsByTagName('ion-toast')[0];
await TestHelper.whenReady(ionToast);
const toastWrapper = ionToast.shadowRoot.querySelector('.toast-wrapper');
const expectedColor =
messageType === 'danger' ? getColor('warning') : getColor(notificationColor);

expect(toastWrapper).toHaveComputedStyle({
'background-color': expectedColor,
'background-color': getColor(notificationColor),
});
});
});

it(`should display warning in console when using 'danger' MessageType`, async () => {
spyOn(console, 'warn');

overlay = await spectator.service.showToast({
message: 'Test message',
messageType: 'danger',
});

expect(console.warn).toHaveBeenCalledWith(
`[DEPRECATED] 'danger' message type is deprecated. Use Kirby Alerts for critical warnings. Toast will be shown as 'warning'`
);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ export class ToastHelper {
private getCssClass(messageType: MessageType): string {
let cssClass = ToastHelper.CSS_CLASS;

if (messageType === 'danger') {
console.warn(
`[DEPRECATED] 'danger' message type is deprecated. Use Kirby Alerts for critical warnings. Toast will be shown as 'warning'`
);

messageType = 'warning';
}

if (messageType) {
cssClass += ' ' + messageType;
}
Expand Down

0 comments on commit 16e2b6d

Please sign in to comment.