quantity-stepper
A number with − and + buttons, between min and max. A form control. editable lets the number be typed as well (a stock count of 40 shouldn't take forty presses); what's typed is clamped to min..max when the field is left.
Try it: events appear here (valuechange).
Source: quantity-stepper.zb, and its registry item.
Install
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/quantity-stepper.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/quantity-stepper.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/quantity-stepper.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/quantity-stepper.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/quantity-stepper.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/quantity-stepper.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/quantity-stepper.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/quantity-stepper.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/quantity-stepper.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/quantity-stepper.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/quantity-stepper.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/quantity-stepper.json
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/quantity-stepper.js"></script>The compiled install writes src/components/zubra/quantity-stepper.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.
Usage
<quantity-stepper label="Tickets" name="tickets"></quantity-stepper>
<script type="module">
import './components/zubra/quantity-stepper.js';
const element = document.querySelector('quantity-stepper');
element.value = 2;
element.min = 1;
element.max = 8;
element.addEventListener('valuechange', (event) => console.log('valuechange', event.detail));
</script>import './components/zubra/quantity-stepper.js';
const value = 2;
const min = 1;
const max = 8;
export function QuantityStepperExample() {
return (
<quantity-stepper
label="Tickets"
name="tickets"
value={value}
min={min}
max={max}
onvaluechange={(event) => console.log('valuechange', event.detail)}
></quantity-stepper>
);
}<script setup>
import './components/zubra/quantity-stepper.js';
const value = 2;
const min = 1;
const max = 8;
const onValuechange = (event) => console.log('valuechange', event.detail);
</script>
<template>
<quantity-stepper
label="Tickets"
name="tickets"
:value.prop="value"
:min.prop="min"
:max.prop="max"
@valuechange="onValuechange"
></quantity-stepper>
</template>
<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) --><script>
import './components/zubra/quantity-stepper.js';
const value = 2;
const min = 1;
const max = 8;
</script>
<quantity-stepper
label="Tickets"
name="tickets"
{value}
{min}
{max}
onvaluechange={(event) => console.log('valuechange', event.detail)}
></quantity-stepper>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/quantity-stepper.js';
@Component({
selector: 'app-quantity-stepper-example',
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<quantity-stepper
label="Tickets"
name="tickets"
[value]="value"
[min]="min"
[max]="max"
(valuechange)="onValuechange($event)"
></quantity-stepper>
`,
})
export class QuantityStepperExample {
value = 2;
min = 1;
max = 8;
onValuechange(event: Event) {
console.log('valuechange', (event as CustomEvent).detail);
}
}API
| Property | Type | Default |
|---|---|---|
value | number | 1 |
min | number | 0 |
max | number | 10 |
label | string | "Quantity" |
editable | boolean | false |
disabled | boolean | false |
| Event | When |
|---|---|
valuechange | The value changed; detail is the new value. |
Size
1.4 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 17.5 KB.