Button Group

Table Density

Table density with a live sample: the checked radio rewrites the row-height variable on the root and the three rows below rebuild themselves without JS.

  • buttongroup
  • density
  • table
  • css-only

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-027?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-027" (Table Density) 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-027.json

Registry item: https://vibeui.ru/r/buttongroup-027.json
Installs to: components/vibeui/buttongroup-027.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
Table density with a live sample: the checked radio rewrites the row-height variable on the root and the three rows below rebuild themselves without JS.

A table density switcher with a row sample that rebuilds itself in pure CSS. Zero dependencies, one file, a server component.

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

<Buttongroup027
  compactLabel="Compact"
  regularLabel="Regular"
  roomyLabel="Roomy"
  defaultValue="regular"
/>

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-027-* palette — do not swap it for your theme tokens
- declaring the row variable inside :where(): at normal specificity the :has rules could not override it
- the sample under the group: words like "compact" and "roomy" cannot convey a quarter-line difference
- aria-hidden on the sample — it adds nothing to the density name
- the matching spacing in the glyph and in the sample: diverging pictures teach a lie
- the z-index on the selected and focused segment with collapsed borders

## 6. You may change
- the option captions through compactLabel, regularLabel and roomyLabel
- the initial density through defaultValue
- the accessible group name through label
- the form field name through name and the accent through accent

## 7. Rules
- There are exactly three options: the :has rules are written on nth-of-type and do not expect a fourth.
- The sample is three invented rows: there is no need to feed it real data.
- The component does not restyle your table: apply the value yourself 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-027.json
https://vibeui.ru/r/buttongroup-027.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в переменных --vibeui-buttongroup-027-*. Серверный: выбор держат radio внутри fieldset. Приём — переменная --vibeui-buttongroup-027-row объявлена в :where() с нулевой специфичностью, а правила вида [data-vibeui-block]:has([data-part="segment"]:nth-of-type(2) input:checked) переопределяют её на корне; образец строк читает переменную и перестраивается сам. Значок сегмента — те же три полосы с тем же просветом, что и в образце: подпись, значок и результат говорят об одном. Образец помечен 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 Buttongroup027Props = Omit<
  ComponentPropsWithoutRef<"fieldset">,
  "children"
> & {
  compactLabel?: string
  regularLabel?: string
  roomyLabel?: string
  defaultValue?: string
  label?: string
  name?: string
  accent?: string
}

