Button Group

Quantity Stepper

A quantity you can both click and type: a real input[type=number] sits between the buttons, and the value is clamped on blur.

  • buttongroup
  • stepper
  • number
  • input

Preview

1440pxHost theme

Use it with AI

  1. 1. Copy the link.
  2. 2. Write to your agent in your own words and drop the link into the sentence.
  3. 3. The agent opens the link and installs the component from the registry.

put this in the header: https://vibeui.ru/c/buttongroup-044?lang=en

pcs
Show the full instructions

What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.

# Install and place "buttongroup-044" (Quantity Stepper) from VibeUI

## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/buttongroup-044.json

Registry item: https://vibeui.ru/r/buttongroup-044.json
Installs to: components/vibeui/buttongroup-044.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.

Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.

## 2. What it is
A quantity you can both click and type: a real input[type=number] sits between the buttons, and the value is clamped on blur.

A quantity stepper: step buttons around a real number field. Zero dependencies, one file, a client component.

## 3. How to use it
import { Buttongroup044 } from "@/components/vibeui/buttongroup-044"

<Buttongroup044
  defaultValue={2}
  min={1}
  max={20}
  unit="pcs"
  onChange={(quantity) => setQuantity(quantity)}
/>

Read the installed file for the full prop list.

## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.

Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)

## 5. Keep exactly as installed
- the local --vibeui-buttongroup-044-* palette — do not swap it for your theme tokens
- the real input between the buttons: without it typing, pasting and the phone numeric keypad are gone
- storing a string rather than a number: clamping on every keystroke makes two-digit values impossible
- clamping on blur — it returns the value to the range without fighting the typing
- the removed native spinners: they duplicate the buttons and are too small to hit
- the focus ring on the field cell via :has — the input's own outline is removed

## 6. You may change
- the initial quantity through defaultValue
- the bounds through min and max
- the unit caption through unit and the accessible name through label
- the change callback through onChange and the ring colour through accent

## 7. Rules
- The component is uncontrolled from outside: the value lives inside and leaves only through onChange.
- Fractions are unsupported: the step is always one, weights need a step of their own.
- An empty field falls back to the minimum on blur — a deliberate choice, not a bug.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.

## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.

For developers

npx shadcn@latest add https://vibeui.ru/r/buttongroup-044.json
https://vibeui.ru/r/buttongroup-044.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в переменных --vibeui-buttongroup-044-*. Клиентский: useState хранит строку ввода, а не число — иначе набрать «12» в поле с максимумом 20 было бы невозможно, «1» уже упёрлось бы в минимум. Зажатие в диапазон происходит по onBlur и по нажатию кнопок. Родные стрелки браузера убраны через appearance:textfield и ::-webkit-inner-spin-button: они дублируют кнопки и на шестнадцати пикселях в них не попасть. Единица измерения стоит внутри поля отдельным узлом, поэтому не мешает вводу. Обводка фокуса рисуется на ячейке поля через :has(input:focus-visible), потому что у самого input убран outline.

Component source

The same file your agent installs. Here in case you would rather copy it by hand.

"use client"

import { useState } from "react"
import type { ComponentPropsWithoutRef, CSSProperties } from "react"

export type Buttongroup044Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "children" | "onChange"
> & {
  defaultValue?: number
  min?: number
  max?: number
  unit?: string
  label?: string
  onChange?: (quantity: number) => void
  accent?: string
}

