Counter

counter — quantity input with +/- buttons

Numeric input with increment/decrement buttons, min/max/step bounds, an optional unit label. Emits a counter:change custom event on every value change so other code (cart, calculator, filter) can react.

Most common use: product quantity in a cart. Also fits range filters ("od ... do ..."), age inputs, dosage calculators.

Install

npx czg-ui add counter

@import 'components/counter'; to app.scss, import './components/counter'; to app.js.

Requires base.

Parameters

ParamTypeDefaultNotes
namestring'qty'name attribute on <input>
valueint1Initial value
minint1Lower bound
maxint\nullUpper bound (no limit if null)
stepint1Increment per click
unitstring\nullSuffix label (e.g. 'ks', 'kg')
idstring\nullid attribute on <input>
disabledboolfalseDisable both buttons + input
classstring\nullExtra wrapper class

Usage

{include /app/components/Form/counter.latte,
    value => 1, min => 1, max => 99, unit => 'ks'}

{include /app/components/Form/counter.latte,
    value => 0, min => 0, step => 5, unit => 'kg'}

JS event

document.addEventListener('counter:change', (e) => {
    console.log(e.detail.value, e.detail.previousValue);
    // e.target = the .counter root element
});

The component clamps to min / max automatically and disables the - button at min, + button at max.

When NOT to use

  • Free-form numeric input (price, weight in grams) — plain `<input

type="number">` with min/max validation

  • Boolean toggle — use a checkbox or a switch

Live preview

ui.czechgroup.cz/component/counter

Další kategorie