Zubra UI
Code for
GitHub

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

Compiled (any project)
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
One file, no dependencies (3.2 KB gzipped)
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
.zb source (to edit it with Zubra)
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
No build: a script tag, straight from this site
HTML
<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

index.html
<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>
Example.jsx
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>
  );
}
Example.vue
<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('-') } } }) -->
Example.svelte
<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>
example.component.ts
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

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
valuenumber1
minnumber0
maxnumber10
labelstring"Quantity"
editablebooleanfalse
disabledbooleanfalse
Events
EventWhen
valuechangeThe 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.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour