Button Group

Zoom Stepper

A "minus — value — plus" zoom control whose steps follow familiar numbers, with the middle cell returning to one hundred per cent.

  • buttongroup
  • stepper
  • zoom
  • toolbar

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-022?lang=en

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-022" (Zoom 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-022.json

Registry item: https://vibeui.ru/r/buttongroup-022.json
Installs to: components/vibeui/buttongroup-022.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 "minus — value — plus" zoom control whose steps follow familiar numbers, with the middle cell returning to one hundred per cent.

A stepped zoom control with the value inside the cluster and a reset on click. Zero dependencies, one file, a client component.

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

<Buttongroup022
  steps={[50, 75, 100, 150, 200]}
  defaultValue={100}
  label="Zoom"
  onChange={(zoom) => setZoom(zoom)}
/>

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-022-* palette — do not swap it for your theme tokens
- steps taken from a list of familiar values: an even step turns zooming into a dozen clicks
- the pinned width and tabular figures on the value — otherwise the buttons jump on every step
- disabled at the ends of the range: a live "minus" at minimum zoom is a lie
- aria-label on the icon buttons — a "plus" without a name is announced as "button"
- outline-offset:-2px on focus: an outside ring would be clipped by the container border

## 6. You may change
- the list of values through steps
- the initial and reset value through defaultValue
- the accessible group name through label
- the change callback through onChange and the ring colour through accent

## 7. Rules
- A value missing from steps collapses to the first step: the index is matched exactly.
- The component scales nothing: applying the value is your onChange handler's job.
- The middle cell is clickable and resets the zoom — replace the button with a span if that is unwanted.
- 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-022.json
https://vibeui.ru/r/buttongroup-022.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в переменных --vibeui-buttongroup-022-*. Клиентский: useState хранит текущее значение, шаг двигает индекс по массиву steps. Масштаб идёт не арифметическим шагом, а по списку привычных значений — равномерный шаг в пять процентов заставил бы щёлкать десяток раз. Средняя ячейка — кнопка сброса к defaultValue, у неё min-width:4rem и font-variant-numeric:tabular-nums, поэтому «75 %» и «100 %» занимают одно место. Рамка одна — на контейнере, разделители рисует button + button {border-inline-start}. Крайние значения гасят кнопку через disabled, обводка фокуса уводится внутрь outline-offset:-2px, иначе её срежет рамка контейнера.

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 Buttongroup022Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "children" | "onChange"
> & {
  steps?: number[]
  defaultValue?: number
  label?: string
  onChange?: (zoom: number) => void
  accent?: string
}

