Inputs
Preset Range
A range with presets: people think "budget" or "premium" while the system does the conversion to numbers — and the slider still works.
- range
- presets
- slider
- filter
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/range-007?lang=en
Budget per night4 000 — 9 000 ₽
0 ₽20 000 ₽
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 "range-007" (Preset 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/range-007.json
Registry item: https://vibeui.ru/r/range-007.json
Installs to: components/vibeui/range-007.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 with presets: people think "budget" or "premium" while the system does the conversion to numbers — and the slider still works.
A dual slider with preset buttons: a button sets both bounds and its mark clears itself after a manual edit. Zero dependencies, one file.
## 3. How to use it
import { Range007 } from "@/components/vibeui/range-007"
<Range007 label="Budget per night" min={0} max={20000} step={500} presets={[{ text: "Budget", from: 0, to: 4000 }]} />
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-range-007-* palette — do not swap it for your theme tokens
- its own light surface: the filter gets shown over any background
- presets in words: people think "budget", not "under 4,000"
- deriving the mark from the current bounds: a separate preset state desynchronises after the first edit
- the working slider next to the presets: a button is a quick start, not the only way to answer
- aria-pressed on the buttons: this is a selection state, not a one-off press
- pointer-events on the thumbs while the track is disabled: otherwise the top slider swallows every click
## 6. You may change
- label — the filter caption
- presets — the names and bounds of the quick options
- min, max and step of the scale
- unit — the currency sign
- the accent through the accent prop
## 7. Rules
- Preset bounds must land on the scale step, otherwise the mark never lights up.
- The starting range comes from the middle of the preset list: an empty filter says nothing.
- Keep presets non-overlapping: two identical ranges light up two buttons at once.
- 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/range-007.jsonhttps://vibeui.ru/r/range-007.jsonКомпонент самодостаточен: один файл, ноль зависимостей, палитра в локальных переменных --vibeui-range-007-*. Клиентский: обе границы в состоянии, отдельного состояния «выбранный пресет» нет. Отметка кнопки вычисляется сравнением текущих границ с её значениями, поэтому после ручной правки ползунка отметка гаснет сама и не врёт о текущем фильтре. Ползунков два, они лежат друг на друге: дорожка отключена для событий, ручки — нет.
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 Range007Props = Omit<
ComponentPropsWithoutRef<"div">,
"children" | "defaultValue" | "onChange"
> & {
label?: string
min?: number
max?: number
step?: number
presets?: { text: string; from: number; to: number }[]
unit?: string
accent?: string
}
// Идея компонента: пресеты задают обе границы разом. Человек редко думает
// числами — он думает «эконом» или «бизнес», а перевод в рубли и обратно
// делает система. Кнопка отмечается только тогда, когда обе ручки стоят ровно
// на её значениях, поэтому после ручной правки отметка гаснет сама и не врёт.
// Ползунок остаётся рабочим: пресет — это быстрый старт, а не единственный
// способ ответить.
const STYLES = `
:where([data-vibeui-block="range-007"]){
--vibeui-range-007-surface:oklch(1 0 0);
--vibeui-range-007-shell:oklch(0.9 0.006 265);
--vibeui-range-007-fg:oklch(0.23 0.014 265);
--vibeui-range-007-muted:oklch(0.55 0.014 265);
--vibeui-range-007-border:oklch(0.88 0.008 265);
--vibeui-range-007-track:oklch(0.93 0.006 265);
--vibeui-range-007-accent:oklch(0.55 0.18 45);
--vibeui-range-007-soft:oklch(0.55 0.18 45 / 12%);
--vibeui-range-007-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
--vibeui-range-007-from:0%;
--vibeui-range-007-to:100%;
}
/* Своя светлая подложка: фильтр показывают поверх любого фона. */
[data-vibeui-block="range-007"]{
display:flex;flex-direction:column;gap:0.625rem;
width:100%;max-width:21rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-range-007-surface);
border:1px solid var(--vibeui-range-007-shell);border-radius:0.875rem;
font-family:var(--vibeui-range-007-font);color:var(--vibeui-range-007-fg);
}
[data-vibeui-block="range-007"] [data-part="head"]{
display:flex;align-items:baseline;justify-content:space-between;gap:0.75rem;margin:0;
font-size:0.8125rem;
}
[data-vibeui-block="range-007"] [data-part="value"]{font-weight:700;font-variant-numeric:tabular-nums}
/* Пресеты словами: человек думает «эконом», а не «до 4 000». */
[data-vibeui-block="range-007"] [data-part="presets"]{display:flex;flex-wrap:wrap;gap:0.375rem}
[data-vibeui-block="range-007"] button{
appearance:none;cursor:pointer;flex:1 1 auto;
height:1.875rem;padding:0 0.75rem;border-radius:9999px;
border:1px solid var(--vibeui-range-007-border);
background:var(--vibeui-range-007-surface);color:inherit;
font:inherit;font-size:0.75rem;font-weight:650;
transition:background-color .14s ease,border-color .14s ease,color .14s ease;
}
[data-vibeui-block="range-007"] button:hover{border-color:var(--vibeui-range-007-accent)}
[data-vibeui-block="range-007"] button:focus-visible{outline:2px solid var(--vibeui-range-007-accent);outline-offset:2px}
/* Отметка гаснет после ручной правки: иначе кнопка врёт о текущем фильтре. */
[data-vibeui-block="range-007"] button[aria-pressed="true"]{
background:var(--vibeui-range-007-soft);border-color:var(--vibeui-range-007-accent);
color:var(--vibeui-range-007-accent);
}
[data-vibeui-block="range-007"] [data-part="rail"]{position:relative;height:1.25rem}
[data-vibeui-block="range-007"] [data-part="rail"]::before{
content:"";position:absolute;left:0;right:0;top:0.4375rem;height:0.375rem;border-radius:9999px;
background:linear-gradient(to right,
var(--vibeui-range-007-track) var(--vibeui-range-007-from),
var(--vibeui-range-007-accent) var(--vibeui-range-007-from),
var(--vibeui-range-007-accent) var(--vibeui-range-007-to),
var(--vibeui-range-007-track) var(--vibeui-range-007-to));
}
[data-vibeui-block="range-007"] input{
position:absolute;left:0;top:0;width:100%;height:1.25rem;margin:0;
appearance:none;background:none;pointer-events:none;
}
[data-vibeui-block="range-007"] input::-webkit-slider-runnable-track{background:none;height:0.375rem}
[data-vibeui-block="range-007"] input::-moz-range-track{background:none;height:0.375rem}
/* Дорожка событий не ловит, ручки ловят: иначе верхний ползунок съедает клики. */
[data-vibeui-block="range-007"] input::-webkit-slider-thumb{
appearance:none;pointer-events:auto;cursor:pointer;margin-top:-0.3125rem;
width:1rem;height:1rem;border-radius:9999px;
background:var(--vibeui-range-007-surface);border:2px solid var(--vibeui-range-007-accent);
box-shadow:0 1px 3px oklch(0.2 0.02 265 / 25%);
}
[data-vibeui-block="range-007"] input::-moz-range-thumb{
pointer-events:auto;cursor:pointer;box-sizing:border-box;
width:1rem;height:1rem;border-radius:9999px;
background:var(--vibeui-range-007-surface);border:2px solid var(--vibeui-range-007-accent);
}
[data-vibeui-block="range-007"] input:focus-visible{outline:2px solid var(--vibeui-range-007-accent);outline-offset:4px;border-radius:0.5rem}
[data-vibeui-block="range-007"] [data-part="scale"]{
display:flex;justify-content:space-between;margin:0;
font-size:0.6875rem;color:var(--vibeui-range-007-muted);font-variant-numeric:tabular-nums;
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="range-007"] *{animation:none!important;transition:none!important}}
`
const DEFAULT_PRESETS = [
{ text: "Эконом", from: 0, to: 4000 },
{ text: "Средний", from: 4000, to: 9000 },
{ text: "Премиум", from: 9000, to: 20000 },
]
/**
* Диапазон с пресетами: кнопка задаёт обе границы, ползунок остаётся рабочим.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Range007({
label = "Бюджет на ночь",
min = 0,
max = 20000,
step = 500,
presets = DEFAULT_PRESETS,
unit = "₽",
accent,
className,
style,
...props
}: Range007Props) {
// Стартуем с середины списка пресетов: пустой фильтр ничего не сообщает.
const start = presets[Math.floor(presets.length / 2)]
const [from, setFrom] = useState(start?.from ?? min)
const [to, setTo] = useState(start?.to ?? max)
const percent = (value: number) => `${((value - min) / (max - min)) * 100}%`
const palette = {
"--vibeui-range-007-from": percent(from),
"--vibeui-range-007-to": percent(to),
...(accent ? { "--vibeui-range-007-accent": accent } : null),
...style,
} as CSSProperties
return (
<>
<style href="vibeui-range-007" precedence="medium">
{STYLES}
</style>
<div
{...props}
data-vibeui-block="range-007"
className={className}
style={palette}
>
<p data-part="head">
{label}
<span data-part="value">
{from.toLocaleString("ru-RU")} — {to.toLocaleString("ru-RU")} {unit}
</span>
</p>
<div data-part="presets">
{presets.map((preset) => (
<button
key={preset.text}
type="button"
// Отметка считается от текущих границ, а не хранится отдельно.
aria-pressed={from === preset.from && to === preset.to}
onClick={() => {
setFrom(preset.from)
setTo(preset.to)
}}
>
{preset.text}
</button>
))}
</div>
<div data-part="rail">
<input
type="range"
min={min}
max={max}
step={step}
value={from}
aria-label={`${label}: от`}
onChange={(event) =>
setFrom(Math.min(Number(event.target.value), to - step))
}
/>
<input
type="range"
min={min}
max={max}
step={step}
value={to}
aria-label={`${label}: до`}
onChange={(event) =>
setTo(Math.max(Number(event.target.value), from + step))
}
/>
</div>
<p data-part="scale">
<span>
{min.toLocaleString("ru-RU")} {unit}
</span>
<span>
{max.toLocaleString("ru-RU")} {unit}
</span>
</p>
</div>
</>
)
}