@himal_bhattarai/nepali-datepicker 1.0.0 → 1.1.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 CHANGED
@@ -0,0 +1,331 @@
1
+ # @himal_bhattarai/nepali-datepicker
2
+
3
+ A modern, lightweight **Nepali (Bikram Sambat) Date Picker** for React with accurate BS↔AD conversion, bilingual support, and full theming control.
4
+
5
+ ---
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @himal_bhattarai/nepali-datepicker
11
+ ```
12
+
13
+ ---
14
+
15
+ ## Quick Start
16
+
17
+ ```jsx
18
+ import { useState } from "react";
19
+ import { NepaliDatePicker } from "@himal_bhattarai/nepali-datepicker";
20
+
21
+ function App() {
22
+ const [date, setDate] = useState(null);
23
+
24
+ return (
25
+ <NepaliDatePicker
26
+ value={date}
27
+ onChange={(bs, ad) => setDate(bs)}
28
+ />
29
+ );
30
+ }
31
+ ```
32
+
33
+ ---
34
+
35
+ ## Props
36
+
37
+ ### `value`
38
+ - **Type:** `{ year, month, day } | null`
39
+ - **Default:** `null`
40
+ - The currently selected BS date. Pass `null` for no selection.
41
+
42
+ ```jsx
43
+ const [date, setDate] = useState(null);
44
+
45
+ <NepaliDatePicker value={date} onChange={(bs) => setDate(bs)} />
46
+ ```
47
+
48
+ ---
49
+
50
+ ### `onChange`
51
+ - **Type:** `(bsDate, adDate) => void`
52
+ - **Required:** Yes
53
+ - Called when the user picks a date. Receives two arguments:
54
+ - `bsDate` — `{ year, month, day }` in Bikram Sambat
55
+ - `adDate` — JavaScript `Date` object in AD
56
+
57
+ ```jsx
58
+ <NepaliDatePicker
59
+ value={date}
60
+ onChange={(bs, ad) => {
61
+ console.log(bs); // { year: 2081, month: 11, day: 22 }
62
+ console.log(ad); // Wed Mar 05 2025 (JS Date)
63
+ setDate(bs);
64
+ }}
65
+ />
66
+ ```
67
+
68
+ ---
69
+
70
+ ### `language`
71
+ - **Type:** `"np" | "en"`
72
+ - **Default:** `"np"`
73
+ - Controls the display language of the entire calendar — month names, day headers, numerals, placeholder, and buttons.
74
+
75
+ ```jsx
76
+ // Nepali — Devanagari script (default)
77
+ <NepaliDatePicker language="np" value={date} onChange={(bs) => setDate(bs)} />
78
+
79
+ // English — Romanized month names, Arabic numerals
80
+ <NepaliDatePicker language="en" value={date} onChange={(bs) => setDate(bs)} />
81
+ ```
82
+
83
+ ---
84
+
85
+ ### `placeholder`
86
+ - **Type:** `string`
87
+ - **Default:** `"मिति छान्नुहोस्"` (np) or `"Select BS date"` (en)
88
+ - Text shown in the input when no date is selected.
89
+
90
+ ```jsx
91
+ <NepaliDatePicker
92
+ placeholder="Enter booking date"
93
+ value={date}
94
+ onChange={(bs) => setDate(bs)}
95
+ />
96
+ ```
97
+
98
+ ---
99
+
100
+ ### `minYear`
101
+ - **Type:** `number`
102
+ - **Default:** `2060`
103
+ - The earliest BS year available in the year dropdown.
104
+
105
+ ---
106
+
107
+ ### `maxYear`
108
+ - **Type:** `number`
109
+ - **Default:** `2090`
110
+ - The latest BS year available in the year dropdown.
111
+
112
+ ```jsx
113
+ <NepaliDatePicker
114
+ minYear={2075}
115
+ maxYear={2085}
116
+ value={date}
117
+ onChange={(bs) => setDate(bs)}
118
+ />
119
+ ```
120
+
121
+ ---
122
+
123
+ ### `className`
124
+ - **Type:** `string`
125
+ - **Default:** `""`
126
+ - Adds a custom CSS class to the root element. Use this to override styles via CSS variables in your own stylesheet.
127
+
128
+ ```css
129
+ /* your-styles.css */
130
+ .my-picker {
131
+ --ndp-primary: #1a56db;
132
+ --ndp-background: #fff;
133
+ --ndp-border: #bfdbfe;
134
+ }
135
+ ```
136
+
137
+ ```jsx
138
+ import "./your-styles.css";
139
+
140
+ <NepaliDatePicker
141
+ className="my-picker"
142
+ value={date}
143
+ onChange={(bs) => setDate(bs)}
144
+ />
145
+ ```
146
+
147
+ ---
148
+
149
+ ### `styles`
150
+ - **Type:** `object`
151
+ - **Default:** `{}`
152
+ - Override the color theme directly in JSX without a CSS file. Useful for dynamic theming.
153
+
154
+ ```jsx
155
+ <NepaliDatePicker
156
+ value={date}
157
+ onChange={(bs) => setDate(bs)}
158
+ styles={{
159
+ primary: "#1a56db", // main accent color (header, selected day, etc.)
160
+ primarySoft: "#e8f0fe", // light tint of primary (hover backgrounds)
161
+ background: "#ffffff", // calendar popup and input background
162
+ text: "#1e293b", // main text color
163
+ textMuted: "#94a3b8", // muted text (day headers, placeholder, AD date)
164
+ border: "#e2e8f0", // all borders
165
+ todayBg: "#dbeafe", // today's date highlight background
166
+ controlsBg: "#eff6ff", // month/year selector bar background
167
+ radius: "12px", // border radius of the popup
168
+ shadow: "0 8px 32px rgba(0,0,0,0.12)", // popup drop shadow
169
+ }}
170
+ />
171
+ ```
172
+
173
+ **All `styles` keys and their CSS variables:**
174
+
175
+ | Key | CSS Variable | Default | Controls |
176
+ |---|---|---|---|
177
+ | `primary` | `--ndp-primary` | `#C0392B` | Header bg, selected day, accents |
178
+ | `primarySoft` | `--ndp-primary-soft` | `#fff0ee` | Hover background on days |
179
+ | `background` | `--ndp-background` | `#ffffff` | Input + popup background |
180
+ | `text` | `--ndp-text` | `#1A1208` | Main text |
181
+ | `textMuted` | `--ndp-text-muted` | `#8C7B6B` | Day headers, muted labels |
182
+ | `border` | `--ndp-border` | `#E8DED0` | All borders |
183
+ | `todayBg` | `--ndp-today-bg` | `#fde8e6` | Today's date cell background |
184
+ | `controlsBg` | `--ndp-controls-bg` | `#fffaee` | Month/year bar background |
185
+ | `radius` | `--ndp-radius` | `16px` | Popup corner radius |
186
+ | `shadow` | `--ndp-shadow` | `0 24px 64px …` | Popup drop shadow |
187
+
188
+ > **Note:** You don't need to pass all keys — only pass what you want to change. Unset keys keep their defaults.
189
+
190
+ ---
191
+
192
+ ## Utility Functions
193
+
194
+ Standalone BS↔AD helpers exported from the package.
195
+
196
+ ```jsx
197
+ import { bsToAd, adToBs, getTodayBS } from "@himal_bhattarai/nepali-datepicker";
198
+ ```
199
+
200
+ ### `bsToAd(year, month, day)` → `Date`
201
+ Converts a BS date to a JavaScript `Date` object.
202
+ ```js
203
+ bsToAd(2081, 11, 22) // → Wed Mar 05 2025
204
+ ```
205
+
206
+ ### `adToBs(jsDate)` → `{ year, month, day }`
207
+ Converts a JavaScript `Date` to a BS date object.
208
+ ```js
209
+ adToBs(new Date("2025-03-05")) // → { year: 2081, month: 11, day: 22 }
210
+ ```
211
+
212
+ ### `getTodayBS()` → `{ year, month, day }`
213
+ Returns today's date in BS, always computed live from the browser clock.
214
+ ```js
215
+ getTodayBS() // → { year: 2082, month: 11, day: 22 }
216
+ ```
217
+
218
+ ---
219
+
220
+ ## Examples
221
+
222
+ ### Default (no config)
223
+ ```jsx
224
+ <NepaliDatePicker value={date} onChange={(bs) => setDate(bs)} />
225
+ ```
226
+
227
+ ### English language + custom year range
228
+ ```jsx
229
+ <NepaliDatePicker
230
+ language="en"
231
+ minYear={2075}
232
+ maxYear={2085}
233
+ placeholder="Select date"
234
+ value={date}
235
+ onChange={(bs, ad) => setDate(bs)}
236
+ />
237
+ ```
238
+
239
+ ### Dark theme via `styles` prop
240
+ ```jsx
241
+ <NepaliDatePicker
242
+ value={date}
243
+ onChange={(bs) => setDate(bs)}
244
+ styles={{
245
+ primary: "#e05c4d",
246
+ background: "#1e2235",
247
+ text: "#e2e8f0",
248
+ textMuted: "#94a3b8",
249
+ border: "#2d3554",
250
+ todayBg: "#1e3a5f",
251
+ controlsBg: "#252a42",
252
+ }}
253
+ />
254
+ ```
255
+
256
+ ### Green theme via `className`
257
+ ```css
258
+ /* app.css */
259
+ .green-picker {
260
+ --ndp-primary: #16a34a;
261
+ --ndp-primary-soft: #dcfce7;
262
+ --ndp-today-bg: #bbf7d0;
263
+ --ndp-border: #86efac;
264
+ --ndp-controls-bg: #f0fdf4;
265
+ }
266
+ ```
267
+ ```jsx
268
+ <NepaliDatePicker
269
+ className="green-picker"
270
+ value={date}
271
+ onChange={(bs) => setDate(bs)}
272
+ />
273
+ ```
274
+
275
+ ### Using AD date for a backend API
276
+ ```jsx
277
+ <NepaliDatePicker
278
+ value={date}
279
+ onChange={(bs, ad) => {
280
+ setDate(bs);
281
+ // Send AD date to your backend
282
+ fetch("/api/booking", {
283
+ method: "POST",
284
+ body: JSON.stringify({ date: ad.toISOString() }),
285
+ });
286
+ }}
287
+ />
288
+ ```
289
+
290
+ ---
291
+
292
+ ## How the Calendar Works
293
+
294
+ - **BS to AD** — computed at runtime using a single verified epoch: `BS 2000/1/1 = AD 1943/04/14`
295
+ - **Today's date** — always from `new Date()`, never hardcoded
296
+ - **Month lengths** — stored as a static lookup table (BS month lengths are astronomical, not mathematical)
297
+ - **Saturday** is highlighted as Nepal's weekly holiday (not Sunday)
298
+ - **Calendar grid** — always 6 rows × 7 columns (no layout shift between months)
299
+ - **Overflow days** — previous/next month's dates shown as dimmed, non-clickable
300
+
301
+ ---
302
+
303
+ ## BS Month Names
304
+
305
+ | # | Nepali | English |
306
+ |---|--------|---------|
307
+ | 1 | बैशाख | Baisakh |
308
+ | 2 | जेठ | Jestha |
309
+ | 3 | असार | Ashadh |
310
+ | 4 | श्रावण | Shrawan |
311
+ | 5 | भाद्र | Bhadra |
312
+ | 6 | असोज | Ashwin |
313
+ | 7 | कार्तिक | Kartik |
314
+ | 8 | मङ्सिर | Mangsir |
315
+ | 9 | पुष | Poush |
316
+ | 10 | माघ | Magh |
317
+ | 11 | फागुन | Falgun |
318
+ | 12 | चैत्र | Chaitra |
319
+
320
+ ---
321
+
322
+ ## Requirements
323
+
324
+ - React `>= 17`
325
+ - Modern browser (Chrome, Firefox, Safari, Edge)
326
+
327
+ ---
328
+
329
+ ## License
330
+
331
+ MIT © [Himal Bhattarai](https://github.com/himal-bhattarai)