Checkbox

Row Selection

Table row selection: the action bar appears only with a selection and always names how many rows are picked.

  • checkbox
  • table
  • selection
  • bulk

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/checkbox-006?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 "checkbox-006" (Row Selection) 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/checkbox-006.json

Registry item: https://vibeui.ru/r/checkbox-006.json
Installs to: components/vibeui/checkbox-006.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 row selection: the action bar appears only with a selection and always names how many rows are picked.

Row selection with bulk actions: a header checkbox with an indeterminate state, highlighted rows and a bar with the count. Zero dependencies, one file.

## 3. How to use it
import { Checkbox006 } from "@/components/vibeui/checkbox-006"

<Checkbox006 rows={rows} onChange={setSelected} />

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-checkbox-006-* palette — do not swap it for your theme tokens
- the count in the action bar: "apply to selected" without a number deletes the wrong thing
- the "on this page" wording on the header checkbox — it does not select the database
- the indeterminate header on partial selection
- highlighting selected rows rather than relying on the tick alone
- an aria-label on every row checkbox: a bare "select" is useless

## 6. You may change
- the rows array and its fields
- the actions in the bar
- the onChange handler
- the accent through the accent prop

## 7. Rules
- Selection lives on the current page only: "select everything" is a separate, explicit action.
- Destructive bulk actions need confirmation: the bar is not a place for instant deletion.
- The component neither sorts nor filters: it only selects.
- 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/checkbox-006.json
https://vibeui.ru/r/checkbox-006.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-checkbox-006-*. Клиентский: "use client". Заголовочный чекбокс получает indeterminate через эффект и подписан «выбрать все строки на странице». Выбранные строки подсвечиваются через :has(input:checked). Полоса действий объявлена role="status", поэтому число выбранного проговаривается.

Component source

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

"use client"

import { useEffect, useRef, useState } from "react"
import type { ComponentPropsWithoutRef, CSSProperties } from "react"

export type Checkbox006Row = {
  id: string
  name: string
  meta: string
}

export type Checkbox006Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "children" | "onChange"
> & {
  rows?: Checkbox006Row[]
  defaultValue?: string[]
  onChange?: (value: string[]) => void
  accent?: string
}

