@saurabhroys/nepali-datepicker 1.0.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 +19 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +148 -0
- package/dist/index.mjs +111 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @saurabhroys/nepali-datepicker 🇳🇵
|
|
2
|
+
|
|
3
|
+
A modern, lightweight, and TypeScript-ready Nepali Date Picker component for React applications. Built with Tailwind CSS.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
- 📅 **Bikram Sambat (BS)** Support
|
|
10
|
+
- 🎨 **Tailwind CSS** Styling (Fully Customizable)
|
|
11
|
+
- 🔒 **TypeScript** Support (IntelliSense)
|
|
12
|
+
- 🔢 **Nepali Digits** (१, २, ३) Display
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @saurabhroys/nepali-datepicker
|
|
18
|
+
# or
|
|
19
|
+
yarn add @saurabhroys/nepali-datepicker
|
package/dist/index.d.mts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
NepaliDatePicker: () => NepaliDatePicker_default
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
|
|
37
|
+
// src/NepaliDatePicker.tsx
|
|
38
|
+
var import_react = require("react");
|
|
39
|
+
var import_nepali_date_converter = __toESM(require("nepali-date-converter"));
|
|
40
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
41
|
+
var NEPALI_MONTHS = [
|
|
42
|
+
"Baisakh",
|
|
43
|
+
"Jestha",
|
|
44
|
+
"Ashad",
|
|
45
|
+
"Shrawan",
|
|
46
|
+
"Bhadra",
|
|
47
|
+
"Ashwin",
|
|
48
|
+
"Kartik",
|
|
49
|
+
"Mangsir",
|
|
50
|
+
"Poush",
|
|
51
|
+
"Magh",
|
|
52
|
+
"Falgun",
|
|
53
|
+
"Chaitra"
|
|
54
|
+
];
|
|
55
|
+
var WEEK_DAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
56
|
+
var toNepaliDigits = (num) => {
|
|
57
|
+
const map = {
|
|
58
|
+
0: "\u0966",
|
|
59
|
+
1: "\u0967",
|
|
60
|
+
2: "\u0968",
|
|
61
|
+
3: "\u0969",
|
|
62
|
+
4: "\u096A",
|
|
63
|
+
5: "\u096B",
|
|
64
|
+
6: "\u096C",
|
|
65
|
+
7: "\u096D",
|
|
66
|
+
8: "\u096E",
|
|
67
|
+
9: "\u096F"
|
|
68
|
+
};
|
|
69
|
+
return num.toString().split("").map((d) => map[d] || d).join("");
|
|
70
|
+
};
|
|
71
|
+
var NepaliDatePicker = () => {
|
|
72
|
+
const [currentBS, setCurrentBS] = (0, import_react.useState)(new import_nepali_date_converter.default());
|
|
73
|
+
const [selectedDate, setSelectedDate] = (0, import_react.useState)(null);
|
|
74
|
+
const [daysInMonth, setDaysInMonth] = (0, import_react.useState)([]);
|
|
75
|
+
const [startDayIndex, setStartDayIndex] = (0, import_react.useState)(0);
|
|
76
|
+
(0, import_react.useEffect)(() => {
|
|
77
|
+
const year = currentBS.getYear();
|
|
78
|
+
const month = currentBS.getMonth();
|
|
79
|
+
const firstDayOfMonth = new import_nepali_date_converter.default(year, month, 1);
|
|
80
|
+
const startDay = firstDayOfMonth.getDay();
|
|
81
|
+
setStartDayIndex(startDay);
|
|
82
|
+
let daysCount = 0;
|
|
83
|
+
for (let i = 29; i <= 32; i++) {
|
|
84
|
+
try {
|
|
85
|
+
const temp = new import_nepali_date_converter.default(year, month, i);
|
|
86
|
+
if (temp.getMonth() === month) {
|
|
87
|
+
daysCount = i;
|
|
88
|
+
} else {
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
} catch (e) {
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
setDaysInMonth(Array.from({ length: daysCount }, (_, i) => i + 1));
|
|
96
|
+
}, [currentBS]);
|
|
97
|
+
const prevMonth = () => {
|
|
98
|
+
const prev = new import_nepali_date_converter.default(currentBS.getYear(), currentBS.getMonth() - 1, 1);
|
|
99
|
+
setCurrentBS(prev);
|
|
100
|
+
};
|
|
101
|
+
const nextMonth = () => {
|
|
102
|
+
const next = new import_nepali_date_converter.default(currentBS.getYear(), currentBS.getMonth() + 1, 1);
|
|
103
|
+
setCurrentBS(next);
|
|
104
|
+
};
|
|
105
|
+
const onDateClick = (day) => {
|
|
106
|
+
const selected = new import_nepali_date_converter.default(currentBS.getYear(), currentBS.getMonth(), day);
|
|
107
|
+
setSelectedDate(selected);
|
|
108
|
+
console.log("User Selected (BS):", selected.format("YYYY-MM-DD"));
|
|
109
|
+
console.log("User Selected (AD):", new Date(selected.toJsDate()).toDateString());
|
|
110
|
+
};
|
|
111
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "w-80 mx-auto bg-white rounded-xl shadow-lg border border-gray-200 overflow-hidden font-sans", children: [
|
|
112
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex justify-between items-center bg-blue-600 p-4 text-white", children: [
|
|
113
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { onClick: prevMonth, className: "hover:bg-blue-700 p-1 rounded", children: "<" }),
|
|
114
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "font-bold text-lg", children: [
|
|
115
|
+
NEPALI_MONTHS[currentBS.getMonth()],
|
|
116
|
+
" ",
|
|
117
|
+
toNepaliDigits(currentBS.getYear())
|
|
118
|
+
] }),
|
|
119
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { onClick: nextMonth, className: "hover:bg-blue-700 p-1 rounded", children: ">" })
|
|
120
|
+
] }),
|
|
121
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "grid grid-cols-7 text-center bg-gray-50 border-b border-gray-100", children: WEEK_DAYS.map((day) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "text-xs font-semibold text-gray-500 py-2", children: day }, day)) }),
|
|
122
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "grid grid-cols-7 p-2 gap-1", children: [
|
|
123
|
+
Array.from({ length: startDayIndex }).map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "h-8" }, `empty-${i}`)),
|
|
124
|
+
daysInMonth.map((day) => {
|
|
125
|
+
const isSelected = selectedDate && selectedDate.getDate() === day && selectedDate.getMonth() === currentBS.getMonth() && selectedDate.getYear() === currentBS.getYear();
|
|
126
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
127
|
+
"button",
|
|
128
|
+
{
|
|
129
|
+
onClick: () => onDateClick(day),
|
|
130
|
+
className: `h-8 w-8 flex items-center justify-center rounded-full text-sm transition-colors
|
|
131
|
+
${isSelected ? "bg-blue-600 text-white font-bold shadow-md" : "hover:bg-blue-100 text-gray-700 hover:text-blue-600"}`,
|
|
132
|
+
children: toNepaliDigits(day)
|
|
133
|
+
},
|
|
134
|
+
day
|
|
135
|
+
);
|
|
136
|
+
})
|
|
137
|
+
] }),
|
|
138
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "p-3 border-t text-center text-xs text-gray-500 bg-gray-50", children: [
|
|
139
|
+
"Selected: ",
|
|
140
|
+
selectedDate ? `${toNepaliDigits(selectedDate.getDate())} ${NEPALI_MONTHS[selectedDate.getMonth()]} (BS)` : "None"
|
|
141
|
+
] })
|
|
142
|
+
] });
|
|
143
|
+
};
|
|
144
|
+
var NepaliDatePicker_default = NepaliDatePicker;
|
|
145
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
146
|
+
0 && (module.exports = {
|
|
147
|
+
NepaliDatePicker
|
|
148
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// src/NepaliDatePicker.tsx
|
|
2
|
+
import { useState, useEffect } from "react";
|
|
3
|
+
import NepaliDate from "nepali-date-converter";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
var NEPALI_MONTHS = [
|
|
6
|
+
"Baisakh",
|
|
7
|
+
"Jestha",
|
|
8
|
+
"Ashad",
|
|
9
|
+
"Shrawan",
|
|
10
|
+
"Bhadra",
|
|
11
|
+
"Ashwin",
|
|
12
|
+
"Kartik",
|
|
13
|
+
"Mangsir",
|
|
14
|
+
"Poush",
|
|
15
|
+
"Magh",
|
|
16
|
+
"Falgun",
|
|
17
|
+
"Chaitra"
|
|
18
|
+
];
|
|
19
|
+
var WEEK_DAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
20
|
+
var toNepaliDigits = (num) => {
|
|
21
|
+
const map = {
|
|
22
|
+
0: "\u0966",
|
|
23
|
+
1: "\u0967",
|
|
24
|
+
2: "\u0968",
|
|
25
|
+
3: "\u0969",
|
|
26
|
+
4: "\u096A",
|
|
27
|
+
5: "\u096B",
|
|
28
|
+
6: "\u096C",
|
|
29
|
+
7: "\u096D",
|
|
30
|
+
8: "\u096E",
|
|
31
|
+
9: "\u096F"
|
|
32
|
+
};
|
|
33
|
+
return num.toString().split("").map((d) => map[d] || d).join("");
|
|
34
|
+
};
|
|
35
|
+
var NepaliDatePicker = () => {
|
|
36
|
+
const [currentBS, setCurrentBS] = useState(new NepaliDate());
|
|
37
|
+
const [selectedDate, setSelectedDate] = useState(null);
|
|
38
|
+
const [daysInMonth, setDaysInMonth] = useState([]);
|
|
39
|
+
const [startDayIndex, setStartDayIndex] = useState(0);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
const year = currentBS.getYear();
|
|
42
|
+
const month = currentBS.getMonth();
|
|
43
|
+
const firstDayOfMonth = new NepaliDate(year, month, 1);
|
|
44
|
+
const startDay = firstDayOfMonth.getDay();
|
|
45
|
+
setStartDayIndex(startDay);
|
|
46
|
+
let daysCount = 0;
|
|
47
|
+
for (let i = 29; i <= 32; i++) {
|
|
48
|
+
try {
|
|
49
|
+
const temp = new NepaliDate(year, month, i);
|
|
50
|
+
if (temp.getMonth() === month) {
|
|
51
|
+
daysCount = i;
|
|
52
|
+
} else {
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
} catch (e) {
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
setDaysInMonth(Array.from({ length: daysCount }, (_, i) => i + 1));
|
|
60
|
+
}, [currentBS]);
|
|
61
|
+
const prevMonth = () => {
|
|
62
|
+
const prev = new NepaliDate(currentBS.getYear(), currentBS.getMonth() - 1, 1);
|
|
63
|
+
setCurrentBS(prev);
|
|
64
|
+
};
|
|
65
|
+
const nextMonth = () => {
|
|
66
|
+
const next = new NepaliDate(currentBS.getYear(), currentBS.getMonth() + 1, 1);
|
|
67
|
+
setCurrentBS(next);
|
|
68
|
+
};
|
|
69
|
+
const onDateClick = (day) => {
|
|
70
|
+
const selected = new NepaliDate(currentBS.getYear(), currentBS.getMonth(), day);
|
|
71
|
+
setSelectedDate(selected);
|
|
72
|
+
console.log("User Selected (BS):", selected.format("YYYY-MM-DD"));
|
|
73
|
+
console.log("User Selected (AD):", new Date(selected.toJsDate()).toDateString());
|
|
74
|
+
};
|
|
75
|
+
return /* @__PURE__ */ jsxs("div", { className: "w-80 mx-auto bg-white rounded-xl shadow-lg border border-gray-200 overflow-hidden font-sans", children: [
|
|
76
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-between items-center bg-blue-600 p-4 text-white", children: [
|
|
77
|
+
/* @__PURE__ */ jsx("button", { onClick: prevMonth, className: "hover:bg-blue-700 p-1 rounded", children: "<" }),
|
|
78
|
+
/* @__PURE__ */ jsxs("div", { className: "font-bold text-lg", children: [
|
|
79
|
+
NEPALI_MONTHS[currentBS.getMonth()],
|
|
80
|
+
" ",
|
|
81
|
+
toNepaliDigits(currentBS.getYear())
|
|
82
|
+
] }),
|
|
83
|
+
/* @__PURE__ */ jsx("button", { onClick: nextMonth, className: "hover:bg-blue-700 p-1 rounded", children: ">" })
|
|
84
|
+
] }),
|
|
85
|
+
/* @__PURE__ */ jsx("div", { className: "grid grid-cols-7 text-center bg-gray-50 border-b border-gray-100", children: WEEK_DAYS.map((day) => /* @__PURE__ */ jsx("div", { className: "text-xs font-semibold text-gray-500 py-2", children: day }, day)) }),
|
|
86
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-7 p-2 gap-1", children: [
|
|
87
|
+
Array.from({ length: startDayIndex }).map((_, i) => /* @__PURE__ */ jsx("div", { className: "h-8" }, `empty-${i}`)),
|
|
88
|
+
daysInMonth.map((day) => {
|
|
89
|
+
const isSelected = selectedDate && selectedDate.getDate() === day && selectedDate.getMonth() === currentBS.getMonth() && selectedDate.getYear() === currentBS.getYear();
|
|
90
|
+
return /* @__PURE__ */ jsx(
|
|
91
|
+
"button",
|
|
92
|
+
{
|
|
93
|
+
onClick: () => onDateClick(day),
|
|
94
|
+
className: `h-8 w-8 flex items-center justify-center rounded-full text-sm transition-colors
|
|
95
|
+
${isSelected ? "bg-blue-600 text-white font-bold shadow-md" : "hover:bg-blue-100 text-gray-700 hover:text-blue-600"}`,
|
|
96
|
+
children: toNepaliDigits(day)
|
|
97
|
+
},
|
|
98
|
+
day
|
|
99
|
+
);
|
|
100
|
+
})
|
|
101
|
+
] }),
|
|
102
|
+
/* @__PURE__ */ jsxs("div", { className: "p-3 border-t text-center text-xs text-gray-500 bg-gray-50", children: [
|
|
103
|
+
"Selected: ",
|
|
104
|
+
selectedDate ? `${toNepaliDigits(selectedDate.getDate())} ${NEPALI_MONTHS[selectedDate.getMonth()]} (BS)` : "None"
|
|
105
|
+
] })
|
|
106
|
+
] });
|
|
107
|
+
};
|
|
108
|
+
var NepaliDatePicker_default = NepaliDatePicker;
|
|
109
|
+
export {
|
|
110
|
+
NepaliDatePicker_default as NepaliDatePicker
|
|
111
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@saurabhroys/nepali-datepicker",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "A modern, Tailwind-based Nepali Date Picker for React",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
12
|
+
"prepublishOnly": "npm run build"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"nepal",
|
|
16
|
+
"date-picker",
|
|
17
|
+
"react",
|
|
18
|
+
"bikram-sambat"
|
|
19
|
+
],
|
|
20
|
+
"author": "Saurabh Roy",
|
|
21
|
+
"license": "ISC",
|
|
22
|
+
"type": "commonjs",
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"react": "^19.2.4",
|
|
25
|
+
"react-dom": "^19.2.4"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"nepali-date-converter": "^3.4.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/react": "^19.2.13",
|
|
32
|
+
"@types/react-dom": "^19.2.3",
|
|
33
|
+
"tsup": "^8.5.1",
|
|
34
|
+
"typescript": "^5.9.3"
|
|
35
|
+
}
|
|
36
|
+
}
|