@rushdi94/hijri-datepicker 1.0.1 → 2.0.0

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
@@ -1,9 +1,11 @@
1
1
  # @rushdi94/hijri-datepicker
2
2
 
3
- A fully customizable **Hijri (Islamic) date picker** component.
3
+ A fully customizable **Hijri / Gregorian DateTime Picker** — no framework required.
4
4
 
5
- - No framework required works in React, Angular, Vue, or plain HTML
6
- - Pure Hijri calendar (Tabular Islamic Calendar algorithm)
5
+ - **Switchable calendars**toggle between Hijri and Gregorian in one click
6
+ - **Time picker** hour + minute spinners with AM/PM or 24-hour mode
7
+ - Works in React, Angular, Vue, or plain HTML
8
+ - Tabular Islamic Calendar algorithm — accurate & offline
7
9
  - RTL **and** LTR layout support
8
10
  - Fully customizable colors via simple options
9
11
  - TypeScript types included
@@ -30,42 +32,71 @@ import { HijriDatePicker } from '@rushdi94/hijri-datepicker';
30
32
 
31
33
  const picker = new HijriDatePicker({
32
34
  container: '#my-picker',
33
- onSelect(date, formatted) {
34
- console.log(date); // { year: 1447, month: 11, day: 30 }
35
- console.log(formatted); // "30/11/1447"
35
+ onSelect(value, formatted) {
36
+ console.log(value.hijri); // { year: 1447, month: 11, day: 30 }
37
+ console.log(value.gregorian); // { year: 2026, month: 5, day: 17 }
38
+ console.log(formatted); // "30/11/1447"
36
39
  },
37
40
  });
38
41
  ```
39
42
 
40
43
  ---
41
44
 
42
- ## Custom Colors
45
+ ## With Time Picker
43
46
 
44
47
  ```js
45
48
  new HijriDatePicker({
46
49
  container: '#my-picker',
47
- primaryColor: '#1565c0', // header, selected day, today ring
48
- onPrimaryColor: '#ffffff', // text on colored surfaces
49
- bodyBg: '#f0f4ff', // calendar background
50
- dayColor: '#1a237e', // regular day number color
51
- format: 'YYYY/MM/DD',
50
+ showTime: true, // show hour / minute / AM-PM
51
+ use24h: false, // false = AM/PM (default), true = 24-hour
52
+ onSelect(value, formatted) {
53
+ console.log(value.time); // { hour: 3, minute: 30, ampm: 'PM' }
54
+ console.log(formatted); // "30/11/1447 03:30 PM"
55
+ },
52
56
  });
53
57
  ```
54
58
 
55
59
  ---
56
60
 
57
- ## RTL & LTR Support
61
+ ## Start in Gregorian Mode
58
62
 
59
- **RTL (Arabic / Urdu / Persian) — default:**
60
63
  ```js
61
64
  new HijriDatePicker({
62
- container: '#picker',
63
- dir: 'rtl', // default, Arabic labels
65
+ container: '#my-picker',
66
+ initialMode: 'gregorian', // start showing Gregorian calendar
67
+ showTime: true,
68
+ onSelect(value, formatted) {
69
+ console.log(formatted); // "17/05/2026 03:30 PM"
70
+ },
71
+ });
72
+ ```
73
+
74
+ The header shows a **"G"** button in Hijri mode and **"ه"** in Gregorian mode — clicking it switches the calendar while keeping the same date.
75
+
76
+ ---
77
+
78
+ ## Custom Colors
79
+
80
+ ```js
81
+ new HijriDatePicker({
82
+ container: '#my-picker',
83
+ primaryColor: '#1565c0',
84
+ onPrimaryColor: '#ffffff',
85
+ bodyBg: '#f0f4ff',
86
+ dayColor: '#1a237e',
87
+ format: 'YYYY/MM/DD',
64
88
  });
65
89
  ```
66
90
 
67
- **LTR (English / European interfaces):**
91
+ ---
92
+
93
+ ## RTL & LTR
94
+
68
95
  ```js
96
+ // RTL (default)
97
+ new HijriDatePicker({ container: '#picker', dir: 'rtl' });
98
+
99
+ // LTR (English)
69
100
  new HijriDatePicker({
70
101
  container: '#picker',
71
102
  dir: 'ltr',
@@ -86,7 +117,7 @@ new HijriDatePicker({
86
117
  ```js
87
118
  new HijriDatePicker({
88
119
  container: '#calendar-area',
89
- inline: true, // always visible, no input field
120
+ inline: true,
90
121
  primaryColor: '#2e7d32',
91
122
  });
92
123
  ```
@@ -99,18 +130,22 @@ new HijriDatePicker({
99
130
  |---|---|---|---|
100
131
  | `container` | `string \| HTMLElement` | **required** | CSS selector or DOM element |
101
132
  | `dir` | `'rtl' \| 'ltr'` | `'rtl'` | Layout direction |
102
- | `inline` | `boolean` | `false` | Show calendar without an input |
133
+ | `inline` | `boolean` | `false` | Always-visible calendar (no input) |
134
+ | `initialMode` | `'hijri' \| 'gregorian'` | `'hijri'` | Starting calendar mode |
135
+ | `showTime` | `boolean` | `false` | Show hour/minute/AM-PM spinner |
136
+ | `use24h` | `boolean` | `false` | 24-hour mode (no AM/PM) |
103
137
  | `placeholder` | `string` | Arabic text | Input placeholder |
104
- | `primaryColor` | `string` | `'#8b1a2e'` | Main color (header, selected, today) |
138
+ | `primaryColor` | `string` | `'#8b1a2e'` | Header, selected day, today ring |
105
139
  | `onPrimaryColor` | `string` | `'#ffffff'` | Text on primary-colored surfaces |
106
140
  | `bodyBg` | `string` | `'#ffffff'` | Calendar body background |
107
141
  | `dayColor` | `string` | `'#1f2937'` | Regular day number color |
108
- | `format` | `string` | `'DD/MM/YYYY'` | Date format (tokens: `DD` `MM` `YYYY`) |
142
+ | `format` | `string` | `'DD/MM/YYYY'` | Date format tokens: `DD` `MM` `YYYY` |
109
143
  | `weekdayLabels` | `string[7]` | Arabic | Column headers Sun→Sat |
110
- | `monthLabels` | `string[12]` | Arabic | Muharram→Dhu al-Hijjah |
144
+ | `monthLabels` | `string[12]` | Arabic Hijri | Muharram→Dhu al-Hijjah |
145
+ | `gregorianMonthLabels` | `string[12]` | English | January→December |
111
146
  | `editable` | `boolean` | `false` | Allow typing in the input |
112
- | `initialDate` | `HijriDate` | today | Initial calendar view |
113
- | `onSelect` | `(date, fmt) => void` | — | Date selection callback |
147
+ | `initialDate` | `HijriDate` | today | Initial Hijri date |
148
+ | `onSelect` | `(value, fmt) => void` | — | Selection callback |
114
149
  | `onOpen` | `() => void` | — | Called when picker opens |
115
150
  | `onClose` | `() => void` | — | Called when picker closes |
116
151
 
@@ -119,14 +154,26 @@ new HijriDatePicker({
119
154
  ## Programmatic API
120
155
 
121
156
  ```js
122
- picker.getValue() // → HijriDate | null
123
- picker.setValue({ year: 1447, month: 9, day: 1 }) // select a date
124
- picker.goTo(1447, 12) // navigate calendar view
125
- picker.clear() // clear selection
126
- picker.setColors({ primaryColor: '#e53935' }) // live color update
127
- picker.open() // open programmatically
128
- picker.close() // close programmatically
129
- picker.destroy() // remove from DOM
157
+ picker.getValue() // → DateTimeValue | null
158
+ picker.setValue({ year: 1447, month: 9, day: 1 }) // set by Hijri date
159
+ picker.setValueGregorian({ year: 2026, month: 3, day: 1 }) // set by Gregorian
160
+ picker.setTime(3, 30, 'PM') // set time
161
+ picker.setMode('gregorian') // switch calendar mode
162
+ picker.goTo(1447, 12) // navigate view
163
+ picker.clear() // clear selection
164
+ picker.setColors({ primaryColor: '#e53935' }) // live color update
165
+ picker.open() / picker.close() // programmatic open/close
166
+ picker.destroy() // remove from DOM
167
+ ```
168
+
169
+ ### DateTimeValue shape
170
+
171
+ ```ts
172
+ interface DateTimeValue {
173
+ hijri: { year: number; month: number; day: number };
174
+ gregorian: { year: number; month: number; day: number };
175
+ time: { hour: number; minute: number; ampm: 'AM' | 'PM' } | null;
176
+ }
130
177
  ```
131
178
 
132
179
  ---
@@ -134,7 +181,11 @@ picker.destroy() // remove from DOM
134
181
  ## Helper Functions
135
182
 
136
183
  ```js
137
- import { toHijri, toGregorian, formatHijri, todayHijri } from '@rushdi94/hijri-datepicker';
184
+ import {
185
+ toHijri, toGregorian,
186
+ formatHijri, formatGregorian,
187
+ todayHijri, todayGregorian,
188
+ } from '@rushdi94/hijri-datepicker';
138
189
 
139
190
  toHijri(new Date('2026-05-17'))
140
191
  // → { year: 1447, month: 11, day: 30 }
@@ -145,8 +196,8 @@ toGregorian(1447, 9, 1)
145
196
  formatHijri({ year: 1447, month: 11, day: 30 }, 'YYYY/MM/DD')
146
197
  // → "1447/11/30"
147
198
 
148
- todayHijri()
149
- // → current Hijri date
199
+ todayHijri() // → current Hijri date
200
+ todayGregorian() // → current Gregorian date
150
201
  ```
151
202
 
152
203
  ---
@@ -177,7 +228,8 @@ export class MyComponent implements AfterViewInit {
177
228
  ngAfterViewInit() {
178
229
  this.hdp = new HijriDatePicker({
179
230
  container: this.pickerRef.nativeElement,
180
- onSelect: (date, fmt) => console.log(date, fmt),
231
+ showTime: true,
232
+ onSelect: (value, fmt) => console.log(value, fmt),
181
233
  });
182
234
  }
183
235
  ngOnDestroy() { this.hdp.destroy(); }
@@ -188,15 +240,16 @@ export class MyComponent implements AfterViewInit {
188
240
 
189
241
  ```tsx
190
242
  import { useEffect, useRef } from 'react';
191
- import { HijriDatePicker, HijriDate } from '@rushdi94/hijri-datepicker';
243
+ import { HijriDatePicker, DateTimeValue } from '@rushdi94/hijri-datepicker';
192
244
 
193
- export function HijriPicker({ onSelect }: { onSelect: (d: HijriDate) => void }) {
245
+ export function HijriPicker({ onSelect }: { onSelect: (d: DateTimeValue) => void }) {
194
246
  const ref = useRef<HTMLDivElement>(null);
195
247
 
196
248
  useEffect(() => {
197
249
  const picker = new HijriDatePicker({
198
250
  container: ref.current!,
199
- onSelect: (date) => onSelect(date),
251
+ showTime: true,
252
+ onSelect: (value) => onSelect(value),
200
253
  });
201
254
  return () => picker.destroy();
202
255
  }, []);
@@ -207,6 +260,20 @@ export function HijriPicker({ onSelect }: { onSelect: (d: HijriDate) => void })
207
260
 
208
261
  ---
209
262
 
263
+ ## Changelog
264
+
265
+ ### v2.0.0
266
+ - **Gregorian calendar mode** — toggle between Hijri and Gregorian in the header
267
+ - **Time picker** — hour/minute spinners with AM/PM or 24-hour mode
268
+ - `onSelect` now receives `DateTimeValue` (includes both Hijri + Gregorian + time)
269
+ - New options: `initialMode`, `showTime`, `use24h`, `gregorianMonthLabels`
270
+ - New API: `setValueGregorian()`, `setTime()`, `setMode()`
271
+
272
+ ### v1.0.1
273
+ - Initial public release — Hijri-only date picker
274
+
275
+ ---
276
+
210
277
  ## License
211
278
 
212
279
  MIT