// Идея компонента: шаговый регулятор, где значение живёт внутри сцепки
// третьей ячейкой. Масштаб идёт не арифметическим шагом, а по списку
// привычных значений (25, 50, 75, 100…): равномерный шаг в 5 % заставил бы
// щёлкать десяток раз. Средняя ячейка — кнопка сброса к 100 %, у неё
// фиксированная ширина и табличные цифры, иначе «75 %» и «100 %» дёргали бы
// соседей. Крайние значения гасят кнопку через disabled, а не прячут её.
const STYLES = `
:where([data-vibeui-block="buttongroup-022"]){
--vibeui-buttongroup-022-surface:oklch(1 0 0);
--vibeui-buttongroup-022-fg:oklch(0.25 0.016 265);
--vibeui-buttongroup-022-muted:oklch(0.55 0.014 265);
--vibeui-buttongroup-022-border:oklch(0.88 0.008 265);
--vibeui-buttongroup-022-accent:oklch(0.52 0.16 265);
--vibeui-buttongroup-022-radius:0.625rem;
--vibeui-buttongroup-022-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="buttongroup-022"]{
box-sizing:border-box;display:inline-flex;isolation:isolate;
border:1px solid var(--vibeui-buttongroup-022-border);
border-radius:var(--vibeui-buttongroup-022-radius);
background:var(--vibeui-buttongroup-022-surface);
font-family:var(--vibeui-buttongroup-022-font);
}
[data-vibeui-block="buttongroup-022"] *{box-sizing:border-box}
[data-vibeui-block="buttongroup-022"] button{
appearance:none;cursor:pointer;font:inherit;
position:relative;z-index:0;
display:inline-flex;align-items:center;justify-content:center;
height:2.25rem;border:0;background:transparent;
color:var(--vibeui-buttongroup-022-muted);
transition:background-color .16s ease,color .16s ease;
}
[data-vibeui-block="buttongroup-022"] button + button{
border-inline-start:1px solid var(--vibeui-buttongroup-022-border);
}
[data-vibeui-block="buttongroup-022"] [data-part="step"]{width:2.25rem}
[data-vibeui-block="buttongroup-022"] [data-part="step"] svg{
width:1rem;height:1rem;stroke:currentColor;fill:none;stroke-width:2;stroke-linecap:round;
}
/* Ширина зафиксирована: иначе «100 %» толкает кнопки при каждом шаге. */
[data-vibeui-block="buttongroup-022"] [data-part="value"]{
min-width:4rem;padding:0 0.5rem;
color:var(--vibeui-buttongroup-022-fg);
font-size:0.8125rem;font-weight:650;line-height:1;
font-variant-numeric:tabular-nums;
}
[data-vibeui-block="buttongroup-022"] button:hover:not(:disabled){
background:oklch(0.965 0.005 265);color:var(--vibeui-buttongroup-022-fg);
}
[data-vibeui-block="buttongroup-022"] button:disabled{opacity:.35;cursor:not-allowed}
[data-vibeui-block="buttongroup-022"] button:focus-visible{
z-index:1;outline:2px solid var(--vibeui-buttongroup-022-accent);outline-offset:-2px;
}
[data-vibeui-block="buttongroup-022"] :first-child{
border-start-start-radius:calc(var(--vibeui-buttongroup-022-radius) - 1px);
border-end-start-radius:calc(var(--vibeui-buttongroup-022-radius) - 1px);
}
[data-vibeui-block="buttongroup-022"] :last-child{
border-start-end-radius:calc(var(--vibeui-buttongroup-022-radius) - 1px);
border-end-end-radius:calc(var(--vibeui-buttongroup-022-radius) - 1px);
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="buttongroup-022"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_STEPS = [25, 50, 75, 100, 125, 150, 200, 300]

/**
 * Регулятор масштаба «минус — значение — плюс» с шагами по привычным числам.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Buttongroup022({
  steps = DEFAULT_STEPS,
  defaultValue = 100,
  label = "Масштаб",
  onChange,
  accent,
  className,
  style,
  ...props
}: Buttongroup022Props) {
  const [zoom, setZoom] = useState(defaultValue)
  const index = Math.max(
    0,
    steps.findIndex((step) => step === zoom),
  )

  const move = (delta: number) => {
    const next = steps[Math.min(steps.length - 1, Math.max(0, index + delta))]
    setZoom(next)
    onChange?.(next)
  }

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

  return (
    <>
      <style href="vibeui-buttongroup-022" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="buttongroup-022"
        className={className}
        style={palette}
        role="group"
        aria-label={label}
      >
        <button
          type="button"
          data-part="step"
          onClick={() => move(-1)}
          disabled={index === 0}
          aria-label="Уменьшить масштаб"
        >
          <svg viewBox="0 0 24 24" aria-hidden="true">
            <path d="M5 12h14" />
          </svg>
        </button>
        <button
          type="button"
          data-part="value"
          onClick={() => {
            setZoom(defaultValue)
            onChange?.(defaultValue)
          }}
          aria-label={`Масштаб ${zoom} процентов, вернуть ${defaultValue}`}
        >
          <span aria-hidden="true">{zoom} %</span>
        </button>
        <button
          type="button"
          data-part="step"
          onClick={() => move(1)}
          disabled={index === steps.length - 1}
          aria-label="Увеличить масштаб"
        >
          <svg viewBox="0 0 24 24" aria-hidden="true">
            <path d="M12 5v14M5 12h14" />
          </svg>
        </button>
      </div>
    </>
  )
}