Inputs

Deferred Apply

Filters with a button instead of instant application: clicks change a draft, and the button says how many records will be left after "Show".

  • filters
  • apply
  • draft
  • 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-009?lang=en

Order status

Применено условий: 0

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-009" (Deferred Apply) 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-009.json

Registry item: https://vibeui.ru/r/filters-009.json
Installs to: components/vibeui/filters-009.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
Filters with a button instead of instant application: clicks change a draft, and the button says how many records will be left after "Show".

Filters with deferred application: clicks change a draft, the state line says plainly that the selection is not applied yet, and the button names the number of records that will remain. Zero dependencies, one file, its own palette.

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

<Filters009
  title="Order status"
  baseCount={412}
  onApply={(values) => reload(values)}
/>

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-009-* palette — do not swap it for your theme tokens (bg-primary, border-input and the like)
- the split between the draft and the applied set: on a heavy report four conditions otherwise mean four waits
- the number printed on the button: "Apply" does not say what the press will cost
- the prediction taken from the same counts shown beside the values — the button must not promise what the list does not show
- the disabled button while the draft matches the applied set: there is nothing to press
- the state line with role="status": the gap between draft and results has to be announced, not only highlighted
- the <style> block inside the component — it holds the palette, the checkboxes and the button state

## 6. You may change
- the title and the options array of values and counts
- baseCount — how many records there are with no filters
- the onApply handler: it receives the list of applied values
- the accent through the accent prop — it colours a checked box and the button
- the state line wording

## 7. Rules
- The predicted number is a sum of counts and is therefore only right for conditions joined by "or": for an intersection the server computes it.
- Deferred application earns its keep on heavy results. On a short list instant filtering is better — the button is an extra step there.
- The draft does not survive navigation: it is lost when leaving the page, and that is worth warning about.
- 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-009.json
https://vibeui.ru/r/filters-009.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-filters-009-*. Клиентский: "use client" ради черновика. В состоянии живут два набора — черновик и применённый; их расхождение поднимает data-dirty на корне и меняет строку состояния. Предсказанное число складывается из тех же счётчиков, что стоят у значений, поэтому кнопка не обещает того, чего не видно в списке. Кнопка выключена, пока черновик совпадает с применённым.

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 Filters009Option = {
  value: string
  count: number
}

export type Filters009Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "children" | "onChange"
> & {
  title?: string
  options?: Filters009Option[]
  baseCount?: number
  onApply?: (values: string[]) => void
  accent?: string
}

