salix/front/core/components/avatar/index.js

34 lines
698 B
JavaScript
Raw Normal View History

2023-05-03 09:57:13 +00:00
import ngModule from '../../module';
import Component from 'core/lib/component';
2023-05-19 11:51:20 +00:00
import {hashToColor} from '../../lib/string';
2023-05-03 09:57:13 +00:00
import './style.scss';
/**
* Displays colored avatar based on value.
*
* @property {*} val The value
*/
export default class Avatar extends Component {
get val() {
return this._val;
}
set val(value) {
this._val = value;
const val = value || '';
const el = this.element;
2023-05-19 11:51:20 +00:00
el.style.backgroundColor = hashToColor(val);
2023-05-03 09:57:13 +00:00
el.title = val;
}
}
ngModule.vnComponent('vnAvatar', {
template: require('./index.html'),
controller: Avatar,
bindings: {
val: '@?'
},
transclude: true
});