|
| 1 | +import Component from '@ember/component'; |
| 2 | +import { |
| 3 | + computed |
| 4 | +} from '@ember/object'; |
| 5 | +import layout from '../templates/components/s-alert'; |
| 6 | +import { later } from '@ember/runloop'; |
| 7 | + |
| 8 | +export default Component.extend({ |
| 9 | + layout, |
| 10 | + classNames: ['alert', 's-alert'], |
| 11 | + classNameBindings: ['alertClass', 'disappearing'], |
| 12 | + isHidden: false, |
| 13 | + disappearing: computed('isHidden', function() { |
| 14 | + return this.get('isHidden') ? 'disappearing' : ''; |
| 15 | + }), |
| 16 | + alertClasses: computed(function () { |
| 17 | + return { |
| 18 | + info: 'alert-primary', |
| 19 | + warning: 'alert-warning', |
| 20 | + success: 'alert-success' |
| 21 | + }; |
| 22 | + }), |
| 23 | + alertIcons: computed(function () { |
| 24 | + return { |
| 25 | + info: 'info', |
| 26 | + warning: 'alert-triangle', |
| 27 | + success: 'check-circle' |
| 28 | + }; |
| 29 | + }), |
| 30 | + |
| 31 | + alertClass: computed('type', function () { |
| 32 | + return this.get('alertClasses')[this.get('type')]; |
| 33 | + }), |
| 34 | + alertIcon: computed('type', function () { |
| 35 | + return this.get('alertIcons')[this.get('type')]; |
| 36 | + }), |
| 37 | + actions: { |
| 38 | + dismissAlert() { |
| 39 | + this.set('isHidden', true); |
| 40 | + later(this, function () { |
| 41 | + this.set('isVisible', false); |
| 42 | + }, 500); |
| 43 | + } |
| 44 | + } |
| 45 | +}); |
0 commit comments