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

57 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-02-10 15:18:01 +00:00
import ngModule from '../../module';
import Toggle from '../toggle';
import './style.scss';
2018-02-10 15:18:01 +00:00
/**
* Basic element for user input. You can use this to supply a way for the user
* to pick an option from multiple choices.
*
* @property {String} val The actual value of the option
*/
export default class Radio extends Toggle {
set field(value) {
this._field = value;
this.element.classList.toggle('checked',
Boolean(value) && value == this.val);
}
get field() {
return this._field;
}
set checked(value) {
this.field = value ? this.val : null;
}
get checked() {
return this.field == this.val;
}
set val(value) {
this._val = value;
this.field = this.field;
}
get val() {
return this._val;
}
onClick(event) {
if (super.onClick(event)) return;
this.field = this.val;
this.changed();
}
2018-02-10 15:18:01 +00:00
}
2019-02-15 12:31:14 +00:00
ngModule.component('vnRadio', {
template: require('../toggle/index.html'),
controller: Radio,
bindings: {
label: '@?',
field: '=?',
disabled: '<?',
checked: '<?',
val: '@?'
}
});