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

44 lines
1.0 KiB
JavaScript
Raw Normal View History

2019-10-18 19:36:30 +00:00
import ngModule from '../../module';
import FormInput from '../form-input';
import './style.scss';
export default class Button extends FormInput {
constructor($element, $scope) {
super($element, $scope);
this.design = 'colored';
2019-10-24 08:17:32 +00:00
this.initTabIndex();
2019-10-18 19:36:30 +00:00
this.element.addEventListener('keyup', e => this.onKeyup(e));
this.element.addEventListener('click', e => this.onClick(e));
}
$onInit() {
this.element.classList.add(this.design);
if (!this.type) this.type = 'button';
}
onKeyup(event) {
2019-10-24 08:17:32 +00:00
if (event.defaultPrevented) return;
switch (event.key) {
case ' ':
2019-10-24 08:17:32 +00:00
case 'Enter':
return this.element.click();
}
2019-10-18 19:36:30 +00:00
}
onClick(event) {
2019-10-24 08:17:32 +00:00
if (this.disabled)
event.stopImmediatePropagation();
2019-10-18 19:36:30 +00:00
}
}
Button.$inject = ['$element', '$scope'];
ngModule.vnComponent('vnButton', {
controller: Button,
template: require('./index.html'),
bindings: {
icon: '@?',
type: '@?'
}
});