Navigation

Collapsible Sidebar

A collapsible sidebar without JS: one variable changes the width, and the labels shrink rather than leave the markup.

  • sidebar
  • collapse
  • no-js
  • navigation

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/sidebar-002?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 "sidebar-002" (Collapsible Sidebar) 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/sidebar-002.json

Registry item: https://vibeui.ru/r/sidebar-002.json
Installs to: components/vibeui/sidebar-002.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 collapsible sidebar without JS: one variable changes the width, and the labels shrink rather than leave the markup.

A collapsible sidebar: a toggle on top, glyphs with labels, counters on the right and a filled active section. Zero dependencies, one file, no client JS.

## 3. How to use it
import { Sidebar002 } from "@/components/vibeui/sidebar-002"

<Sidebar002 items={[{ label: "Components", count: 225 }]} activeLabel="Components" />

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-sidebar-002-* palette — do not swap it for your theme tokens
- the checkbox as the state store: without JS the state lives nowhere else
- changing one width variable instead of a second rule set
- shrinking the labels instead of display:none — they stay accessible and findable
- aria-current="page" on the active section
- the filled active item rather than bold text alone

## 6. You may change
- the items array and the counters
- activeLabel and title
- the expanded width
- the accent through the accent prop

## 7. Rules
- The collapsed state is not remembered between pages: persisting it is the caller's job.
- Collapsed, only glyphs remain: they must be recognisable without a label or carry a tooltip.
- The glyphs are drawn with borders: swap in your set, keeping the 1rem size.
- 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/sidebar-002.json
https://vibeui.ru/r/sidebar-002.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-sidebar-002-*. Серверный: хуков нет, состояние держит чекбокс. Свёрнутый вид получается сменой одной переменной ширины через :has(), а подписи сжимаются до нуля с overflow: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 Sidebar002Item = {
  label: string
  href?: string
  count?: number
}

export type Sidebar002Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "children"
> & {
  items?: Sidebar002Item[]
  activeLabel?: string
  title?: string
  accent?: string
}

