Checkbox
Parent Checkbox
A parent checkbox with an indeterminate state: with only some children checked it shows a dash, not emptiness.
- checkbox
- indeterminate
- group
- tree
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/checkbox-003?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-003" (Parent Checkbox) 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-003.json
Registry item: https://vibeui.ru/r/checkbox-003.json
Installs to: components/vibeui/checkbox-003.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 parent checkbox with an indeterminate state: with only some children checked it shows a dash, not emptiness.
A checkbox group with a parent: "select all", an indeterminate state on partial selection and a counter. Zero dependencies, one file.
## 3. How to use it
import { Checkbox003 } from "@/components/vibeui/checkbox-003"
<Checkbox003 items={items} defaultValue={["Catalog"]} onChange={setValue} />
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-003-* palette — do not swap it for your theme tokens
- setting indeterminate in an effect: it cannot be an attribute
- distinct shapes for checked and indeterminate — a tick and a dash
- aria-controls linking the parent to the group
- the indent on children: hierarchy shows in shape, not only order
- the counter under the list
## 6. You may change
- the items array and the initial defaultValue
- legend — the group's name
- the onChange handler
- the accent through the accent prop
## 7. Rules
- One level of nesting: a tree needs a recursive component and a different state model.
- The parent selects nothing on its own — it reflects the children and toggles them together.
- The indeterminate state must not be colour-only: screen readers announce the property itself.
- 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-003.jsonhttps://vibeui.ru/r/checkbox-003.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-checkbox-003-*. Клиентский: "use client". Свойство indeterminate живёт только в DOM и не задаётся атрибутом, поэтому его ставит эффект по ссылке на узел. Галочка и черта нарисованы псевдоэлементами и различаются формой, а не только цветом.
Component source
The same file your agent installs. Here in case you would rather copy it by hand.
"use client"
import { useEffect, useId, useRef, useState } from "react"
import type { ComponentPropsWithoutRef, CSSProperties } from "react"
export type Checkbox003Props = Omit<
ComponentPropsWithoutRef<"fieldset">,
"children" | "onChange"
> & {
legend?: string
items?: string[]
defaultValue?: string[]
onChange?: (value: string[]) => void
accent?: string
}
// Идея компонента: родительский чекбокс с промежуточным состоянием. Когда
// отмечена часть детей, родитель не «выключен» и не «включён» — он показывает
// черту. Это состояние нельзя задать атрибутом в разметке: indeterminate
// живёт только в DOM, поэтому его ставит эффект.
const STYLES = `
:where([data-vibeui-block="checkbox-003"]){
--vibeui-checkbox-003-bg:oklch(1 0 0);
--vibeui-checkbox-003-fg:oklch(0.22 0.014 265);
--vibeui-checkbox-003-muted:oklch(0.56 0.014 265);
--vibeui-checkbox-003-border:oklch(0.88 0.008 265);
--vibeui-checkbox-003-accent:oklch(0.55 0.17 265);
--vibeui-checkbox-003-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="checkbox-003"]{
display:flex;flex-direction:column;gap:0.375rem;
width:100%;max-width:18rem;box-sizing:border-box;
margin:0;padding:0.875rem;
border:1px solid var(--vibeui-checkbox-003-border);border-radius:0.875rem;
background:var(--vibeui-checkbox-003-bg);
font-family:var(--vibeui-checkbox-003-font);color:var(--vibeui-checkbox-003-fg);
}
/* legend у fieldset садится на рамку и обрезается — float возвращает
его в поток обычной строкой. */
[data-vibeui-block="checkbox-003"] legend{float:left;width:100%;padding:0;margin-bottom:0.25rem;font-size:0.8125rem;font-weight:650}
[data-vibeui-block="checkbox-003"] label{
display:flex;align-items:center;gap:0.5rem;
min-height:2rem;font-size:0.875rem;cursor:pointer;
}
/* Дети со сдвигом: иерархия видна отступом, а не только порядком. */
[data-vibeui-block="checkbox-003"] [data-part="child"]{padding-left:1.625rem}
[data-vibeui-block="checkbox-003"] input{
appearance:none;flex:none;cursor:pointer;
width:1.125rem;height:1.125rem;margin:0;box-sizing:border-box;
border:1.5px solid var(--vibeui-checkbox-003-border);border-radius:0.3125rem;
background:var(--vibeui-checkbox-003-bg);position:relative;
}
[data-vibeui-block="checkbox-003"] input:checked,
[data-vibeui-block="checkbox-003"] input:indeterminate{
border-color:transparent;background:var(--vibeui-checkbox-003-accent);
}
/* Галочка у отмеченного, черта у промежуточного — разные фигуры. */
[data-vibeui-block="checkbox-003"] 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-003"] 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-003"] input:focus-visible{outline:2px solid var(--vibeui-checkbox-003-accent);outline-offset:2px}
[data-vibeui-block="checkbox-003"] [data-part="count"]{margin-top:0.25rem;font-size:0.75rem;color:var(--vibeui-checkbox-003-muted)}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="checkbox-003"] *{animation:none!important;transition:none!important}}
`
const DEFAULT_ITEMS = [
"Каталог компонентов",
"Страница компонента",
"Инструкция для агента",
"Тёмная тема",
]
/**
* Родительский чекбокс с промежуточным состоянием и группой детей.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Checkbox003({
legend = "Что перенести в проект",
items = DEFAULT_ITEMS,
defaultValue = ["Каталог компонентов", "Тёмная тема"],
onChange,
accent,
className,
style,
...props
}: Checkbox003Props) {
const id = useId()
const [value, setValue] = useState<string[]>(defaultValue)
const parent = useRef<HTMLInputElement>(null)
const all = value.length === items.length
const some = value.length > 0 && !all
// indeterminate нельзя выставить атрибутом: это свойство DOM-узла.
useEffect(() => {
if (parent.current) parent.current.indeterminate = some
}, [some])
const palette = {
...(accent ? { "--vibeui-checkbox-003-accent": accent } : null),
...style,
} as CSSProperties
const update = (next: string[]) => {
setValue(next)
onChange?.(next)
}
return (
<>
<style href="vibeui-checkbox-003" precedence="medium">
{STYLES}
</style>
<fieldset
{...props}
data-vibeui-block="checkbox-003"
className={className}
style={palette}
>
<legend>{legend}</legend>
<label>
<input
ref={parent}
type="checkbox"
checked={all}
aria-controls={`${id}-group`}
onChange={() => update(all ? [] : [...items])}
/>
Выбрать всё
</label>
<div id={`${id}-group`}>
{items.map((item) => (
<label key={item} data-part="child">
<input
type="checkbox"
checked={value.includes(item)}
onChange={() =>
update(
value.includes(item)
? value.filter((entry) => entry !== item)
: [...value, item],
)
}
/>
{item}
</label>
))}
</div>
<span data-part="count">
Отмечено {value.length} из {items.length}
</span>
</fieldset>
</>
)
}