// Идея компонента: количество, которое можно и нащёлкать, и набрать. Между
// кнопками стоит настоящий input[type=number] — значит, работают ввод с
// клавиатуры, вставка из буфера, стрелки вверх/вниз и подсказка числовой
// клавиатуры на телефоне. Родные стрелки браузера убраны: они дублируют
// кнопки и на 16 пикселях в них не попасть. Значение зажимается в диапазон
// при потере фокуса, а не на каждом нажатии клавиши: иначе набрать «12»
// в поле с максимумом 20 было бы невозможно — «1» уже упёрлось бы в минимум.
const STYLES = `
:where([data-vibeui-block="buttongroup-044"]){
--vibeui-buttongroup-044-surface:oklch(1 0 0);
--vibeui-buttongroup-044-fg:oklch(0.24 0.016 265);
--vibeui-buttongroup-044-muted:oklch(0.56 0.014 265);
--vibeui-buttongroup-044-border:oklch(0.88 0.008 265);
--vibeui-buttongroup-044-accent:oklch(0.5 0.16 265);
--vibeui-buttongroup-044-radius:0.625rem;
--vibeui-buttongroup-044-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="buttongroup-044"]{
box-sizing:border-box;display:inline-flex;align-items:stretch;isolation:isolate;
border:1px solid var(--vibeui-buttongroup-044-border);
border-radius:var(--vibeui-buttongroup-044-radius);
background:var(--vibeui-buttongroup-044-surface);
font-family:var(--vibeui-buttongroup-044-font);
}
[data-vibeui-block="buttongroup-044"] *{box-sizing:border-box}
[data-vibeui-block="buttongroup-044"] button{
appearance:none;cursor:pointer;font:inherit;
position:relative;z-index:0;
display:inline-flex;align-items:center;justify-content:center;
width:2.375rem;height:2.375rem;
border:0;background:transparent;
color:var(--vibeui-buttongroup-044-muted);
transition:background-color .16s ease,color .16s ease;
}
[data-vibeui-block="buttongroup-044"] button:hover:not(:disabled){
background:oklch(0.965 0.005 265);color:var(--vibeui-buttongroup-044-fg);
}
[data-vibeui-block="buttongroup-044"] button:disabled{opacity:.35;cursor:not-allowed}
[data-vibeui-block="buttongroup-044"] svg{
width:1rem;height:1rem;stroke:currentColor;fill:none;stroke-width:2;stroke-linecap:round;
}
[data-vibeui-block="buttongroup-044"] [data-part="field"]{
display:flex;align-items:center;gap:0.1875rem;
padding:0 0.375rem;
border-inline:1px solid var(--vibeui-buttongroup-044-border);
}
/* Родные стрелки убраны: они дублируют кнопки и слишком мелкие. */
[data-vibeui-block="buttongroup-044"] input{
width:2.5rem;height:2.375rem;padding:0;
border:0;background:transparent;
color:var(--vibeui-buttongroup-044-fg);
font:inherit;font-size:0.875rem;font-weight:700;text-align:center;
font-variant-numeric:tabular-nums;
appearance:textfield;
}
[data-vibeui-block="buttongroup-044"] input::-webkit-outer-spin-button,
[data-vibeui-block="buttongroup-044"] input::-webkit-inner-spin-button{
appearance:none;margin:0;
}
[data-vibeui-block="buttongroup-044"] input:focus{outline:none}
[data-vibeui-block="buttongroup-044"] [data-part="field"]:has(input:focus-visible){
outline:2px solid var(--vibeui-buttongroup-044-accent);outline-offset:-2px;
}
[data-vibeui-block="buttongroup-044"] [data-part="unit"]{
color:var(--vibeui-buttongroup-044-muted);
font-size:0.75rem;font-weight:600;line-height:1;
}
[data-vibeui-block="buttongroup-044"] button:focus-visible{
z-index:1;outline:2px solid var(--vibeui-buttongroup-044-accent);outline-offset:-2px;
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="buttongroup-044"] *{animation:none!important;transition:none!important}}
`

/**
 * Количество: кнопки шага вокруг настоящего числового поля.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Buttongroup044({
  defaultValue = 2,
  min = 1,
  max = 20,
  unit = "шт.",
  label = "Количество",
  onChange,
  accent,
  className,
  style,
  ...props
}: Buttongroup044Props) {
  const [raw, setRaw] = useState(String(defaultValue))
  const value = Number(raw)
  const valid = Number.isFinite(value) ? value : min

  const apply = (next: number) => {
    const clamped = Math.min(max, Math.max(min, next))
    setRaw(String(clamped))
    onChange?.(clamped)
  }

  const palette = {
    ...(accent ? { "--vibeui-buttongroup-044-accent": accent } : null),
    ...style,
  } as CSSProperties

  return (
    <>
      <style href="vibeui-buttongroup-044" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="buttongroup-044"
        className={className}
        style={palette}
        role="group"
        aria-label={label}
      >
        <button
          type="button"
          onClick={() => apply(valid - 1)}
          disabled={valid <= min}
          aria-label="Уменьшить количество"
        >
          <svg viewBox="0 0 24 24" aria-hidden="true">
            <path d="M5 12h14" />
          </svg>
        </button>
        <span data-part="field">
          <input
            type="number"
            inputMode="numeric"
            value={raw}
            min={min}
            max={max}
            aria-label={label}
            onChange={(event) => setRaw(event.target.value)}
            onBlur={() => apply(valid)}
          />
          <span data-part="unit">{unit}</span>
        </span>
        <button
          type="button"
          onClick={() => apply(valid + 1)}
          disabled={valid >= max}
          aria-label="Увеличить количество"
        >
          <svg viewBox="0 0 24 24" aria-hidden="true">
            <path d="M12 5v14M5 12h14" />
          </svg>
        </button>
      </div>
    </>
  )
}