Inputs

Range Two Fields

A date range as two fields that keeps its own order: the end follows the start, and the duration is counted on the spot.

  • date
  • range
  • booking
  • validation

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/date-003?lang=en

Stay dates

Длительность5 ночей

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 "date-003" (Range Two Fields) 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/date-003.json

Registry item: https://vibeui.ru/r/date-003.json
Installs to: components/vibeui/date-003.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 date range as two fields that keeps its own order: the end follows the start, and the duration is counted on the spot.

A check-in / check-out pair: the second field refuses anything earlier than the first, the end auto-shifts, and the night count updates instantly. Zero dependencies, one file.

## 3. How to use it
import { Date003 } from "@/components/vibeui/date-003"

<Date003 legend="Stay dates" defaultFrom="2026-09-14" defaultTo="2026-09-19" min="2026-09-01" />

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-date-003-* palette — do not swap it for your theme tokens
- its own light surface: the fields get shown over any background
- the second field's min taken from the first: better to make a reversed range impossible than to catch it later
- auto-shifting the end when the start moves past it: forcing a re-pick of both dates over one edit is rude
- clear:both on the field row: a legend with float:left otherwise makes the fields wrap around it
- the night count: a date range gets mentally converted into a duration anyway
- aria-live on the duration line: the number changes without a reload

## 6. You may change
- legend — the heading over the pair
- defaultFrom and defaultTo — the starting range
- min — the earliest date available
- the "check-in" and "check-out" captions for your scenario
- the accent through the accent prop

## 7. Rules
- String comparison only works for the YYYY-MM-DD format: any other format needs parsing.
- There is no maximum range length — cap it outside if bookings longer than a month are forbidden.
- Nights are counted from the date difference with no timezone maths, which is enough for whole days.
- 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/date-003.json
https://vibeui.ru/r/date-003.json

Компонент самодостаточен: один файл, ноль зависимостей, палитра в локальных переменных --vibeui-date-003-*. Клиентский: обе даты в состоянии, они связаны. Второму полю ставится min по первому, поэтому системный календарь просто не даёт выбрать дату раньше начала. Если начало сдвинули за уже выбранный конец, конец переносится на следующий день вместо ошибки. Даты сравниваются как строки ISO — при одинаковом формате это корректно и не требует парсинга. legend лежит во float, поэтому у ряда полей стоит clear:both.

Component source

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

"use client"

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

export type Date003Props = Omit<
  ComponentPropsWithoutRef<"fieldset">,
  "children" | "defaultValue"
> & {
  legend?: string
  defaultFrom?: string
  defaultTo?: string
  min?: string
  accent?: string
}

