salix/front/core/components/icon/icon.js

35 lines
758 B
JavaScript

import ngModule from '../../module';
import './style.scss';
class Icon {
constructor($attrs) {
this.$attrs = $attrs;
this._icon = null;
}
set icon(value) {
this._icon = value;
this.drawIcon();
}
get icon() {
return this._icon;
}
drawIcon() {
if (this.icon.startsWith('icon-')) {
this.iconClass = this.icon;
this.iconContent = '';
} else {
this.iconClass = 'material-icons';
this.iconContent = this.icon;
}
}
}
Icon.$inject = ['$attrs'];
ngModule.component('vnIcon', {
template: '<i class="{{::$ctrl.iconClass}}">{{::$ctrl.iconContent}}</i>',
controller: Icon,
bindings: {
icon: '@'
}
});