Inputs
Checked Branches
A multi-select cascader: ticking a parent switches on the whole branch, a partial selection shows as the third checkbox state, and the result is echoed as chips below.
- cascader
- multiselect
- checkbox
- tree
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/cascader-007?lang=en
Newsletter topics
выбрано 2- РазработкаФронтенд
- РазработкаБэкенд
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 "cascader-007" (Checked Branches) 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/cascader-007.json
Registry item: https://vibeui.ru/r/cascader-007.json
Installs to: components/vibeui/cascader-007.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 multi-select cascader: ticking a parent switches on the whole branch, a partial selection shows as the third checkbox state, and the result is echoed as chips below.
A cascader with checkboxes and inheritance: a parent toggles its whole branch, a partial selection reads as the third state, and picks are echoed as chips. One file, zero dependencies.
## 3. How to use it
import { Cascader007 } from "@/components/vibeui/cascader-007"
<Cascader007 heading="Newsletter topics" accent="#4338ca" />
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-cascader-007-* palette — do not swap it for your theme tokens
- deriving the parent state from its children: a parent with its own state eventually drifts from the branch
- the third state through a ref: indeterminate has no HTML attribute and cannot be set from markup
- the "picked of total" counter on the parent — a collapsed branch otherwise hides how much is ticked
- the chips below: in a scrolling list the selection cannot be taken in at a glance otherwise
- the panel's own light surface: dark text disappears on the dark catalogue card
## 6. You may change
- the panel heading through heading
- the accent colour through accent
- the set of branches through groups
- the height of the scrolling tree in CSS
## 7. Rules
- The tree here is exactly two levels: a third one needs recursion and indeterminate recomputed over the subtree.
- A pick is keyed by the "parent → child" string, so identically named leaves from different branches never collide.
- Clicking a partially ticked parent completes the branch instead of clearing it: familiar, but verify it on your data.
- 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/cascader-007.jsonhttps://vibeui.ru/r/cascader-007.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-cascader-007-*. Клиентский: список выбранных ключей «родитель → ребёнок» живёт в useState. Родительская галочка не хранит своего состояния — checked и indeterminate вычисляются из детей, поэтому рассинхронизация невозможна. Третье состояние ставится ref-колбэком: у input.indeterminate нет HTML-атрибута. Строки подсвечиваются через :has(input:focus-visible), поэтому фокус виден на всей строке, а не на самом чекбоксе.
Component source
The same file your agent installs. Here in case you would rather copy it by hand.
"use client"
import { useState } from "react"
import type { CSSProperties } from "react"
export type Cascader007Group = {
label: string
children: string[]
}
export type Cascader007Props = {
heading?: string
groups?: Cascader007Group[]
accent?: string
className?: string
style?: CSSProperties
}
// Идея компонента: каскад с множественным выбором. Галочка на родителе
// включает всю ветку, снятие — выключает; частичный выбор показан третьим
// состоянием (indeterminate), иначе половинчатая ветка выглядит как
// невыбранная и её отмечают повторно. Итог собран чипами внизу: по дереву
// с прокруткой нельзя понять, сколько всего набрано.
const STYLES = `
:where([data-vibeui-block="cascader-007"]){
--vibeui-cascader-007-bg:oklch(1 0 0);
--vibeui-cascader-007-fg:oklch(0.23 0.014 275);
--vibeui-cascader-007-muted:oklch(0.55 0.012 275);
--vibeui-cascader-007-border:oklch(0.9 0.006 275);
--vibeui-cascader-007-accent:oklch(0.53 0.2 275);
--vibeui-cascader-007-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="cascader-007"]{
display:flex;flex-direction:column;gap:0.625rem;
width:100%;max-width:23rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-cascader-007-bg);color:var(--vibeui-cascader-007-fg);
border:1px solid var(--vibeui-cascader-007-border);border-radius:1rem;
font-family:var(--vibeui-cascader-007-font);
box-shadow:0 18px 40px -32px oklch(0.2 0.03 275 / 55%);
}
[data-vibeui-block="cascader-007"] *{box-sizing:border-box}
[data-vibeui-block="cascader-007"] [data-part="head"]{
display:flex;align-items:baseline;justify-content:space-between;gap:0.5rem;
}
[data-vibeui-block="cascader-007"] [data-part="heading"]{
margin:0;font-size:0.8125rem;font-weight:650;letter-spacing:-0.01em;
}
[data-vibeui-block="cascader-007"] [data-part="total"]{
font-size:0.6875rem;color:var(--vibeui-cascader-007-muted);
}
[data-vibeui-block="cascader-007"] [data-part="tree"]{
display:flex;flex-direction:column;gap:0.25rem;margin:0;padding:0;list-style:none;
max-height:12rem;overflow:auto;overscroll-behavior:contain;
}
[data-vibeui-block="cascader-007"] [data-part="branch"]{
display:flex;flex-direction:column;gap:0.125rem;margin:0;padding:0;list-style:none;
padding-left:1.0625rem;border-left:1px solid var(--vibeui-cascader-007-border);
margin-left:0.5rem;
}
[data-vibeui-block="cascader-007"] [data-part="row"]{
display:flex;align-items:center;gap:0.5rem;
padding:0.25rem 0.375rem;border-radius:0.5rem;cursor:pointer;
transition:background-color .14s ease;
}
[data-vibeui-block="cascader-007"] [data-part="row"]:hover{
background:color-mix(in oklab,var(--vibeui-cascader-007-accent) 8%,transparent);
}
[data-vibeui-block="cascader-007"] [data-part="row"]:has(input:focus-visible){
outline:2px solid var(--vibeui-cascader-007-accent);outline-offset:-2px;
}
[data-vibeui-block="cascader-007"] [data-part="row"][data-level="parent"]{
font-weight:600;font-size:0.8125rem;
}
[data-vibeui-block="cascader-007"] [data-part="row"][data-level="child"]{
font-size:0.78125rem;
}
[data-vibeui-block="cascader-007"] input[type="checkbox"]{
flex:0 0 auto;width:0.9375rem;height:0.9375rem;margin:0;
accent-color:var(--vibeui-cascader-007-accent);
}
[data-vibeui-block="cascader-007"] [data-part="row"] span{
flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
}
[data-vibeui-block="cascader-007"] [data-part="badge"]{
flex:0 0 auto;font-size:0.6875rem;font-weight:500;
color:var(--vibeui-cascader-007-muted);
}
[data-vibeui-block="cascader-007"] [data-part="chips"]{
display:flex;flex-wrap:wrap;gap:0.25rem;margin:0;padding:0.5rem 0 0;list-style:none;
border-top:1px solid var(--vibeui-cascader-007-border);
}
[data-vibeui-block="cascader-007"] [data-part="chip"]{
display:inline-flex;align-items:center;gap:0.25rem;
padding:0.1875rem 0.4375rem;border-radius:999px;
background:color-mix(in oklab,var(--vibeui-cascader-007-accent) 14%,transparent);
color:var(--vibeui-cascader-007-accent);
font-size:0.6875rem;font-weight:600;
}
[data-vibeui-block="cascader-007"] [data-part="chip"] small{
font-weight:400;opacity:.75;
}
[data-vibeui-block="cascader-007"] [data-part="none"]{
margin:0.5rem 0 0;padding-top:0.5rem;font-size:0.6875rem;
color:var(--vibeui-cascader-007-muted);
border-top:1px solid var(--vibeui-cascader-007-border);
}
@media (prefers-reduced-motion:reduce){
[data-vibeui-block="cascader-007"] *{animation:none!important;transition:none!important}
}
`
const DEFAULT_GROUPS: Cascader007Group[] = [
{
label: "Разработка",
children: ["Фронтенд", "Бэкенд", "Мобильные"],
},
{
label: "Дизайн",
children: ["Продуктовый", "Графический"],
},
{
label: "Маркетинг",
children: ["Контент", "Перформанс", "Партнёрства"],
},
]
function keyOf(group: string, child: string) {
return `${group} → ${child}`
}
/**
* Каскад с галочками: родитель включает всю ветку, частичный выбор виден третьим состоянием.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Cascader007({
heading = "Направления рассылки",
groups = DEFAULT_GROUPS,
accent,
className,
style,
}: Cascader007Props) {
const [selected, setSelected] = useState<string[]>([
keyOf("Разработка", "Фронтенд"),
keyOf("Разработка", "Бэкенд"),
])
const toggleChild = (group: string, child: string) => {
const key = keyOf(group, child)
setSelected((current) =>
current.includes(key)
? current.filter((item) => item !== key)
: [...current, key],
)
}
const toggleGroup = (group: Cascader007Group) => {
const keys = group.children.map((child) => keyOf(group.label, child))
setSelected((current) =>
keys.every((key) => current.includes(key))
? current.filter((item) => !keys.includes(item))
: [...current.filter((item) => !keys.includes(item)), ...keys],
)
}
const palette = {
...(accent ? { "--vibeui-cascader-007-accent": accent } : null),
...style,
} as CSSProperties
return (
<>
<style href="vibeui-cascader-007" precedence="medium">
{STYLES}
</style>
<div
data-vibeui-block="cascader-007"
className={className}
style={palette}
>
<div data-part="head">
<p data-part="heading">{heading}</p>
<span data-part="total" aria-live="polite">
выбрано {selected.length}
</span>
</div>
<ul data-part="tree">
{groups.map((group) => {
const keys = group.children.map((child) =>
keyOf(group.label, child),
)
const picked = keys.filter((key) => selected.includes(key))
const all = picked.length === keys.length
const some = picked.length > 0 && !all
return (
<li key={group.label}>
<label data-part="row" data-level="parent">
<input
type="checkbox"
checked={all}
ref={(node) => {
if (node) {
node.indeterminate = some
}
}}
onChange={() => toggleGroup(group)}
/>
<span>{group.label}</span>
<span data-part="badge">
{picked.length}/{keys.length}
</span>
</label>
<ul data-part="branch">
{group.children.map((child) => (
<li key={child}>
<label data-part="row" data-level="child">
<input
type="checkbox"
checked={selected.includes(keyOf(group.label, child))}
onChange={() => toggleChild(group.label, child)}
/>
<span>{child}</span>
</label>
</li>
))}
</ul>
</li>
)
})}
</ul>
{selected.length ? (
<ul data-part="chips">
{selected.map((key) => (
<li key={key} data-part="chip">
<small>{key.split(" → ")[0]}</small>
{key.split(" → ")[1]}
</li>
))}
</ul>
) : (
<p data-part="none">
Ни одно направление не выбрано — письмо не уйдёт никому.
</p>
)}
</div>
</>
)
}