Inputs

Value Search

A filter with a search over its own values: a two-hundred-row list is searched, not scrolled, and checked items stay pinned at the top.

  • filters
  • search
  • list
  • checkbox

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/filters-006?lang=en

City

Показано 12 из 12 · выбрано 1

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 "filters-006" (Value Search) 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/filters-006.json

Registry item: https://vibeui.ru/r/filters-006.json
Installs to: components/vibeui/filters-006.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 filter with a search over its own values: a two-hundred-row list is searched, not scrolled, and checked items stay pinned at the top.

A single filter with a long value list and a search over it: the query narrows the list, checked values stay pinned on top, and a counter says how many rows remain visible. Zero dependencies, one file, its own palette.

## 3. How to use it
import { Filters006 } from "@/components/vibeui/filters-006"

<Filters006
  title="City"
  values={["London", "Manchester"]}
  onChange={setCities}
/>

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-filters-006-* palette — do not swap it for your theme tokens (bg-muted, border-input and the like)
- pinning the checked values on top: a tick that vanishes because of a query reads as unticked
- the divider between pinned and the rest — without it it is unclear why the first rows do not match the query
- a search that narrows the value list rather than the results: those are two different searches and must not be confused
- the "showing N of M" counter with role="status": it changes as you type and has to be announced
- a real empty state suggesting a spelling check instead of blank space
- the <style> block inside the component — it holds the palette, the magnifier and the list scrolling

## 6. You may change
- the title and the placeholder text in the search field
- the values array — your own filter values
- the onChange handler: it receives the list of checked values
- the accent through the accent prop — it colours a checked box
- the height of the scrolling list

## 7. Rules
- The search is a case-insensitive substring match and knows nothing about word forms: real search belongs on the server.
- The list scrolls inside itself. With thousands of values add virtualisation or lazy loading, or the markup gets heavy.
- Checked values live in component state: lift them out through onChange for a form.
- 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/filters-006.json
https://vibeui.ru/r/filters-006.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-filters-006-*. Клиентский: "use client" ради запроса и отметок. Поиск сужает только список значений, а не выдачу; отмеченные пункты вычисляются отдельно и всегда выводятся сверху с разделителем, даже если не подходят под запрос — иначе галочка исчезает с экрана и читается как снятая. Счётчик «показано N из M» стоит в role="status".

Component source

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

"use client"

import { useMemo, useState } from "react"
import type { ComponentPropsWithoutRef, CSSProperties } from "react"

export type Filters006Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "children" | "onChange"
> & {
  title?: string
  placeholder?: string
  values?: string[]
  onChange?: (checked: string[]) => void
  accent?: string
}

