Badge
Filter Chips
Filter chips as buttons: state lives in aria-pressed, and the selected one also carries a tick — not colour alone.
- badge
- filter
- toggle
- a11y
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/badge-011?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 "badge-011" (Filter Chips) 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/badge-011.json
Registry item: https://vibeui.ru/r/badge-011.json
Installs to: components/vibeui/badge-011.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
Filter chips as buttons: state lives in aria-pressed, and the selected one also carries a tick — not colour alone.
A row of toggleable filter chips: buttons with aria-pressed, a tick on the selected one and colours derived from a single accent. Zero dependencies, one file, its own palette.
## 3. How to use it
import { Badge011 } from "@/components/vibeui/badge-011"
<Badge011
options={["All", "Open", "Mine"]}
defaultValue={["Open"]}
onChange={(value) => setFilters(value)}
/>
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-badge-011-* palette — do not swap it for your theme tokens
- buttons with aria-pressed instead of links: a filter changes the selection, not the URL
- styling the selected state through [aria-pressed="true"] — state and appearance cannot drift apart
- the tick on a selected chip: colour alone fails colour-blind readers
- the 1.75rem height: a filter has to be thumb-sized
- wrapping to a second line — there are often many filters
## 6. You may change
- the options array and the initial defaultValue
- the onChange handler
- the accent through the accent prop
- the shape: a rounded rectangle instead of a pill
## 7. Rules
- The component owns the selection: wiring it to a query or the URL is the caller's job.
- Mutually exclusive options are not filters but a switch: those need radios, not aria-pressed.
- An "All" option should clear the others: add that rule in your onChange.
- 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/badge-011.jsonhttps://vibeui.ru/r/badge-011.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-badge-011-*. Клиентский: "use client". Каждая плашка — <button> с aria-pressed, а не ссылка: адрес не меняется, состояние переключается на месте. Выбранное состояние стилизуется селектором по aria-pressed, поэтому разметка и доступность не расходятся. Цвета выбранной плашки считаются из акцента через color-mix.
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 { ComponentPropsWithoutRef, CSSProperties } from "react"
export type Badge011Props = Omit<
ComponentPropsWithoutRef<"div">,
"children" | "onChange"
> & {
options?: string[]
defaultValue?: string[]
onChange?: (value: string[]) => void
accent?: string
}
// Идея компонента: плашки-фильтры, которые можно нажимать. Они объявлены
// кнопками с aria-pressed, а не ссылками: состояние переключается на месте и
// адрес страницы не меняется. Выбранная плашка отличается не только цветом —
// у неё галочка, иначе выбор не виден при дальтонизме.
const STYLES = `
:where([data-vibeui-block="badge-011"]){
--vibeui-badge-011-bg:oklch(0.97 0.003 265);
--vibeui-badge-011-fg:oklch(0.32 0.014 265);
--vibeui-badge-011-border:oklch(0.89 0.006 265);
--vibeui-badge-011-accent:oklch(0.55 0.17 265);
--vibeui-badge-011-on-bg:color-mix(in oklab,var(--vibeui-badge-011-accent) 14%,oklch(1 0 0));
--vibeui-badge-011-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="badge-011"]{
display:flex;flex-wrap:wrap;gap:0.375rem;
font-family:var(--vibeui-badge-011-font);
}
[data-vibeui-block="badge-011"] button{
appearance:none;cursor:pointer;
display:inline-flex;align-items:center;gap:0.375rem;
height:1.75rem;padding:0 0.6875rem;
border:1px solid var(--vibeui-badge-011-border);border-radius:9999px;
background:var(--vibeui-badge-011-bg);color:var(--vibeui-badge-011-fg);
font:inherit;font-size:0.75rem;font-weight:500;line-height:1;
}
[data-vibeui-block="badge-011"] button:hover{border-color:oklch(0.82 0.008 265)}
[data-vibeui-block="badge-011"] button:focus-visible{outline:2px solid var(--vibeui-badge-011-accent);outline-offset:1px}
/* Выбранная плашка отличается галочкой, а не только цветом. */
[data-vibeui-block="badge-011"] button[aria-pressed="true"]{
background:var(--vibeui-badge-011-on-bg);
border-color:color-mix(in oklab,var(--vibeui-badge-011-accent) 45%,oklch(1 0 0));
color:color-mix(in oklab,var(--vibeui-badge-011-accent) 75%,oklch(0.2 0.02 265));
font-weight:600;
}
[data-vibeui-block="badge-011"] [data-part="tick"]{
width:0.3125rem;height:0.5rem;margin-top:-0.125rem;flex:none;
border-right:1.5px solid currentColor;border-bottom:1.5px solid currentColor;
transform:rotate(45deg);
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="badge-011"] *{animation:none!important;transition:none!important}}
`
const DEFAULT_OPTIONS = ["Все", "Открытые", "Мои", "Срочные", "В архиве"]
/**
* Плашки-фильтры: кнопки с aria-pressed и галочкой у выбранной.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Badge011({
options = DEFAULT_OPTIONS,
defaultValue = ["Открытые"],
onChange,
accent,
className,
style,
...props
}: Badge011Props) {
const [value, setValue] = useState<string[]>(defaultValue)
const palette = {
...(accent ? { "--vibeui-badge-011-accent": accent } : null),
...style,
} as CSSProperties
const toggle = (option: string) => {
const next = value.includes(option)
? value.filter((item) => item !== option)
: [...value, option]
setValue(next)
onChange?.(next)
}
return (
<>
<style href="vibeui-badge-011" precedence="medium">
{STYLES}
</style>
<div
{...props}
data-vibeui-block="badge-011"
className={className}
style={palette}
>
{options.map((option) => {
const on = value.includes(option)
return (
<button
key={option}
type="button"
aria-pressed={on}
onClick={() => toggle(option)}
>
{on ? <span data-part="tick" aria-hidden="true" /> : null}
{option}
</button>
)
})}
</div>
</>
)
}