Button Group

Role Ladder

Roles as a ladder from the most powerful down: choosing one highlights it and everything to its right — showing that an editor can do everything a viewer can.

  • buttongroup
  • roles
  • permissions
  • sibling

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

Роль участника

A role includes every right to its right.

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-050" (Role Ladder) 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-050.json

Registry item: https://vibeui.ru/r/buttongroup-050.json
Installs to: components/vibeui/buttongroup-050.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
Roles as a ladder from the most powerful down: choosing one highlights it and everything to its right — showing that an editor can do everything a viewer can.

A role picker as a ladder where the lesser rights light up together with the selection. Zero dependencies, one file, a server component.

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

<Buttongroup050
  roles={[{ id: "editor", label: "Editor", scope: "content editing" }]}
  defaultValue="editor"
  hint="A role includes every right to its right."
  name="role"
/>

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-050-* palette — do not swap it for your theme tokens
- the order from the highest role down: the highlight is built on a sibling combinator, so the order carries meaning
- the different fill strengths for the selected and the included roles — otherwise the actual choice is unclear
- the rights caption on the second line: role names mean different things in every product
- the explanatory line under the group — the highlight-to-the-right trick does not explain itself
- clear:both on the legend: a floated legend otherwise makes the grid children wrap around it

## 6. You may change
- the roles and their rights through roles
- the initial role through defaultValue
- the explanatory line through hint and the group name through label
- the form field name through name and the selection colour through accent

## 7. Rules
- The roles must be ordered by decreasing power: otherwise the highlight lies about nesting.
- More than four roles stop fitting into equal columns on a phone.
- The component checks no permissions: assigning the role is your code's job after submit.
- 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-050.json
https://vibeui.ru/r/buttongroup-050.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в переменных --vibeui-buttongroup-050-*. Серверный: выбор держат radio внутри fieldset. Вложенность прав показана соседним комбинатором: [data-part="step"]:has(input:checked) ~ [data-part="step"] заливает все младшие роли слабее, чем выбранную. Поэтому порядок сегментов не декоративный, а смысловой — перестановка сломает логику. Границы схлопнуты через margin-inline-start:-1px, скругления только крайним, выбранная роль поднята z-index:1, сфокусированная — z-index:2. Legend видимый, с float:left;width:100%;clear:both, иначе следующие grid-дети обтекали бы его.

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 Buttongroup050Role = {
  id: string
  label: string
  scope: string
}

export type Buttongroup050Props = Omit<
  ComponentPropsWithoutRef<"fieldset">,
  "children"
> & {
  roles?: Buttongroup050Role[]
  defaultValue?: string
  hint?: string
  label?: string
  name?: string
  accent?: string
}

