Navigation

Pill Tabs

Pill tabs in the manner of a system segmented control: the active pill is filled with the accent, thin dividers separate the rest.

  • tabs
  • segmented
  • pills
  • aria

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/tabs-004?lang=en

1 284визита за последние 24 часа, на 8% больше вчерашнего.
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 "tabs-004" (Pill Tabs) 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/tabs-004.json

Registry item: https://vibeui.ru/r/tabs-004.json
Installs to: components/vibeui/tabs-004.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
Pill tabs in the manner of a system segmented control: the active pill is filled with the accent, thin dividers separate the rest.

A segmented control built on tabs: pills in a shared track, the active one filled with the accent, neighbours separated by thin lines. Arrows, Home and End move the selection. Zero dependencies, one file, its own palette.

## 3. How to use it
import { Tabs004 } from "@/components/vibeui/tabs-004"

<Tabs004
  defaultId="week"
  items={[
    { id: "day", label: "Day", content: "1,284 visits" },
    { id: "week", label: "Week", content: "9,470 visits" },
  ]}
/>

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-tabs-004-* palette — do not swap it for your theme tokens (bg-secondary, text-secondary-foreground and the like)
- hiding the divider at the edges of the active pill: a line running into the fill reads as dirt on the seam
- the filled active pill together with its text colour — the contrast has to stay sufficient on the accent
- the WAI-ARIA tabs markup: role="tablist", role="tab" with aria-selected and aria-controls, role="tabpanel" with aria-labelledby
- the roving tabindex: 0 on the active tab and -1 on the rest
- moving focus together with the selection on arrow keys

## 6. You may change
- the items array: ids, labels and panel content
- defaultId — which tab starts open
- the accent through the accent prop — it colours the active pill
- the pill radius and the track height

## 7. Rules
- A segmented control is meant for two to four short options: long labels do not fit.
- This switches content, it is not navigation: moving between pages needs links.
- The component is a client one: "use client" is there for the state and the keyboard.
- 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/tabs-004.json
https://vibeui.ru/r/tabs-004.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-tabs-004-*. Клиентский: "use client" ради выбранной вкладки и клавиатуры. Разделитель — ::before у каждой вкладки, кроме первой; рядом с активной пилюлей он гасится правилами по aria-selected, иначе линия у края заливки выглядит грязью. Разметка следует паттерну tabs из WAI-ARIA, в Tab-порядке живёт только активная вкладка.

Component source

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

"use client"

import { useRef, useState } from "react"
import type { CSSProperties, KeyboardEvent, ReactNode } from "react"

export type Tabs004Item = {
  id: string
  label: string
  content?: ReactNode
}

export type Tabs004Props = {
  items?: Tabs004Item[]
  defaultId?: string
  accent?: string
  className?: string
  style?: CSSProperties
}