// Идея компонента: переключатель плотности, который показывает результат
// на месте. Под сцепкой лежат три строки-образца, и высота их ячеек берётся
// из переменной --vibeui-buttongroup-027-row; выбранный radio меняет эту
// переменную на корне через :has, поэтому образец перестраивается без единой
// строки JS. Значок каждого сегмента — те же три полосы с тем же просветом,
// что и в образце: подпись, образец и значок говорят об одном.
const STYLES = `
:where([data-vibeui-block="buttongroup-027"]){
--vibeui-buttongroup-027-surface:oklch(1 0 0);
--vibeui-buttongroup-027-fg:oklch(0.25 0.016 265);
--vibeui-buttongroup-027-muted:oklch(0.57 0.014 265);
--vibeui-buttongroup-027-border:oklch(0.89 0.008 265);
--vibeui-buttongroup-027-on:oklch(0.96 0.03 215);
--vibeui-buttongroup-027-accent:oklch(0.48 0.13 215);
--vibeui-buttongroup-027-radius:0.625rem;
--vibeui-buttongroup-027-row:1.75rem;
--vibeui-buttongroup-027-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="buttongroup-027"]{
box-sizing:border-box;display:block;width:100%;max-width:22rem;
margin:0;padding:0;border:0;
font-family:var(--vibeui-buttongroup-027-font);
}
[data-vibeui-block="buttongroup-027"] *{box-sizing:border-box}
[data-vibeui-block="buttongroup-027"] legend{
position:absolute;width:1px;height:1px;padding:0;margin:-1px;
overflow:hidden;clip-path:inset(50%);white-space:nowrap;
}
[data-vibeui-block="buttongroup-027"] [data-part="track"]{display:flex;isolation:isolate}
[data-vibeui-block="buttongroup-027"] [data-part="segment"]{
position:relative;z-index:0;flex:1 1 0;min-width:0;
display:inline-flex;align-items:center;justify-content:center;gap:0.375rem;
height:2.375rem;padding:0 0.5rem;margin-inline-start:-1px;
border:1px solid var(--vibeui-buttongroup-027-border);
background:var(--vibeui-buttongroup-027-surface);
color:var(--vibeui-buttongroup-027-muted);
font-size:0.75rem;font-weight:650;line-height:1;white-space:nowrap;cursor:pointer;
transition:background-color .16s ease,color .16s ease,border-color .16s ease;
}
[data-vibeui-block="buttongroup-027"] [data-part="segment"]:first-child{
margin-inline-start:0;
border-start-start-radius:var(--vibeui-buttongroup-027-radius);
border-end-start-radius:var(--vibeui-buttongroup-027-radius);
}
[data-vibeui-block="buttongroup-027"] [data-part="segment"]:last-child{
border-start-end-radius:var(--vibeui-buttongroup-027-radius);
border-end-end-radius:var(--vibeui-buttongroup-027-radius);
}
[data-vibeui-block="buttongroup-027"] input{
position:absolute;inset:0;width:100%;height:100%;margin:0;opacity:0;cursor:pointer;
}
[data-vibeui-block="buttongroup-027"] [data-part="glyph"]{
display:flex;flex-direction:column;justify-content:center;
width:0.9375rem;height:0.9375rem;flex:none;
}
[data-vibeui-block="buttongroup-027"] [data-part="glyph"] i{
display:block;height:2px;border-radius:1px;background:currentColor;
}
[data-vibeui-block="buttongroup-027"] [data-density="compact"] i + i{margin-top:1px}
[data-vibeui-block="buttongroup-027"] [data-density="regular"] i + i{margin-top:3px}
[data-vibeui-block="buttongroup-027"] [data-density="roomy"] i + i{margin-top:5px}
[data-vibeui-block="buttongroup-027"] [data-part="segment"]:hover{color:var(--vibeui-buttongroup-027-fg)}
[data-vibeui-block="buttongroup-027"] [data-part="segment"]:has(input:checked){
z-index:1;
background:var(--vibeui-buttongroup-027-on);
border-color:var(--vibeui-buttongroup-027-accent);
color:var(--vibeui-buttongroup-027-accent);
}
[data-vibeui-block="buttongroup-027"] [data-part="segment"]:has(input:focus-visible){
z-index:2;outline:2px solid var(--vibeui-buttongroup-027-accent);outline-offset:1px;
}
/* Выбор меняет переменную на корне — образец перестраивается сам. */
[data-vibeui-block="buttongroup-027"]:has([data-part="segment"]:nth-of-type(1) input:checked){--vibeui-buttongroup-027-row:1.375rem}
[data-vibeui-block="buttongroup-027"]:has([data-part="segment"]:nth-of-type(2) input:checked){--vibeui-buttongroup-027-row:1.875rem}
[data-vibeui-block="buttongroup-027"]:has([data-part="segment"]:nth-of-type(3) input:checked){--vibeui-buttongroup-027-row:2.5rem}
[data-vibeui-block="buttongroup-027"] [data-part="sample"]{
margin-top:0.625rem;padding:0 0.75rem;
border:1px solid var(--vibeui-buttongroup-027-border);
border-radius:var(--vibeui-buttongroup-027-radius);
background:var(--vibeui-buttongroup-027-surface);
}
[data-vibeui-block="buttongroup-027"] [data-part="line"]{
display:flex;align-items:center;gap:0.5rem;
height:var(--vibeui-buttongroup-027-row);
color:var(--vibeui-buttongroup-027-muted);
font-size:0.75rem;line-height:1;
transition:height .2s ease;
}
[data-vibeui-block="buttongroup-027"] [data-part="line"] + [data-part="line"]{
border-top:1px solid oklch(0.94 0.005 265);
}
[data-vibeui-block="buttongroup-027"] [data-part="line"] span:first-child{
flex:1 1 auto;color:var(--vibeui-buttongroup-027-fg);font-weight:600;
}
[data-vibeui-block="buttongroup-027"] [data-part="line"] span:last-child{font-variant-numeric:tabular-nums}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="buttongroup-027"] *{animation:none!important;transition:none!important}}
`

const SAMPLE = [
  ["Договор № 118", "12.04"],
  ["Акт сверки", "09.04"],
  ["Счёт на оплату", "02.04"],
]

/**
 * Плотность таблицы с живым образцом строк под сцепкой, без JS.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Buttongroup027({
  compactLabel = "Плотно",
  regularLabel = "Обычно",
  roomyLabel = "Свободно",
  defaultValue = "regular",
  label = "Плотность таблицы",
  name = "buttongroup-027",
  accent,
  className,
  style,
  ...props
}: Buttongroup027Props) {
  const options = [
    { id: "compact", label: compactLabel },
    { id: "regular", label: regularLabel },
    { id: "roomy", label: roomyLabel },
  ]

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

  return (
    <>
      <style href="vibeui-buttongroup-027" precedence="medium">
        {STYLES}
      </style>
      <fieldset
        {...props}
        data-vibeui-block="buttongroup-027"
        className={className}
        style={palette}
      >
        <legend>{label}</legend>
        <div data-part="track">
          {options.map((option) => (
            <label key={option.id} data-part="segment">
              <input
                type="radio"
                name={name}
                value={option.id}
                defaultChecked={option.id === defaultValue}
              />
              <span
                data-part="glyph"
                data-density={option.id}
                aria-hidden="true"
              >
                <i />
                <i />
                <i />
              </span>
              <span>{option.label}</span>
            </label>
          ))}
        </div>
        <div data-part="sample" aria-hidden="true">
          {SAMPLE.map(([title, date]) => (
            <div key={title} data-part="line">
              <span>{title}</span>
              <span>{date}</span>
            </div>
          ))}
        </div>
      </fieldset>
    </>
  )
}