// Идея компонента: роли выстроены лестницей от старшей к младшей, и выбор
// подсвечивает не только сам сегмент, но и все, что правее. Это показывает
// вложенность прав: редактор умеет всё, что умеет читатель. Приём держится
// на соседнем комбинаторе — label:has(input:checked) ~ label, — поэтому
// порядок сегментов не декоративный, а смысловой: перестановка сломает
// логику. Младшие сегменты залиты слабее старшего: включённое право и
// выбранная роль не должны выглядеть одинаково.
const STYLES = `
:where([data-vibeui-block="buttongroup-050"]){
--vibeui-buttongroup-050-surface:oklch(1 0 0);
--vibeui-buttongroup-050-fg:oklch(0.25 0.016 265);
--vibeui-buttongroup-050-muted:oklch(0.58 0.014 265);
--vibeui-buttongroup-050-border:oklch(0.89 0.008 265);
--vibeui-buttongroup-050-accent:oklch(0.48 0.16 285);
--vibeui-buttongroup-050-radius:0.75rem;
--vibeui-buttongroup-050-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="buttongroup-050"]{
box-sizing:border-box;display:block;width:100%;max-width:30rem;
margin:0;padding:0;border:0;
font-family:var(--vibeui-buttongroup-050-font);
}
[data-vibeui-block="buttongroup-050"] *{box-sizing:border-box}
[data-vibeui-block="buttongroup-050"] legend{
padding:0;margin:0 0 0.5rem;float:left;width:100%;clear:both;
color:var(--vibeui-buttongroup-050-fg);
font-size:0.8125rem;font-weight:650;line-height:1.35;
}
[data-vibeui-block="buttongroup-050"] [data-part="track"]{
display:grid;grid-auto-flow:column;grid-auto-columns:1fr;isolation:isolate;clear:both;
}
[data-vibeui-block="buttongroup-050"] [data-part="step"]{
position:relative;z-index:0;
display:flex;flex-direction:column;align-items:center;justify-content:center;gap:0.1875rem;
min-height:3.5rem;padding:0.5rem 0.375rem;margin-inline-start:-1px;
border:1px solid var(--vibeui-buttongroup-050-border);
background:var(--vibeui-buttongroup-050-surface);
cursor:pointer;text-align:center;
transition:background-color .16s ease,border-color .16s ease;
}
[data-vibeui-block="buttongroup-050"] [data-part="step"]:first-child{
margin-inline-start:0;
border-start-start-radius:var(--vibeui-buttongroup-050-radius);
border-end-start-radius:var(--vibeui-buttongroup-050-radius);
}
[data-vibeui-block="buttongroup-050"] [data-part="step"]:last-child{
border-start-end-radius:var(--vibeui-buttongroup-050-radius);
border-end-end-radius:var(--vibeui-buttongroup-050-radius);
}
[data-vibeui-block="buttongroup-050"] input{
position:absolute;inset:0;width:100%;height:100%;margin:0;opacity:0;cursor:pointer;
}
[data-vibeui-block="buttongroup-050"] [data-part="name"]{
color:var(--vibeui-buttongroup-050-fg);
font-size:0.8125rem;font-weight:650;line-height:1.2;
}
[data-vibeui-block="buttongroup-050"] [data-part="scope"]{
color:var(--vibeui-buttongroup-050-muted);
font-size:0.6875rem;line-height:1.25;
}
/* Выбранная роль включает все, что правее: младшие права залиты слабее. */
[data-vibeui-block="buttongroup-050"] [data-part="step"]:has(input:checked) ~ [data-part="step"]{
background:oklch(0.975 0.015 285);
}
[data-vibeui-block="buttongroup-050"] [data-part="step"]:has(input:checked){
z-index:1;
background:oklch(0.95 0.04 285);
border-color:var(--vibeui-buttongroup-050-accent);
}
[data-vibeui-block="buttongroup-050"] [data-part="step"]:has(input:checked) [data-part="name"]{
color:var(--vibeui-buttongroup-050-accent);
}
[data-vibeui-block="buttongroup-050"] [data-part="step"]:has(input:focus-visible){
z-index:2;outline:2px solid var(--vibeui-buttongroup-050-accent);outline-offset:1px;
}
[data-vibeui-block="buttongroup-050"] [data-part="hint"]{
display:flex;align-items:flex-start;gap:0.375rem;
margin:0.5rem 0 0;
color:var(--vibeui-buttongroup-050-muted);
font-size:0.75rem;line-height:1.4;
}
[data-vibeui-block="buttongroup-050"] [data-part="hint"] svg{
width:0.9375rem;height:0.9375rem;flex:none;margin-top:0.0625rem;
stroke:currentColor;fill:none;stroke-width:1.9;stroke-linecap:round;
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="buttongroup-050"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_ROLES: Buttongroup050Role[] = [
  { id: "owner", label: "Владелец", scope: "биллинг и удаление" },
  { id: "admin", label: "Админ", scope: "настройки и люди" },
  { id: "editor", label: "Редактор", scope: "правка контента" },
  { id: "viewer", label: "Читатель", scope: "только просмотр" },
]

/**
 * Роли лестницей: выбранная подсвечивает все младшие, права видно вложенными.
 * Один файл, ноль зависимостей, серверный компонент.
 */
export function Buttongroup050({
  roles = DEFAULT_ROLES,
  defaultValue = "editor",
  hint = "Роль включает все права, что правее неё.",
  label = "Роль участника",
  name = "buttongroup-050",
  accent,
  className,
  style,
  ...props
}: Buttongroup050Props) {
  const palette = {
    ...(accent ? { "--vibeui-buttongroup-050-accent": accent } : null),
    ...style,
  } as CSSProperties

  return (
    <>
      <style href="vibeui-buttongroup-050" precedence="medium">
        {STYLES}
      </style>
      <fieldset
        {...props}
        data-vibeui-block="buttongroup-050"
        className={className}
        style={palette}
      >
        <legend>{label}</legend>
        <div data-part="track">
          {roles.map((role) => (
            <label key={role.id} data-part="step">
              <input
                type="radio"
                name={name}
                value={role.id}
                defaultChecked={role.id === defaultValue}
              />
              <span data-part="name">{role.label}</span>
              <span data-part="scope">{role.scope}</span>
            </label>
          ))}
        </div>
        <p data-part="hint">
          <svg viewBox="0 0 24 24" aria-hidden="true">
            <path d="M12 8h.01M11 12h1v5h1M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18" />
          </svg>
          <span>{hint}</span>
        </p>
      </fieldset>
    </>
  )
}