setting up front 1

This commit is contained in:
elvira
2026-07-31 17:41:55 +03:00
parent b88fde739c
commit bf8b9219fc
48 changed files with 2250 additions and 11 deletions
@@ -0,0 +1,39 @@
import { Controller } from '@hotwired/stimulus'
export default class extends Controller {
static targets = ['input', 'decrement']
static values = { min: { type: Number, default: 1 } }
connect() {
this.#updateDecrement()
}
increment() {
this.#setValue(this.#current + 1)
}
decrement() {
this.#setValue(this.#current - 1)
}
clamp() {
this.#setValue(this.#current)
}
get #current() {
return parseInt(this.inputTarget.value, 10) || this.minValue
}
#setValue(val) {
const clamped = Math.max(this.minValue, val)
this.inputTarget.value = clamped
this.#updateDecrement()
this.inputTarget.dispatchEvent(new Event('quantity:change', { bubbles: true }))
}
#updateDecrement() {
const atMin = this.#current <= this.minValue
this.decrementTarget.disabled = atMin
this.decrementTarget.setAttribute('aria-disabled', atMin)
}
}