Button Group

Vote Pill

Up and down voting with the score between the buttons: pressing again withdraws your own vote, which a pair of radios cannot offer.

  • buttongroup
  • vote
  • toggle
  • score

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

42
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-042" (Vote Pill) 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-042.json

Registry item: https://vibeui.ru/r/buttongroup-042.json
Installs to: components/vibeui/buttongroup-042.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
Up and down voting with the score between the buttons: pressing again withdraws your own vote, which a pair of radios cannot offer.

A vote pair with the score in the middle and the ability to withdraw your vote. Zero dependencies, one file, a client component.

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

<Buttongroup042
  score={42}
  upLabel="Helpful answer"
  downLabel="Unhelpful answer"
  onChange={(vote) => send(vote)}
/>

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-042-* palette — do not swap it for your theme tokens
- the aria-pressed pair instead of radios: a radio cannot be unchecked by pressing it again
- the filled glyph on the cast vote — colour alone does not separate "for" from "against" for colour-blind users
- the tabular figures and min-width on the score: a minus sign would otherwise shift both buttons
- aria-live on the score, because a changing number is announced by nothing else
- aria-label on both buttons — a bare arrow is announced as "button"

## 6. You may change
- the base score through score
- the button names through upLabel and downLabel
- the accessible group name through label
- the vote callback through onChange and the ring colour through accent

## 7. Rules
- score is the tally without your vote: your own is added on top, so do not include yourself in score.
- The component sends nothing: the request is your onChange handler's job.
- The initial state is always "not voted": restore an existing vote from outside.
- 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-042.json
https://vibeui.ru/r/buttongroup-042.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в переменных --vibeui-buttongroup-042-*. Клиентский: useState хранит "up", "down" или null; взаимное исключение сделано в обработчике, потому что снять выбор у radio без третьей кнопки нельзя. Состояние объявлено через aria-pressed на каждой кнопке. Отданный голос помечен не только цветом: у значка появляется заливка (fill:currentColor), и это работает при дальтонизме. Счёт стоит между кнопками, набран табличными цифрами и имеет min-width, поэтому переход через ноль и появление минуса не двигают кнопки. Счёт объявлен aria-live="polite": изменение цифры иначе остаётся незамеченным.

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 Buttongroup042Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "children" | "onChange"
> & {
  score?: number
  upLabel?: string
  downLabel?: string
  label?: string
  onChange?: (vote: "up" | "down" | null) => void
  accent?: string
}

