Inputs

Number Range

A range in numbers rather than on a slider: quick presets on top, two fields below, and flipped bounds that swap themselves on blur.

  • filters
  • range
  • number
  • presets

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

Price

Границы не заданы — цена любая.

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-004" (Number Range) 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-004.json

Registry item: https://vibeui.ru/r/filters-004.json
Installs to: components/vibeui/filters-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
A range in numbers rather than on a slider: quick presets on top, two fields below, and flipped bounds that swap themselves on blur.

A numeric range built from two inputs: exact bounds like "3000 to 3500" are typed, while the common cases are covered by presets. Flipped bounds fix themselves. Zero dependencies, one file, its own palette.

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

<Filters004
  title="Price"
  unit="£"
  onChange={(range) => setPrice(range)}
/>

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-004-* palette — do not swap it for your theme tokens (bg-muted, border-input and the like)
- text inputs instead of a slider: exact bounds cannot be dragged, and a slider is awkward from the keyboard
- swapping the bounds on blur instead of raising an error — the user already sees the mix-up and does not need another step
- aria-pressed on the presets: they are state toggles, not ordinary buttons
- an aria-label naming the filter on each field — bare "from" and "to" do not read
- tabular figures in the fields: otherwise the number jitters while typing
- the <style> block inside the component — it holds the palette, the presets and the field pair

## 6. You may change
- the title and the unit shown in the labels
- the presets array — your own common ranges
- the onChange handler: it receives an object with from and to
- the accent through the accent prop — it colours the active preset and the focus ring
- the summary wording under the fields

## 7. Rules
- An empty field means "no bound": do not substitute zero, or free items drop out of the results.
- The values arrive as strings — convert them to numbers before querying.
- For rough selection with a visible distribution, a dual slider serves better.
- 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-004.json
https://vibeui.ru/r/filters-004.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-filters-004-*. Клиентский: "use client" ради значений и пресетов. Пресеты — кнопки с aria-pressed, они подсвечиваются, когда оба поля совпали с набором. Границы меняются местами в обработчике onBlur, а не подсвечиваются ошибкой: перепутанные «от» и «до» человек и так уже видит. Сводка стоит в role="status" и повторяет итог словами.

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 Filters004Preset = {
  label: string
  from: string
  to: string
}

export type Filters004Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "children" | "onChange"
> & {
  title?: string
  unit?: string
  presets?: Filters004Preset[]
  onChange?: (range: { from: string; to: string }) => void
  accent?: string
}

