SwipeUI

Date range picker

A field that opens a calendar for a range: hold a day and drag (turning months at the edge), shortcuts, a draft until Apply, length limits and a rolling "5 nights".

npx @swipeui/cli add date-range-picker
Variant
Preset
Material
Scheme
Feel
Real free component with a browser animation bridge. Native motion, haptics and materials need a device.

When to use it

  • Booking stays, rentals or trips with a first and last day, counted in nights.
  • Report and analytics filters, with shortcuts like Last 7 days.
  • Leave requests and campaigns where some days in between can't be chosen, or the length is limited.

When not to use it

  • A single date. Use Date picker.
  • A calendar that stays on screen. Use Calendar with `mode="range"`.
  • Relative periods only (Day, Week, Month). Use Segmented control.

Installation

Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.

npx @swipeui/cli add date-range-picker
  • Adds components/swipeui/ui/date-range-picker.tsx, components/swipeui/ui/use-date-range-picker.ts and 19 shared helpers.
  • Installs react-native-gesture-handler, react-native-reanimated, react-native-worklets, uniwind, clsx, tailwind-merge, expo-haptics, class-variance-authority, react-native-svg, react-native-safe-area-context, @expo/ui, @gorhom/bottom-sheet, expo-blur. In Expo apps it uses npx expo install so versions match your SDK.

Usage

app/booking.tsx
import { DateRangePicker } from '@/components/swipeui/ui/date-range-picker';

<DateRangePicker label="Travel dates" />;

Sheets need SheetProvider near the app root; on wide screens the calendar opens in a popover, which needs OverlayProvider.

Examples

A stay counted in nights, at least two and at most three weeks, that never crosses a booked night:

<DateRangePicker
  label="Stay"
  lengthUnit="nights"
  minLength={2}
  maxLength={21}
  isDateDisabled={isBooked}
/>

Report shortcuts (Today, Last 7 days, Last 30 days, This month, Year to date) that keep the range as soon as it's finished:

<DateRangePicker label="Report period" presets="standard" commit="instant" clearable />

Your own shortcuts:

<DateRangePicker
  label="Compare with"
  presets={[{ label: 'Launch week', value: { start: launch, end: addDays(launch, 6) } }]}
/>

API reference

DateRangePickerProps

PropTypeDefaultDescription
labelstring—

The visible and spoken name. An empty string hides it visually.

value?DateRange—

The chosen range (controlled).

defaultValue?DateRange{}

The range it starts with (uncontrolled).

onValueChange?((value: DateRange) => void)—

Reports a range once it's applied (or finished, with commit="instant"), or {} after clearing.

placeholder?string'Choose dates'

Shown, muted, when nothing is chosen.

presets?"none" | "standard" | readonly DateRangePreset[]'none'

Shortcuts above the calendar: your own, standard (Today, Last 7 days, Last 30 days, This month, Year to date) or none.

presetLayout?"auto" | "list" | "row"'auto'

Shortcuts as a scrolling row of chips, a side list, or auto: a row on phones and a list when the panel is wide.

commit?"apply" | "instant"'apply'

apply keeps a draft until Apply (Cancel, Escape or an outside tap discard it); instant commits as soon as a range is finished.

closeDelay?number400

With commit="instant", how long the finished range stays in view before the panel closes, in milliseconds (content timing).

months?"auto" | 1 | 2'auto'

Months side by side: one, two, or auto (two when the panel is wide enough).

presentation?"auto" | "popover" | "sheet"'auto'

Where the calendar opens: a sheet, a popover under the field, or auto (a sheet on phones, a popover on wide screens).

minDate?Date—

The earliest day that can be chosen.

maxDate?Date—

The latest day that can be chosen.

isDateDisabled?((date: Date) => boolean)—

Your own rule for days that can't be chosen; ranges never cross one.

minLength?number1

The shortest range, in lengthUnit. Shorter ranges can't be applied.

maxLength?numberunlimited

The longest range, in lengthUnit. Drags and taps stop there.

lengthUnit?RangeLengthUnit'days'

How length is counted and shown: days (both ends) or nights (stays).

showLength?booleantrue

★ The footer's rolling length ("5 nights").

caption?booleantrue