// Идея компонента: поиск внутри одного фильтра. Список брендов или городов
// длиной в двести строк не пролистывают — в нём ищут. Поиск не перерисовывает
// выдачу, а только сужает сам список значений, и уже отмеченные пункты
// остаются наверху, даже если не подходят под запрос: иначе галочка исчезает
// с экрана и кажется снятой.
const STYLES = `
:where([data-vibeui-block="filters-006"]){
--vibeui-filters-006-surface:oklch(1 0 0);
--vibeui-filters-006-fill:oklch(0.975 0.004 265);
--vibeui-filters-006-fg:oklch(0.23 0.014 265);
--vibeui-filters-006-muted:oklch(0.55 0.014 265);
--vibeui-filters-006-border:oklch(0.89 0.008 265);
--vibeui-filters-006-shell:oklch(0.91 0.006 265);
--vibeui-filters-006-accent:oklch(0.53 0.18 30);
--vibeui-filters-006-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
/* Своя светлая подложка: фильтр показывают поверх любого фона. */
[data-vibeui-block="filters-006"]{
display:flex;flex-direction:column;gap:0.5rem;
width:100%;max-width:17rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-filters-006-surface);
border:1px solid var(--vibeui-filters-006-shell);border-radius:0.875rem;
font-family:var(--vibeui-filters-006-font);color:var(--vibeui-filters-006-fg);
}
[data-vibeui-block="filters-006"] *{box-sizing:border-box}
[data-vibeui-block="filters-006"] h3{margin:0;font-size:0.8125rem;font-weight:650}
[data-vibeui-block="filters-006"] [data-part="search"]{
display:flex;align-items:center;gap:0.375rem;
height:2.125rem;padding:0 0.5rem;
background:var(--vibeui-filters-006-fill);
border:1px solid var(--vibeui-filters-006-border);border-radius:0.5rem;
transition:border-color .16s ease;
}
[data-vibeui-block="filters-006"] [data-part="search"]:focus-within{border-color:var(--vibeui-filters-006-accent)}
/* Лупа из круга и палочки: иконочная библиотека не нужна. */
[data-vibeui-block="filters-006"] [data-part="lens"]{
position:relative;flex:none;width:0.75rem;height:0.75rem;
border:1.5px solid var(--vibeui-filters-006-muted);border-radius:9999px;
}
[data-vibeui-block="filters-006"] [data-part="lens"]::after{
content:"";position:absolute;right:-0.25rem;bottom:-0.1875rem;
width:0.3125rem;height:1.5px;border-radius:9999px;
background:var(--vibeui-filters-006-muted);transform:rotate(45deg);
}
[data-vibeui-block="filters-006"] input[type="search"]{
flex:1;min-width:0;border:0;background:none;color:inherit;padding:0;
font:inherit;font-size:0.8125rem;appearance:none;
}
[data-vibeui-block="filters-006"] input[type="search"]:focus{outline:none}
[data-vibeui-block="filters-006"] input[type="search"]::-webkit-search-cancel-button{appearance:none}
[data-vibeui-block="filters-006"] input[type="search"]::placeholder{color:var(--vibeui-filters-006-muted)}
[data-vibeui-block="filters-006"] ul{
display:flex;flex-direction:column;gap:0.0625rem;
margin:0;padding:0;list-style:none;
max-height:11rem;overflow-y:auto;
}
[data-vibeui-block="filters-006"] label{
display:flex;align-items:center;gap:0.5rem;cursor:pointer;
padding:0.25rem 0.125rem;font-size:0.8125rem;
}
[data-vibeui-block="filters-006"] input[type="checkbox"]{
appearance:none;flex:none;margin:0;cursor:pointer;position:relative;
width:1rem;height:1rem;border-radius:0.3125rem;
border:1.5px solid var(--vibeui-filters-006-border);background:oklch(1 0 0);
transition:background-color .16s ease,border-color .16s ease;
}
[data-vibeui-block="filters-006"] input[type="checkbox"]:checked{
background:var(--vibeui-filters-006-accent);border-color:var(--vibeui-filters-006-accent);
}
[data-vibeui-block="filters-006"] input[type="checkbox"]:checked::after{
content:"";position:absolute;left:0.3125rem;top:0.0625rem;
width:0.25rem;height:0.5rem;transform:rotate(42deg);
border-right:2px solid oklch(1 0 0);border-bottom:2px solid oklch(1 0 0);
}
[data-vibeui-block="filters-006"] input[type="checkbox"]:focus-visible{outline:2px solid var(--vibeui-filters-006-accent);outline-offset:2px}
/* Отмеченное всегда на виду: пропавшая галочка читается как снятая. */
[data-vibeui-block="filters-006"] li[data-pinned="true"]{
border-bottom:1px solid var(--vibeui-filters-006-border);
padding-bottom:0.125rem;margin-bottom:0.125rem;
}
[data-vibeui-block="filters-006"] [data-part="count"]{
margin:0;font-size:0.6875rem;color:var(--vibeui-filters-006-muted);
font-variant-numeric:tabular-nums;
}
[data-vibeui-block="filters-006"] [data-part="empty"]{
margin:0;padding:0.5rem 0;font-size:0.8125rem;color:var(--vibeui-filters-006-muted);
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="filters-006"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_VALUES = [
  "Москва",
  "Санкт-Петербург",
  "Новосибирск",
  "Екатеринбург",
  "Казань",
  "Нижний Новгород",
  "Челябинск",
  "Самара",
  "Уфа",
  "Ростов-на-Дону",
  "Краснодар",
  "Пермь",
]

/**
 * Фильтр с поиском по значениям: отмеченное закреплено сверху списка.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Filters006({
  title = "Город",
  placeholder = "Найти город",
  values = DEFAULT_VALUES,
  onChange,
  accent,
  className,
  style,
  ...props
}: Filters006Props) {
  const [query, setQuery] = useState("")
  const [checked, setChecked] = useState<string[]>(["Казань"])

  const shown = useMemo(() => {
    const needle = query.trim().toLowerCase()
    const matched = needle
      ? values.filter((value) => value.toLowerCase().includes(needle))
      : values

    // Отмеченные всегда наверху и всегда видимы, даже мимо запроса.
    const pinned = values.filter((value) => checked.includes(value))
    const rest = matched.filter((value) => !checked.includes(value))

    return { pinned, rest, matched: matched.length }
  }, [query, values, checked])

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

  const toggle = (value: string) => {
    const next = checked.includes(value)
      ? checked.filter((item) => item !== value)
      : [...checked, value]

    setChecked(next)
    onChange?.(next)
  }

  return (
    <>
      <style href="vibeui-filters-006" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="filters-006"
        className={className}
        style={palette}
      >
        <h3>{title}</h3>

        <div data-part="search">
          <span data-part="lens" aria-hidden="true" />
          <input
            type="search"
            value={query}
            placeholder={placeholder}
            aria-label={`${title}: поиск по значениям`}
            onChange={(event) => setQuery(event.target.value)}
          />
        </div>

        {shown.pinned.length === 0 && shown.rest.length === 0 ? (
          <p data-part="empty">Ничего не нашлось. Проверьте написание.</p>
        ) : (
          <ul>
            {shown.pinned.map((value) => (
              <li key={value} data-pinned="true">
                <label>
                  <input
                    type="checkbox"
                    checked
                    onChange={() => toggle(value)}
                  />
                  {value}
                </label>
              </li>
            ))}
            {shown.rest.map((value) => (
              <li key={value}>
                <label>
                  <input
                    type="checkbox"
                    checked={false}
                    onChange={() => toggle(value)}
                  />
                  {value}
                </label>
              </li>
            ))}
          </ul>
        )}

        <p data-part="count" role="status">
          Показано {shown.matched} из {values.length} · выбрано {checked.length}
        </p>
      </div>
    </>
  )
}