// Идея компонента: диапазон числами, а не ползунком. Ползунок хорош, пока
// границы приблизительные; «от 3000 до 3500» им не поставить, а с клавиатуры
// он вовсе неудобен. Здесь два обычных числовых поля, быстрые пресеты сверху
// и одно правило: если «от» больше «до», значения меняются местами при уходе
// фокуса, а не подсвечиваются ошибкой — человек и так уже понял, что перепутал.
const STYLES = `
:where([data-vibeui-block="filters-004"]){
--vibeui-filters-004-surface:oklch(1 0 0);
--vibeui-filters-004-fill:oklch(0.975 0.004 265);
--vibeui-filters-004-fg:oklch(0.23 0.014 265);
--vibeui-filters-004-muted:oklch(0.55 0.014 265);
--vibeui-filters-004-border:oklch(0.89 0.008 265);
--vibeui-filters-004-shell:oklch(0.91 0.006 265);
--vibeui-filters-004-accent:oklch(0.52 0.16 165);
--vibeui-filters-004-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
/* Своя светлая подложка: фильтр показывают поверх любого фона. */
[data-vibeui-block="filters-004"]{
display:flex;flex-direction:column;gap:0.5rem;
width:100%;max-width:19rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-filters-004-surface);
border:1px solid var(--vibeui-filters-004-shell);border-radius:0.875rem;
font-family:var(--vibeui-filters-004-font);color:var(--vibeui-filters-004-fg);
}
[data-vibeui-block="filters-004"] *{box-sizing:border-box}
[data-vibeui-block="filters-004"] h3{margin:0;font-size:0.8125rem;font-weight:650}
/* Пресеты сверху: девять из десяти запросов закрываются ими. */
[data-vibeui-block="filters-004"] [data-part="presets"]{
display:flex;flex-wrap:wrap;gap:0.3125rem;
}
[data-vibeui-block="filters-004"] [data-part="preset"]{
appearance:none;cursor:pointer;
padding:0.25rem 0.5625rem;border-radius:9999px;
border:1px solid var(--vibeui-filters-004-border);
background:var(--vibeui-filters-004-fill);color:inherit;
font:inherit;font-size:0.6875rem;font-weight:600;
transition:border-color .16s ease,color .16s ease;
}
[data-vibeui-block="filters-004"] [data-part="preset"]:hover{border-color:var(--vibeui-filters-004-accent)}
[data-vibeui-block="filters-004"] [data-part="preset"]:focus-visible{outline:2px solid var(--vibeui-filters-004-accent);outline-offset:2px}
[data-vibeui-block="filters-004"] [data-part="preset"][aria-pressed="true"]{
border-color:var(--vibeui-filters-004-accent);
color:var(--vibeui-filters-004-accent);
background:color-mix(in oklab,var(--vibeui-filters-004-accent) 10%,oklch(1 0 0));
}
[data-vibeui-block="filters-004"] [data-part="pair"]{
display:flex;align-items:center;gap:0.375rem;
}
[data-vibeui-block="filters-004"] [data-part="cell"]{
flex:1;min-width:0;display:flex;align-items:center;gap:0.25rem;
height:2.375rem;padding:0 0.5rem;
border:1px solid var(--vibeui-filters-004-border);border-radius:0.625rem;
transition:border-color .16s ease,box-shadow .16s ease;
}
[data-vibeui-block="filters-004"] [data-part="cell"]:focus-within{
border-color:var(--vibeui-filters-004-accent);
box-shadow:0 0 0 3px color-mix(in oklab,var(--vibeui-filters-004-accent) 16%,transparent);
}
[data-vibeui-block="filters-004"] [data-part="cell"] > span{
flex:none;font-size:0.6875rem;color:var(--vibeui-filters-004-muted);user-select:none;
}
[data-vibeui-block="filters-004"] input{
width:100%;min-width:0;border:0;background:none;color:inherit;padding:0;
font:inherit;font-size:0.875rem;font-weight:600;
font-variant-numeric:tabular-nums;
}
[data-vibeui-block="filters-004"] input:focus{outline:none}
[data-vibeui-block="filters-004"] input::-webkit-outer-spin-button,
[data-vibeui-block="filters-004"] input::-webkit-inner-spin-button{appearance:none;margin:0}
[data-vibeui-block="filters-004"] [data-part="dash"]{
flex:none;width:0.5rem;height:1px;background:var(--vibeui-filters-004-border);
}
[data-vibeui-block="filters-004"] [data-part="summary"]{
margin:0;font-size:0.75rem;line-height:1.4;color:var(--vibeui-filters-004-muted);
}
[data-vibeui-block="filters-004"] [data-part="summary"] b{color:var(--vibeui-filters-004-fg);font-variant-numeric:tabular-nums}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="filters-004"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_PRESETS: Filters004Preset[] = [
  { label: "до 1000", from: "", to: "1000" },
  { label: "1000 — 5000", from: "1000", to: "5000" },
  { label: "5000 — 20 000", from: "5000", to: "20000" },
  { label: "от 20 000", from: "20000", to: "" },
]

/**
 * Числовой диапазон полями ввода с быстрыми пресетами и починкой перевёрнутых границ.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Filters004({
  title = "Цена",
  unit = "₽",
  presets = DEFAULT_PRESETS,
  onChange,
  accent,
  className,
  style,
  ...props
}: Filters004Props) {
  const [from, setFrom] = useState("")
  const [to, setTo] = useState("")

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

  const push = (next: { from: string; to: string }) => {
    setFrom(next.from)
    setTo(next.to)
    onChange?.(next)
  }

  // Границы меняются местами по уходу фокуса: подсвечивать ошибкой то, что
  // человек уже понял, — лишний шаг.
  const settle = () => {
    if (!from || !to) return
    if (Number(from) <= Number(to)) return
    push({ from: to, to: from })
  }

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

        <div data-part="presets">
          {presets.map((preset) => (
            <button
              key={preset.label}
              type="button"
              data-part="preset"
              aria-pressed={from === preset.from && to === preset.to}
              onClick={() => push({ from: preset.from, to: preset.to })}
            >
              {preset.label}
            </button>
          ))}
        </div>

        <div data-part="pair">
          <span data-part="cell">
            <span aria-hidden="true">от</span>
            <input
              type="number"
              inputMode="numeric"
              min={0}
              value={from}
              placeholder="0"
              aria-label={`${title}: нижняя граница, ${unit}`}
              onChange={(event) => setFrom(event.target.value)}
              onBlur={settle}
            />
          </span>
          <span data-part="dash" aria-hidden="true" />
          <span data-part="cell">
            <span aria-hidden="true">до</span>
            <input
              type="number"
              inputMode="numeric"
              min={0}
              value={to}
              placeholder="любая"
              aria-label={`${title}: верхняя граница, ${unit}`}
              onChange={(event) => setTo(event.target.value)}
              onBlur={settle}
            />
          </span>
        </div>

        <p data-part="summary" role="status">
          {from || to ? (
            <>
              Отбор: <b>{from || "0"}</b> — <b>{to || "∞"}</b> {unit}
            </>
          ) : (
            "Границы не заданы — цена любая."
          )}
        </p>
      </div>
    </>
  )
}