"From … to …" under the calendar once a range is finished.

paintSelect?booleantrue

★ Hold a day and drag to draw the range; the tint follows the finger.

edgePaging?booleantrue

★ While holding, resting against the calendar's side edges turns the month.

weekStartsOn?"locale" | WeekStart1

First day of the week, Sunday = 0, or locale. Monday by default, so the app and the web match.

firstDayOfWeek?WeekStart—

1.x name for weekStartsOn.

locale?stringthe device's

Locale for month and weekday names and the field's dates.

formatValue?((range: { start: Date; end: Date; }) => string)"12 – 18 Nov" in the locale's order

Your own field text for a range.

rollValue?booleantrue

The field's text rolls up for a later range and down for an earlier one.

clearable?booleanfalse

A clear button inside the field while a range is chosen.

open?boolean—

Whether the calendar is open (controlled).

defaultOpen?booleanfalse

Open on mount (uncontrolled).

onOpenChange?((open: boolean) => void)—

Reports opening and closing.

helper?string—

Supporting text under the field.

error?string—

Validation message. A new one shakes the field once and plays an error haptic.

success?string—

Confirmation text; replaces the helper.

status?FieldStatus'idle'

Validation state shown on the field.

required?booleanfalse

Marks the field required; "Required" is spoken.

requiredIndicator?FieldRequiredIndicator'asterisk'

How a required field is marked.

optionalIndicator?booleanfalse

Show "Optional" after the label.

disabled?booleanfalse

Prevents opening and clearing.

disabledStyle?FieldDisabledStyle'muted'

muted lightens the field without opacity; dim lowers it to 50%.

appearance?FieldAppearance'filled'

The field's surface.

size?FieldSize'md'

sm 36pt, md 44pt, lg 52pt.

shape?FieldShape'preset'

preset follows the preset's corners; pill is a capsule.

labelPlacement?FieldLabelPlacement'above'

Where the label sits: above, inside at the top (inset), or spoken only.

focusRing?FieldFocusRing'halo'

The ring and halo shown while open.

leadingIcon?ButtonIcon—

A leading icon in the field: a node, or a function given the state colour and size.

messages?Partial<DateRangePickerMessages>DATE_RANGE_PICKER_MESSAGES (English)

Built-in strings, for translation.

haptics?boolean | SelectionHapticstrue

Haptics: a switch, or per part (select for days and shortcuts, detent for drags and turned months, limit at the longest range, clear).

motion?MotionOverridethe app's feel

Field, panel, calendar and footer motion.

className?string—

Classes on the field.

style?StyleProp<ViewStyle>—

Field style.

testID?string—

The field's identifier. Parts append -calendar (days add -<y>-<m>-<d>), -calendar-2, -preset-<n>, -caption, -length, -apply, -cancel, -clear.

Ranges are { start?, end? } of local days. onValueChange reports a finished range, or {} after clearing.