// Идея компонента: фильтры с кнопкой, а не мгновенные. Мгновенное применение
// хорошо на списке из ста строк и мучительно на тяжёлом отчёте: каждый щелчок
// уходит в запрос, а собрать отбор из четырёх условий — это четыре ожидания.
// Здесь щелчки меняют черновик, кнопка сообщает, сколько записей останется, и
// пока черновик отличается от применённого, панель честно говорит об этом.
const STYLES = `
:where([data-vibeui-block="filters-009"]){
--vibeui-filters-009-surface:oklch(1 0 0);
--vibeui-filters-009-fill:oklch(0.975 0.004 265);
--vibeui-filters-009-fg:oklch(0.23 0.014 265);
--vibeui-filters-009-muted:oklch(0.55 0.014 265);
--vibeui-filters-009-border:oklch(0.89 0.008 265);
--vibeui-filters-009-shell:oklch(0.91 0.006 265);
--vibeui-filters-009-accent:oklch(0.5 0.17 145);
--vibeui-filters-009-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
/* Своя светлая подложка: панель показывают поверх любого фона. */
[data-vibeui-block="filters-009"]{
display:flex;flex-direction:column;gap:0.5rem;
width:100%;max-width:18rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-filters-009-surface);
border:1px solid var(--vibeui-filters-009-shell);border-radius:0.875rem;
font-family:var(--vibeui-filters-009-font);color:var(--vibeui-filters-009-fg);
}
[data-vibeui-block="filters-009"] *{box-sizing:border-box}
[data-vibeui-block="filters-009"] h3{margin:0;font-size:0.8125rem;font-weight:650}
[data-vibeui-block="filters-009"] ul{
display:flex;flex-direction:column;gap:0.0625rem;margin:0;padding:0;list-style:none;
}
[data-vibeui-block="filters-009"] label{
display:flex;align-items:center;gap:0.5rem;cursor:pointer;
padding:0.3125rem 0.375rem;border-radius:0.4375rem;font-size:0.8125rem;
transition:background-color .16s ease;
}
[data-vibeui-block="filters-009"] label:hover{background:var(--vibeui-filters-009-fill)}
[data-vibeui-block="filters-009"] input{
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-009-border);background:oklch(1 0 0);
transition:background-color .16s ease,border-color .16s ease;
}
[data-vibeui-block="filters-009"] input:checked{
background:var(--vibeui-filters-009-accent);border-color:var(--vibeui-filters-009-accent);
}
[data-vibeui-block="filters-009"] input: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-009"] input:focus-visible{outline:2px solid var(--vibeui-filters-009-accent);outline-offset:2px}
[data-vibeui-block="filters-009"] [data-part="value"]{flex:1;min-width:0}
[data-vibeui-block="filters-009"] [data-part="count"]{
flex:none;font-size:0.6875rem;color:var(--vibeui-filters-009-muted);
font-variant-numeric:tabular-nums;
}
/* Кнопка называет результат: «Применить» не говорит, во что это обойдётся. */
[data-vibeui-block="filters-009"] [data-part="apply"]{
appearance:none;cursor:pointer;width:100%;
height:2.375rem;border:0;border-radius:0.625rem;
background:var(--vibeui-filters-009-accent);color:oklch(1 0 0);
font:inherit;font-size:0.8125rem;font-weight:700;
font-variant-numeric:tabular-nums;
transition:opacity .16s ease;
}
[data-vibeui-block="filters-009"] [data-part="apply"]:focus-visible{outline:2px solid var(--vibeui-filters-009-accent);outline-offset:2px}
[data-vibeui-block="filters-009"] [data-part="apply"]:disabled{cursor:default;opacity:.4}
[data-vibeui-block="filters-009"] [data-part="state"]{
margin:0;font-size:0.6875rem;line-height:1.4;color:var(--vibeui-filters-009-muted);
}
[data-vibeui-block="filters-009"][data-dirty="true"] [data-part="state"]{
color:var(--vibeui-filters-009-accent);font-weight:650;
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="filters-009"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_OPTIONS: Filters009Option[] = [
  { value: "Оплачен", count: 184 },
  { value: "В сборке", count: 76 },
  { value: "Доставляется", count: 51 },
  { value: "Возврат", count: 12 },
]

/**
 * Фильтры с отложенным применением: кнопка сообщает, сколько записей останется.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Filters009({
  title = "Статус заказа",
  options = DEFAULT_OPTIONS,
  baseCount = 412,
  onApply,
  accent,
  className,
  style,
  ...props
}: Filters009Props) {
  const [draft, setDraft] = useState<string[]>([])
  const [applied, setApplied] = useState<string[]>([])

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

  // Предсказанное число берётся из тех же счётчиков, что стоят у значений:
  // кнопка не имеет права обещать то, чего не видно в списке.
  const predicted = draft.length
    ? options
        .filter((option) => draft.includes(option.value))
        .reduce((sum, option) => sum + option.count, 0)
    : baseCount

  const dirty = draft.join("|") !== applied.join("|")

  const toggle = (value: string) =>
    setDraft((current) =>
      current.includes(value)
        ? current.filter((item) => item !== value)
        : [...current, value],
    )

  return (
    <>
      <style href="vibeui-filters-009" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="filters-009"
        data-dirty={dirty ? "true" : undefined}
        className={className}
        style={palette}
      >
        <h3>{title}</h3>
        <ul>
          {options.map((option) => (
            <li key={option.value}>
              <label>
                <input
                  type="checkbox"
                  checked={draft.includes(option.value)}
                  onChange={() => toggle(option.value)}
                />
                <span data-part="value">{option.value}</span>
                <span data-part="count">{option.count}</span>
              </label>
            </li>
          ))}
        </ul>
        <p data-part="state" role="status">
          {dirty
            ? "Черновик изменён — отбор ещё не применён."
            : `Применено условий: ${applied.length}`}
        </p>
        <button
          type="button"
          data-part="apply"
          disabled={!dirty}
          onClick={() => {
            setApplied(draft)
            onApply?.(draft)
          }}
        >
          Показать {predicted}
        </button>
      </div>
    </>
  )
}