Sha256: 3fdaeb179b5802dbe5ed5b579a0e58ebc7e9c00415f1df8e6d20fb7bc706d60b
Contents?: true
Size: 1.08 KB
Versions: 24
Compression:
Stored size: 1.08 KB
Contents
import { Controller } from '@hotwired/stimulus'; class AccumulatorController extends Controller { connect() { this.accumulate(); } accumulate() { let sum = 0; for (const i in this.sumTargets) { const target = this.sumTargets[i]; const value = Number(target.getAttribute(this.sumAttrValue)); if (!isNaN(value)) { sum += value; } } this.setAttributesTo(sum); } setAttributesTo(sum) { for (const i in this.syncAttrsValue) { const attr = this.syncAttrsValue[i]; this.accumulator.setAttribute(attr, sum.toString()); } } get accumulator() { var _a; return (_a = this.accumulatorTarget) !== null && _a !== void 0 ? _a : this.element; } } AccumulatorController.targets = ['sum', 'accumulator']; AccumulatorController.values = { syncAttrs: { type: Array, default: ['aria-valuenow'], }, sumAttr: { type: 'string', default: 'data-value', }, }; export default AccumulatorController;
Version data entries
24 entries across 24 versions & 1 rubygems