2018-02-10 15:18:01 +00:00
|
|
|
import ngModule from '../../module';
|
2019-10-04 10:33:16 +00:00
|
|
|
import Toggle from '../toggle';
|
2018-02-12 12:16:49 +00:00
|
|
|
import './style.scss';
|
2018-02-10 15:18:01 +00:00
|
|
|
|
2019-10-01 09:15:15 +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
|
|
|
|
*/
|
2019-10-04 10:33:16 +00:00
|
|
|
export default class Check extends Toggle {
|
2019-09-30 18:46:22 +00:00
|
|
|
set field(value) {
|
2019-10-09 22:47:29 +00:00
|
|
|
super.field = value;
|
2019-10-01 09:15:15 +00:00
|
|
|
this.element.classList.toggle('checked', Boolean(value));
|
|
|
|
this.indeterminate = Boolean(value == null && this.tripleState);
|
2019-09-30 18:46:22 +00:00
|
|
|
}
|
2019-02-15 07:02:29 +00:00
|
|
|
|
2019-09-30 18:46:22 +00:00
|
|
|
get field() {
|
2019-10-09 22:47:29 +00:00
|
|
|
return super.field;
|
2019-09-30 18:46:22 +00:00
|
|
|
}
|
2019-02-14 19:17:22 +00:00
|
|
|
|
2019-10-04 10:33:16 +00:00
|
|
|
set checked(value) {
|
|
|
|
this.field = Boolean(value);
|
2019-02-14 19:17:22 +00:00
|
|
|
}
|
|
|
|
|
2019-10-04 10:33:16 +00:00
|
|
|
get checked() {
|
|
|
|
return Boolean(this.field);
|
2019-09-30 18:46:22 +00:00
|
|
|
}
|
2019-02-14 19:17:22 +00:00
|
|
|
|
2019-10-01 09:15:15 +00:00
|
|
|
set indeterminate(value) {
|
|
|
|
this._indeterminate = value;
|
|
|
|
this.element.classList.toggle('indeterminate', Boolean(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
get indeterminate() {
|
|
|
|
return this._indeterminate;
|
|
|
|
}
|
|
|
|
|
2019-09-30 18:46:22 +00:00
|
|
|
set tripleState(value) {
|
|
|
|
this._tripleState = value;
|
|
|
|
this.field = this.field;
|
2018-02-12 12:16:49 +00:00
|
|
|
}
|
2019-02-14 19:17:22 +00:00
|
|
|
|
2019-09-30 18:46:22 +00:00
|
|
|
get tripleState() {
|
|
|
|
return this._tripleState;
|
2019-02-15 07:49:44 +00:00
|
|
|
}
|
|
|
|
|
2019-09-30 18:46:22 +00:00
|
|
|
onClick(event) {
|
2019-10-04 10:33:16 +00:00
|
|
|
if (super.onClick(event)) return;
|
2019-09-30 18:46:22 +00:00
|
|
|
|
|
|
|
if (this.tripleState) {
|
|
|
|
if (this.field == null)
|
|
|
|
this.field = true;
|
2019-10-01 09:15:15 +00:00
|
|
|
else if (this.field)
|
|
|
|
this.field = false;
|
2019-09-30 18:46:22 +00:00
|
|
|
else
|
|
|
|
this.field = null;
|
|
|
|
} else
|
|
|
|
this.field = !this.field;
|
2019-02-18 08:14:39 +00:00
|
|
|
|
2019-10-04 10:33:16 +00:00
|
|
|
this.changed();
|
2018-02-12 12:16:49 +00:00
|
|
|
}
|
2018-02-10 15:18:01 +00:00
|
|
|
}
|
2019-02-15 12:31:14 +00:00
|
|
|
|
2019-10-08 21:57:02 +00:00
|
|
|
ngModule.vnComponent('vnCheck', {
|
2019-10-01 09:15:15 +00:00
|
|
|
template: require('./index.html'),
|
2019-10-04 10:33:16 +00:00
|
|
|
controller: Check,
|
2018-02-12 12:16:49 +00:00
|
|
|
bindings: {
|
2019-02-14 19:17:22 +00:00
|
|
|
tripleState: '<?',
|
2019-10-01 09:15:15 +00:00
|
|
|
indeterminate: '<?',
|
|
|
|
info: '@?'
|
2018-02-12 12:16:49 +00:00
|
|
|
}
|
|
|
|
});
|