// Идея компонента: вкладки-пилюли, где активная залита акцентом, а между
// неактивными стоят тонкие разделители — как в системном сегментированном
// переключателе. Разделитель рисуется псевдоэлементом и гаснет у соседей
// активной пилюли, иначе рядом с заливкой он выглядит грязью.
const STYLES = `
:where([data-vibeui-block="tabs-004"]){
--vibeui-tabs-004-bg:oklch(1 0 0);
--vibeui-tabs-004-track:oklch(0.96 0.003 265);
--vibeui-tabs-004-fg:oklch(0.22 0.014 265);
--vibeui-tabs-004-muted:oklch(0.52 0.014 265);
--vibeui-tabs-004-border:oklch(0.91 0.006 265);
--vibeui-tabs-004-line:oklch(0.86 0.006 265);
--vibeui-tabs-004-accent:oklch(0.55 0.2 262);
--vibeui-tabs-004-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="tabs-004"]{
box-sizing:border-box;width:100%;max-width:26rem;padding:0.75rem;
background:var(--vibeui-tabs-004-bg);color:var(--vibeui-tabs-004-fg);
border:1px solid var(--vibeui-tabs-004-border);border-radius:0.875rem;
font-family:var(--vibeui-tabs-004-font);
}
[data-vibeui-block="tabs-004"] [data-part="list"]{
display:inline-flex;padding:0.1875rem;box-sizing:border-box;
background:var(--vibeui-tabs-004-track);border-radius:999px;
}
[data-vibeui-block="tabs-004"] [data-part="tab"]{
position:relative;appearance:none;border:0;background:none;cursor:pointer;
min-height:1.875rem;padding:0 0.875rem;border-radius:999px;
font:inherit;font-size:0.8125rem;font-weight:550;white-space:nowrap;
color:var(--vibeui-tabs-004-muted);
transition:background-color .18s ease,color .18s ease;
}
[data-vibeui-block="tabs-004"] [data-part="tab"]:hover{color:var(--vibeui-tabs-004-fg)}
[data-vibeui-block="tabs-004"] [data-part="tab"]:focus-visible{outline:2px solid var(--vibeui-tabs-004-accent);outline-offset:2px}
[data-vibeui-block="tabs-004"] [data-part="tab"][aria-selected="true"]{
background:var(--vibeui-tabs-004-accent);color:oklch(1 0 0);
box-shadow:0 1px 2px oklch(0.2 0.02 265 / 18%);
}
/* Разделитель между соседями; у краёв активной пилюли он не нужен. */
[data-vibeui-block="tabs-004"] [data-part="tab"] + [data-part="tab"]::before{
content:"";position:absolute;left:-0.0625rem;top:25%;bottom:25%;width:1px;
background:var(--vibeui-tabs-004-line);
}
[data-vibeui-block="tabs-004"] [data-part="tab"][aria-selected="true"]::before,
[data-vibeui-block="tabs-004"] [data-part="tab"][aria-selected="true"] + [data-part="tab"]::before{background:transparent}
[data-vibeui-block="tabs-004"] [data-part="panel"]{
margin-top:0.875rem;font-size:0.875rem;line-height:1.6;color:var(--vibeui-tabs-004-muted);
}
[data-vibeui-block="tabs-004"] [data-part="panel"]:focus-visible{outline:2px solid var(--vibeui-tabs-004-accent);outline-offset:3px;border-radius:0.5rem}
[data-vibeui-block="tabs-004"] [data-part="figure"]{
display:block;font-size:1.5rem;font-weight:700;letter-spacing:-0.02em;
color:var(--vibeui-tabs-004-fg);font-variant-numeric:tabular-nums;
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="tabs-004"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_ITEMS: Tabs004Item[] = [
  {
    id: "day",
    label: "Сутки",
    content: (
      <>
        <b data-part="figure">1 284</b>
        визита за последние 24 часа, на 8% больше вчерашнего.
      </>
    ),
  },
  {
    id: "week",
    label: "Неделя",
    content: (
      <>
        <b data-part="figure">9 470</b>
        визитов за семь дней, пик пришёлся на четверг.
      </>
    ),
  },
  {
    id: "month",
    label: "Месяц",
    content: (
      <>
        <b data-part="figure">38 902</b>
        визита за месяц, половина — из поиска.
      </>
    ),
  },
]

/**
 * Вкладки-пилюли: активная залита акцентом, соседи разделены линиями.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Tabs004({
  items = DEFAULT_ITEMS,
  defaultId,
  accent,
  className,
  style,
}: Tabs004Props) {
  const [active, setActive] = useState(defaultId ?? items[0]?.id)
  const listRef = useRef<HTMLDivElement>(null)

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

  const index = Math.max(
    0,
    items.findIndex((item) => item.id === active),
  )

  function onKeyDown(event: KeyboardEvent<HTMLDivElement>) {
    const keys = ["ArrowLeft", "ArrowRight", "Home", "End"]

    if (!keys.includes(event.key)) {
      return
    }

    event.preventDefault()

    const last = items.length - 1
    const next =
      event.key === "Home"
        ? 0
        : event.key === "End"
          ? last
          : event.key === "ArrowLeft"
            ? (index - 1 + items.length) % items.length
            : (index + 1) % items.length

    setActive(items[next].id)
    listRef.current
      ?.querySelectorAll<HTMLButtonElement>('[data-part="tab"]')
      [next]?.focus()
  }

  const current = items[index]

  return (
    <>
      <style href="vibeui-tabs-004" precedence="medium">
        {STYLES}
      </style>
      <div data-vibeui-block="tabs-004" className={className} style={palette}>
        <div
          data-part="list"
          role="tablist"
          aria-label="Период"
          ref={listRef}
          onKeyDown={onKeyDown}
        >
          {items.map((item) => (
            <button
              key={item.id}
              type="button"
              data-part="tab"
              role="tab"
              id={`vibeui-tabs-004-${item.id}-tab`}
              aria-selected={item.id === active}
              aria-controls={`vibeui-tabs-004-${item.id}-panel`}
              tabIndex={item.id === active ? 0 : -1}
              onClick={() => setActive(item.id)}
            >
              {item.label}
            </button>
          ))}
        </div>
        {current ? (
          <div
            data-part="panel"
            role="tabpanel"
            id={`vibeui-tabs-004-${current.id}-panel`}
            aria-labelledby={`vibeui-tabs-004-${current.id}-tab`}
            tabIndex={0}
          >
            {current.content}
          </div>
        ) : null}
      </div>
    </>
  )
}