Pick a range or a single date in a popover: one or two months, presets, keyboard navigation, min/max and disabled days. No date library.
- Filter run history
- Report date window
- Usage period
- Compare two weeks
Examples
Installation
npx knowns-ui@latest add date-range-pickerPaste this into your coding agent (Claude Code, Cursor, Codex). It checks your project, sets up the registry, runs the install and verifies it.
Install Date range picker from Knowns UI into this project. Work step by step, show me each change, and ask before you edit files outside this project.
Context: Knowns UI (https://ui.knowns.dev) is a shadcn registry. Items land in the project as source files. Docs: https://ui.knowns.dev/docs/date-range-picker
1. Check the project first. Stop and tell me if any of these is missing:
- React 19 and Tailwind CSS v4.
- A components.json at the project root. If there is none, ask me before running `npx knowns-ui@latest init --no-key` (it runs shadcn init when needed, then adds the registries).
2. Run:
```bash
npx knowns-ui@latest add date-range-picker
```
It writes these files:
- lib/knowns/run.ts
- lib/knowns/json.tsx
- lib/knowns/status.ts
- lib/knowns/tone.ts
- lib/knowns/types.ts
- lib/knowns/use-abortable.ts
- lib/knowns/utils.ts
- lib/knowns/motion.tsx
- lib/knowns/motion-utils.ts
- components/ui/knowns/calendar/calendar.tsx
- components/ui/knowns/calendar/calendar-utils.ts
- components/ui/knowns/calendar/calendar-zone.ts
- components/ui/knowns/field-class.ts
- components/ui/knowns/use-floating.ts
- components/ui/knowns/popover.tsx
- components/ui/knowns/date-range-picker.tsx
and installs these npm packages: clsx@^2.1.1, tailwind-merge@^3.7.0.
3. While it runs:
- It also adds a few @keyframes (all named kn-*) to the global CSS file (globals.css or the file components.json points at). Let it: they only add animations.
- If it asks to overwrite files under lib/knowns/: these are shared by every Knowns UI item. List them, say whether I changed them (check git), and ask me before you answer.
- If it asks to overwrite any other file, show me the diff and ask me.
4. Verify:
- Every file in the list above exists.
- The project type-checks (for example `npx tsc --noEmit`) and the dev build has no new errors.
5. Use it: follow the examples and props on https://ui.knowns.dev/docs/date-range-picker, and ask me if anything about my data is unclear.
If the Knowns UI MCP server is connected (https://ui.knowns.dev/docs/ai-and-mcp), use get_component({ name: "date-range-picker" }) or search_docs for details.
Finish with a short summary: the files you added or changed, the packages you installed, and anything I still need to do.Props
- mode
"range"|"single"- Default
"range" - Single keeps one day in value.from.
- value / defaultValue / onValueChange
{ from, to? }|null- Default
null - onValueChange gets a complete range (or a day), or null on Clear.
- min / max / isDateDisabled
Date / Date / (d) => boolean- Days outside can't be picked or reached with the keyboard (min / max).
- presets
boolean|{ id, label, range }[]- Default
true in range mode - Today, Yesterday, Last 7 / 30 days, This / Last month, This year.
- months
1|2- Default
2 from 640px, else 1 - Months side by side.
- weekStartsOn / locale
number / string- Default
1 / browser - Names and formats come from Intl.DateTimeFormat; no date library.
- size / invalid / disabled / clearable
…- Default
"md" / false / false / true - Same field look and sizes as Input; works inside Field.
| Prop | Type | Default | Description |
|---|---|---|---|
| mode | "range" | "single" | "range" | Single keeps one day in value.from. |
| value / defaultValue / onValueChange | { from, to? } | null | null | onValueChange gets a complete range (or a day), or null on Clear. |
| min / max / isDateDisabled | Date / Date / (d) => boolean | - | Days outside can't be picked or reached with the keyboard (min / max). |
| presets | boolean | { id, label, range }[] | true in range mode | Today, Yesterday, Last 7 / 30 days, This / Last month, This year. |
| months | 1 | 2 | 2 from 640px, else 1 | Months side by side. |
| weekStartsOn / locale | number / string | 1 / browser | Names and formats come from Intl.DateTimeFormat; no date library. |
| size / invalid / disabled / clearable | … | "md" / false / false / true | Same field look and sizes as Input; works inside Field. |
Keyboard: the selected day (or today) gets focus. ← → move a day, ↑ ↓ a week, Home / End the week, PageUp / PageDown a month (with Shift a year), Enter or Space picks, Escape closes and returns focus. The first pick starts a range, the second ends it; hovering previews the range.
What it handles
- 01Opens one or two months in a popover and picks a range, or a single day when mode is single.
- 02Shows two months side by side from 640px wide and one below, unless you force months to 1 or 2.
- 03Offers presets beside the grid (Today, Yesterday, Last 7 days, Last 30 days, This month, Last month, This year), and highlights the one that matches the draft.
- 04Keeps a draft while the panel is open and only calls onValueChange for a complete range, so a start with no end is discarded on close.
- 05Writes the range with Intl formatRange, and the footer reads "pick an end date" until the second click lands.
- 06Clamps a preset to min and max, disables ones fully outside them, and greys days that isDateDisabled rejects.
States
- First render
- Nothing. The trigger paints with its range or placeholder
- none
- Panel opens
- The panel fades in under the trigger
- 120ms, opacity only
- Start picked
- The footer asks for an end date; the range is not committed yet
- none, at once
- Preset hover
- The preset row background changes
- 120ms, ease out
- Reduced motion
- The panel appears and leaves at once
- 0ms
| State | What moves | Timing |
|---|---|---|
| First render | Nothing. The trigger paints with its range or placeholder | none |
| Panel opens | The panel fades in under the trigger | 120ms, opacity only |
| Start picked | The footer asks for an end date; the range is not committed yet | none, at once |
| Preset hover | The preset row background changes | 120ms, ease out |
| Reduced motion | The panel appears and leaves at once | 0ms |
Works with
When to use
When to use
- Choosing a date or a range with presets, min and max dates and disabled days.
When not to use
- A date the user knows by heart, such as a birthday: typed fields are faster: use Input.
Using with AI
Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:
- Add the Knowns UI Date Range Picker to my app and wire it to my own data.
- I need choosing a date or a range with presets, min and max dates and disabled days. Set that up with the Knowns UI Date Range Picker.
- Which Date Range Picker props do I need for a minimal setup? Show me a short example.
With the server connected, your assistant calls get_component({ name: "date-range-picker" }) and search_docs({ query: "date range picker" }).