Date Range Picker (AD)
shadcn-lexical-editor/date-range-pickerFreeComponent
A date range picker (Gregorian/AD) with quick presets, two-month view, hover preview, and a minimum date option.
Install it
npx shadcn@latest add http://www.alishpawn.com.np/r/date-range-picker.jsonSource
1"use client";23import { useState, useRef, useEffect, useMemo, useCallback } from "react";4import { Calendar, ChevronLeft, ChevronRight } from "lucide-react";5import { cn } from "@/lib/utils";67export interface DateRange {8 from: string; // 'YYYY-MM-DD'9 to: string; // 'YYYY-MM-DD'10}1112interface DateRangePickerProps {13 value: DateRange;14 onChange: (value: DateRange) => void;15 placeholder?: string;16 className?: string;17 min?: string; // 'YYYY-MM-DD'18 id?: string;19}2021function toLocalDate(value: string): Date | null {22 if (!value) return null;23 const [y, m, d] = value.split("-").map(Number);24 return new Date(y, m - 1, d);25}2627function toValue(date: Date): string {28 const y = date.getFullYear();29 const m = String(date.getMonth() + 1).padStart(2, "0");30 const d = String(date.getDate()).padStart(2, "0");31 return `${y}-${m}-${d}`;32}3334function addDays(date: Date, days: number): Date {35 const d = new Date(date);36 d.setDate(d.getDate() + days);37 return d;38}3940function addMonths(date: Date, months: number): Date {41 return new Date(date.getFullYear(), date.getMonth() + months, 1);42}4344// Monday-start week helpers45function startOfWeek(date: Date): Date {46 const d = new Date(date);47 const day = d.getDay(); // 0 = Sun ... 6 = Sat48 const diff = day === 0 ? -6 : 1 - day;49 return addDays(d, diff);50}5152function endOfWeek(date: Date): Date {53 return addDays(startOfWeek(date), 6);54}5556function startOfMonth(date: Date): Date {57 return new Date(date.getFullYear(), date.getMonth(), 1);58}5960function endOfMonth(date: Date): Date {61 return new Date(date.getFullYear(), date.getMonth() + 1, 0);62}6364function startOfYear(date: Date): Date {65 return new Date(date.getFullYear(), 0, 1);66}6768function endOfYear(date: Date): Date {69 return new Date(date.getFullYear(), 11, 31);70}7172function isSameDay(a: Date | null, b: Date | null): boolean {73 if (!a || !b) return false;74 return (75 a.getFullYear() === b.getFullYear() &&76 a.getMonth() === b.getMonth() &&77 a.getDate() === b.getDate()78 );79}8081function stripTime(date: Date): Date {82 return new Date(date.getFullYear(), date.getMonth(), date.getDate());83}8485function formatDisplay(date: Date): string {86 const d = String(date.getDate()).padStart(2, "0");87 const m = String(date.getMonth() + 1).padStart(2, "0");88 const y = date.getFullYear();89 return `${d}/${m}/${y}`;90}9192const WEEKDAYS = ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"];9394interface Preset {95 label: string;96 range: () => DateRange;97}9899// … truncated
What it pulls in
npm packages
Files it writes
More from shadcn-lexical-editor
All 6 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Date Picker (AD)date-picker | shadcn-lexical-editor | Components | Free | 1 dep | |
| Date Picker (BS / Nepali)date-picker-bs | shadcn-lexical-editor | Components | Free | 2 deps · 3 files | |
| Date Range Picker (BS / Nepali)date-range-picker-bs | shadcn-lexical-editor | Components | Free | 2 deps · 2 files | |
| Rich Text Editorrich-text-editor | shadcn-lexical-editor | Components | Free | 15 deps · 52 files |
