Date Range Picker (BS / Nepali)
shadcn-lexical-editor/date-range-picker-bsFreeComponent
A Nepali Bikram Sambat date range picker (AD values in, BS calendar UI) with quick presets and a two-month view.
Install it
npx shadcn@latest add http://www.alishpawn.com.np/r/date-range-picker-bs.jsonSource
1"use client";23import { useState, useRef, useEffect, useMemo, useCallback } from "react";4import { Calendar, ChevronLeft, ChevronRight } from "lucide-react";5import { cn } from "@/lib/utils";6import {7 adToBs,8 bsToAd,9 bsDaysInMonth,10 bsWeekdayOffset,11 bsMonthName,12} from "@/lib/nepali";1314export interface DateRange {15 from: string; // 'YYYY-MM-DD'16 to: string; // 'YYYY-MM-DD'17}1819interface DateRangePickerProps {20 value: DateRange;21 onChange: (value: DateRange) => void;22 placeholder?: string;23 className?: string;24 min?: string; // 'YYYY-MM-DD'25 id?: string;26}2728function toLocalDate(value: string): Date | null {29 if (!value) return null;30 const [y, m, d] = value.split("-").map(Number);31 return new Date(y, m - 1, d);32}3334function toValue(date: Date): string {35 const y = date.getFullYear();36 const m = String(date.getMonth() + 1).padStart(2, "0");37 const d = String(date.getDate()).padStart(2, "0");38 return `${y}-${m}-${d}`;39}4041function addDays(date: Date, days: number): Date {42 const d = new Date(date);43 d.setDate(d.getDate() + days);44 return d;45}4647function startOfWeek(date: Date): Date {48 const d = new Date(date);49 const day = d.getDay(); // 0 = Sun ... 6 = Sat50 return addDays(d, -day);51}5253function endOfWeek(date: Date): Date {54 return addDays(startOfWeek(date), 6);55}5657function startOfMonth(date: Date): Date {58 return new Date(date.getFullYear(), date.getMonth(), 1);59}6061function endOfMonth(date: Date): Date {62 return new Date(date.getFullYear(), date.getMonth() + 1, 0);63}6465function startOfYear(date: Date): Date {66 return new Date(date.getFullYear(), 0, 1);67}6869function endOfYear(date: Date): Date {70 return new Date(date.getFullYear(), 11, 31);71}7273function isSameDay(a: Date | null, b: Date | null): boolean {74 if (!a || !b) return false;75 return (76 a.getFullYear() === b.getFullYear() &&77 a.getMonth() === b.getMonth() &&78 a.getDate() === b.getDate()79 );80}8182function stripTime(date: Date): Date {83 return new Date(date.getFullYear(), date.getMonth(), date.getDate());84}8586function formatDisplay(date: Date): string {87 const d = String(date.getDate()).padStart(2, "0");88 const m = String(date.getMonth() + 1).padStart(2, "0");89 const y = date.getFullYear();90 return `${d}/${m}/${y}`;91}9293function formatBsDateValue(date: Date): string {94 const iso = toValue(date);95 const bs = adToBs(iso);96 if (!bs) return formatDisplay(date);97 return `${bs.year} ${bsMonthName(bs.month)} ${bs.date}`;98}99100// … 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 (AD)date-range-picker | shadcn-lexical-editor | Components | Free | 1 dep | |
| Rich Text Editorrich-text-editor | shadcn-lexical-editor | Components | Free | 15 deps · 52 files |
