Resettable Counter

Change the step size, increment, and reset to a fixed value.

Resettable Counter

Count: 42

PHP
<?php $count = state(42); $step = state(1); $increment = el('input', [ cls('form-control'), attrs(['type' => 'number', 'value' => read($step)]), on('input', set($step, num(ev('target.value')))), ]); $app = el('div', [cls('container')], [ el('h1', [cls('mt-5')], [ text('Resettable Counter') ]), el('h2', [], [ text(concat('Count: ', read($count))) ]), $increment, el('div', [cls('d-flex justify-content-around p-5')], [ el('button', [ cls('btn btn-primary'), on('click', add($count, read($step))) ], [ text('Inc by input') ]), el('button', [ cls('btn btn-danger'), on('click', set($count, 1000)) ], [ text('Reset to 1000') ]) ]), ]);