Button Group

Yes No Toggle

A "yes / no" answer as two segments with a sliding surface: the track itself detects the checked radio through :has, and no client JS is needed.

  • buttongroup
  • boolean
  • css-only
  • survey

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

Email me the report every Monday?

Письмо придёт в 9:00 по вашему времени.Отчёт останется доступен только в интерфейсе.

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-017" (Yes No Toggle) 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-017.json

Registry item: https://vibeui.ru/r/buttongroup-017.json
Installs to: components/vibeui/buttongroup-017.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 "yes / no" answer as two segments with a sliding surface: the track itself detects the checked radio through :has, and no client JS is needed.

A "yes / no" pair with a sliding surface and a hint that swaps with pure CSS. Zero dependencies, one file, a server component.

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

<Buttongroup017
  question="Email me the report every Monday?"
  yesHint="The email arrives at 9:00."
  noHint="The report stays in the app only."
  defaultValue="yes"
/>

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-017-* palette — do not swap it for your theme tokens
- radios instead of a switch: in a survey both answers are equal and must stay visible
- the surface driven by :has on the track — the state and the look then cannot drift apart
- clear:both on the legend and the track: a floated legend otherwise makes the flex children wrap around it
- different surface colours for "yes" and "no": one fill erases the meaning of the answer
- the prefers-reduced-motion rule — a sliding surface is the first thing to hurt with vestibular disorders

## 6. You may change
- the question text through question
- the answer captions through yesLabel and noLabel
- the hints below the group through yesHint and noHint
- the initial answer through defaultValue, the field name through name and the agreement colour through accent

## 7. Rules
- There are exactly two answers: a third one breaks both the sliding surface and the hint rules.
- All radios share one name: two groups with the same name cancel each other out.
- Both hints ship in the markup, the hidden one is merely not shown — do not put secrets there.
- 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-017.json
https://vibeui.ru/r/buttongroup-017.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в переменных --vibeui-buttongroup-017-*. Серверный: подложка переезжает без JS — правило [data-part="track"]:has([data-part="option"]:nth-of-type(2) input:checked) сдвигает единственный thumb на 100% и меняет его цвет на «отказ». Пояснение под группой тоже переключается CSS: оба текста лежат в разметке, показан тот, чей radio отмечен. Здесь сознательно не switch: switch честен, когда «выключено» — это отсутствие действия, а в анкете оба ответа равнозначны и должны быть видны целиком. Legend оформлен видимым заголовком с float:left;width:100%;clear:both — без clear следующие flex-дети обтекали бы его.

Component source

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

import type { ComponentPropsWithoutRef, CSSProperties } from "react"

export type Buttongroup017Props = Omit<
  ComponentPropsWithoutRef<"fieldset">,
  "children"
> & {
  question?: string
  yesLabel?: string
  noLabel?: string
  yesHint?: string
  noHint?: string
  defaultValue?: "yes" | "no"
  name?: string
  accent?: string
}

