Buttons
Segmented Control
A segmented control built on real radios: arrows, Home/End and position announcements come from the browser.
- button
- segmented
- radio
- keyboard
Preview
1440pxHost theme
Use it with AI
- 1. Copy the link.
- 2. Write to your agent in your own words and drop the link into the sentence.
- 3. The agent opens the link and installs the component from the registry.
put this in the header: https://vibeui.ru/c/button-013?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 "button-013" (Segmented Control) 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/button-013.json
Registry item: https://vibeui.ru/r/button-013.json
Installs to: components/vibeui/button-013.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 segmented control built on real radios: arrows, Home/End and position announcements come from the browser.
A two-to-four segment switch on real radios: keyboard and position announcements for free, the selected segment on a white pad. Zero dependencies, one file.
## 3. How to use it
import { Button013 } from "@/components/vibeui/button-013"
<Button013 options={["Day", "Week"]} defaultValue="Week" onChange={setRange} />
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-button-013-* palette — do not swap it for your theme tokens
- radios inside instead of buttons: arrows, Home/End and "2 of 3" come free
- role="radiogroup" with a name on the wrapper
- styling through :has(input:checked) — state and appearance cannot drift
- the focus ring on the label rather than the hidden input
- a thumb-sized segment height
## 6. You may change
- the options array and defaultValue
- label — the group's name
- the onChange handler
- the accent through the accent prop
## 7. Rules
- Two to four segments is the range: beyond it use a select or tabs.
- Keep labels short: equal-width segments read as a scale.
- This picks one value, not filters: for multi-select use badge-011.
- 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/button-013.jsonhttps://vibeui.ru/r/button-013.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-button-013-*. Клиентский: "use client". Внутри настоящие input type="radio" с общим именем из useId; они прозрачны и растянуты на подпись, поэтому клавиатурная модель радиогруппы работает без единой строки обработчиков. Выбранный сегмент стилизуется через :has(input:checked).
Component source
The same file your agent installs. Here in case you would rather copy it by hand.
"use client"
import { useId, useState } from "react"
import type { ComponentPropsWithoutRef, CSSProperties } from "react"
export type Button013Props = Omit<
ComponentPropsWithoutRef<"div">,
"children" | "onChange"
> & {
options?: string[]
defaultValue?: string
label?: string
onChange?: (value: string) => void
accent?: string
}
// Идея компонента: сегментированный переключатель — выбор одного из немногих.
// Внутри настоящие radio, а не кнопки: стрелки, Home/End и объявление
// «выбрано 2 из 3» браузер даёт сам. Подложка выбранного двигается за
// значением, но состояние держит форма, а не анимация.
const STYLES = `
:where([data-vibeui-block="button-013"]){
--vibeui-button-013-fg:oklch(0.3 0.014 265);
--vibeui-button-013-muted:oklch(0.5 0.014 265);
--vibeui-button-013-bg:oklch(0.96 0.004 265);
--vibeui-button-013-on:oklch(1 0 0);
--vibeui-button-013-border:oklch(0.9 0.006 265);
--vibeui-button-013-accent:oklch(0.55 0.17 265);
--vibeui-button-013-radius:0.625rem;
--vibeui-button-013-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="button-013"]{
display:inline-flex;align-items:center;gap:0.125rem;
padding:0.1875rem;box-sizing:border-box;
border:1px solid var(--vibeui-button-013-border);
border-radius:calc(var(--vibeui-button-013-radius) + 0.1875rem);
background:var(--vibeui-button-013-bg);
font-family:var(--vibeui-button-013-font);
}
[data-vibeui-block="button-013"] label{
position:relative;display:inline-flex;align-items:center;justify-content:center;
height:1.875rem;padding:0 0.75rem;border-radius:var(--vibeui-button-013-radius);
color:var(--vibeui-button-013-muted);font-size:0.8125rem;font-weight:600;
cursor:pointer;white-space:nowrap;
transition:color .16s ease,background-color .16s ease;
}
/* Настоящие radio под подписями: стрелки и объявление позиции — от браузера. */
[data-vibeui-block="button-013"] input{
position:absolute;inset:0;width:100%;height:100%;margin:0;
opacity:0;cursor:pointer;
}
[data-vibeui-block="button-013"] label:has(input:checked){
background:var(--vibeui-button-013-on);color:var(--vibeui-button-013-fg);
box-shadow:0 1px 2px oklch(0.2 0.02 265 / 12%);
}
[data-vibeui-block="button-013"] label:has(input:focus-visible){outline:2px solid var(--vibeui-button-013-accent);outline-offset:2px}
[data-vibeui-block="button-013"] label:hover{color:var(--vibeui-button-013-fg)}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="button-013"] *{animation:none!important;transition:none!important}}
`
const DEFAULT_OPTIONS = ["День", "Неделя", "Месяц"]
/**
* Сегментированный переключатель на настоящих radio.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Button013({
options = DEFAULT_OPTIONS,
defaultValue = "Неделя",
label = "Период",
onChange,
accent,
className,
style,
...props
}: Button013Props) {
const id = useId()
const [value, setValue] = useState(defaultValue)
const palette = {
...(accent ? { "--vibeui-button-013-accent": accent } : null),
...style,
} as CSSProperties
return (
<>
<style href="vibeui-button-013" precedence="medium">
{STYLES}
</style>
<div
{...props}
data-vibeui-block="button-013"
role="radiogroup"
aria-label={label}
className={className}
style={palette}
>
{options.map((option) => (
<label key={option}>
<input
type="radio"
name={id}
value={option}
checked={value === option}
onChange={() => {
setValue(option)
onChange?.(option)
}}
/>
{option}
</label>
))}
</div>
</>
)
}