// Идея компонента: выбор строк таблицы с полосой действий. Полоса появляется
// только когда что-то выбрано и говорит числом, сколько именно: «применить к
// выбранным» без числа — самый частый способ удалить не то. Заголовочный
// чекбокс отмечает страницу, а не всю базу, и об этом сказано словами.
const STYLES = `
:where([data-vibeui-block="checkbox-006"]){
--vibeui-checkbox-006-bg:oklch(1 0 0);
--vibeui-checkbox-006-fg:oklch(0.22 0.014 265);
--vibeui-checkbox-006-muted:oklch(0.56 0.014 265);
--vibeui-checkbox-006-border:oklch(0.9 0.006 265);
--vibeui-checkbox-006-row:oklch(0.97 0.004 265);
--vibeui-checkbox-006-accent:oklch(0.55 0.17 265);
--vibeui-checkbox-006-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="checkbox-006"]{
display:flex;flex-direction:column;
width:100%;max-width:22rem;box-sizing:border-box;overflow:hidden;
background:var(--vibeui-checkbox-006-bg);
border:1px solid var(--vibeui-checkbox-006-border);border-radius:0.875rem;
font-family:var(--vibeui-checkbox-006-font);color:var(--vibeui-checkbox-006-fg);
}
/* Полоса действий появляется только с выбором и всегда называет число. */
[data-vibeui-block="checkbox-006"] [data-part="bar"]{
display:flex;align-items:center;justify-content:space-between;gap:0.75rem;
padding:0.5rem 0.75rem;
background:color-mix(in oklab,var(--vibeui-checkbox-006-accent) 10%,oklch(1 0 0));
border-bottom:1px solid var(--vibeui-checkbox-006-border);
font-size:0.8125rem;font-weight:600;
}
[data-vibeui-block="checkbox-006"] [data-part="bar"] button{
appearance:none;border:0;background:transparent;cursor:pointer;padding:0;
color:var(--vibeui-checkbox-006-accent);font:inherit;font-size:0.8125rem;font-weight:650;
}
[data-vibeui-block="checkbox-006"] [data-part="head"],
[data-vibeui-block="checkbox-006"] [data-part="row"]{
display:grid;grid-template-columns:auto 1fr auto;align-items:center;gap:0.625rem;
padding:0.5rem 0.75rem;border-bottom:1px solid var(--vibeui-checkbox-006-border);
font-size:0.8125rem;
}
[data-vibeui-block="checkbox-006"] [data-part="row"]:last-child{border-bottom:0}
[data-vibeui-block="checkbox-006"] [data-part="row"]:has(input:checked){background:var(--vibeui-checkbox-006-row)}
[data-vibeui-block="checkbox-006"] [data-part="head"]{color:var(--vibeui-checkbox-006-muted);font-size:0.75rem}
[data-vibeui-block="checkbox-006"] input{
appearance:none;flex:none;cursor:pointer;position:relative;
width:1.0625rem;height:1.0625rem;margin:0;box-sizing:border-box;
border:1.5px solid var(--vibeui-checkbox-006-border);border-radius:0.3125rem;
background:var(--vibeui-checkbox-006-bg);
}
[data-vibeui-block="checkbox-006"] input:checked,
[data-vibeui-block="checkbox-006"] input:indeterminate{border-color:transparent;background:var(--vibeui-checkbox-006-accent)}
[data-vibeui-block="checkbox-006"] input:checked::after{
content:"";position:absolute;left:50%;top:50%;
width:0.25rem;height:0.4375rem;margin:-0.3125rem 0 0 -0.125rem;
border-right:2px solid oklch(0.99 0.01 265);border-bottom:2px solid oklch(0.99 0.01 265);
transform:rotate(45deg);
}
[data-vibeui-block="checkbox-006"] input:indeterminate::after{
content:"";position:absolute;left:50%;top:50%;
width:0.5rem;height:2px;margin:-1px 0 0 -0.25rem;
background:oklch(0.99 0.01 265);border-radius:9999px;
}
[data-vibeui-block="checkbox-006"] input:focus-visible{outline:2px solid var(--vibeui-checkbox-006-accent);outline-offset:2px}
[data-vibeui-block="checkbox-006"] [data-part="name"]{font-weight:600}
[data-vibeui-block="checkbox-006"] [data-part="meta"]{color:var(--vibeui-checkbox-006-muted);font-size:0.75rem;justify-self:end}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="checkbox-006"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_ROWS: Checkbox006Row[] = [
  { id: "1", name: "Акт № 42-118", meta: "12 480 ₽" },
  { id: "2", name: "Акт № 42-119", meta: "8 900 ₽" },
  { id: "3", name: "Счёт № 300", meta: "24 000 ₽" },
  { id: "4", name: "Счёт № 301", meta: "6 200 ₽" },
]

/**
 * Выбор строк таблицы: полоса действий с числом выбранного.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Checkbox006({
  rows = DEFAULT_ROWS,
  defaultValue = [],
  onChange,
  accent,
  className,
  style,
  ...props
}: Checkbox006Props) {
  const [value, setValue] = useState<string[]>(defaultValue)
  const head = useRef<HTMLInputElement>(null)

  const all = value.length === rows.length && rows.length > 0
  const some = value.length > 0 && !all

  useEffect(() => {
    if (head.current) head.current.indeterminate = some
  }, [some])

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

  const update = (next: string[]) => {
    setValue(next)
    onChange?.(next)
  }

  return (
    <>
      <style href="vibeui-checkbox-006" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="checkbox-006"
        className={className}
        style={palette}
      >
        {value.length ? (
          <div data-part="bar" role="status">
            <span>Выбрано на странице: {value.length}</span>
            <button type="button" onClick={() => update([])}>
              Снять выбор
            </button>
          </div>
        ) : null}
        <div data-part="head">
          <input
            ref={head}
            type="checkbox"
            checked={all}
            aria-label="Выбрать все строки на странице"
            onChange={() => update(all ? [] : rows.map((row) => row.id))}
          />
          <span>Документ</span>
          <span data-part="meta">Сумма</span>
        </div>
        {rows.map((row) => (
          <label key={row.id} data-part="row">
            <input
              type="checkbox"
              checked={value.includes(row.id)}
              aria-label={`Выбрать ${row.name}`}
              onChange={() =>
                update(
                  value.includes(row.id)
                    ? value.filter((item) => item !== row.id)
                    : [...value, row.id],
                )
              }
            />
            <span data-part="name">{row.name}</span>
            <span data-part="meta">{row.meta}</span>
          </label>
        ))}
      </div>
    </>
  )
}