// Идея компонента: ответ «да / нет» как пара сегментов, а не как switch.
// Switch честен только тогда, когда «выключено» — это отсутствие действия;
// в анкете оба ответа равнозначны, и вариант должен быть виден целиком.
// Подложка переезжает без JS: трек ловит через :has, какой из двух radio
// отмечен, и сдвигает единственный thumb. Пояснение под группой тоже
// меняется правилами CSS — оба текста лежат в разметке, показан один.
const STYLES = `
:where([data-vibeui-block="buttongroup-017"]){
--vibeui-buttongroup-017-surface:oklch(1 0 0);
--vibeui-buttongroup-017-track:oklch(0.955 0.004 265);
--vibeui-buttongroup-017-fg:oklch(0.25 0.016 265);
--vibeui-buttongroup-017-muted:oklch(0.55 0.014 265);
--vibeui-buttongroup-017-border:oklch(0.9 0.006 265);
--vibeui-buttongroup-017-accent:oklch(0.55 0.15 150);
--vibeui-buttongroup-017-deny:oklch(0.6 0.15 25);
--vibeui-buttongroup-017-thumb:var(--vibeui-buttongroup-017-accent);
--vibeui-buttongroup-017-radius:0.5rem;
--vibeui-buttongroup-017-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="buttongroup-017"]{
box-sizing:border-box;display:block;width:100%;max-width:20rem;
margin:0;padding:0.875rem;
border:1px solid var(--vibeui-buttongroup-017-border);border-radius:0.875rem;
background:var(--vibeui-buttongroup-017-surface);
font-family:var(--vibeui-buttongroup-017-font);
}
[data-vibeui-block="buttongroup-017"] *{box-sizing:border-box}
[data-vibeui-block="buttongroup-017"] legend{
padding:0;margin:0 0 0.625rem;float:left;width:100%;clear:both;
color:var(--vibeui-buttongroup-017-fg);
font-size:0.8125rem;font-weight:650;line-height:1.35;
}
[data-vibeui-block="buttongroup-017"] [data-part="track"]{
position:relative;display:grid;grid-template-columns:1fr 1fr;clear:both;
padding:0.1875rem;
border-radius:calc(var(--vibeui-buttongroup-017-radius) + 0.1875rem);
background:var(--vibeui-buttongroup-017-track);
}
[data-vibeui-block="buttongroup-017"] [data-part="thumb"]{
position:absolute;top:0.1875rem;bottom:0.1875rem;left:0.1875rem;
width:calc((100% - 0.375rem) / 2);
border-radius:var(--vibeui-buttongroup-017-radius);
background:var(--vibeui-buttongroup-017-thumb);
transition:translate .2s cubic-bezier(.2,.7,.3,1),background-color .2s ease;
}
/* Трек сам решает, где стоит подложка: JS для двух вариантов не нужен. */
[data-vibeui-block="buttongroup-017"] [data-part="track"]:has([data-part="option"]:nth-of-type(2) input:checked) [data-part="thumb"]{
translate:100% 0;
--vibeui-buttongroup-017-thumb:var(--vibeui-buttongroup-017-deny);
}
[data-vibeui-block="buttongroup-017"] [data-part="option"]{
position:relative;z-index:1;
display:inline-flex;align-items:center;justify-content:center;gap:0.375rem;
height:2.125rem;
color:var(--vibeui-buttongroup-017-muted);
font-size:0.8125rem;font-weight:650;line-height:1;cursor:pointer;
transition:color .18s ease;
}
[data-vibeui-block="buttongroup-017"] input{
position:absolute;inset:0;width:100%;height:100%;margin:0;opacity:0;cursor:pointer;
}
[data-vibeui-block="buttongroup-017"] [data-part="option"]:has(input:checked){
color:oklch(0.99 0.004 265);
}
[data-vibeui-block="buttongroup-017"] [data-part="option"]:has(input:focus-visible){
outline:2px solid var(--vibeui-buttongroup-017-fg);outline-offset:2px;
border-radius:var(--vibeui-buttongroup-017-radius);
}
[data-vibeui-block="buttongroup-017"] [data-part="hint"]{
margin:0.5rem 0 0;min-height:1.125rem;
color:var(--vibeui-buttongroup-017-muted);
font-size:0.75rem;line-height:1.4;
}
[data-vibeui-block="buttongroup-017"] [data-part="hint"] span{display:none}
[data-vibeui-block="buttongroup-017"]:has([data-part="option"]:nth-of-type(1) input:checked) [data-part="hint"] [data-when="yes"]{display:inline}
[data-vibeui-block="buttongroup-017"]:has([data-part="option"]:nth-of-type(2) input:checked) [data-part="hint"] [data-when="no"]{display:inline}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="buttongroup-017"] *{animation:none!important;transition:none!important}}
`

/**
 * Ответ «да / нет» парой сегментов с переезжающей подложкой без JS.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Buttongroup017({
  question = "Присылать отчёт на почту каждый понедельник?",
  yesLabel = "Да",
  noLabel = "Нет",
  yesHint = "Письмо придёт в 9:00 по вашему времени.",
  noHint = "Отчёт останется доступен только в интерфейсе.",
  defaultValue = "yes",
  name = "buttongroup-017",
  accent,
  className,
  style,
  ...props
}: Buttongroup017Props) {
  const palette = {
    ...(accent ? { "--vibeui-buttongroup-017-accent": accent } : null),
    ...style,
  } as CSSProperties

  return (
    <>
      <style href="vibeui-buttongroup-017" precedence="medium">
        {STYLES}
      </style>
      <fieldset
        {...props}
        data-vibeui-block="buttongroup-017"
        className={className}
        style={palette}
      >
        <legend>{question}</legend>
        <div data-part="track">
          <span data-part="thumb" aria-hidden="true" />
          <label data-part="option">
            <input
              type="radio"
              name={name}
              value="yes"
              defaultChecked={defaultValue === "yes"}
            />
            {yesLabel}
          </label>
          <label data-part="option">
            <input
              type="radio"
              name={name}
              value="no"
              defaultChecked={defaultValue === "no"}
            />
            {noLabel}
          </label>
        </div>
        <p data-part="hint">
          <span data-when="yes">{yesHint}</span>
          <span data-when="no">{noHint}</span>
        </p>
      </fieldset>
    </>
  )
}