react-native-hilal 0.0.0-stage → 0.2.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.
Files changed (95) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +300 -2
  3. package/lib/module/calendar/Appear.js +75 -0
  4. package/lib/module/calendar/Appear.js.map +1 -0
  5. package/lib/module/calendar/Chevron.js +60 -0
  6. package/lib/module/calendar/Chevron.js.map +1 -0
  7. package/lib/module/calendar/DayCell.js +51 -0
  8. package/lib/module/calendar/DayCell.js.map +1 -0
  9. package/lib/module/calendar/HilalCalendar.js +565 -0
  10. package/lib/module/calendar/HilalCalendar.js.map +1 -0
  11. package/lib/module/calendar/PickerGrid.js +66 -0
  12. package/lib/module/calendar/PickerGrid.js.map +1 -0
  13. package/lib/module/calendar/index.js +5 -0
  14. package/lib/module/calendar/index.js.map +1 -0
  15. package/lib/module/calendar/month.js +291 -0
  16. package/lib/module/calendar/month.js.map +1 -0
  17. package/lib/module/calendar/styles.js +338 -0
  18. package/lib/module/calendar/styles.js.map +1 -0
  19. package/lib/module/calendar/theme.js +49 -0
  20. package/lib/module/calendar/theme.js.map +1 -0
  21. package/lib/module/calendar/types.js +4 -0
  22. package/lib/module/calendar/types.js.map +1 -0
  23. package/lib/module/core/convert.js +191 -0
  24. package/lib/module/core/convert.js.map +1 -0
  25. package/lib/module/core/days.js +61 -0
  26. package/lib/module/core/days.js.map +1 -0
  27. package/lib/module/core/format.js +37 -0
  28. package/lib/module/core/format.js.map +1 -0
  29. package/lib/module/core/index.js +6 -0
  30. package/lib/module/core/index.js.map +1 -0
  31. package/lib/module/core/locale.js +62 -0
  32. package/lib/module/core/locale.js.map +1 -0
  33. package/lib/module/core/types.js +2 -0
  34. package/lib/module/core/types.js.map +1 -0
  35. package/lib/module/core/umalqura-data.js +24 -0
  36. package/lib/module/core/umalqura-data.js.map +1 -0
  37. package/lib/module/index.js +5 -0
  38. package/lib/module/index.js.map +1 -0
  39. package/lib/module/package.json +1 -0
  40. package/lib/typescript/package.json +1 -0
  41. package/lib/typescript/src/calendar/Appear.d.ts +22 -0
  42. package/lib/typescript/src/calendar/Appear.d.ts.map +1 -0
  43. package/lib/typescript/src/calendar/Chevron.d.ts +13 -0
  44. package/lib/typescript/src/calendar/Chevron.d.ts.map +1 -0
  45. package/lib/typescript/src/calendar/DayCell.d.ts +24 -0
  46. package/lib/typescript/src/calendar/DayCell.d.ts.map +1 -0
  47. package/lib/typescript/src/calendar/HilalCalendar.d.ts +7 -0
  48. package/lib/typescript/src/calendar/HilalCalendar.d.ts.map +1 -0
  49. package/lib/typescript/src/calendar/PickerGrid.d.ts +28 -0
  50. package/lib/typescript/src/calendar/PickerGrid.d.ts.map +1 -0
  51. package/lib/typescript/src/calendar/index.d.ts +4 -0
  52. package/lib/typescript/src/calendar/index.d.ts.map +1 -0
  53. package/lib/typescript/src/calendar/month.d.ts +86 -0
  54. package/lib/typescript/src/calendar/month.d.ts.map +1 -0
  55. package/lib/typescript/src/calendar/styles.d.ts +206 -0
  56. package/lib/typescript/src/calendar/styles.d.ts.map +1 -0
  57. package/lib/typescript/src/calendar/theme.d.ts +51 -0
  58. package/lib/typescript/src/calendar/theme.d.ts.map +1 -0
  59. package/lib/typescript/src/calendar/types.d.ts +162 -0
  60. package/lib/typescript/src/calendar/types.d.ts.map +1 -0
  61. package/lib/typescript/src/core/convert.d.ts +77 -0
  62. package/lib/typescript/src/core/convert.d.ts.map +1 -0
  63. package/lib/typescript/src/core/days.d.ts +24 -0
  64. package/lib/typescript/src/core/days.d.ts.map +1 -0
  65. package/lib/typescript/src/core/format.d.ts +23 -0
  66. package/lib/typescript/src/core/format.d.ts.map +1 -0
  67. package/lib/typescript/src/core/index.d.ts +5 -0
  68. package/lib/typescript/src/core/index.d.ts.map +1 -0
  69. package/lib/typescript/src/core/locale.d.ts +21 -0
  70. package/lib/typescript/src/core/locale.d.ts.map +1 -0
  71. package/lib/typescript/src/core/types.d.ts +7 -0
  72. package/lib/typescript/src/core/types.d.ts.map +1 -0
  73. package/lib/typescript/src/core/umalqura-data.d.ts +15 -0
  74. package/lib/typescript/src/core/umalqura-data.d.ts.map +1 -0
  75. package/lib/typescript/src/index.d.ts +3 -0
  76. package/lib/typescript/src/index.d.ts.map +1 -0
  77. package/package.json +180 -4
  78. package/src/calendar/Appear.tsx +94 -0
  79. package/src/calendar/Chevron.tsx +55 -0
  80. package/src/calendar/DayCell.tsx +89 -0
  81. package/src/calendar/HilalCalendar.tsx +728 -0
  82. package/src/calendar/PickerGrid.tsx +99 -0
  83. package/src/calendar/index.ts +13 -0
  84. package/src/calendar/month.ts +364 -0
  85. package/src/calendar/styles.ts +357 -0
  86. package/src/calendar/theme.ts +89 -0
  87. package/src/calendar/types.ts +168 -0
  88. package/src/core/convert.ts +256 -0
  89. package/src/core/days.ts +64 -0
  90. package/src/core/format.ts +65 -0
  91. package/src/core/index.ts +19 -0
  92. package/src/core/locale.ts +141 -0
  93. package/src/core/types.ts +6 -0
  94. package/src/core/umalqura-data.ts +34 -0
  95. package/src/index.tsx +2 -0
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 2ve2
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,301 @@
1
- # Temporary Holding Version
1
+ <div align="center">
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # Hilal
4
+
5
+ **A Hijri (Umm al-Qura) and Gregorian date picker for React Native.**
6
+ iOS, Android, web and Expo Go. Zero dependencies. Arabic-first.
7
+
8
+ [![npm version](https://img.shields.io/npm/v/react-native-hilal.svg)](https://www.npmjs.com/package/react-native-hilal)
9
+ [![CI](https://github.com/2ve2/hilal/actions/workflows/ci.yml/badge.svg)](https://github.com/2ve2/hilal/actions/workflows/ci.yml)
10
+ [![license: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
11
+
12
+ <!--
13
+ DEMO: replace this comment with the demo, for example
14
+ <img src="docs/assets/demo.gif" width="720" alt="Hilal demo" />
15
+ or a video link from GitHub (drag the .mp4 into an issue comment and
16
+ paste the https://github.com/user-attachments/... URL on its own line).
17
+ -->
18
+
19
+ </div>
20
+
21
+ ## Features
22
+
23
+ - **Umm al-Qura**, the official calendar of Saudi Arabia, tested against ICU on every day from 1937 to 2077.
24
+ - **Hijri and Gregorian together**: switch the grid between them, and every day also shows its date in the other calendar.
25
+ - **Arabic-first**: Arabic month and day names, Arabic-Indic digits (`١٢٣`), proper right-to-left layout. English with Latin digits is one prop away.
26
+ - **Cross-platform**: pure TypeScript and React Native core components. The same code runs on iOS, Android, the web and in Expo Go, with no native modules.
27
+ - **Zero runtime dependencies**: no moment, no dayjs, no `Intl` calendars at runtime.
28
+ - **Customizable**: light, dark, follow the system, or your own colors and fonts; styles for every part and your own button texts.
29
+ - **Accessible**: every day is a button with a full spoken date, its selected and disabled state, and "today". Text follows the phone's text size within limits that keep the layout intact, and animations respect reduce motion.
30
+ - **The engine is public**: convert and format Hijri dates without using the UI.
31
+
32
+ ## Installation
33
+
34
+ ```sh
35
+ npm install react-native-hilal
36
+ # or
37
+ yarn add react-native-hilal
38
+ # or
39
+ npx expo install react-native-hilal
40
+ ```
41
+
42
+ `react` and `react-native` are the only peer dependencies. There is nothing to link and no native build step.
43
+
44
+ Hilal is designed for phones first. On the web (React Native Web) it works the same, but text is drawn with the browser's fonts, so it can look slightly different.
45
+
46
+ ## Quick start
47
+
48
+ ```tsx
49
+ import { useState } from 'react';
50
+ import { Text, View } from 'react-native';
51
+ import { HilalCalendar, type SelectedDate } from 'react-native-hilal';
52
+
53
+ export default function Screen() {
54
+ const [date, setDate] = useState<SelectedDate>();
55
+
56
+ return (
57
+ <View>
58
+ <HilalCalendar value={date?.gregorian} onChange={setDate} />
59
+ {date && (
60
+ <Text>
61
+ {date.formatted.hijri} · {date.formatted.gregorian}
62
+ </Text>
63
+ )}
64
+ </View>
65
+ );
66
+ }
67
+ ```
68
+
69
+ `onChange` gives you both calendars at once. For 1 Ramadan 1446 with `locale="en"`:
70
+
71
+ ```ts
72
+ {
73
+ gregorian: Date, // Sat Mar 01 2025, local midnight
74
+ hijri: { year: 1446, month: 9, day: 1 },
75
+ formatted: { gregorian: '1 March 2025', hijri: '1 Ramadan 1446 AH' },
76
+ }
77
+ ```
78
+
79
+ With the default `locale="ar"`, `formatted.hijri` is `'١ رمضان ١٤٤٦ هـ'` and `formatted.gregorian` is `'١ مارس ٢٠٢٥'`, in Arabic-Indic digits.
80
+
81
+ ## Examples
82
+
83
+ ```tsx
84
+ // English, Latin digits, left-to-right
85
+ <HilalCalendar locale="en" />
86
+
87
+ // Gregorian grid, week starting on Saturday
88
+ <HilalCalendar calendar="gregorian" firstDayOfWeek={6} />
89
+
90
+ // Only the next 30 days, no Fridays
91
+ <HilalCalendar
92
+ minDate={today}
93
+ maxDate={in30Days}
94
+ isDateDisabled={({ gregorian }) => gregorian.getDay() === 5}
95
+ />
96
+
97
+ // Dark theme, or your own colors on top of the light/dark default
98
+ <HilalCalendar theme="dark" />
99
+ <HilalCalendar theme={{ primary: '#B45309', radius: 24 }} />
100
+ ```
101
+
102
+ The [example app](example) shows every feature side by side. Run it with `yarn example start` and open it in Expo Go.
103
+
104
+ ## `<HilalCalendar />` props
105
+
106
+ | Prop | Type | Default | Description |
107
+ | ----------------------- | ---------------------------------------------------- | ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
108
+ | `value` | `Date` | | Selected day (controlled). Only the local calendar day is used. |
109
+ | `defaultValue` | `Date` | | Initially selected day (uncontrolled). |
110
+ | `onChange` | `(date: SelectedDate) => void` | | Called when the user picks a day. |
111
+ | `calendar` | `'hijri' \| 'gregorian'` | `'hijri'` | Calendar of the month grid. The grid follows this prop when it changes. |
112
+ | `onCalendarChange` | `(calendar) => void` | | Called when the user switches calendars with the toggle. |
113
+ | `showCalendarToggle` | `boolean` | `true` | Show the Hijri / Gregorian toggle. |
114
+ | `showSecondaryDate` | `boolean` | `true` | Show the other calendar's day under each day. |
115
+ | `locale` | `'ar' \| 'en'` | `'ar'` | Language of month names, weekdays and labels. |
116
+ | `digits` | `'arabic' \| 'latin'` | `'arabic'` for `ar`, else `'latin'` | Arabic-Indic (`١٢٣`) or Latin (`123`) digits. |
117
+ | `direction` | `'rtl' \| 'ltr' \| 'auto'` | `'auto'` | `auto` is right-to-left when the app is RTL (`I18nManager.isRTL`) or the locale is `ar`. |
118
+ | `firstDayOfWeek` | `0 \| 1 \| 6` | `0` | `0` Sunday, `1` Monday, `6` Saturday. |
119
+ | `weekdayFormat` | `'short' \| 'narrow'` | `'short'` | Weekday names above the days: `'أحد'` / `'Sun'`, or `'ح'` / `'S'`. |
120
+ | `minDate` | `Date` | | Earliest selectable day. Navigation stops at its month. |
121
+ | `maxDate` | `Date` | | Latest selectable day. Navigation stops at its month. |
122
+ | `isDateDisabled` | `(date: SelectedDate) => boolean` | | Return `true` to disable a day. |
123
+ | `hijriAdjustment` | `number` | `0` | Shift Hijri dates by whole days, from `-2` to `2`. `1` makes every Hijri date one day later. See [Adjusting to local moon sighting](#adjusting-to-local-moon-sighting). |
124
+ | `showMonthYearPicker` | `boolean` | `true` | Pressing the month title opens a grid of months, and from there a grid of years. |
125
+ | `theme` | `'light' \| 'dark' \| 'auto' \| Partial<HilalTheme>` | `'auto'` | `auto` follows `useColorScheme()`. A partial theme is merged over the `auto` theme. |
126
+ | `styles` | `HilalStyles` | | Styles for parts of the calendar. See [Customization](#customization). |
127
+ | `labels` | `HilalLabels` | | Texts of the toggle and buttons. See [Customization](#customization). |
128
+ | `style` | `StyleProp<ViewStyle>` | | Style of the outer container. |
129
+ | `dayStyle` | `StyleProp<ViewStyle>` | | Style of every day cell. Unlike `styles.day`, it also wins over the selected and today styles. |
130
+ | `maxFontSizeMultiplier` | `number` | `1.3` in cells, `2` in the header | How far the phone's text size setting may grow the text. `1` turns it off, `0` removes the limit. |
131
+
132
+ Navigation never goes past `minDate`/`maxDate` or the edges of the supported range (1356–1500 AH), so the calendar can't show a broken month.
133
+
134
+ To jump far, for example to a date of birth, press the month title: it opens the 12 months of that year, the arrows change the year, and pressing the year opens a page of 12 years. Months and years with no selectable day are disabled. The grids fade in, keeping the calendar the same height, and switch without animation when the system asks to reduce motion. Turn the picker off with `showMonthYearPicker={false}`.
135
+
136
+ ### Theme
137
+
138
+ ```ts
139
+ type HilalTheme = {
140
+ background: string; // calendar background
141
+ text: string; // day numbers, month title
142
+ textSecondary: string; // secondary dates, weekday names
143
+ primary: string; // selected day, active toggle
144
+ onPrimary: string; // text on primary
145
+ today: string; // ring around today
146
+ disabled: string; // disabled days and arrows
147
+ border: string; // toggle outline
148
+ radius: number; // corner radius of a day cell
149
+ arrow?: string; // month arrows, default: text
150
+ fontFamily?: string; // all text, default: the system font
151
+ fontFamilyBold?: string; // bold text: title, selected day, today, weekdays, toggle, picker
152
+ fontScale?: number; // multiplies every font size, default 1
153
+ };
154
+ ```
155
+
156
+ `lightTheme` and `darkTheme` are exported if you want to build a full theme from one of them.
157
+
158
+ ### Customization
159
+
160
+ Fonts go in the theme. Load them first (for example with `expo-font`) and pass their names. With `fontFamilyBold`, the bold text uses that font as it is, without a bold weight on top. `fontScale` makes all text larger or smaller, and day cells grow with larger text. Weekday names and the month and year names in the picker never grow, so they still fit their columns on small phones.
161
+
162
+ ```tsx
163
+ <HilalCalendar
164
+ theme={{
165
+ fontFamily: 'Cairo-Regular',
166
+ fontFamilyBold: 'Cairo-Bold',
167
+ fontScale: 1.1,
168
+ arrow: '#0F766E',
169
+ }}
170
+ />
171
+ ```
172
+
173
+ For anything else, `styles` takes a style for each part, merged over the theme's styles:
174
+
175
+ ```tsx
176
+ <HilalCalendar
177
+ styles={{
178
+ title: { fontSize: 20 },
179
+ selectedDay: { borderRadius: 8 },
180
+ weekdayText: { color: '#6B7280' },
181
+ }}
182
+ />
183
+ ```
184
+
185
+ | Part | Slots |
186
+ | ------------------------ | ---------------------------------------------------------------------------- |
187
+ | Container | `container` |
188
+ | Hijri / Gregorian toggle | `toggle`, `toggleOption`, `toggleText` |
189
+ | Header | `header`, `title`, `subtitle`, `arrow` |
190
+ | Weekday names | `weekdayText` |
191
+ | Days | `day`, `dayText`, `secondaryDayText` |
192
+ | Day states | `selectedDay`, `selectedDayText`, `today`, `todayDayText`, `disabledDayText` |
193
+ | Month and year picker | `pickerItem`, `pickerText` |
194
+
195
+ The day states apply to day cells only, not to the month and year picker.
196
+
197
+ `labels` replaces the texts of the toggle, and the names screen readers give the buttons. Labels you don't pass keep the locale's text:
198
+
199
+ ```tsx
200
+ <HilalCalendar labels={{ hijri: 'هـ', gregorian: 'م' }} />
201
+ ```
202
+
203
+ The keys are `hijri`, `gregorian`, `today`, `thisMonth`, `thisYear`, `previousMonth`, `nextMonth`, `previousYear`, `nextYear`, `previousYears`, `nextYears`, `chooseMonth` and `chooseYear`.
204
+
205
+ ## Core API
206
+
207
+ The conversion engine is exported on its own: pure functions, no React.
208
+
209
+ ```ts
210
+ import {
211
+ toHijri,
212
+ toGregorian,
213
+ formatHijri,
214
+ getHijriMonthLength,
215
+ } from 'react-native-hilal';
216
+
217
+ toHijri(new Date(2024, 6, 7)); // { year: 1446, month: 1, day: 1 }
218
+ toGregorian({ year: 1445, month: 9, day: 1 }); // Mon Mar 11 2024, local midnight
219
+ formatHijri({ year: 1446, month: 9, day: 1 }, { locale: 'en' }); // '1 Ramadan 1446 AH'
220
+ getHijriMonthLength(1446, 9); // 29
221
+ ```
222
+
223
+ Without options, `formatHijri` returns `'١ رمضان ١٤٤٦ هـ'` (Arabic, Arabic-Indic digits).
224
+
225
+ | Function | Description |
226
+ | --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
227
+ | `toHijri(date: Date, { adjustment? }): HijriDate` | Hijri date of the local calendar day of `date`. The time of day is ignored. |
228
+ | `toGregorian(hijri: HijriDate, { adjustment? }): Date` | A `Date` at local midnight of the matching Gregorian day. |
229
+ | `getHijriMonthLength(year, month): 29 \| 30` | Days in a Hijri month (`month` is 1–12). |
230
+ | `isValidHijri(hijri: HijriDate): boolean` | Whether the date exists and is in the supported range. |
231
+ | `getSupportedRange(): { min: HijriDate; max: HijriDate }` | `1 Muharram 1356` to `30 Dhu al-Hijjah 1500`. |
232
+ | `formatHijri(hijri, { locale?, digits? }): string` | Arabic by default (`'١ رمضان ١٤٤٦ هـ'`), or `'1 Ramadan 1446 AH'` with `locale: 'en'`. |
233
+ | `getMonthNames(calendar, locale): string[]` | 12 month names. Arabic Gregorian names use the Gulf style (`'يناير'`, `'فبراير'`, `'مارس'`), not the Levantine one. |
234
+ | `getWeekdayNames(locale, format?): string[]` | 7 weekday names, Sunday first (matches `Date#getDay()`), `'long'`, `'short'` or `'narrow'`. |
235
+ | `toArabicDigits(input: string \| number): string` | `'1446'` → `'١٤٤٦'`. |
236
+
237
+ `HijriDate` is `{ year: number; month: number; day: number }` with `month` from 1 to 12. Dates outside the supported range (1937-03-14 to 2077-11-16) throw a `RangeError`.
238
+
239
+ All types are exported too: `HilalCalendarProps`, `SelectedDate`, `HilalTheme`, `ThemeProp`, `HilalStyles`, `HilalLabels`, `HijriDate`, `HijriConversionOptions`, `FormatHijriOptions`, `CalendarType`, `Locale`, `Digits` and `WeekdayFormat`.
240
+
241
+ Dates are always handled as **local calendar days**. A day is never derived from a UTC timestamp, so the result doesn't depend on the time of day or the time zone offset.
242
+
243
+ ## Why Hilal?
244
+
245
+ Other Hijri pickers for React Native tend to have at least one of these problems: they run on Android only or iOS only, they are no longer maintained, they depend on `moment`, or they only convert dates and ship no UI.
246
+
247
+ | | Hilal |
248
+ | -------------------------------------- | -------------------------------------------------------------- |
249
+ | iOS, Android and web from one codebase | ✅ pure TypeScript, React Native core components only |
250
+ | Runs in Expo Go | ✅ no native modules |
251
+ | Runtime dependencies | ✅ none |
252
+ | Hijri calendar | ✅ Umm al-Qura, checked against ICU for every day of 1937–2077 |
253
+ | UI included | ✅ month grid, both calendars, themes, RTL, accessibility |
254
+ | Use the engine without the UI | ✅ `toHijri`, `toGregorian`, `formatHijri`, ... |
255
+
256
+ ## Accuracy
257
+
258
+ Hilal uses the **Umm al-Qura** calendar, the official calendar of Saudi Arabia. It is computed in advance, so the date of any day is known years ahead.
259
+
260
+ Religious occasions such as the start of Ramadan or Eid are announced from the actual sighting of the crescent moon (_hilal_), and can differ from the Umm al-Qura date by a day. Use Hilal for scheduling and display, and rely on the official announcement for religious observances.
261
+
262
+ ### Adjusting to local moon sighting
263
+
264
+ Where months start a day before or after Umm al-Qura, shift the Hijri calendar by whole days, from `-2` to `2`:
265
+
266
+ ```tsx
267
+ // The month started a day earlier here: Umm al-Qura's 29 Sha'ban 1445
268
+ // (10 March 2024) shows as 1 Ramadan 1445.
269
+ <HilalCalendar hijriAdjustment={1} />
270
+ ```
271
+
272
+ ```ts
273
+ toHijri(new Date(2024, 2, 10), { adjustment: 1 }); // { year: 1445, month: 9, day: 1 }
274
+ toGregorian({ year: 1445, month: 9, day: 1 }, { adjustment: 1 }); // Sun Mar 10 2024
275
+ ```
276
+
277
+ Gregorian dates never change. The shift moves the whole calendar, so months keep their Umm al-Qura lengths: a month of 29 days stays 29 days. This is the common approach in Islamic apps, and it matches a local calendar that runs a fixed number of days ahead of or behind Umm al-Qura.
278
+
279
+ ### How the Umm al-Qura table is made and verified
280
+
281
+ - **Generated, not copied.** [`scripts/generate-umalqura-table.ts`](scripts/generate-umalqura-table.ts) reads the `islamic-umalqura` calendar from Node's built-in ICU and writes [`src/core/umalqura-data.ts`](src/core/umalqura-data.ts). Run `yarn generate:umalqura` to rebuild it.
282
+ - **Compact.** The table is one 12-bit number per Hijri year (bit set means a 30-day month), plus the start day of 1 Muharram 1356: 145 numbers, about 1.5 KB.
283
+ - **No `Intl` at runtime.** Support for the `islamic-umalqura` calendar differs between Hermes versions and platforms, so the library only reads the table.
284
+ - **Tested day by day.** The test suite compares `toHijri` with ICU for all 51,383 days in the range, at 00:00 and 23:59, and checks every month length and the round trip `toGregorian(toHijri(d)) === d`, also for every Hijri adjustment. The suite runs in a UTC+14 time zone, so any code that takes the day from a UTC timestamp fails.
285
+
286
+ ## Roadmap
287
+
288
+ Planned next:
289
+
290
+ - Range selection
291
+ - Event dots on days
292
+ - Swipe between months
293
+ - Ready-made bottom sheet and modal variants
294
+
295
+ ## Contributing
296
+
297
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for the development workflow, commit conventions and how to send a pull request. To report a security issue, see [SECURITY.md](SECURITY.md).
298
+
299
+ ## License
300
+
301
+ [MIT](LICENSE) © 2ve2
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ import { useEffect, useState } from 'react';
4
+ import { AccessibilityInfo, Animated, Easing, Platform, View } from 'react-native';
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ const DURATION = 220;
7
+ /** Scale the content starts from, just under its full size. */
8
+ const FROM_SCALE = 0.96;
9
+ /**
10
+ * Fades its content in with a slight zoom when it mounts, so switching
11
+ * between the days and the month or year picker is not an abrupt jump.
12
+ * Give it a new `key` to play it again.
13
+ */
14
+ export function Appear({
15
+ animate,
16
+ style,
17
+ onLayout,
18
+ children
19
+ }) {
20
+ const [animated] = useState(animate);
21
+ const [progress] = useState(() => new Animated.Value(animated ? 0 : 1));
22
+ useEffect(() => {
23
+ if (!animated) {
24
+ return;
25
+ }
26
+ const animation = Animated.timing(progress, {
27
+ toValue: 1,
28
+ duration: DURATION,
29
+ easing: Easing.out(Easing.cubic),
30
+ // React Native Web has no native animation driver.
31
+ useNativeDriver: Platform.OS !== 'web'
32
+ });
33
+ animation.start();
34
+ return () => animation.stop();
35
+ // Plays once, on mount.
36
+ // eslint-disable-next-line react-hooks/exhaustive-deps
37
+ }, []);
38
+ if (!animated) {
39
+ return /*#__PURE__*/_jsx(View, {
40
+ style: style,
41
+ onLayout: onLayout,
42
+ children: children
43
+ });
44
+ }
45
+ const scale = progress.interpolate({
46
+ inputRange: [0, 1],
47
+ outputRange: [FROM_SCALE, 1]
48
+ });
49
+ return /*#__PURE__*/_jsx(Animated.View, {
50
+ style: [style, {
51
+ opacity: progress,
52
+ transform: [{
53
+ scale
54
+ }]
55
+ }],
56
+ onLayout: onLayout,
57
+ children: children
58
+ });
59
+ }
60
+
61
+ /** Whether the user asked the system to reduce motion. */
62
+ export function useReduceMotion() {
63
+ const [reduceMotion, setReduceMotion] = useState(false);
64
+ useEffect(() => {
65
+ let mounted = true;
66
+ AccessibilityInfo.isReduceMotionEnabled().then(enabled => mounted && setReduceMotion(enabled), () => {});
67
+ const subscription = AccessibilityInfo.addEventListener('reduceMotionChanged', setReduceMotion);
68
+ return () => {
69
+ mounted = false;
70
+ subscription.remove();
71
+ };
72
+ }, []);
73
+ return reduceMotion;
74
+ }
75
+ //# sourceMappingURL=Appear.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useEffect","useState","AccessibilityInfo","Animated","Easing","Platform","View","jsx","_jsx","DURATION","FROM_SCALE","Appear","animate","style","onLayout","children","animated","progress","Value","animation","timing","toValue","duration","easing","out","cubic","useNativeDriver","OS","start","stop","scale","interpolate","inputRange","outputRange","opacity","transform","useReduceMotion","reduceMotion","setReduceMotion","mounted","isReduceMotionEnabled","then","enabled","subscription","addEventListener","remove"],"sourceRoot":"../../../src","sources":["calendar/Appear.tsx"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAwB,OAAO;AAC3D,SACEC,iBAAiB,EACjBC,QAAQ,EACRC,MAAM,EACNC,QAAQ,EACRC,IAAI,QAIC,cAAc;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAEtB,MAAMC,QAAQ,GAAG,GAAG;AACpB;AACA,MAAMC,UAAU,GAAG,IAAI;AAavB;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,MAAMA,CAAC;EAAEC,OAAO;EAAEC,KAAK;EAAEC,QAAQ;EAAEC;AAAsB,CAAC,EAAE;EAC1E,MAAM,CAACC,QAAQ,CAAC,GAAGf,QAAQ,CAACW,OAAO,CAAC;EACpC,MAAM,CAACK,QAAQ,CAAC,GAAGhB,QAAQ,CAAC,MAAM,IAAIE,QAAQ,CAACe,KAAK,CAACF,QAAQ,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;EAEvEhB,SAAS,CAAC,MAAM;IACd,IAAI,CAACgB,QAAQ,EAAE;MACb;IACF;IACA,MAAMG,SAAS,GAAGhB,QAAQ,CAACiB,MAAM,CAACH,QAAQ,EAAE;MAC1CI,OAAO,EAAE,CAAC;MACVC,QAAQ,EAAEb,QAAQ;MAClBc,MAAM,EAAEnB,MAAM,CAACoB,GAAG,CAACpB,MAAM,CAACqB,KAAK,CAAC;MAChC;MACAC,eAAe,EAAErB,QAAQ,CAACsB,EAAE,KAAK;IACnC,CAAC,CAAC;IACFR,SAAS,CAACS,KAAK,CAAC,CAAC;IACjB,OAAO,MAAMT,SAAS,CAACU,IAAI,CAAC,CAAC;IAC7B;IACA;EACF,CAAC,EAAE,EAAE,CAAC;EAEN,IAAI,CAACb,QAAQ,EAAE;IACb,oBACER,IAAA,CAACF,IAAI;MAACO,KAAK,EAAEA,KAAM;MAACC,QAAQ,EAAEA,QAAS;MAAAC,QAAA,EACpCA;IAAQ,CACL,CAAC;EAEX;EACA,MAAMe,KAAK,GAAGb,QAAQ,CAACc,WAAW,CAAC;IACjCC,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IAClBC,WAAW,EAAE,CAACvB,UAAU,EAAE,CAAC;EAC7B,CAAC,CAAC;EACF,oBACEF,IAAA,CAACL,QAAQ,CAACG,IAAI;IACZO,KAAK,EAAE,CAACA,KAAK,EAAE;MAAEqB,OAAO,EAAEjB,QAAQ;MAAEkB,SAAS,EAAE,CAAC;QAAEL;MAAM,CAAC;IAAE,CAAC,CAAE;IAC9DhB,QAAQ,EAAEA,QAAS;IAAAC,QAAA,EAElBA;EAAQ,CACI,CAAC;AAEpB;;AAEA;AACA,OAAO,SAASqB,eAAeA,CAAA,EAAG;EAChC,MAAM,CAACC,YAAY,EAAEC,eAAe,CAAC,GAAGrC,QAAQ,CAAC,KAAK,CAAC;EACvDD,SAAS,CAAC,MAAM;IACd,IAAIuC,OAAO,GAAG,IAAI;IAClBrC,iBAAiB,CAACsC,qBAAqB,CAAC,CAAC,CAACC,IAAI,CAC3CC,OAAO,IAAKH,OAAO,IAAID,eAAe,CAACI,OAAO,CAAC,EAChD,MAAM,CAAC,CACT,CAAC;IACD,MAAMC,YAAY,GAAGzC,iBAAiB,CAAC0C,gBAAgB,CACrD,qBAAqB,EACrBN,eACF,CAAC;IACD,OAAO,MAAM;MACXC,OAAO,GAAG,KAAK;MACfI,YAAY,CAACE,MAAM,CAAC,CAAC;IACvB,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;EACN,OAAOR,YAAY;AACrB","ignoreList":[]}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ import { StyleSheet, View } from 'react-native';
4
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
+ const SIZE = 14;
6
+ const LENGTH = 10;
7
+ const THICKNESS = 2.5;
8
+ // Vertical offset of each stroke's center so their ends meet at the tip.
9
+ const OFFSET = LENGTH / (2 * Math.SQRT2);
10
+
11
+ /**
12
+ * A chevron drawn with two rotated strokes. Not a text glyph: '‹' and '›'
13
+ * are mirrored by the Unicode bidi algorithm in right-to-left text, so they
14
+ * would point the wrong way in RTL apps. No left/right styles either, since
15
+ * React Native swaps those in RTL layouts.
16
+ */
17
+ export function Chevron({
18
+ direction,
19
+ color
20
+ }) {
21
+ const upper = direction === 'left' ? '-45deg' : '45deg';
22
+ const lower = direction === 'left' ? '45deg' : '-45deg';
23
+ return /*#__PURE__*/_jsxs(View, {
24
+ testID: `hilal-chevron-${direction}`,
25
+ style: styles.box,
26
+ children: [/*#__PURE__*/_jsx(View, {
27
+ style: [styles.stroke, {
28
+ backgroundColor: color,
29
+ top: SIZE / 2 - OFFSET - THICKNESS / 2
30
+ }, {
31
+ transform: [{
32
+ rotate: upper
33
+ }]
34
+ }]
35
+ }), /*#__PURE__*/_jsx(View, {
36
+ style: [styles.stroke, {
37
+ backgroundColor: color,
38
+ top: SIZE / 2 + OFFSET - THICKNESS / 2
39
+ }, {
40
+ transform: [{
41
+ rotate: lower
42
+ }]
43
+ }]
44
+ })]
45
+ });
46
+ }
47
+ const styles = StyleSheet.create({
48
+ box: {
49
+ alignItems: 'center',
50
+ height: SIZE,
51
+ width: SIZE
52
+ },
53
+ stroke: {
54
+ borderRadius: THICKNESS / 2,
55
+ height: THICKNESS,
56
+ position: 'absolute',
57
+ width: LENGTH
58
+ }
59
+ });
60
+ //# sourceMappingURL=Chevron.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["StyleSheet","View","jsx","_jsx","jsxs","_jsxs","SIZE","LENGTH","THICKNESS","OFFSET","Math","SQRT2","Chevron","direction","color","upper","lower","testID","style","styles","box","children","stroke","backgroundColor","top","transform","rotate","create","alignItems","height","width","borderRadius","position"],"sourceRoot":"../../../src","sources":["calendar/Chevron.tsx"],"mappings":";;AAAA,SAASA,UAAU,EAAEC,IAAI,QAAQ,cAAc;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAOhD,MAAMC,IAAI,GAAG,EAAE;AACf,MAAMC,MAAM,GAAG,EAAE;AACjB,MAAMC,SAAS,GAAG,GAAG;AACrB;AACA,MAAMC,MAAM,GAAGF,MAAM,IAAI,CAAC,GAAGG,IAAI,CAACC,KAAK,CAAC;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,OAAOA,CAAC;EAAEC,SAAS;EAAEC;AAAoB,CAAC,EAAE;EAC1D,MAAMC,KAAK,GAAGF,SAAS,KAAK,MAAM,GAAG,QAAQ,GAAG,OAAO;EACvD,MAAMG,KAAK,GAAGH,SAAS,KAAK,MAAM,GAAG,OAAO,GAAG,QAAQ;EACvD,oBACER,KAAA,CAACJ,IAAI;IAACgB,MAAM,EAAE,iBAAiBJ,SAAS,EAAG;IAACK,KAAK,EAAEC,MAAM,CAACC,GAAI;IAAAC,QAAA,gBAC5DlB,IAAA,CAACF,IAAI;MACHiB,KAAK,EAAE,CACLC,MAAM,CAACG,MAAM,EACb;QAAEC,eAAe,EAAET,KAAK;QAAEU,GAAG,EAAElB,IAAI,GAAG,CAAC,GAAGG,MAAM,GAAGD,SAAS,GAAG;MAAE,CAAC,EAClE;QAAEiB,SAAS,EAAE,CAAC;UAAEC,MAAM,EAAEX;QAAM,CAAC;MAAE,CAAC;IAClC,CACH,CAAC,eACFZ,IAAA,CAACF,IAAI;MACHiB,KAAK,EAAE,CACLC,MAAM,CAACG,MAAM,EACb;QAAEC,eAAe,EAAET,KAAK;QAAEU,GAAG,EAAElB,IAAI,GAAG,CAAC,GAAGG,MAAM,GAAGD,SAAS,GAAG;MAAE,CAAC,EAClE;QAAEiB,SAAS,EAAE,CAAC;UAAEC,MAAM,EAAEV;QAAM,CAAC;MAAE,CAAC;IAClC,CACH,CAAC;EAAA,CACE,CAAC;AAEX;AAEA,MAAMG,MAAM,GAAGnB,UAAU,CAAC2B,MAAM,CAAC;EAC/BP,GAAG,EAAE;IACHQ,UAAU,EAAE,QAAQ;IACpBC,MAAM,EAAEvB,IAAI;IACZwB,KAAK,EAAExB;EACT,CAAC;EACDgB,MAAM,EAAE;IACNS,YAAY,EAAEvB,SAAS,GAAG,CAAC;IAC3BqB,MAAM,EAAErB,SAAS;IACjBwB,QAAQ,EAAE,UAAU;IACpBF,KAAK,EAAEvB;EACT;AACF,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ import { memo } from 'react';
4
+ import { Pressable, Text, View } from 'react-native';
5
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
6
+ /**
7
+ * One day of the grid. Memoized: every prop is either a primitive or kept
8
+ * stable by the calendar, so pressing a day only re-renders the old and
9
+ * the new selected day.
10
+ */
11
+ export function DayCellView({
12
+ epochDay,
13
+ label,
14
+ secondaryLabel,
15
+ accessibilityLabel,
16
+ selected,
17
+ today,
18
+ disabled,
19
+ styles,
20
+ dayStyle,
21
+ maxFontScale,
22
+ onSelect
23
+ }) {
24
+ return /*#__PURE__*/_jsx(View, {
25
+ style: styles.slot,
26
+ children: /*#__PURE__*/_jsxs(Pressable, {
27
+ accessibilityRole: "button",
28
+ accessibilityLabel: accessibilityLabel,
29
+ accessibilityState: {
30
+ selected,
31
+ disabled
32
+ },
33
+ disabled: disabled,
34
+ onPress: () => onSelect(epochDay),
35
+ style: ({
36
+ pressed
37
+ }) => [styles.day, today && styles.today, selected && styles.selected, pressed && !selected && styles.pressed, dayStyle],
38
+ children: [/*#__PURE__*/_jsx(Text, {
39
+ maxFontSizeMultiplier: maxFontScale,
40
+ style: [styles.dayText, disabled && styles.disabledText, today && styles.todayText, selected && styles.selectedText],
41
+ children: label
42
+ }), secondaryLabel !== null && /*#__PURE__*/_jsx(Text, {
43
+ maxFontSizeMultiplier: maxFontScale,
44
+ style: [styles.secondaryText, disabled && styles.disabledText, selected && styles.selectedSecondaryText],
45
+ children: secondaryLabel
46
+ })]
47
+ })
48
+ });
49
+ }
50
+ export const DayCell = /*#__PURE__*/memo(DayCellView);
51
+ //# sourceMappingURL=DayCell.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["memo","Pressable","Text","View","jsx","_jsx","jsxs","_jsxs","DayCellView","epochDay","label","secondaryLabel","accessibilityLabel","selected","today","disabled","styles","dayStyle","maxFontScale","onSelect","style","slot","children","accessibilityRole","accessibilityState","onPress","pressed","day","maxFontSizeMultiplier","dayText","disabledText","todayText","selectedText","secondaryText","selectedSecondaryText","DayCell"],"sourceRoot":"../../../src","sources":["calendar/DayCell.tsx"],"mappings":";;AAAA,SAASA,IAAI,QAAQ,OAAO;AAC5B,SACEC,SAAS,EACTC,IAAI,EACJC,IAAI,QAGC,cAAc;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAmBtB;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,WAAWA,CAAC;EAC1BC,QAAQ;EACRC,KAAK;EACLC,cAAc;EACdC,kBAAkB;EAClBC,QAAQ;EACRC,KAAK;EACLC,QAAQ;EACRC,MAAM;EACNC,QAAQ;EACRC,YAAY;EACZC;AACY,CAAC,EAAE;EACf,oBACEd,IAAA,CAACF,IAAI;IAACiB,KAAK,EAAEJ,MAAM,CAACK,IAAK;IAAAC,QAAA,eACvBf,KAAA,CAACN,SAAS;MACRsB,iBAAiB,EAAC,QAAQ;MAC1BX,kBAAkB,EAAEA,kBAAmB;MACvCY,kBAAkB,EAAE;QAAEX,QAAQ;QAAEE;MAAS,CAAE;MAC3CA,QAAQ,EAAEA,QAAS;MACnBU,OAAO,EAAEA,CAAA,KAAMN,QAAQ,CAACV,QAAQ,CAAE;MAClCW,KAAK,EAAEA,CAAC;QAAEM;MAAQ,CAAC,KAAK,CACtBV,MAAM,CAACW,GAAG,EACVb,KAAK,IAAIE,MAAM,CAACF,KAAK,EACrBD,QAAQ,IAAIG,MAAM,CAACH,QAAQ,EAC3Ba,OAAO,IAAI,CAACb,QAAQ,IAAIG,MAAM,CAACU,OAAO,EACtCT,QAAQ,CACR;MAAAK,QAAA,gBAEFjB,IAAA,CAACH,IAAI;QACH0B,qBAAqB,EAAEV,YAAa;QACpCE,KAAK,EAAE,CACLJ,MAAM,CAACa,OAAO,EACdd,QAAQ,IAAIC,MAAM,CAACc,YAAY,EAC/BhB,KAAK,IAAIE,MAAM,CAACe,SAAS,EACzBlB,QAAQ,IAAIG,MAAM,CAACgB,YAAY,CAC/B;QAAAV,QAAA,EAEDZ;MAAK,CACF,CAAC,EACNC,cAAc,KAAK,IAAI,iBACtBN,IAAA,CAACH,IAAI;QACH0B,qBAAqB,EAAEV,YAAa;QACpCE,KAAK,EAAE,CACLJ,MAAM,CAACiB,aAAa,EACpBlB,QAAQ,IAAIC,MAAM,CAACc,YAAY,EAC/BjB,QAAQ,IAAIG,MAAM,CAACkB,qBAAqB,CACxC;QAAAZ,QAAA,EAEDX;MAAc,CACX,CACP;IAAA,CACQ;EAAC,CACR,CAAC;AAEX;AAEA,OAAO,MAAMwB,OAAO,gBAAGnC,IAAI,CAACQ,WAAW,CAAC","ignoreList":[]}