react-native-hilal 0.1.0 → 0.3.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 +165 -49
- package/lib/module/calendar/Appear.js +75 -0
- package/lib/module/calendar/Appear.js.map +1 -0
- package/lib/module/calendar/DayCell.js +32 -5
- package/lib/module/calendar/DayCell.js.map +1 -1
- package/lib/module/calendar/HilalCalendar.js +434 -76
- package/lib/module/calendar/HilalCalendar.js.map +1 -1
- package/lib/module/calendar/PickerGrid.js +66 -0
- package/lib/module/calendar/PickerGrid.js.map +1 -0
- package/lib/module/calendar/month.js +135 -22
- package/lib/module/calendar/month.js.map +1 -1
- package/lib/module/calendar/range.js +103 -0
- package/lib/module/calendar/range.js.map +1 -0
- package/lib/module/calendar/styles.js +233 -7
- package/lib/module/calendar/styles.js.map +1 -1
- package/lib/module/calendar/theme.js +3 -3
- package/lib/module/calendar/theme.js.map +1 -1
- package/lib/module/core/convert.js +52 -21
- package/lib/module/core/convert.js.map +1 -1
- package/lib/module/core/index.js.map +1 -1
- package/lib/module/core/locale.js +5 -2
- package/lib/module/core/locale.js.map +1 -1
- package/lib/typescript/src/calendar/Appear.d.ts +22 -0
- package/lib/typescript/src/calendar/Appear.d.ts.map +1 -0
- package/lib/typescript/src/calendar/DayCell.d.ts +8 -1
- package/lib/typescript/src/calendar/DayCell.d.ts.map +1 -1
- package/lib/typescript/src/calendar/HilalCalendar.d.ts +1 -1
- package/lib/typescript/src/calendar/HilalCalendar.d.ts.map +1 -1
- package/lib/typescript/src/calendar/PickerGrid.d.ts +28 -0
- package/lib/typescript/src/calendar/PickerGrid.d.ts.map +1 -0
- package/lib/typescript/src/calendar/index.d.ts +1 -1
- package/lib/typescript/src/calendar/index.d.ts.map +1 -1
- package/lib/typescript/src/calendar/month.d.ts +30 -7
- package/lib/typescript/src/calendar/month.d.ts.map +1 -1
- package/lib/typescript/src/calendar/range.d.ts +39 -0
- package/lib/typescript/src/calendar/range.d.ts.map +1 -0
- package/lib/typescript/src/calendar/styles.d.ts +207 -113
- package/lib/typescript/src/calendar/styles.d.ts.map +1 -1
- package/lib/typescript/src/calendar/theme.d.ts +21 -1
- package/lib/typescript/src/calendar/theme.d.ts.map +1 -1
- package/lib/typescript/src/calendar/types.d.ts +153 -2
- package/lib/typescript/src/calendar/types.d.ts.map +1 -1
- package/lib/typescript/src/core/convert.d.ts +38 -15
- package/lib/typescript/src/core/convert.d.ts.map +1 -1
- package/lib/typescript/src/core/index.d.ts +1 -1
- package/lib/typescript/src/core/index.d.ts.map +1 -1
- package/lib/typescript/src/core/locale.d.ts +1 -1
- package/lib/typescript/src/core/locale.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/calendar/Appear.tsx +94 -0
- package/src/calendar/DayCell.tsx +41 -1
- package/src/calendar/HilalCalendar.tsx +541 -85
- package/src/calendar/PickerGrid.tsx +99 -0
- package/src/calendar/index.ts +8 -1
- package/src/calendar/month.ts +174 -23
- package/src/calendar/range.ts +114 -0
- package/src/calendar/styles.ts +249 -6
- package/src/calendar/theme.ts +23 -3
- package/src/calendar/types.ts +156 -2
- package/src/core/convert.ts +87 -23
- package/src/core/index.ts +1 -0
- package/src/core/locale.ts +4 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<img src="https://raw.githubusercontent.com/2ve2/hilal/main/docs/assets/banner.png" alt="Hilal هلال" width="720" />
|
|
4
4
|
|
|
5
5
|
**A Hijri (Umm al-Qura) and Gregorian date picker for React Native.**
|
|
6
6
|
iOS, Android, web and Expo Go. Zero dependencies. Arabic-first.
|
|
@@ -9,12 +9,7 @@ iOS, Android, web and Expo Go. Zero dependencies. Arabic-first.
|
|
|
9
9
|
[](https://github.com/2ve2/hilal/actions/workflows/ci.yml)
|
|
10
10
|
[](LICENSE)
|
|
11
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
|
-
-->
|
|
12
|
+
<img src="https://raw.githubusercontent.com/2ve2/hilal/main/docs/assets/demo.gif" alt="Hilal in action: switching between Hijri and Gregorian, picking a day, the month picker, English and a dark custom theme" width="380" />
|
|
18
13
|
|
|
19
14
|
</div>
|
|
20
15
|
|
|
@@ -22,11 +17,12 @@ iOS, Android, web and Expo Go. Zero dependencies. Arabic-first.
|
|
|
22
17
|
|
|
23
18
|
- **Umm al-Qura**, the official calendar of Saudi Arabia, tested against ICU on every day from 1937 to 2077.
|
|
24
19
|
- **Hijri and Gregorian together**: switch the grid between them, and every day also shows its date in the other calendar.
|
|
25
|
-
- **
|
|
20
|
+
- **One day or a range**: pick a single day, or a start and an end for bookings and leave.
|
|
21
|
+
- **Arabic-first**: Arabic month and day names, Arabic-Indic digits (`١٢٣`), proper right-to-left layout. English with Latin digits is one prop away.
|
|
26
22
|
- **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
23
|
- **Zero runtime dependencies**: no moment, no dayjs, no `Intl` calendars at runtime.
|
|
28
|
-
- **
|
|
29
|
-
- **Accessible**: every day is a button with a full spoken date
|
|
24
|
+
- **Customizable**: light, dark, follow the system, or your own colors and fonts; styles for every part and your own button texts.
|
|
25
|
+
- **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
26
|
- **The engine is public**: convert and format Hijri dates without using the UI.
|
|
31
27
|
|
|
32
28
|
## Installation
|
|
@@ -41,6 +37,8 @@ npx expo install react-native-hilal
|
|
|
41
37
|
|
|
42
38
|
`react` and `react-native` are the only peer dependencies. There is nothing to link and no native build step.
|
|
43
39
|
|
|
40
|
+
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.
|
|
41
|
+
|
|
44
42
|
## Quick start
|
|
45
43
|
|
|
46
44
|
```tsx
|
|
@@ -74,7 +72,7 @@ export default function Screen() {
|
|
|
74
72
|
}
|
|
75
73
|
```
|
|
76
74
|
|
|
77
|
-
With the default `locale="ar"`, `formatted.hijri` is ١ رمضان ١٤٤٦ هـ and `formatted.gregorian` is ١ مارس ٢٠٢٥ in Arabic-Indic digits.
|
|
75
|
+
With the default `locale="ar"`, `formatted.hijri` is `'١ رمضان ١٤٤٦ هـ'` and `formatted.gregorian` is `'١ مارس ٢٠٢٥'`, in Arabic-Indic digits.
|
|
78
76
|
|
|
79
77
|
## Examples
|
|
80
78
|
|
|
@@ -101,34 +99,84 @@ The [example app](example) shows every feature side by side. Run it with `yarn e
|
|
|
101
99
|
|
|
102
100
|
## `<HilalCalendar />` props
|
|
103
101
|
|
|
104
|
-
| Prop
|
|
105
|
-
|
|
|
106
|
-
| `value`
|
|
107
|
-
| `defaultValue`
|
|
108
|
-
| `onChange`
|
|
109
|
-
| `
|
|
110
|
-
| `
|
|
111
|
-
| `
|
|
112
|
-
| `
|
|
113
|
-
| `
|
|
114
|
-
| `
|
|
115
|
-
| `
|
|
116
|
-
| `
|
|
117
|
-
| `
|
|
118
|
-
| `
|
|
119
|
-
| `
|
|
120
|
-
| `
|
|
121
|
-
| `
|
|
122
|
-
| `
|
|
102
|
+
| Prop | Type | Default | Description |
|
|
103
|
+
| ----------------------- | ---------------------------------------------------- | ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
104
|
+
| `value` | `Date` | | Selected day (controlled). Only the local calendar day is used. |
|
|
105
|
+
| `defaultValue` | `Date` | | Initially selected day (uncontrolled). |
|
|
106
|
+
| `onChange` | `(date: SelectedDate) => void` | | Called when the user picks a day. |
|
|
107
|
+
| `selectionMode` | `'single' \| 'range'` | `'single'` | Pick one day, or a range. See [Range selection](#range-selection). |
|
|
108
|
+
| `rangeValue` | `DateRange \| null` | | Picked range (controlled), or `null` for none. |
|
|
109
|
+
| `defaultRangeValue` | `DateRange` | | Initially picked range (uncontrolled). |
|
|
110
|
+
| `onRangeChange` | `(range: SelectedRange) => void` | | Called after each press in range mode. |
|
|
111
|
+
| `minRangeDays` | `number` | `1` | Fewest days in a range, both ends included. |
|
|
112
|
+
| `maxRangeDays` | `number` | no limit | Most days in a range, both ends included. |
|
|
113
|
+
| `calendar` | `'hijri' \| 'gregorian'` | `'hijri'` | Calendar of the month grid. The grid follows this prop when it changes. |
|
|
114
|
+
| `onCalendarChange` | `(calendar) => void` | | Called when the user switches calendars with the toggle. |
|
|
115
|
+
| `showCalendarToggle` | `boolean` | `true` | Show the Hijri / Gregorian toggle. |
|
|
116
|
+
| `showSecondaryDate` | `boolean` | `true` | Show the other calendar's day under each day. |
|
|
117
|
+
| `locale` | `'ar' \| 'en'` | `'ar'` | Language of month names, weekdays and labels. |
|
|
118
|
+
| `digits` | `'arabic' \| 'latin'` | `'arabic'` for `ar`, else `'latin'` | Arabic-Indic (`١٢٣`) or Latin (`123`) digits. |
|
|
119
|
+
| `direction` | `'rtl' \| 'ltr' \| 'auto'` | `'auto'` | `auto` is right-to-left when the app is RTL (`I18nManager.isRTL`) or the locale is `ar`. |
|
|
120
|
+
| `firstDayOfWeek` | `0 \| 1 \| 6` | `0` | `0` Sunday, `1` Monday, `6` Saturday. |
|
|
121
|
+
| `weekdayFormat` | `'short' \| 'narrow'` | `'short'` | Weekday names above the days: `'أحد'` / `'Sun'`, or `'ح'` / `'S'`. |
|
|
122
|
+
| `minDate` | `Date` | | Earliest selectable day. Navigation stops at its month. |
|
|
123
|
+
| `maxDate` | `Date` | | Latest selectable day. Navigation stops at its month. |
|
|
124
|
+
| `isDateDisabled` | `(date: SelectedDate) => boolean` | | Return `true` to disable a day. |
|
|
125
|
+
| `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). |
|
|
126
|
+
| `showMonthYearPicker` | `boolean` | `true` | Pressing the month title opens a grid of months, and from there a grid of years. |
|
|
127
|
+
| `theme` | `'light' \| 'dark' \| 'auto' \| Partial<HilalTheme>` | `'auto'` | `auto` follows `useColorScheme()`. A partial theme is merged over the `auto` theme. |
|
|
128
|
+
| `styles` | `HilalStyles` | | Styles for parts of the calendar. See [Customization](#customization). |
|
|
129
|
+
| `labels` | `HilalLabels` | | Texts of the toggle and buttons. See [Customization](#customization). |
|
|
130
|
+
| `style` | `StyleProp<ViewStyle>` | | Style of the outer container. |
|
|
131
|
+
| `dayStyle` | `StyleProp<ViewStyle>` | | Style of every day cell. Unlike `styles.day`, it also wins over the selected and today styles. |
|
|
132
|
+
| `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. |
|
|
123
133
|
|
|
124
134
|
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.
|
|
125
135
|
|
|
136
|
+
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}`.
|
|
137
|
+
|
|
138
|
+
### Range selection
|
|
139
|
+
|
|
140
|
+
```tsx
|
|
141
|
+
const [range, setRange] = useState<SelectedRange>();
|
|
142
|
+
|
|
143
|
+
<HilalCalendar selectionMode="range" onRangeChange={setRange} />;
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
The first press picks the start and the second the end; pressing the start again picks a one-day range. A third press starts a new range, and so does a press before the start. A range never crosses a day disabled by `isDateDisabled`: a press past one starts a new range there. `onRangeChange` is called after every press:
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
type SelectedRange = {
|
|
150
|
+
start: SelectedDate;
|
|
151
|
+
end: SelectedDate | null; // null while only the start is picked
|
|
152
|
+
days: number | null; // both ends included: 1 for a one-day range
|
|
153
|
+
};
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
To limit the length, pass `minRangeDays` and `maxRangeDays`. They count both ends like `days`, so a stay of 2 to 14 nights is `minRangeDays={3}` and `maxRangeDays={15}`. After the start is picked, the days that would make the range too short or too long can't be pressed; a day before the start still starts over. Limits that aren't whole numbers of at least 1, or a minimum above the maximum, throw a `RangeError`.
|
|
157
|
+
|
|
158
|
+
In range mode, `value`, `defaultValue` and `onChange` are not used. To control it, pass `rangeValue={{ start, end }}` (leave `end` out while only the start is picked, or pass `null` for no range) and update it in `onRangeChange` from `start.gregorian` and `end?.gregorian`. The calendar opens on the month of the start.
|
|
159
|
+
|
|
160
|
+
The ends are drawn like the selected day, joined by a band in the theme's `primary` color at 15% opacity, so a custom `primary` colors both. To style the band on its own, use `styles.rangeBand`. Screen readers hear "Start of range" and "End of range" at the ends (`'بداية الفترة'` and `'نهاية الفترة'` in Arabic), which `labels` can change:
|
|
161
|
+
|
|
162
|
+
```tsx
|
|
163
|
+
<HilalCalendar
|
|
164
|
+
selectionMode="range"
|
|
165
|
+
theme={{ primary: '#7C3AED' }}
|
|
166
|
+
styles={{
|
|
167
|
+
selectedDay: { borderRadius: 999 },
|
|
168
|
+
rangeBand: { backgroundColor: '#F59E0B', opacity: 0.25 },
|
|
169
|
+
}}
|
|
170
|
+
labels={{ rangeStart: 'Check-in', rangeEnd: 'Check-out' }}
|
|
171
|
+
/>
|
|
172
|
+
```
|
|
173
|
+
|
|
126
174
|
### Theme
|
|
127
175
|
|
|
128
176
|
```ts
|
|
129
177
|
type HilalTheme = {
|
|
130
178
|
background: string; // calendar background
|
|
131
|
-
text: string; // day numbers, month title
|
|
179
|
+
text: string; // day numbers, month title
|
|
132
180
|
textSecondary: string; // secondary dates, weekday names
|
|
133
181
|
primary: string; // selected day, active toggle
|
|
134
182
|
onPrimary: string; // text on primary
|
|
@@ -136,11 +184,63 @@ type HilalTheme = {
|
|
|
136
184
|
disabled: string; // disabled days and arrows
|
|
137
185
|
border: string; // toggle outline
|
|
138
186
|
radius: number; // corner radius of a day cell
|
|
187
|
+
arrow?: string; // month arrows, default: text
|
|
188
|
+
fontFamily?: string; // all text, default: the system font
|
|
189
|
+
fontFamilyBold?: string; // bold text: title, selected day, today, weekdays, toggle, picker
|
|
190
|
+
fontScale?: number; // multiplies every font size, default 1
|
|
139
191
|
};
|
|
140
192
|
```
|
|
141
193
|
|
|
142
194
|
`lightTheme` and `darkTheme` are exported if you want to build a full theme from one of them.
|
|
143
195
|
|
|
196
|
+
### Customization
|
|
197
|
+
|
|
198
|
+
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.
|
|
199
|
+
|
|
200
|
+
```tsx
|
|
201
|
+
<HilalCalendar
|
|
202
|
+
theme={{
|
|
203
|
+
fontFamily: 'Cairo-Regular',
|
|
204
|
+
fontFamilyBold: 'Cairo-Bold',
|
|
205
|
+
fontScale: 1.1,
|
|
206
|
+
arrow: '#0F766E',
|
|
207
|
+
}}
|
|
208
|
+
/>
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
For anything else, `styles` takes a style for each part, merged over the theme's styles:
|
|
212
|
+
|
|
213
|
+
```tsx
|
|
214
|
+
<HilalCalendar
|
|
215
|
+
styles={{
|
|
216
|
+
title: { fontSize: 20 },
|
|
217
|
+
selectedDay: { borderRadius: 8 },
|
|
218
|
+
weekdayText: { color: '#6B7280' },
|
|
219
|
+
}}
|
|
220
|
+
/>
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
| Part | Slots |
|
|
224
|
+
| ------------------------ | ---------------------------------------------------------------------------- |
|
|
225
|
+
| Container | `container` |
|
|
226
|
+
| Hijri / Gregorian toggle | `toggle`, `toggleOption`, `toggleText` |
|
|
227
|
+
| Header | `header`, `title`, `subtitle`, `arrow` |
|
|
228
|
+
| Weekday names | `weekdayText` |
|
|
229
|
+
| Days | `day`, `dayText`, `secondaryDayText` |
|
|
230
|
+
| Day states | `selectedDay`, `selectedDayText`, `today`, `todayDayText`, `disabledDayText` |
|
|
231
|
+
| Range | `rangeBand` |
|
|
232
|
+
| Month and year picker | `pickerItem`, `pickerText` |
|
|
233
|
+
|
|
234
|
+
The day states apply to day cells only, not to the month and year picker.
|
|
235
|
+
|
|
236
|
+
`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:
|
|
237
|
+
|
|
238
|
+
```tsx
|
|
239
|
+
<HilalCalendar labels={{ hijri: 'هـ', gregorian: 'م' }} />
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
The keys are `hijri`, `gregorian`, `today`, `thisMonth`, `thisYear`, `rangeStart`, `rangeEnd`, `previousMonth`, `nextMonth`, `previousYear`, `nextYear`, `previousYears`, `nextYears`, `chooseMonth` and `chooseYear`.
|
|
243
|
+
|
|
144
244
|
## Core API
|
|
145
245
|
|
|
146
246
|
The conversion engine is exported on its own: pure functions, no React.
|
|
@@ -159,22 +259,24 @@ formatHijri({ year: 1446, month: 9, day: 1 }, { locale: 'en' }); // '1 Ramadan 1
|
|
|
159
259
|
getHijriMonthLength(1446, 9); // 29
|
|
160
260
|
```
|
|
161
261
|
|
|
162
|
-
Without options, `formatHijri` returns ١ رمضان ١٤٤٦ هـ (Arabic, Arabic-Indic digits).
|
|
262
|
+
Without options, `formatHijri` returns `'١ رمضان ١٤٤٦ هـ'` (Arabic, Arabic-Indic digits).
|
|
163
263
|
|
|
164
|
-
| Function | Description
|
|
165
|
-
| --------------------------------------------------------- |
|
|
166
|
-
| `toHijri(date: Date): HijriDate`
|
|
167
|
-
| `toGregorian(hijri: HijriDate): Date`
|
|
168
|
-
| `getHijriMonthLength(year, month): 29 \| 30` | Days in a Hijri month (`month` is 1–12).
|
|
169
|
-
| `isValidHijri(hijri: HijriDate): boolean` | Whether the date exists and is in the supported range.
|
|
170
|
-
| `getSupportedRange(): { min: HijriDate; max: HijriDate }` | `1 Muharram 1356` to `30 Dhu al-Hijjah 1500`.
|
|
171
|
-
| `formatHijri(hijri, { locale?, digits? }): string` | Arabic by default (١ رمضان ١٤٤٦ هـ), or `'1 Ramadan 1446 AH'` with `locale: 'en'`.
|
|
172
|
-
| `getMonthNames(calendar, locale): string[]` | 12 month names. Arabic Gregorian names use the Gulf style (
|
|
173
|
-
| `getWeekdayNames(locale, format?): string[]` | 7 weekday names, Sunday first (matches `Date#getDay()`), `'long'` or `'
|
|
174
|
-
| `toArabicDigits(input: string \| number): string` | `'1446'` → `'١٤٤٦'`.
|
|
264
|
+
| Function | Description |
|
|
265
|
+
| --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
|
|
266
|
+
| `toHijri(date: Date, { adjustment? }): HijriDate` | Hijri date of the local calendar day of `date`. The time of day is ignored. |
|
|
267
|
+
| `toGregorian(hijri: HijriDate, { adjustment? }): Date` | A `Date` at local midnight of the matching Gregorian day. |
|
|
268
|
+
| `getHijriMonthLength(year, month): 29 \| 30` | Days in a Hijri month (`month` is 1–12). |
|
|
269
|
+
| `isValidHijri(hijri: HijriDate): boolean` | Whether the date exists and is in the supported range. |
|
|
270
|
+
| `getSupportedRange(): { min: HijriDate; max: HijriDate }` | `1 Muharram 1356` to `30 Dhu al-Hijjah 1500`. |
|
|
271
|
+
| `formatHijri(hijri, { locale?, digits? }): string` | Arabic by default (`'١ رمضان ١٤٤٦ هـ'`), or `'1 Ramadan 1446 AH'` with `locale: 'en'`. |
|
|
272
|
+
| `getMonthNames(calendar, locale): string[]` | 12 month names. Arabic Gregorian names use the Gulf style (`'يناير'`, `'فبراير'`, `'مارس'`), not the Levantine one. |
|
|
273
|
+
| `getWeekdayNames(locale, format?): string[]` | 7 weekday names, Sunday first (matches `Date#getDay()`), `'long'`, `'short'` or `'narrow'`. |
|
|
274
|
+
| `toArabicDigits(input: string \| number): string` | `'1446'` → `'١٤٤٦'`. |
|
|
175
275
|
|
|
176
276
|
`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`.
|
|
177
277
|
|
|
278
|
+
All types are exported too: `HilalCalendarProps`, `SelectedDate`, `SelectedRange`, `DateRange`, `HilalTheme`, `ThemeProp`, `HilalStyles`, `HilalLabels`, `HijriDate`, `HijriConversionOptions`, `FormatHijriOptions`, `CalendarType`, `Locale`, `Digits` and `WeekdayFormat`.
|
|
279
|
+
|
|
178
280
|
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.
|
|
179
281
|
|
|
180
282
|
## Why Hilal?
|
|
@@ -196,26 +298,40 @@ Hilal uses the **Umm al-Qura** calendar, the official calendar of Saudi Arabia.
|
|
|
196
298
|
|
|
197
299
|
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.
|
|
198
300
|
|
|
301
|
+
### Adjusting to local moon sighting
|
|
302
|
+
|
|
303
|
+
Where months start a day before or after Umm al-Qura, shift the Hijri calendar by whole days, from `-2` to `2`:
|
|
304
|
+
|
|
305
|
+
```tsx
|
|
306
|
+
// The month started a day earlier here: Umm al-Qura's 29 Sha'ban 1445
|
|
307
|
+
// (10 March 2024) shows as 1 Ramadan 1445.
|
|
308
|
+
<HilalCalendar hijriAdjustment={1} />
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
```ts
|
|
312
|
+
toHijri(new Date(2024, 2, 10), { adjustment: 1 }); // { year: 1445, month: 9, day: 1 }
|
|
313
|
+
toGregorian({ year: 1445, month: 9, day: 1 }, { adjustment: 1 }); // Sun Mar 10 2024
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
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.
|
|
317
|
+
|
|
199
318
|
### How the Umm al-Qura table is made and verified
|
|
200
319
|
|
|
201
320
|
- **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.
|
|
202
321
|
- **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.
|
|
203
322
|
- **No `Intl` at runtime.** Support for the `islamic-umalqura` calendar differs between Hermes versions and platforms, so the library only reads the table.
|
|
204
|
-
- **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
|
|
323
|
+
- **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.
|
|
205
324
|
|
|
206
325
|
## Roadmap
|
|
207
326
|
|
|
208
|
-
|
|
327
|
+
Hilal does what it set out to do. These ideas are open for contributions; open an issue first to talk about the design:
|
|
209
328
|
|
|
210
|
-
- Range selection
|
|
211
|
-
- Quick year and month picker
|
|
212
329
|
- Event dots on days
|
|
213
330
|
- Swipe between months
|
|
214
|
-
- Ready-made bottom sheet and modal variants
|
|
215
331
|
|
|
216
332
|
## Contributing
|
|
217
333
|
|
|
218
|
-
See [CONTRIBUTING.md](CONTRIBUTING.md) for the development workflow, commit conventions and how to send a pull request.
|
|
334
|
+
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).
|
|
219
335
|
|
|
220
336
|
## License
|
|
221
337
|
|
|
@@ -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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AEqB,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":[]}
|
|
@@ -14,19 +14,28 @@ export function DayCellView({
|
|
|
14
14
|
secondaryLabel,
|
|
15
15
|
accessibilityLabel,
|
|
16
16
|
selected,
|
|
17
|
+
rangePosition,
|
|
18
|
+
nextSide,
|
|
17
19
|
today,
|
|
18
20
|
disabled,
|
|
19
21
|
styles,
|
|
20
22
|
dayStyle,
|
|
23
|
+
maxFontScale,
|
|
21
24
|
onSelect
|
|
22
25
|
}) {
|
|
23
|
-
return /*#__PURE__*/
|
|
26
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
24
27
|
style: styles.slot,
|
|
25
|
-
children:
|
|
28
|
+
children: [rangePosition !== null && rangePosition !== 'single' &&
|
|
29
|
+
/*#__PURE__*/
|
|
30
|
+
// Joins the days of a range; half a band at its ends.
|
|
31
|
+
_jsx(View, {
|
|
32
|
+
testID: "hilal-range-band",
|
|
33
|
+
style: [styles.rangeBand, rangePosition === 'middle' ? fullBand : halfBand[rangePosition === 'start' ? nextSide : otherSide(nextSide)]]
|
|
34
|
+
}), /*#__PURE__*/_jsxs(Pressable, {
|
|
26
35
|
accessibilityRole: "button",
|
|
27
36
|
accessibilityLabel: accessibilityLabel,
|
|
28
37
|
accessibilityState: {
|
|
29
|
-
selected,
|
|
38
|
+
selected: selected || rangePosition === 'middle',
|
|
30
39
|
disabled
|
|
31
40
|
},
|
|
32
41
|
disabled: disabled,
|
|
@@ -35,14 +44,32 @@ export function DayCellView({
|
|
|
35
44
|
pressed
|
|
36
45
|
}) => [styles.day, today && styles.today, selected && styles.selected, pressed && !selected && styles.pressed, dayStyle],
|
|
37
46
|
children: [/*#__PURE__*/_jsx(Text, {
|
|
38
|
-
|
|
47
|
+
maxFontSizeMultiplier: maxFontScale,
|
|
48
|
+
style: [styles.dayText, disabled && styles.disabledText, today && styles.todayText, selected && styles.selectedText],
|
|
39
49
|
children: label
|
|
40
50
|
}), secondaryLabel !== null && /*#__PURE__*/_jsx(Text, {
|
|
51
|
+
maxFontSizeMultiplier: maxFontScale,
|
|
41
52
|
style: [styles.secondaryText, disabled && styles.disabledText, selected && styles.selectedSecondaryText],
|
|
42
53
|
children: secondaryLabel
|
|
43
54
|
})]
|
|
44
|
-
})
|
|
55
|
+
})]
|
|
45
56
|
});
|
|
46
57
|
}
|
|
58
|
+
const fullBand = {
|
|
59
|
+
start: 0,
|
|
60
|
+
end: 0
|
|
61
|
+
};
|
|
62
|
+
/** Half a band, on the start or the end side of the cell. */
|
|
63
|
+
const halfBand = {
|
|
64
|
+
start: {
|
|
65
|
+
start: 0,
|
|
66
|
+
width: '50%'
|
|
67
|
+
},
|
|
68
|
+
end: {
|
|
69
|
+
end: 0,
|
|
70
|
+
width: '50%'
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const otherSide = side => side === 'start' ? 'end' : 'start';
|
|
47
74
|
export const DayCell = /*#__PURE__*/memo(DayCellView);
|
|
48
75
|
//# sourceMappingURL=DayCell.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["memo","Pressable","Text","View","jsx","_jsx","jsxs","_jsxs","DayCellView","epochDay","label","secondaryLabel","accessibilityLabel","selected","today","disabled","styles","dayStyle","onSelect","style","slot","children","accessibilityRole","accessibilityState","onPress","pressed","day","dayText","disabledText","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;
|
|
1
|
+
{"version":3,"names":["memo","Pressable","Text","View","jsx","_jsx","jsxs","_jsxs","DayCellView","epochDay","label","secondaryLabel","accessibilityLabel","selected","rangePosition","nextSide","today","disabled","styles","dayStyle","maxFontScale","onSelect","style","slot","children","testID","rangeBand","fullBand","halfBand","otherSide","accessibilityRole","accessibilityState","onPress","pressed","day","maxFontSizeMultiplier","dayText","disabledText","todayText","selectedText","secondaryText","selectedSecondaryText","start","end","width","side","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;AAwBtB;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,WAAWA,CAAC;EAC1BC,QAAQ;EACRC,KAAK;EACLC,cAAc;EACdC,kBAAkB;EAClBC,QAAQ;EACRC,aAAa;EACbC,QAAQ;EACRC,KAAK;EACLC,QAAQ;EACRC,MAAM;EACNC,QAAQ;EACRC,YAAY;EACZC;AACY,CAAC,EAAE;EACf,oBACEd,KAAA,CAACJ,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