// Идея компонента: сворачиваемая боковая навигация без JS. Состояние держит
// чекбокс, ширина меняется одной переменной, а подписи не прячутся display:none
// — они сжимаются до нуля с overflow:hidden, поэтому остаются в дереве
// доступности и находятся поиском по странице.
const STYLES = `
:where([data-vibeui-block="sidebar-002"]){
--vibeui-sidebar-002-width:12.5rem;
--vibeui-sidebar-002-bg:oklch(0.985 0.002 265);
--vibeui-sidebar-002-fg:oklch(0.24 0.014 265);
--vibeui-sidebar-002-muted:oklch(0.56 0.014 265);
--vibeui-sidebar-002-border:oklch(0.91 0.006 265);
--vibeui-sidebar-002-hover:oklch(0.55 0.02 265 / 8%);
--vibeui-sidebar-002-active:oklch(0.55 0.02 265 / 13%);
--vibeui-sidebar-002-accent:oklch(0.55 0.2 262);
--vibeui-sidebar-002-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="sidebar-002"]{
display:flex;flex-direction:column;gap:0.25rem;
width:var(--vibeui-sidebar-002-width);box-sizing:border-box;padding:0.5rem;
background:var(--vibeui-sidebar-002-bg);
border:1px solid var(--vibeui-sidebar-002-border);border-radius:0.875rem;
font-family:var(--vibeui-sidebar-002-font);color:var(--vibeui-sidebar-002-fg);
transition:width .16s ease;
}
/* Свёрнутое состояние — одна переменная ширины, а не второй набор правил. */
[data-vibeui-block="sidebar-002"]:has([data-part="toggle"]:checked){--vibeui-sidebar-002-width:3.5rem}
[data-vibeui-block="sidebar-002"] [data-part="toggle"]{position:absolute;opacity:0;pointer-events:none}
[data-vibeui-block="sidebar-002"] [data-part="switch"]{
display:flex;align-items:center;gap:0.5rem;cursor:pointer;
min-height:2rem;padding:0 0.5rem;border-radius:0.5rem;
font-size:0.75rem;color:var(--vibeui-sidebar-002-muted);
}
[data-vibeui-block="sidebar-002"] [data-part="switch"]:hover{background:var(--vibeui-sidebar-002-hover)}
[data-vibeui-block="sidebar-002"] [data-part="toggle"]:focus-visible + [data-part="switch"]{outline:2px solid var(--vibeui-sidebar-002-accent);outline-offset:-2px}
[data-vibeui-block="sidebar-002"] [data-part="bars"]{
flex:none;width:1rem;height:0.625rem;
border-top:1.5px solid currentColor;border-bottom:1.5px solid currentColor;
}
[data-vibeui-block="sidebar-002"] nav{display:flex;flex-direction:column;gap:0.125rem}
[data-vibeui-block="sidebar-002"] [data-part="row"]{
display:flex;align-items:center;gap:0.5rem;
min-height:2rem;padding:0 0.5rem;border-radius:0.5rem;
color:inherit;text-decoration:none;font-size:0.8125rem;
}
[data-vibeui-block="sidebar-002"] [data-part="row"]:hover{background:var(--vibeui-sidebar-002-hover)}
[data-vibeui-block="sidebar-002"] [data-part="row"]:focus-visible{outline:2px solid var(--vibeui-sidebar-002-accent);outline-offset:-2px}
[data-vibeui-block="sidebar-002"] [data-part="row"][aria-current="page"]{background:var(--vibeui-sidebar-002-active);font-weight:650}
/* Заливка, а не рамка: пустой квадрат с рамкой читается как чекбокс. */
[data-vibeui-block="sidebar-002"] [data-part="glyph"]{
flex:none;width:1rem;height:1rem;border-radius:0.3125rem;
background:var(--vibeui-sidebar-002-muted);opacity:.35;
}
[data-vibeui-block="sidebar-002"] [data-part="row"][aria-current="page"] [data-part="glyph"]{background:var(--vibeui-sidebar-002-accent);opacity:1}
/* Подпись сжимается до нуля, а не скрывается: она остаётся доступной. */
[data-vibeui-block="sidebar-002"] [data-part="text"]{
flex:1 1 auto;min-width:0;overflow:hidden;white-space:nowrap;
transition:opacity .12s ease;
}
[data-vibeui-block="sidebar-002"] [data-part="count"]{
flex:none;font-size:0.6875rem;color:var(--vibeui-sidebar-002-muted);
font-variant-numeric:tabular-nums;
}
[data-vibeui-block="sidebar-002"]:has([data-part="toggle"]:checked) [data-part="text"],
[data-vibeui-block="sidebar-002"]:has([data-part="toggle"]:checked) [data-part="count"]{
flex-basis:0;width:0;opacity:0;
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="sidebar-002"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_ITEMS: Sidebar002Item[] = [
  { label: "Обзор", href: "#" },
  { label: "Компоненты", href: "#", count: 225 },
  { label: "Блоки", href: "#", count: 12 },
  { label: "Настройки", href: "#" },
]

/**
 * Сворачиваемая боковая навигация на чекбоксе: ширина в одной переменной.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Sidebar002({
  items = DEFAULT_ITEMS,
  activeLabel = "Компоненты",
  title = "Свернуть",
  accent,
  className,
  style,
  ...props
}: Sidebar002Props) {
  const palette = {
    ...(accent ? { "--vibeui-sidebar-002-accent": accent } : null),
    ...style,
  } as CSSProperties

  return (
    <>
      <style href="vibeui-sidebar-002" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="sidebar-002"
        className={className}
        style={palette}
      >
        <label>
          <input data-part="toggle" type="checkbox" />
          <span data-part="switch">
            <span data-part="bars" aria-hidden="true" />
            <span data-part="text">{title}</span>
          </span>
        </label>
        <nav aria-label="Разделы">
          {items.map((item) => (
            <a
              key={item.label}
              data-part="row"
              href={item.href ?? "#"}
              aria-current={item.label === activeLabel ? "page" : undefined}
            >
              <span data-part="glyph" aria-hidden="true" />
              <span data-part="text">{item.label}</span>
              {item.count ? <span data-part="count">{item.count}</span> : null}
            </a>
          ))}
        </nav>
      </div>
    </>
  )
}