@itzsa/nepali-datepicker 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -0
- package/dist/index.d.mts +328 -0
- package/dist/index.d.ts +328 -0
- package/dist/index.js +2217 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2145 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +67 -0
- package/src/styles.css +619 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ClassValue } from 'clsx';
|
|
3
|
+
|
|
4
|
+
type Locale = "en" | "ne";
|
|
5
|
+
type DateParts = {
|
|
6
|
+
year: number;
|
|
7
|
+
month: number;
|
|
8
|
+
day: number;
|
|
9
|
+
};
|
|
10
|
+
/** BS civil date + clock time (24h). */
|
|
11
|
+
type DateTimeParts = DateParts & {
|
|
12
|
+
hour: number;
|
|
13
|
+
minute: number;
|
|
14
|
+
/** Optional; included in string only when `withSeconds` is used. */
|
|
15
|
+
second?: number;
|
|
16
|
+
};
|
|
17
|
+
type DatePattern = "YYYY-MM-DD" | "YYYY/MM/DD" | "DD-MM-YYYY" | "DD/MM/YYYY";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Optional CSS variable overrides applied on the root / popover.
|
|
21
|
+
* Prefer these over forking styles.css.
|
|
22
|
+
*/
|
|
23
|
+
type NepaliDatePickerVars = {
|
|
24
|
+
accent?: string;
|
|
25
|
+
accentForeground?: string;
|
|
26
|
+
background?: string;
|
|
27
|
+
foreground?: string;
|
|
28
|
+
muted?: string;
|
|
29
|
+
border?: string;
|
|
30
|
+
surface?: string;
|
|
31
|
+
radius?: string;
|
|
32
|
+
font?: string;
|
|
33
|
+
};
|
|
34
|
+
type NepaliDatePickerClassNames = {
|
|
35
|
+
root?: string;
|
|
36
|
+
field?: string;
|
|
37
|
+
input?: string;
|
|
38
|
+
trigger?: string;
|
|
39
|
+
popover?: string;
|
|
40
|
+
day?: string;
|
|
41
|
+
daySelected?: string;
|
|
42
|
+
footer?: string;
|
|
43
|
+
};
|
|
44
|
+
type NepaliDateRangeClassNames = NepaliDatePickerClassNames & {
|
|
45
|
+
rangeTrigger?: string;
|
|
46
|
+
rangeLabel?: string;
|
|
47
|
+
rangeMonths?: string;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
type BsDateRange = {
|
|
51
|
+
from?: string;
|
|
52
|
+
to?: string;
|
|
53
|
+
};
|
|
54
|
+
type NepaliDateRangePickerProps = {
|
|
55
|
+
value?: BsDateRange;
|
|
56
|
+
defaultValue?: BsDateRange;
|
|
57
|
+
onChange?: (range: BsDateRange) => void;
|
|
58
|
+
locale?: Locale;
|
|
59
|
+
valueLocale?: Locale;
|
|
60
|
+
minDate?: string;
|
|
61
|
+
maxDate?: string;
|
|
62
|
+
minYear?: number;
|
|
63
|
+
maxYear?: number;
|
|
64
|
+
/** Show one or two months. Default `2`. */
|
|
65
|
+
numberOfMonths?: 1 | 2;
|
|
66
|
+
/** Close after both ends are selected. Default `true`. */
|
|
67
|
+
closeOnSelect?: boolean;
|
|
68
|
+
placeholder?: string;
|
|
69
|
+
disabled?: boolean;
|
|
70
|
+
className?: string;
|
|
71
|
+
triggerClassName?: string;
|
|
72
|
+
popoverClassName?: string;
|
|
73
|
+
classNames?: NepaliDateRangeClassNames;
|
|
74
|
+
vars?: NepaliDatePickerVars;
|
|
75
|
+
style?: React.CSSProperties;
|
|
76
|
+
popoverStyle?: React.CSSProperties;
|
|
77
|
+
id?: string;
|
|
78
|
+
"aria-label"?: string;
|
|
79
|
+
};
|
|
80
|
+
declare function NepaliDateRangePicker({ value: valueProp, defaultValue, onChange, locale, valueLocale, minDate, maxDate, minYear, maxYear, numberOfMonths, closeOnSelect, placeholder, disabled, className, triggerClassName, popoverClassName, classNames, vars, style, popoverStyle, id, "aria-label": ariaLabel, }: NepaliDateRangePickerProps): React.JSX.Element;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* BS month lengths (Baisakh o Chaitra), years 2000–2100.
|
|
84
|
+
* Community-verified Nepal Panchanga tables (same range used by common BS libraries).
|
|
85
|
+
*/
|
|
86
|
+
declare const BS_MONTH_DAYS: Record<number, readonly number[]>;
|
|
87
|
+
declare const BS_MIN_YEAR = 2000;
|
|
88
|
+
declare const BS_MAX_YEAR = 2100;
|
|
89
|
+
/** BS 2000-01-01 corresponds to AD 1943-04-14 (civil date). */
|
|
90
|
+
declare const BS_EPOCH_AD: {
|
|
91
|
+
readonly year: 1943;
|
|
92
|
+
readonly month: 4;
|
|
93
|
+
readonly day: 14;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/** Days in a BS month (1–12). */
|
|
97
|
+
declare function getDaysInBsMonth(year: number, month: number): number;
|
|
98
|
+
/** Total days in a BS year. */
|
|
99
|
+
declare function getDaysInBsYear(year: number): number;
|
|
100
|
+
declare function isValidBsDate(year: number, month: number, day: number): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Convert Bikram Sambat → Anno Domini (civil calendar).
|
|
103
|
+
* Month is 1–12 (Baisakh = 1).
|
|
104
|
+
*/
|
|
105
|
+
declare function bsToAd(year: number, month: number, day: number): DateParts;
|
|
106
|
+
/**
|
|
107
|
+
* Convert Anno Domini → Bikram Sambat.
|
|
108
|
+
* Month is 1–12.
|
|
109
|
+
*/
|
|
110
|
+
declare function adToBs(year: number, month: number, day: number): DateParts;
|
|
111
|
+
/** Today's date in BS (local timezone civil date → BS). */
|
|
112
|
+
declare function todayBs(): DateParts;
|
|
113
|
+
/** Today + current local clock as BS datetime. */
|
|
114
|
+
declare function todayBsDateTime(): DateTimeParts;
|
|
115
|
+
/** Weekday for a BS date: 0 = Sunday … 6 = Saturday (UTC civil). */
|
|
116
|
+
declare function getBsWeekday(year: number, month: number, day: number): number;
|
|
117
|
+
/** Compare two date parts: -1 / 0 / 1. */
|
|
118
|
+
declare function compareDateParts(a: DateParts, b: DateParts): number;
|
|
119
|
+
declare function clampBsDate(parts: DateParts, min?: DateParts | null, max?: DateParts | null): DateParts;
|
|
120
|
+
declare function addBsMonths(year: number, month: number, delta: number): {
|
|
121
|
+
year: number;
|
|
122
|
+
month: number;
|
|
123
|
+
};
|
|
124
|
+
/** Signed day difference: `b − a` (same calendar day → 0). */
|
|
125
|
+
declare function diffBsDays(a: DateParts, b: DateParts): number;
|
|
126
|
+
/** Add (or subtract) days on the BS calendar via AD civil arithmetic. */
|
|
127
|
+
declare function addBsDays(parts: DateParts, delta: number): DateParts;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Parse `YYYY-MM-DD HH:mm`, `YYYY-MM-DDTHH:mm`, or with `:ss`.
|
|
131
|
+
* Date-only strings get `00:00:00`.
|
|
132
|
+
*/
|
|
133
|
+
declare function parseDateTimeString(value: string): DateTimeParts | null;
|
|
134
|
+
declare function toDateTimeString(parts: DateTimeParts, opts?: {
|
|
135
|
+
withSeconds?: boolean;
|
|
136
|
+
}): string;
|
|
137
|
+
declare function dateTimeToDateParts(dt: DateTimeParts): DateParts;
|
|
138
|
+
declare function compareDateTimeParts(a: DateTimeParts, b: DateTimeParts): number;
|
|
139
|
+
declare function clampDateTime(parts: DateTimeParts, min?: DateTimeParts | null, max?: DateTimeParts | null): DateTimeParts;
|
|
140
|
+
/** Bound string may be date-only (`YYYY-MM-DD`) or full datetime. */
|
|
141
|
+
declare function parseDateTimeBound(value: string | undefined, edge: "min" | "max"): DateTimeParts | null;
|
|
142
|
+
declare function isCompleteBsDateTime(value: string, opts?: {
|
|
143
|
+
requireSeconds?: boolean;
|
|
144
|
+
}): boolean;
|
|
145
|
+
/** Round minute down to step (e.g. 15 → 0,15,30,45). */
|
|
146
|
+
declare function snapMinute(minute: number, step: number): number;
|
|
147
|
+
|
|
148
|
+
/** Parse `YYYY-MM-DD` or `YYYY/MM/DD` (ASCII) into parts. Returns null if invalid. */
|
|
149
|
+
declare function parseDateString(value: string): DateParts | null;
|
|
150
|
+
/**
|
|
151
|
+
* Mask typed digits into `YYYY-MM-DD` as the user types (max 8 digits).
|
|
152
|
+
* Does not validate calendar correctness — only formatting.
|
|
153
|
+
*/
|
|
154
|
+
declare function formatTypedBsDate(raw: string): string;
|
|
155
|
+
/** True when the string is a complete, calendar-valid BS date. */
|
|
156
|
+
declare function isCompleteBsDate(value: string): boolean;
|
|
157
|
+
/** Format parts as ASCII `YYYY-MM-DD` (canonical value format). */
|
|
158
|
+
declare function toDateString(parts: DateParts): string;
|
|
159
|
+
declare function formatDateParts(parts: DateParts, pattern?: DatePattern, locale?: Locale): string;
|
|
160
|
+
/** Human-readable label, e.g. `15 Magh 2082` / `१५ माघ २०८२`. */
|
|
161
|
+
declare function formatBsLabel(parts: DateParts, locale?: Locale): string;
|
|
162
|
+
/** e.g. `15 Magh 2082, 14:30` */
|
|
163
|
+
declare function formatBsDateTimeLabel(parts: DateTimeParts, locale?: Locale, opts?: {
|
|
164
|
+
withSeconds?: boolean;
|
|
165
|
+
}): string;
|
|
166
|
+
|
|
167
|
+
declare const NEPALI_MONTH_NAMES_EN: readonly ["Baisakh", "Jestha", "Ashar", "Shrawan", "Bhadra", "Ashwin", "Kartik", "Mangsir", "Poush", "Magh", "Falgun", "Chaitra"];
|
|
168
|
+
declare const NEPALI_MONTH_NAMES_NE: readonly ["बैशाख", "जेठ", "असार", "साउन", "भदौ", "असोज", "कार्तिक", "मंसिर", "पुष", "माघ", "फाल्गुन", "चैत"];
|
|
169
|
+
declare const WEEKDAY_NAMES_EN: readonly ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
170
|
+
declare const WEEKDAY_NAMES_NE: readonly ["आइत", "सोम", "मंगल", "बुध", "बिही", "शुक्र", "शनि"];
|
|
171
|
+
declare function getMonthName(month: number, locale?: Locale): string;
|
|
172
|
+
declare function getWeekdayNames(locale?: Locale): readonly string[];
|
|
173
|
+
/** Map ASCII digits to Devanagari when locale is `ne`. */
|
|
174
|
+
declare function localizeDigits(value: string | number, locale: Locale): string;
|
|
175
|
+
|
|
176
|
+
type ValidationResult = {
|
|
177
|
+
ok: true;
|
|
178
|
+
} | {
|
|
179
|
+
ok: false;
|
|
180
|
+
code: ValidationCode;
|
|
181
|
+
message: string;
|
|
182
|
+
};
|
|
183
|
+
type ValidationCode = "required" | "type" | "year_range" | "month_range" | "day_range" | "invalid_date";
|
|
184
|
+
/** Assert BS year is an integer in the supported table range. */
|
|
185
|
+
declare function assertBsYear(year: number): void;
|
|
186
|
+
declare function assertBsMonth(month: number): void;
|
|
187
|
+
declare function assertBsDay(day: number): void;
|
|
188
|
+
/**
|
|
189
|
+
* Soft validation (no throw). Use in forms before submit.
|
|
190
|
+
* Equivalent purpose to the jQuery plugin checks — without its compressed calendar codec.
|
|
191
|
+
*/
|
|
192
|
+
declare function validateBsDate(year: number, month: number, day: number): ValidationResult;
|
|
193
|
+
declare function validateBsDateParts(parts: DateParts): ValidationResult;
|
|
194
|
+
/** Throw if invalid — mirrors jQuery plugin hard checks. */
|
|
195
|
+
declare function assertValidBsDate(year: number, month: number, day: number): void;
|
|
196
|
+
|
|
197
|
+
type NepaliDatePickerProps = {
|
|
198
|
+
/** Controlled BS date as `YYYY-MM-DD` (ASCII). Empty string = no selection. */
|
|
199
|
+
value?: string;
|
|
200
|
+
/** Uncontrolled initial value. */
|
|
201
|
+
defaultValue?: string;
|
|
202
|
+
/** Called with canonical `YYYY-MM-DD` BS string (or `""` when cleared). */
|
|
203
|
+
onChange?: (value: string) => void;
|
|
204
|
+
/** Fired when a day is clicked (before close). */
|
|
205
|
+
onSelect?: (value: string) => void;
|
|
206
|
+
/** Calendar UI locale (month/weekday names + digits). Default `"ne"`. */
|
|
207
|
+
locale?: Locale;
|
|
208
|
+
/** Digits/locale for the input display. Default matches `locale`. */
|
|
209
|
+
valueLocale?: Locale;
|
|
210
|
+
/** Minimum selectable BS date `YYYY-MM-DD`. */
|
|
211
|
+
minDate?: string;
|
|
212
|
+
/** Maximum selectable BS date `YYYY-MM-DD`. */
|
|
213
|
+
maxDate?: string;
|
|
214
|
+
/** Inclusive year bounds (defaults to supported calendar range). */
|
|
215
|
+
minYear?: number;
|
|
216
|
+
maxYear?: number;
|
|
217
|
+
/** Close popover after picking a day. Default `true`. */
|
|
218
|
+
closeOnSelect?: boolean;
|
|
219
|
+
/** If value is empty, show today as the initial calendar month. Default `true`. */
|
|
220
|
+
todayIfEmpty?: boolean;
|
|
221
|
+
placeholder?: string;
|
|
222
|
+
disabled?: boolean;
|
|
223
|
+
readOnly?: boolean;
|
|
224
|
+
id?: string;
|
|
225
|
+
name?: string;
|
|
226
|
+
required?: boolean;
|
|
227
|
+
className?: string;
|
|
228
|
+
inputClassName?: string;
|
|
229
|
+
popoverClassName?: string;
|
|
230
|
+
/** Per-part class overrides (merged with defaults). */
|
|
231
|
+
classNames?: NepaliDatePickerClassNames;
|
|
232
|
+
/** Theme tokens as CSS variables (`accent`, `border`, `radius`, …). */
|
|
233
|
+
vars?: NepaliDatePickerVars;
|
|
234
|
+
/** Inline styles on the root (merged with `vars`). */
|
|
235
|
+
style?: React.CSSProperties;
|
|
236
|
+
/** Inline styles on the popover panel. */
|
|
237
|
+
popoverStyle?: React.CSSProperties;
|
|
238
|
+
"aria-label"?: string;
|
|
239
|
+
"aria-labelledby"?: string;
|
|
240
|
+
};
|
|
241
|
+
declare const NepaliDatePicker: React.ForwardRefExoticComponent<NepaliDatePickerProps & React.RefAttributes<HTMLInputElement>>;
|
|
242
|
+
|
|
243
|
+
type EditableNepaliDatePickerProps = {
|
|
244
|
+
/** Controlled value — may be partial while typing (`2082-0`, `2082-04-1`, …). */
|
|
245
|
+
value?: string;
|
|
246
|
+
defaultValue?: string;
|
|
247
|
+
/**
|
|
248
|
+
* Fires on every keystroke with masked `YYYY-MM-DD` digits,
|
|
249
|
+
* and when a calendar day is picked (always complete & valid).
|
|
250
|
+
*/
|
|
251
|
+
onChange?: (value: string) => void;
|
|
252
|
+
onSelect?: (value: string) => void;
|
|
253
|
+
locale?: Locale;
|
|
254
|
+
minDate?: string;
|
|
255
|
+
maxDate?: string;
|
|
256
|
+
minYear?: number;
|
|
257
|
+
maxYear?: number;
|
|
258
|
+
closeOnSelect?: boolean;
|
|
259
|
+
placeholder?: string;
|
|
260
|
+
disabled?: boolean;
|
|
261
|
+
readOnly?: boolean;
|
|
262
|
+
id?: string;
|
|
263
|
+
name?: string;
|
|
264
|
+
required?: boolean;
|
|
265
|
+
className?: string;
|
|
266
|
+
inputClassName?: string;
|
|
267
|
+
popoverClassName?: string;
|
|
268
|
+
classNames?: NepaliDatePickerClassNames;
|
|
269
|
+
vars?: NepaliDatePickerVars;
|
|
270
|
+
style?: React.CSSProperties;
|
|
271
|
+
popoverStyle?: React.CSSProperties;
|
|
272
|
+
"aria-label"?: string;
|
|
273
|
+
"aria-labelledby"?: string;
|
|
274
|
+
};
|
|
275
|
+
declare const EditableNepaliDatePicker: React.ForwardRefExoticComponent<EditableNepaliDatePickerProps & React.RefAttributes<HTMLInputElement>>;
|
|
276
|
+
|
|
277
|
+
type NepaliDateTimePickerProps = {
|
|
278
|
+
/** Controlled BS datetime `YYYY-MM-DD HH:mm` (ASCII). Empty = none. */
|
|
279
|
+
value?: string;
|
|
280
|
+
defaultValue?: string;
|
|
281
|
+
onChange?: (value: string) => void;
|
|
282
|
+
onSelect?: (value: string) => void;
|
|
283
|
+
locale?: Locale;
|
|
284
|
+
valueLocale?: Locale;
|
|
285
|
+
/**
|
|
286
|
+
* Minimum — date-only (`YYYY-MM-DD` → start of day) or full
|
|
287
|
+
* `YYYY-MM-DD HH:mm`.
|
|
288
|
+
*/
|
|
289
|
+
minDateTime?: string;
|
|
290
|
+
/** Alias of `minDateTime` (date-only or datetime). */
|
|
291
|
+
minDate?: string;
|
|
292
|
+
/**
|
|
293
|
+
* Maximum — date-only (`YYYY-MM-DD` → end of day) or full datetime.
|
|
294
|
+
*/
|
|
295
|
+
maxDateTime?: string;
|
|
296
|
+
/** Alias of `maxDateTime`. */
|
|
297
|
+
maxDate?: string;
|
|
298
|
+
minYear?: number;
|
|
299
|
+
maxYear?: number;
|
|
300
|
+
/** Minute increment. Default `5`. */
|
|
301
|
+
minuteStep?: number;
|
|
302
|
+
/** Include seconds in value / UI. Default `false`. */
|
|
303
|
+
withSeconds?: boolean;
|
|
304
|
+
/** Close after Confirm. Default `true`. */
|
|
305
|
+
closeOnSelect?: boolean;
|
|
306
|
+
todayIfEmpty?: boolean;
|
|
307
|
+
placeholder?: string;
|
|
308
|
+
disabled?: boolean;
|
|
309
|
+
readOnly?: boolean;
|
|
310
|
+
id?: string;
|
|
311
|
+
name?: string;
|
|
312
|
+
required?: boolean;
|
|
313
|
+
className?: string;
|
|
314
|
+
inputClassName?: string;
|
|
315
|
+
popoverClassName?: string;
|
|
316
|
+
classNames?: NepaliDatePickerClassNames;
|
|
317
|
+
vars?: NepaliDatePickerVars;
|
|
318
|
+
style?: React.CSSProperties;
|
|
319
|
+
popoverStyle?: React.CSSProperties;
|
|
320
|
+
"aria-label"?: string;
|
|
321
|
+
"aria-labelledby"?: string;
|
|
322
|
+
};
|
|
323
|
+
declare const NepaliDateTimePicker: React.ForwardRefExoticComponent<NepaliDateTimePickerProps & React.RefAttributes<HTMLInputElement>>;
|
|
324
|
+
|
|
325
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
326
|
+
declare function mergeRefs<T>(...refs: Array<React.Ref<T> | undefined | null>): React.RefCallback<T>;
|
|
327
|
+
|
|
328
|
+
export { BS_EPOCH_AD, BS_MAX_YEAR, BS_MIN_YEAR, BS_MONTH_DAYS, type BsDateRange, type DateParts, type DatePattern, type DateTimeParts, EditableNepaliDatePicker, type EditableNepaliDatePickerProps, type Locale, NEPALI_MONTH_NAMES_EN, NEPALI_MONTH_NAMES_NE, NepaliDatePicker, type NepaliDatePickerClassNames, type NepaliDatePickerProps, type NepaliDatePickerVars, type NepaliDateRangeClassNames, NepaliDateRangePicker, type NepaliDateRangePickerProps, NepaliDateTimePicker, type NepaliDateTimePickerProps, type ValidationCode, type ValidationResult, WEEKDAY_NAMES_EN, WEEKDAY_NAMES_NE, adToBs, addBsDays, addBsMonths, assertBsDay, assertBsMonth, assertBsYear, assertValidBsDate, bsToAd, clampBsDate, clampDateTime, cn, compareDateParts, compareDateTimeParts, dateTimeToDateParts, diffBsDays, formatBsDateTimeLabel, formatBsLabel, formatDateParts, formatTypedBsDate, getBsWeekday, getDaysInBsMonth, getDaysInBsYear, getMonthName, getWeekdayNames, isCompleteBsDate, isCompleteBsDateTime, isValidBsDate, localizeDigits, mergeRefs, parseDateString, parseDateTimeBound, parseDateTimeString, snapMinute, toDateString, toDateTimeString, todayBs, todayBsDateTime, validateBsDate, validateBsDateParts };
|