ember-assembly
Version:
A collection of beautiful UI components built by Goods
70 lines (58 loc) • 1.69 kB
text/typescript
import Component from '@ember/component';
import { get, set, action } from '@ember/object';
import { notEmpty } from '@ember/object/computed';
// @ts-ignore: Ignore import of compiled template
import template from './template';
// @ts-ignore
import { timeout } from 'ember-concurrency';
import { task } from 'ember-concurrency-decorators';
import { computed } from '@ember/object';
import { htmlSafe } from '@ember/template';
export default class UiNotification extends Component {
layout = template;
tagName: string = '';
notification!: any;
onDismiss!: Function;
interval?: number = 20; //ms
progress: number = 0;
get intentClass(): string {
return `intent-${this.notification.intent}`;
}
hasDescription!: boolean;
get safeDescription() {
return htmlSafe(get(this.notification, 'description'));
}
progressTask = function* (
this: UiNotification,
notification: any,
intervalMs: number
) {
while (this.progress < 100) {
yield timeout(intervalMs);
let progressTotal =
(this.progress * notification.timeout) / 100 + intervalMs;
let progress = (progressTotal / notification.timeout) * 100;
set(this, 'progress', progress);
}
this.onDismiss();
};
cancelProgress() {
//@ts-ignore
this.progressTask.cancelAll();
}
resumeProgress() {
//@ts-ignore
this.progressTask.perform(this.notification, this.interval);
}
init() {
super.init();
//@ts-ignore
this.progressTask.perform(this.notification, this.interval);
}
}