Button Group
Anchored Hints
Segments with a hint on each: the anchor name is granted only to the hovered or focused segment, so exactly one anchor exists at any moment.
- buttongroup
- tooltip
- anchor-positioning
- progressive
Preview
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/buttongroup-056?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-056" (Anchored Hints) 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-056.json
Registry item: https://vibeui.ru/r/buttongroup-056.json
Installs to: components/vibeui/buttongroup-056.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
Segments with a hint on each: the anchor name is granted only to the hovered or focused segment, so exactly one anchor exists at any moment.
A segmented filter with a per-segment hint built on CSS anchor positioning. Zero dependencies, one file, a server component.
## 3. How to use it
import { Buttongroup056 } from "@/components/vibeui/buttongroup-056"
<Buttongroup056
options={[{ label: "Mine", hint: "Records you authored" }]}
defaultValue="Mine"
label="Scope"
name="scope"
/>
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-056-* palette — do not swap it for your theme tokens
- granting anchor-name only to the active segment: exactly one anchor exists and the names never clash
- the @supports guard around anchor positioning — without it older browsers park the hint anywhere
- the absolute fallback: it has to stand on its own, not act as a placeholder
- showing the hint on :focus-visible, not just :hover: from the keyboard it is otherwise unreachable
- aria-hidden on the hint — the segment caption has already been read and a repeat gets in the way
## 6. You may change
- the segments and their hint texts through options
- the initially selected segment through defaultValue
- the accessible group name through label
- the form field name through name and the accent through accent
## 7. Rules
- A hover hint is unreachable on a phone: never put essential content there.
- In the fallback the hint is clipped by an overflow:hidden parent — that is the price of compatibility.
- Hint text wraps no wider than 15rem: long explanations belong in the page copy.
- 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-056.jsonhttps://vibeui.ru/r/buttongroup-056.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра в переменных --vibeui-buttongroup-056-*. Серверный: выбор держат radio внутри fieldset. Подсказку обычно позиционируют абсолютно внутри сегмента — и она обрезается первым же родителем с overflow. Здесь применено CSS anchor positioning: anchor-name объявлен в правиле :hover / :has(:focus-visible), поэтому в каждый момент якорь ровно один, и общий приём работает без уникальных имён на каждый сегмент. Всё завёрнуто в @supports (anchor-name: …): без поддержки подсказка остаётся абсолютно спозиционированной под сегментом, а не уезжает в угол экрана. Подсказка помечена aria-hidden — то же самое сказано подписью сегмента.
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 Buttongroup056Option = {
label: string
hint: string
}
export type Buttongroup056Props = Omit<
ComponentPropsWithoutRef<"fieldset">,
"children"
> & {
options?: Buttongroup056Option[]
defaultValue?: string
label?: string
name?: string
accent?: string
}
// Идея компонента: подсказка у каждого сегмента, поставленная якорем CSS.
// Обычно такую подсказку позиционируют абсолютно внутри сегмента — и она
// обрезается первым же родителем с overflow. Здесь имя якоря выдаётся не
// всем сегментам сразу, а только тому, на который навели или который в
// фокусе: anchor-name живёт в правиле :hover / :has(:focus-visible), поэтому
// в каждый момент якорь ровно один, и общий узел подсказки может встать
// куда нужно. Всё завёрнуто в @supports: без поддержки якорей подсказка
// остаётся под группой обычным блоком, а не уезжает в угол экрана.
const STYLES = `
:where([data-vibeui-block="buttongroup-056"]){
--vibeui-buttongroup-056-surface:oklch(1 0 0);
--vibeui-buttongroup-056-fg:oklch(0.25 0.016 265);
--vibeui-buttongroup-056-muted:oklch(0.57 0.014 265);
--vibeui-buttongroup-056-border:oklch(0.89 0.008 265);
--vibeui-buttongroup-056-on:oklch(0.96 0.03 265);
--vibeui-buttongroup-056-accent:oklch(0.5 0.16 265);
--vibeui-buttongroup-056-tip:oklch(0.26 0.02 265);
--vibeui-buttongroup-056-radius:0.625rem;
--vibeui-buttongroup-056-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="buttongroup-056"]{
box-sizing:border-box;display:inline-block;position:relative;
margin:0;padding:0;border:0;
font-family:var(--vibeui-buttongroup-056-font);
}
[data-vibeui-block="buttongroup-056"] *{box-sizing:border-box}
[data-vibeui-block="buttongroup-056"] legend{
position:absolute;width:1px;height:1px;padding:0;margin:-1px;
overflow:hidden;clip-path:inset(50%);white-space:nowrap;
}
[data-vibeui-block="buttongroup-056"] [data-part="track"]{display:flex;isolation:isolate}
[data-vibeui-block="buttongroup-056"] [data-part="segment"]{
position:relative;z-index:0;
display:inline-flex;align-items:center;
height:2.375rem;padding:0 0.875rem;margin-inline-start:-1px;
border:1px solid var(--vibeui-buttongroup-056-border);
background:var(--vibeui-buttongroup-056-surface);
color:var(--vibeui-buttongroup-056-muted);
font-size:0.8125rem;font-weight:600;line-height:1;white-space:nowrap;cursor:pointer;
transition:background-color .16s ease,color .16s ease,border-color .16s ease;
}
[data-vibeui-block="buttongroup-056"] [data-part="segment"]:first-child{
margin-inline-start:0;
border-start-start-radius:var(--vibeui-buttongroup-056-radius);
border-end-start-radius:var(--vibeui-buttongroup-056-radius);
}
[data-vibeui-block="buttongroup-056"] [data-part="segment"]:last-child{
border-start-end-radius:var(--vibeui-buttongroup-056-radius);
border-end-end-radius:var(--vibeui-buttongroup-056-radius);
}
[data-vibeui-block="buttongroup-056"] input{
position:absolute;inset:0;width:100%;height:100%;margin:0;opacity:0;cursor:pointer;
}
[data-vibeui-block="buttongroup-056"] [data-part="segment"]:hover{color:var(--vibeui-buttongroup-056-fg)}
[data-vibeui-block="buttongroup-056"] [data-part="segment"]:has(input:checked){
z-index:1;
background:var(--vibeui-buttongroup-056-on);
border-color:var(--vibeui-buttongroup-056-accent);
color:var(--vibeui-buttongroup-056-accent);
}
[data-vibeui-block="buttongroup-056"] [data-part="segment"]:has(input:focus-visible){
z-index:2;outline:2px solid var(--vibeui-buttongroup-056-accent);outline-offset:1px;
}
/* Подсказка живёт у сегмента и объясняет, что именно он отфильтрует. */
[data-vibeui-block="buttongroup-056"] [data-part="tip"]{
position:absolute;left:0;top:calc(100% + 0.5rem);z-index:3;
max-width:15rem;padding:0.375rem 0.5625rem;border-radius:0.5rem;
background:var(--vibeui-buttongroup-056-tip);
color:oklch(0.985 0.002 265);
font-size:0.6875rem;font-weight:600;line-height:1.35;
opacity:0;translate:0 0.25rem;pointer-events:none;
transition:opacity .14s ease,translate .14s ease;
}
[data-vibeui-block="buttongroup-056"] [data-part="segment"]:hover [data-part="tip"],
[data-vibeui-block="buttongroup-056"] [data-part="segment"]:has(input:focus-visible) [data-part="tip"]{
opacity:1;translate:0 0;
}
/* Якорь выдаётся только активному сегменту: в каждый момент он ровно один. */
@supports (anchor-name: --vibeui-buttongroup-056-anchor){
[data-vibeui-block="buttongroup-056"] [data-part="segment"]:hover,
[data-vibeui-block="buttongroup-056"] [data-part="segment"]:has(input:focus-visible){
anchor-name:--vibeui-buttongroup-056-anchor;
}
[data-vibeui-block="buttongroup-056"] [data-part="tip"]{
position:fixed;
position-anchor:--vibeui-buttongroup-056-anchor;
position-area:block-end span-inline-end;
margin-block-start:0.5rem;left:auto;top:auto;
position-try-fallbacks:flip-block;
}
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="buttongroup-056"] *{animation:none!important;transition:none!important}}
`
const DEFAULT_OPTIONS: Buttongroup056Option[] = [
{ label: "Все", hint: "Ничего не отфильтровано: 128 записей" },
{ label: "Мои", hint: "Записи, где вы автор или ответственный" },
{ label: "Команда", hint: "Записи вашего отдела, включая чужие черновики" },
{ label: "Архив", hint: "Закрытые больше 90 дней назад, только чтение" },
]
/**
* Сегменты с подсказкой у каждого: якорь выдаётся активному сегменту.
* Один файл, ноль зависимостей, серверный компонент.
*/
export function Buttongroup056({
options = DEFAULT_OPTIONS,
defaultValue = "Мои",
label = "Область просмотра",
name = "buttongroup-056",
accent,
className,
style,
...props
}: Buttongroup056Props) {
const palette = {
...(accent ? { "--vibeui-buttongroup-056-accent": accent } : null),
...style,
} as CSSProperties
return (
<>
<style href="vibeui-buttongroup-056" precedence="medium">
{STYLES}
</style>
<fieldset
{...props}
data-vibeui-block="buttongroup-056"
className={className}
style={palette}
>
<legend>{label}</legend>
<div data-part="track">
{options.map((option) => (
<label key={option.label} data-part="segment">
<input
type="radio"
name={name}
value={option.label}
defaultChecked={option.label === defaultValue}
/>
<span>{option.label}</span>
<span data-part="tip" aria-hidden="true">
{option.hint}
</span>
</label>
))}
</div>
</fieldset>
</>
)
}