1 import {Component} from './component';
3 export class Notification extends Component {
6 this.container = this.$el;
7 this.type = this.$opts.type;
8 this.textElem = this.container.querySelector('span');
9 this.autoHide = this.$opts.autoHide === 'true';
10 this.initialShow = this.$opts.show === 'true';
11 this.container.style.display = 'grid';
13 window.$events.listen(this.type, text => {
16 this.container.addEventListener('click', this.hide.bind(this));
18 if (this.initialShow) {
19 setTimeout(() => this.show(this.textElem.textContent), 100);
22 this.hideCleanup = this.hideCleanup.bind(this);
25 show(textToShow = '') {
26 this.container.removeEventListener('transitionend', this.hideCleanup);
27 this.textElem.textContent = textToShow;
28 this.container.style.display = 'grid';
30 this.container.classList.add('showing');
34 const words = textToShow.split(' ').length;
35 const timeToShow = Math.max(2000, 1000 + (250 * words));
36 setTimeout(this.hide.bind(this), timeToShow);
41 this.container.classList.remove('showing');
42 this.container.addEventListener('transitionend', this.hideCleanup);
46 this.container.style.display = 'none';
47 this.container.removeEventListener('transitionend', this.hideCleanup);