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

52 lines
1.0 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) {
2019-10-09 22:47:29 +00:00
super.field = value;
this.element.classList.toggle('checked',
Boolean(value) && value == this.val);
}
get field() {
2019-10-09 22:47:29 +00:00
return super.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;
2019-10-28 20:40:24 +00:00
this.change(this.val);
}
2018-02-10 15:18:01 +00:00
}
2019-02-15 12:31:14 +00:00
ngModule.vnComponent('vnRadio', {
template: require('../toggle/index.html'),
controller: Radio,
bindings: {
val: '@?'
}
});