Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/ui / dist / inputs / Incrementer / IncrementerState.js
Size: Mime:
"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.count = 1;
    this.shouldIncrement = true;
    this.shouldDecrement = false;
    this.step = 1;
    this.maxValue = 99;
    this.minValue = 0;
  } // === actions ===


  update(values) {
    Object.keys(values).forEach(key => {
      if (this[key] !== undefined) {
        this[key] = values[key];
      }
    });
  }

  incrementCount() {
    if (this.count < this.maxValue) {
      this.count += this.step;
      this.shouldDecrement = true;
    }

    if (this.count === this.maxValue) {
      this.shouldIncrement = false;
    }
  }

  decrementCount() {
    if (this.count > this.minValue) {
      this.count -= this.step;
      this.shouldIncrement = true;
    }

    if (this.count === this.minValue) {
      this.shouldDecrement = false;
    }
  } // === handlers ===


  handleChange(event) {
    event.preventDefault();
    const isValueEmpty = event.target.value === '';
    const value = exotic_1.toNumber(event.target.value);

    if (isValueEmpty || value >= this.minValue && value <= this.maxValue) {
      this.count = value;
    } else if (value === 0) {
      this.count = 1;
    }

    this.shouldDecrement = !(this.count <= this.minValue);
    this.shouldIncrement = !(this.count >= this.maxValue);
  }

  handleBlur(event) {
    event.preventDefault();
    const isValueEmpty = event.target.value === '';
    const value = exotic_1.toNumber(event.target.value);

    if (isValueEmpty || value <= this.minValue) {
      this.count = this.minValue;
    } else if (value >= this.maxValue) {
      this.count = this.maxValue;
    }
  }

}

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.observable], IncrementerState.prototype, "step", void 0);

tslib_1.__decorate([mobx_1.observable], IncrementerState.prototype, "maxValue", void 0);

tslib_1.__decorate([mobx_1.observable], IncrementerState.prototype, "minValue", void 0);

tslib_1.__decorate([mobx_1.action], IncrementerState.prototype, "update", null);

tslib_1.__decorate([mobx_1.action.bound], IncrementerState.prototype, "incrementCount", null);

tslib_1.__decorate([mobx_1.action.bound], IncrementerState.prototype, "decrementCount", null);

tslib_1.__decorate([mobx_1.action.bound], IncrementerState.prototype, "handleChange", null);

tslib_1.__decorate([mobx_1.action.bound], IncrementerState.prototype, "handleBlur", null);

exports.IncrementerState = IncrementerState; //# sourceMappingURL=IncrementerState.js.map