// Идея компонента: диапазон двумя полями, где порядок дат чинится сам. Второму
// полю ставится min по первому, поэтому системный календарь физически не даёт
// выбрать дату раньше начала. Если начало сдвинули вперёд уже выбранного конца,
// конец подтягивается за ним, а не превращается в ошибку: перевыбирать обе даты
// из-за одной правки — обидно. Число ночей считается тут же: диапазон дат
// пользователь всё равно мысленно переводит в длительность.
const STYLES = `
:where([data-vibeui-block="date-003"]){
--vibeui-date-003-surface:oklch(1 0 0);
--vibeui-date-003-field:oklch(1 0 0);
--vibeui-date-003-shell:oklch(0.9 0.006 265);
--vibeui-date-003-fg:oklch(0.23 0.014 265);
--vibeui-date-003-muted:oklch(0.55 0.014 265);
--vibeui-date-003-border:oklch(0.88 0.008 265);
--vibeui-date-003-accent:oklch(0.52 0.16 210);
--vibeui-date-003-soft:oklch(0.52 0.16 210 / 10%);
--vibeui-date-003-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
/* Своя светлая подложка: поля показывают поверх любого фона. */
[data-vibeui-block="date-003"]{
display:flex;flex-direction:column;gap:0.5rem;
width:100%;max-width:22rem;box-sizing:border-box;margin:0;padding:0.875rem;
background:var(--vibeui-date-003-surface);
border:1px solid var(--vibeui-date-003-shell);border-radius:0.875rem;
font-family:var(--vibeui-date-003-font);color:var(--vibeui-date-003-fg);
}
/* legend во float даёт обтекание: clear возвращает нормальный поток. */
[data-vibeui-block="date-003"] legend{
float:left;width:100%;padding:0;margin-bottom:0.5rem;font-size:0.875rem;font-weight:650;
}
[data-vibeui-block="date-003"] [data-part="pair"]{clear:both;display:flex;gap:0.5rem;flex-wrap:wrap}
[data-vibeui-block="date-003"] [data-part="cell"]{
flex:1 1 8rem;min-width:0;display:flex;flex-direction:column;gap:0.25rem;
}
[data-vibeui-block="date-003"] label{font-size:0.6875rem;font-weight:650;color:var(--vibeui-date-003-muted);text-transform:uppercase;letter-spacing:0.04em}
[data-vibeui-block="date-003"] input{
width:100%;box-sizing:border-box;height:2.625rem;padding:0 0.625rem;
background:var(--vibeui-date-003-field);color:inherit;
border:1px solid var(--vibeui-date-003-border);border-radius:0.625rem;
font:inherit;font-size:0.875rem;font-variant-numeric:tabular-nums;
}
[data-vibeui-block="date-003"] input:focus-visible{
outline:2px solid var(--vibeui-date-003-accent);outline-offset:1px;border-color:var(--vibeui-date-003-accent);
}
[data-vibeui-block="date-003"] input::-webkit-calendar-picker-indicator{cursor:pointer;opacity:.55}
[data-vibeui-block="date-003"] input::-webkit-calendar-picker-indicator:hover{opacity:1}
/* Длительность важнее самих дат: её всё равно считают в уме. */
[data-vibeui-block="date-003"] [data-part="summary"]{
display:flex;align-items:center;justify-content:space-between;gap:0.75rem;
margin:0;padding:0.5rem 0.625rem;border-radius:0.5rem;
background:var(--vibeui-date-003-soft);
font-size:0.8125rem;font-variant-numeric:tabular-nums;
}
[data-vibeui-block="date-003"] [data-part="nights"]{font-weight:700;color:var(--vibeui-date-003-accent)}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="date-003"] *{animation:none!important;transition:none!important}}
`

const DAY = 86400000

function nightsBetween(from: string, to: string) {
  const start = Date.parse(from)
  const end = Date.parse(to)
  if (!Number.isFinite(start) || !Number.isFinite(end)) return 0
  return Math.max(0, Math.round((end - start) / DAY))
}

function plusDay(date: string) {
  const next = Date.parse(date)
  if (!Number.isFinite(next)) return date
  return new Date(next + DAY).toISOString().slice(0, 10)
}

function nightsWord(count: number) {
  const tail = count % 10
  const teen = count % 100
  if (teen > 10 && teen < 20) return "ночей"
  if (tail === 1) return "ночь"
  if (tail > 1 && tail < 5) return "ночи"
  return "ночей"
}

/**
 * Диапазон дат двумя полями: порядок чинится сам, длительность считается сразу.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Date003({
  legend = "Даты проживания",
  defaultFrom = "2026-09-14",
  defaultTo = "2026-09-19",
  min = "2026-09-01",
  accent,
  className,
  style,
  ...props
}: Date003Props) {
  const id = useId()
  const [from, setFrom] = useState(defaultFrom)
  const [to, setTo] = useState(defaultTo)
  const nights = nightsBetween(from, to)

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

  return (
    <>
      <style href="vibeui-date-003" precedence="medium">
        {STYLES}
      </style>
      <fieldset
        {...props}
        data-vibeui-block="date-003"
        className={className}
        style={palette}
      >
        <legend>{legend}</legend>
        <div data-part="pair">
          <div data-part="cell">
            <label htmlFor={`${id}-from`}>Заезд</label>
            <input
              id={`${id}-from`}
              type="date"
              value={from}
              min={min}
              onChange={(event) => {
                const next = event.target.value
                setFrom(next)
                // Конец подтягивается за началом: перевыбирать обе даты обидно.
                if (next && next >= to) setTo(plusDay(next))
              }}
            />
          </div>
          <div data-part="cell">
            <label htmlFor={`${id}-to`}>Выезд</label>
            <input
              id={`${id}-to`}
              type="date"
              value={to}
              min={plusDay(from)}
              onChange={(event) => setTo(event.target.value)}
            />
          </div>
        </div>
        <p data-part="summary" aria-live="polite">
          <span>Длительность</span>
          <span data-part="nights">
            {nights} {nightsWord(nights)}
          </span>
        </p>
      </fieldset>
    </>
  )
}