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

76 lines
1.8 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 toggle an option.
*
* @property {Boolean} tripleState Switch between three states when clicked
* @property {Boolean} indeterminate Sets the element into indeterminate state
* @property {String} info Shows a text information tooltip to the user
*/
export default class Check extends Toggle {
set field(value) {
2019-10-09 22:47:29 +00:00
super.field = value;
this.element.classList.toggle('checked', Boolean(value));
this.indeterminate = Boolean(value == null && this.tripleState);
}
get field() {
2019-10-09 22:47:29 +00:00
return super.field;
}
set checked(value) {
this.field = Boolean(value);
}
get checked() {
return Boolean(this.field);
}
set indeterminate(value) {
this._indeterminate = value;
this.element.classList.toggle('indeterminate', Boolean(value));
}
get indeterminate() {
return this._indeterminate;
}
set tripleState(value) {
this._tripleState = value;
this.field = this.field;
}
get tripleState() {
return this._tripleState;
2019-02-15 07:49:44 +00:00
}
onClick(event) {
if (super.onClick(event)) return;
if (this.tripleState) {
if (this.field == null)
this.field = true;
else if (this.field)
this.field = false;
else
this.field = null;
} else
this.field = !this.field;
this.changed();
}
2018-02-10 15:18:01 +00:00
}
2019-02-15 12:31:14 +00:00
ngModule.vnComponent('vnCheck', {
template: require('./index.html'),
controller: Check,
bindings: {
tripleState: '<?',
indeterminate: '<?',
info: '@?'
}
});