afghan-datepicker 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +244 -2
- package/dist/index.cjs +3120 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +406 -0
- package/dist/index.d.ts +406 -0
- package/dist/index.js +3029 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +420 -0
- package/package.json +82 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Abdul Sami Fazilyar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,245 @@
|
|
|
1
|
-
#
|
|
1
|
+
# afghan-datepicker
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/afghan-datepicker)
|
|
4
|
+
[](https://github.com/Abdulsami-hub/afghan-datepicker/blob/main/LICENSE)
|
|
5
|
+
[](https://www.npmjs.com/package/afghan-datepicker)
|
|
6
|
+
|
|
7
|
+
A TypeScript-first calendar engine, date utilities, and React date-picker
|
|
8
|
+
components for Afghan Solar Hijri, Iranian Jalali, and Gregorian calendars.
|
|
9
|
+
`afghan-datepicker` is available on npm.
|
|
10
|
+
|
|
11
|
+
## Supported calendars and locales
|
|
12
|
+
|
|
13
|
+
The package supports these calendar systems:
|
|
14
|
+
|
|
15
|
+
- Afghan Solar Hijri (`"afghan"`)
|
|
16
|
+
- Iranian Jalali (`"iranian"`)
|
|
17
|
+
- Gregorian (`"gregorian"`)
|
|
18
|
+
|
|
19
|
+
Built-in locales:
|
|
20
|
+
|
|
21
|
+
| Code | Locale | Direction |
|
|
22
|
+
| ------- | --------------- | --------- |
|
|
23
|
+
| `fa-AF` | Afghan Dari | RTL |
|
|
24
|
+
| `ps-AF` | Afghan Pashto | RTL |
|
|
25
|
+
| `fa-IR` | Iranian Persian | RTL |
|
|
26
|
+
| `en` | English | LTR |
|
|
27
|
+
|
|
28
|
+
Calendar and locale selection are independent. Core utilities include date
|
|
29
|
+
conversion, leap-year checks, month lengths, validation, weekday calculation,
|
|
30
|
+
date arithmetic, comparisons, and calendar boundaries. Supported year ranges
|
|
31
|
+
and algorithm sources are documented in
|
|
32
|
+
[calendar rules](./docs/calendar-rules.md).
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
npm install afghan-datepicker
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Import the stylesheet separately when using the React components:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import "afghan-datepicker/styles.css";
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The styles are namespaced and do not require a CSS framework. See
|
|
47
|
+
[component styling](./docs/components.md#styling) for customization.
|
|
48
|
+
|
|
49
|
+
## React components
|
|
50
|
+
|
|
51
|
+
### Calendar
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
import { Calendar } from "afghan-datepicker";
|
|
55
|
+
|
|
56
|
+
function AfghanCalendar() {
|
|
57
|
+
return (
|
|
58
|
+
<Calendar
|
|
59
|
+
calendar="afghan"
|
|
60
|
+
locale="fa-AF"
|
|
61
|
+
defaultValue={{ year: 1405, month: 1, day: 1 }}
|
|
62
|
+
/>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### DatePicker
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
import { DatePicker } from "afghan-datepicker";
|
|
71
|
+
|
|
72
|
+
function IranianDatePicker() {
|
|
73
|
+
return (
|
|
74
|
+
<DatePicker
|
|
75
|
+
calendar="iranian"
|
|
76
|
+
locale="fa-IR"
|
|
77
|
+
defaultValue={{ year: 1405, month: 1, day: 1 }}
|
|
78
|
+
label="تاریخ"
|
|
79
|
+
/>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### DateRangePicker
|
|
85
|
+
|
|
86
|
+
```tsx
|
|
87
|
+
import { DateRangePicker } from "afghan-datepicker";
|
|
88
|
+
|
|
89
|
+
function EnglishDateRangePicker() {
|
|
90
|
+
return (
|
|
91
|
+
<DateRangePicker
|
|
92
|
+
calendar="gregorian"
|
|
93
|
+
locale="en"
|
|
94
|
+
minRangeDays={2}
|
|
95
|
+
maxRangeDays={14}
|
|
96
|
+
/>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Controlled and uncontrolled values
|
|
102
|
+
|
|
103
|
+
Use `value` with `onChange` for controlled selection, or `defaultValue` for
|
|
104
|
+
uncontrolled selection:
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
import { useState } from "react";
|
|
108
|
+
import { DatePicker, DateRangePicker } from "afghan-datepicker";
|
|
109
|
+
import type { CalendarDate, DateRange } from "afghan-datepicker";
|
|
110
|
+
|
|
111
|
+
function ControlledPickers() {
|
|
112
|
+
const [date, setDate] = useState<CalendarDate | null>(null);
|
|
113
|
+
const [range, setRange] = useState<DateRange | null>(null);
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<>
|
|
117
|
+
<DatePicker
|
|
118
|
+
calendar="afghan"
|
|
119
|
+
locale="ps-AF"
|
|
120
|
+
value={date}
|
|
121
|
+
onChange={setDate}
|
|
122
|
+
/>
|
|
123
|
+
<DateRangePicker
|
|
124
|
+
calendar="gregorian"
|
|
125
|
+
locale="en"
|
|
126
|
+
value={range}
|
|
127
|
+
onChange={setRange}
|
|
128
|
+
/>
|
|
129
|
+
</>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
See the [component guide](./docs/components.md) for all props, validation,
|
|
135
|
+
range selection, keyboard behavior, and styling.
|
|
136
|
+
|
|
137
|
+
## Date utilities
|
|
138
|
+
|
|
139
|
+
Date operations take an explicit calendar and use calendar-aware arithmetic;
|
|
140
|
+
they do not rely on JavaScript `Date`, time zones, or daylight-saving rules.
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
import {
|
|
144
|
+
addDays,
|
|
145
|
+
addMonths,
|
|
146
|
+
convertDate,
|
|
147
|
+
differenceInYears,
|
|
148
|
+
isValidGregorianDate,
|
|
149
|
+
} from "afghan-datepicker";
|
|
150
|
+
|
|
151
|
+
addDays({ year: 1405, month: 1, day: 1 }, 1, "afghan");
|
|
152
|
+
addMonths({ year: 1395, month: 12, day: 30 }, 1, "iranian");
|
|
153
|
+
convertDate({ year: 1382, month: 1, day: 1 }, "afghan", "gregorian");
|
|
154
|
+
differenceInYears(
|
|
155
|
+
{ year: 2026, month: 3, day: 21 },
|
|
156
|
+
{ year: 2025, month: 3, day: 21 },
|
|
157
|
+
"gregorian",
|
|
158
|
+
);
|
|
159
|
+
isValidGregorianDate({ year: 2024, month: 2, day: 29 });
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Month and year arithmetic constrains missing target days by default; pass
|
|
163
|
+
`{ overflow: "reject" }` to throw instead. See
|
|
164
|
+
[date utilities](./docs/date-utilities.md) for boundaries, validation, and
|
|
165
|
+
complete semantics.
|
|
166
|
+
|
|
167
|
+
## Localization, direction, and numerals
|
|
168
|
+
|
|
169
|
+
The locale supplies translated interface text, month and weekday names,
|
|
170
|
+
direction, and a default numeral system. For example, `fa-AF`, `ps-AF`, and
|
|
171
|
+
`fa-IR` provide RTL interfaces; `en` provides LTR. Components set direction
|
|
172
|
+
from the selected locale.
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
import {
|
|
176
|
+
formatCalendarDate,
|
|
177
|
+
getLocaleDirection,
|
|
178
|
+
toLocalizedDigits,
|
|
179
|
+
} from "afghan-datepicker";
|
|
180
|
+
|
|
181
|
+
formatCalendarDate(
|
|
182
|
+
{ year: 1405, month: 1, day: 1 },
|
|
183
|
+
{ calendar: "afghan", locale: "fa-AF" },
|
|
184
|
+
); // "۱۴۰۵/۰۱/۰۱"
|
|
185
|
+
|
|
186
|
+
formatCalendarDate(
|
|
187
|
+
{ year: 1405, month: 1, day: 1 },
|
|
188
|
+
{ calendar: "afghan", locale: "en", format: "full" },
|
|
189
|
+
); // "Saturday, Hamal 1, 1405"
|
|
190
|
+
|
|
191
|
+
getLocaleDirection("fa-AF"); // "rtl"
|
|
192
|
+
toLocalizedDigits("1405/01/01", "persian"); // "۱۴۰۵/۰۱/۰۱"
|
|
193
|
+
toLocalizedDigits("1405/01/01", "arabic"); // "١٤٠٥/٠١/٠١"
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
The supported numeral systems are `"latin"`, `"persian"`, and `"arabic"`.
|
|
197
|
+
Components accept a `numerals` prop to override the locale default. See the
|
|
198
|
+
[localization guide](./docs/localization.md) for locale data, formatting, and
|
|
199
|
+
custom locale registration.
|
|
200
|
+
|
|
201
|
+
## TypeScript, accessibility, and compatibility
|
|
202
|
+
|
|
203
|
+
TypeScript declarations and public types are included. Import types such as
|
|
204
|
+
`CalendarDate`, `DateRange`, `CalendarProps`, and `DateRangePickerProps` from
|
|
205
|
+
the package root. `DateRange` uses the existing calendar date type and
|
|
206
|
+
represents an incomplete range with `end: null`.
|
|
207
|
+
|
|
208
|
+
The components provide localized accessible names, native labels and buttons,
|
|
209
|
+
calendar grid/dialog semantics, visible focus states, and keyboard navigation.
|
|
210
|
+
Calendar navigation supports arrow keys, Home/End, Page Up/Down, and Enter or
|
|
211
|
+
Space selection. Escape closes picker popovers. Horizontal keyboard movement
|
|
212
|
+
follows the RTL/LTR layout. The [component guide](./docs/components.md#keyboard-and-accessibility)
|
|
213
|
+
describes the behavior in more detail.
|
|
214
|
+
|
|
215
|
+
The package targets ES2022 and declares React and React DOM peer dependencies
|
|
216
|
+
for versions 18 and 19. Browser-specific compatibility is not covered by a
|
|
217
|
+
complete automated browser matrix; test in your target browsers.
|
|
218
|
+
|
|
219
|
+
## Development
|
|
220
|
+
|
|
221
|
+
Install dependencies with `npm ci`, then use:
|
|
222
|
+
|
|
223
|
+
```sh
|
|
224
|
+
npm run dev # Start the Vite playground
|
|
225
|
+
npm run build # Build ESM, CommonJS, declarations, and CSS assets
|
|
226
|
+
npm test # Run tests once
|
|
227
|
+
npm run test:watch # Run tests in watch mode
|
|
228
|
+
npm run typecheck # Type-check source, playground, and tests
|
|
229
|
+
npm run lint # Run ESLint
|
|
230
|
+
npm run format # Format project files with Prettier
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## Contributing
|
|
234
|
+
|
|
235
|
+
Contributions are welcome. Keep calendar engines independent from React and
|
|
236
|
+
localization, avoid timezone-dependent calendar calculations, and include
|
|
237
|
+
focused tests for new behavior.
|
|
238
|
+
|
|
239
|
+
## Repository
|
|
240
|
+
|
|
241
|
+
[github.com/Abdulsami-hub/afghan-datepicker](https://github.com/Abdulsami-hub/afghan-datepicker)
|
|
242
|
+
|
|
243
|
+
## License
|
|
244
|
+
|
|
245
|
+
MIT © 2026 Abdul Sami Fazilyar. See [LICENSE](./LICENSE).
|