Composition and behavior

  • The trigger is a field: filled by default, a compact range ("Nov 12 – 18", in the locale's order, with years when the range leaves this year), an optional leading icon and a chevron that turns while open, with the focus ring. The text rolls up for a later range and down for an earlier one.
  • Tap the first day, then the last. A last day before the first swaps them, and a range stops before a day that can't be chosen.
  • ★ Hold a day and drag: a tinted highlight follows the finger and lifting sets the last day. Rest the finger on the calendar's side edge to turn the month without lifting; the range keeps following.
  • Once a range is finished, "From … to …" appears under the calendar and the footer rolls its length in days or nights. The first day, then the finished range and its length, are announced.
  • With commit apply, the range is a draft until Apply; Cancel, Escape or a tap outside discard it. With instant, a finished range is kept at once and the panel closes after closeDelay.
  • minLength keeps Apply off until the range is long enough and says why; maxLength stops a drag or a second tap at the longest range, with a limit tick.
  • Shortcuts are a scrolling row of chips on phones and a side list when the panel is wide; two months show side by side from 600pt.

Date range picker settings

PropDoesDefault
presetsYour own shortcuts, standard or nonenone
presetLayoutauto (chips, side list when wide), row or listauto
commit / closeDelayapply draft or instant (ms before closing)apply, 400
monthsauto, 1 or 2 side by sideauto
presentationauto (sheet on phones), sheet or popoverauto
lengthUnitCount days or nightsdays
minLength / maxLengthShortest and longest range, in the unit1, unlimited
showLength★ The footer's rolling lengthtrue
caption"From … to …" under the calendartrue
paintSelect / edgePaging★ Hold and drag; turn months at the edgetrue, true
minDate / maxDate / isDateDisabledDays that can't be chosennone
weekStartsOnFirst weekday (Sunday = 0) or locale1 (Monday)
formatValueYour own field textlocale "Nov 12 – 18"
rollValue / clearableRolling field text; a clear buttontrue, false
appearance / size / shapeField look: filled…, sm/md/lg, preset/pillfilled, md, preset
labelPlacement / leadingIconabove, inset or hidden; an iconabove, none
helper / error / successMessages under the fieldnone
required / disabledRequired mark; no opening or clearingfalse
hapticsAll, or { select, detent, limit, clear }select, detent, limit
messagesBuilt-in strings (and calendar), for translationEnglish
motionA local motion feel or overridethe app's feel

Behavior and gestures

  • Tap the field to open the calendar: a sheet on phones, a popover under the field on wide screens (`presentation`).
  • Tap the first day, then the last; a last day before the first swaps them, and a range stops before a day that can't be chosen.
  • ★ Hold a day (350 ms) and drag: a tinted highlight follows the finger, and lifting sets the last day. Resting on the calendar's side edge turns the month without lifting (`paintSelect`, `edgePaging`).
  • Once a range is finished, "From … to …" appears under the calendar and the footer rolls its length (`lengthUnit` days or nights).
  • Shortcuts (`presets`, or `standard`) fill the range in one tap and turn the calendar to it: a scrolling row of chips on phones, a side list when the panel is wide.
  • Apply keeps the range; Cancel, Escape or a tap outside discard the draft (`commit="apply"`). With `commit="instant"` a finished range is kept at once and the panel closes after `closeDelay`.
  • `minLength` keeps Apply off until the range is long enough and says so; `maxLength` stops a drag or a second tap at the longest range with a limit tick.
  • With `clearable`, a clear button inside the field empties it.

Accessibility

  • The field is a button named "Label: range" (or the placeholder) that reports expanded; helper or error text is its hint.
  • Each day reads its full date and whether it's chosen, inside the range or unavailable.
  • The first day is announced, then the finished range with its length in the unit ("From Nov 9 to Nov 14, 5 nights"); shortcuts announce the same way.
  • Shortcuts report `selected` when the draft matches them. Apply is named "Apply <label>" and is disabled until the range is valid; the footer note is a polite live region.
  • Every gesture has a tap path: tap the first and last day, and use the header buttons to turn months.

Motion

  • Uses the select, toggle, morph, number, overlay, drag and press motion roles, so it follows your app's feel. Pass motion to tune this one instance.
  • The sheet or popover opens on the overlay role; the ring and chevron turn on the toggle role.
  • Inside, the calendar's highlight, range bars and months move on its own roles (select, toggle, overlay, drag).
  • The field's text rolls up for a later range and down for an earlier one on the morph role; "From … to …" rises in on morph; the length rolls its digits on the number role.
  • Reduce Motion: the text and caption fade, the length swaps, and the calendar jumps instead of sliding; haptics stay.

Performance

  • The calendar mounts only while the panel is open. Drags run on the UI thread with one tick per day crossed.
  • Dates are counted on calendar fields (no millisecond maths), so ranges are right across daylight-saving changes.

Notes for AI

  • Ranges are `{ start?, end? }` of local days; `onValueChange` reports a finished range (or `{}` after clearing).
  • Pass presets as `{ label, value: { start, end } }`, or `presets="standard"` for Today, Last 7 days, Last 30 days, This month and Year to date (names through `messages.presetNames`).
  • `minLength` and `maxLength` count in `lengthUnit`: a 2-night minimum is `minLength={2} lengthUnit="nights"`.
  • Popovers need `OverlayProvider` at the app root; sheets need `SheetProvider`.
  • Strings (including the calendar's, under `messages.calendar`) are translatable; month names fall back to English on engines without `Intl` month names.

Compatibility

Runs onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items