Repository URL to install this package:
|
Version:
2.3.13 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const tslib_1 = require("tslib");
const mobx_1 = require("xmobx/mobx");
const exotic_1 = require("exotic");
class IncrementerState {
constructor() {
this.shouldIncrement = true;
this.shouldDecrement = false;
}
incrementCount(props) {
const {
maxValue,
step
} = props;
if (this.count < maxValue) {
this.count += step;
this.shouldDecrement = true;
}
if (this.count === maxValue) {
this.shouldIncrement = false;
}
}
handleChange(props, event) {
const {
minValue,
maxValue
} = props;
let value = event.target.value;
value = value === '' ? '' : exotic_1.toNumber(value);
if (value === '' || value >= minValue && value <= maxValue) {
this.count = value;
}
if (value === 0) {
this.count = 1;
}
this.shouldDecrement = !(this.count <= minValue);
this.shouldIncrement = !(this.count >= maxValue);
}
handleBlur(props, event) {
let value = event.target.value;
if (value === '' || value <= props.minValue) {
value = props.minValue;
this.count = value;
} else if (value >= props.maxValue) {
value = props.maxValue;
this.count = value;
}
}
decrementCount(props) {
const {
minValue,
step
} = props;
if (this.count > minValue) {
this.count -= step;
this.shouldIncrement = true;
}
if (this.count === minValue) {
this.shouldDecrement = false;
}
}
}
tslib_1.__decorate([mobx_1.observable], IncrementerState.prototype, "count", void 0);
tslib_1.__decorate([mobx_1.observable], IncrementerState.prototype, "shouldIncrement", void 0);
tslib_1.__decorate([mobx_1.observable], IncrementerState.prototype, "shouldDecrement", void 0);
tslib_1.__decorate([mobx_1.action.bound], IncrementerState.prototype, "incrementCount", null);
tslib_1.__decorate([mobx_1.action.bound], IncrementerState.prototype, "handleChange", null);
tslib_1.__decorate([mobx_1.action.bound], IncrementerState.prototype, "handleBlur", null);
tslib_1.__decorate([mobx_1.action.bound], IncrementerState.prototype, "decrementCount", null);
exports.IncrementerState = IncrementerState; //# sourceMappingURL=state.js.map