// Идея компонента: голосование, где два тумблера гасят друг друга, но
// каждый умеет сняться сам. Повторное нажатие на уже отданный голос
// отзывает его — это ожидаемое поведение, которое radio дать не может:
// снять выбор у radio без второй кнопки нельзя. Поэтому здесь пара
// aria-pressed, а взаимное исключение сделано в обработчике. Счёт стоит
// между кнопками, набран табличными цифрами и не меняет ширину при
// переходе через ноль; знак минуса рисуется текстом, а не цветом.
const STYLES = `
:where([data-vibeui-block="buttongroup-042"]){
--vibeui-buttongroup-042-surface:oklch(1 0 0);
--vibeui-buttongroup-042-fg:oklch(0.25 0.016 265);
--vibeui-buttongroup-042-muted:oklch(0.56 0.014 265);
--vibeui-buttongroup-042-border:oklch(0.88 0.008 265);
--vibeui-buttongroup-042-up:oklch(0.52 0.15 150);
--vibeui-buttongroup-042-down:oklch(0.55 0.18 27);
--vibeui-buttongroup-042-accent:oklch(0.5 0.15 265);
--vibeui-buttongroup-042-radius:9999px;
--vibeui-buttongroup-042-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="buttongroup-042"]{
box-sizing:border-box;display:inline-flex;align-items:center;
border:1px solid var(--vibeui-buttongroup-042-border);
border-radius:var(--vibeui-buttongroup-042-radius);
background:var(--vibeui-buttongroup-042-surface);
font-family:var(--vibeui-buttongroup-042-font);
}
[data-vibeui-block="buttongroup-042"] *{box-sizing:border-box}
[data-vibeui-block="buttongroup-042"] button{
appearance:none;cursor:pointer;font:inherit;
display:inline-flex;align-items:center;justify-content:center;
width:2.125rem;height:2.125rem;
border:0;border-radius:var(--vibeui-buttongroup-042-radius);
background:transparent;
color:var(--vibeui-buttongroup-042-muted);
transition:background-color .16s ease,color .16s ease;
}
[data-vibeui-block="buttongroup-042"] svg{
width:1.0625rem;height:1.0625rem;
stroke:currentColor;fill:none;stroke-width:1.9;stroke-linecap:round;stroke-linejoin:round;
transition:fill .16s ease;
}
[data-vibeui-block="buttongroup-042"] button:hover{
background:oklch(0.965 0.005 265);color:var(--vibeui-buttongroup-042-fg);
}
[data-vibeui-block="buttongroup-042"] [data-vote="up"][aria-pressed="true"]{color:var(--vibeui-buttongroup-042-up)}
[data-vibeui-block="buttongroup-042"] [data-vote="down"][aria-pressed="true"]{color:var(--vibeui-buttongroup-042-down)}
/* Заливка значка — второй признак: цвет один при дальтонизме не работает. */
[data-vibeui-block="buttongroup-042"] button[aria-pressed="true"] svg{fill:currentColor}
[data-vibeui-block="buttongroup-042"] button:focus-visible{
outline:2px solid var(--vibeui-buttongroup-042-accent);outline-offset:-2px;
}
[data-vibeui-block="buttongroup-042"] [data-part="score"]{
min-width:2.25rem;padding:0 0.25rem;text-align:center;
border-inline:1px solid var(--vibeui-buttongroup-042-border);
color:var(--vibeui-buttongroup-042-fg);
font-size:0.8125rem;font-weight:700;line-height:2.125rem;
font-variant-numeric:tabular-nums;
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="buttongroup-042"] *{animation:none!important;transition:none!important}}
`

const UP = "M7 21V10l5-7 1 1-1 5h6a2 2 0 0 1 2 2l-2 8a2 2 0 0 1-2 2z"
const DOWN = "M7 3v11l5 7 1-1-1-5h6a2 2 0 0 0 2-2l-2-8a2 2 0 0 0-2-2z"

/**
 * Голосование вверх/вниз, где повторное нажатие отзывает собственный голос.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Buttongroup042({
  score = 42,
  upLabel = "Полезный ответ",
  downLabel = "Бесполезный ответ",
  label = "Оценка ответа",
  onChange,
  accent,
  className,
  style,
  ...props
}: Buttongroup042Props) {
  const [vote, setVote] = useState<"up" | "down" | null>(null)
  const shown = score + (vote === "up" ? 1 : vote === "down" ? -1 : 0)

  const toggle = (next: "up" | "down") => {
    const value = vote === next ? null : next
    setVote(value)
    onChange?.(value)
  }

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

  return (
    <>
      <style href="vibeui-buttongroup-042" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="buttongroup-042"
        className={className}
        style={palette}
        role="group"
        aria-label={label}
      >
        <button
          type="button"
          data-vote="up"
          aria-pressed={vote === "up"}
          aria-label={upLabel}
          onClick={() => toggle("up")}
        >
          <svg viewBox="0 0 24 24" aria-hidden="true">
            <path d={UP} />
          </svg>
        </button>
        <span data-part="score" aria-live="polite">
          {shown}
        </span>
        <button
          type="button"
          data-vote="down"
          aria-pressed={vote === "down"}
          aria-label={downLabel}
          onClick={() => toggle("down")}
        >
          <svg viewBox="0 0 24 24" aria-hidden="true">
            <path d={DOWN} />
          </svg>
        </button>
      </div>
    </>
  )
}