2024-03-29 00:50:46 +00:00
|
|
|
import { Controller } from "@hotwired/stimulus";
|
|
|
|
|
|
|
|
export default class extends Controller {
|
|
|
|
static targets = ["result"];
|
|
|
|
|
|
|
|
static values = {
|
2024-03-29 00:50:46 +00:00
|
|
|
canBeNegative: Boolean,
|
2024-03-29 00:50:46 +00:00
|
|
|
count: Number,
|
2024-03-29 00:50:46 +00:00
|
|
|
maximumCountNumber: Number,
|
2024-03-29 00:50:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
connect() {
|
|
|
|
console.log("count#connect");
|
|
|
|
|
|
|
|
this.resultTarget.textContent = this.countValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
countValueChanged() {
|
|
|
|
console.log("count#countValueChanged");
|
|
|
|
|
|
|
|
this.resultTarget.textContent = this.countValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
decrement() {
|
|
|
|
console.log("count#decrement");
|
|
|
|
|
2024-03-29 00:50:46 +00:00
|
|
|
if (this.canBeNegativeValue === false && this.countValue === 0) {
|
|
|
|
return;
|
2024-03-29 00:50:46 +00:00
|
|
|
}
|
2024-03-29 00:50:46 +00:00
|
|
|
|
|
|
|
this.countValue = this.countValue - 1;
|
2024-03-29 00:50:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
increment() {
|
|
|
|
console.log("count#increment");
|
|
|
|
|
2024-03-29 00:50:46 +00:00
|
|
|
const maximumCountNumber = this.maximumCountNumberValue || 10;
|
|
|
|
|
|
|
|
if (this.countValue === maximumCountNumber) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-29 00:50:46 +00:00
|
|
|
this.countValue = this.countValue + 1;
|
|
|
|
}
|
|
|
|
}
|