Ghost/ghost/admin/app/components/gh-notification.js
Kevin Ansfield f07940f0e7 Collapsed @service injection definitions to single-line style
no issue

- find+replace to make service injection style consistent and take up much less space at the top of files that used multi-line syntax
2022-02-01 17:03:54 +00:00

57 lines
1.5 KiB
JavaScript

import Component from '@ember/component';
import classic from 'ember-classic-decorator';
import {action, computed} from '@ember/object';
import {classNameBindings, classNames, tagName} from '@ember-decorators/component';
import {run} from '@ember/runloop';
import {inject as service} from '@ember/service';
@classic
@tagName('article')
@classNames('gh-notification', 'gh-notification-passive')
@classNameBindings('typeClass')
export default class GhNotification extends Component {
@service notifications;
message = null;
@computed('message.type')
get typeClass() {
let type = this.get('message.type');
let classes = '';
let typeMapping;
typeMapping = {
error: 'red',
warn: 'yellow'
};
if (typeMapping[type] !== undefined) {
classes += `gh-notification-${typeMapping[type]}`;
}
return classes;
}
didInsertElement() {
super.didInsertElement(...arguments);
this._animationEndHandler = run.bind(this, function () {
if (event.animationName === 'fade-out') {
this.notifications.closeNotification(this.message);
}
});
this.element.addEventListener('animationend', this._animationEndHandler);
}
willDestroyElement() {
super.willDestroyElement(...arguments);
this.element.removeEventListener('animationend', this._animationEndHandler);
}
@action
closeNotification() {
this.notifications.closeNotification(this.message);
}
}