react-native-hilal 0.0.0-stage → 0.1.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/LICENSE +20 -0
- package/README.md +221 -2
- package/lib/module/calendar/Chevron.js +60 -0
- package/lib/module/calendar/Chevron.js.map +1 -0
- package/lib/module/calendar/DayCell.js +48 -0
- package/lib/module/calendar/DayCell.js.map +1 -0
- package/lib/module/calendar/HilalCalendar.js +288 -0
- package/lib/module/calendar/HilalCalendar.js.map +1 -0
- package/lib/module/calendar/index.js +5 -0
- package/lib/module/calendar/index.js.map +1 -0
- package/lib/module/calendar/month.js +178 -0
- package/lib/module/calendar/month.js.map +1 -0
- package/lib/module/calendar/styles.js +125 -0
- package/lib/module/calendar/styles.js.map +1 -0
- package/lib/module/calendar/theme.js +49 -0
- package/lib/module/calendar/theme.js.map +1 -0
- package/lib/module/calendar/types.js +4 -0
- package/lib/module/calendar/types.js.map +1 -0
- package/lib/module/core/convert.js +160 -0
- package/lib/module/core/convert.js.map +1 -0
- package/lib/module/core/days.js +61 -0
- package/lib/module/core/days.js.map +1 -0
- package/lib/module/core/format.js +37 -0
- package/lib/module/core/format.js.map +1 -0
- package/lib/module/core/index.js +6 -0
- package/lib/module/core/index.js.map +1 -0
- package/lib/module/core/locale.js +59 -0
- package/lib/module/core/locale.js.map +1 -0
- package/lib/module/core/types.js +2 -0
- package/lib/module/core/types.js.map +1 -0
- package/lib/module/core/umalqura-data.js +24 -0
- package/lib/module/core/umalqura-data.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/calendar/Chevron.d.ts +13 -0
- package/lib/typescript/src/calendar/Chevron.d.ts.map +1 -0
- package/lib/typescript/src/calendar/DayCell.d.ts +22 -0
- package/lib/typescript/src/calendar/DayCell.d.ts.map +1 -0
- package/lib/typescript/src/calendar/HilalCalendar.d.ts +7 -0
- package/lib/typescript/src/calendar/HilalCalendar.d.ts.map +1 -0
- package/lib/typescript/src/calendar/index.d.ts +4 -0
- package/lib/typescript/src/calendar/index.d.ts.map +1 -0
- package/lib/typescript/src/calendar/month.d.ts +63 -0
- package/lib/typescript/src/calendar/month.d.ts.map +1 -0
- package/lib/typescript/src/calendar/styles.d.ts +119 -0
- package/lib/typescript/src/calendar/styles.d.ts.map +1 -0
- package/lib/typescript/src/calendar/theme.d.ts +31 -0
- package/lib/typescript/src/calendar/theme.d.ts.map +1 -0
- package/lib/typescript/src/calendar/types.d.ts +58 -0
- package/lib/typescript/src/calendar/types.d.ts.map +1 -0
- package/lib/typescript/src/core/convert.d.ts +54 -0
- package/lib/typescript/src/core/convert.d.ts.map +1 -0
- package/lib/typescript/src/core/days.d.ts +24 -0
- package/lib/typescript/src/core/days.d.ts.map +1 -0
- package/lib/typescript/src/core/format.d.ts +23 -0
- package/lib/typescript/src/core/format.d.ts.map +1 -0
- package/lib/typescript/src/core/index.d.ts +5 -0
- package/lib/typescript/src/core/index.d.ts.map +1 -0
- package/lib/typescript/src/core/locale.d.ts +21 -0
- package/lib/typescript/src/core/locale.d.ts.map +1 -0
- package/lib/typescript/src/core/types.d.ts +7 -0
- package/lib/typescript/src/core/types.d.ts.map +1 -0
- package/lib/typescript/src/core/umalqura-data.d.ts +15 -0
- package/lib/typescript/src/core/umalqura-data.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +3 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +180 -4
- package/src/calendar/Chevron.tsx +55 -0
- package/src/calendar/DayCell.tsx +83 -0
- package/src/calendar/HilalCalendar.tsx +399 -0
- package/src/calendar/index.ts +8 -0
- package/src/calendar/month.ts +213 -0
- package/src/calendar/styles.ts +127 -0
- package/src/calendar/theme.ts +69 -0
- package/src/calendar/types.ts +61 -0
- package/src/core/convert.ts +192 -0
- package/src/core/days.ts +64 -0
- package/src/core/format.ts +65 -0
- package/src/core/index.ts +18 -0
- package/src/core/locale.ts +138 -0
- package/src/core/types.ts +6 -0
- package/src/core/umalqura-data.ts +34 -0
- 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,222 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
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
|
+
[](https://www.npmjs.com/package/react-native-hilal)
|
|
9
|
+
[](https://github.com/2ve2/hilal/actions/workflows/ci.yml)
|
|
10
|
+
[](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
|
+
- **Themeable**: light, dark, follow the system, or your own colors.
|
|
29
|
+
- **Accessible**: every day is a button with a full spoken date and its selected and disabled state.
|
|
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
|
+
## Quick start
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
import { useState } from 'react';
|
|
48
|
+
import { Text, View } from 'react-native';
|
|
49
|
+
import { HilalCalendar, type SelectedDate } from 'react-native-hilal';
|
|
50
|
+
|
|
51
|
+
export default function Screen() {
|
|
52
|
+
const [date, setDate] = useState<SelectedDate>();
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<View>
|
|
56
|
+
<HilalCalendar value={date?.gregorian} onChange={setDate} />
|
|
57
|
+
{date && (
|
|
58
|
+
<Text>
|
|
59
|
+
{date.formatted.hijri} · {date.formatted.gregorian}
|
|
60
|
+
</Text>
|
|
61
|
+
)}
|
|
62
|
+
</View>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`onChange` gives you both calendars at once. For 1 Ramadan 1446 with `locale="en"`:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
{
|
|
71
|
+
gregorian: Date, // Sat Mar 01 2025, local midnight
|
|
72
|
+
hijri: { year: 1446, month: 9, day: 1 },
|
|
73
|
+
formatted: { gregorian: '1 March 2025', hijri: '1 Ramadan 1446 AH' },
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
With the default `locale="ar"`, `formatted.hijri` is ١ رمضان ١٤٤٦ هـ and `formatted.gregorian` is ١ مارس ٢٠٢٥ in Arabic-Indic digits.
|
|
78
|
+
|
|
79
|
+
## Examples
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
// English, Latin digits, left-to-right
|
|
83
|
+
<HilalCalendar locale="en" />
|
|
84
|
+
|
|
85
|
+
// Gregorian grid, week starting on Saturday
|
|
86
|
+
<HilalCalendar calendar="gregorian" firstDayOfWeek={6} />
|
|
87
|
+
|
|
88
|
+
// Only the next 30 days, no Fridays
|
|
89
|
+
<HilalCalendar
|
|
90
|
+
minDate={today}
|
|
91
|
+
maxDate={in30Days}
|
|
92
|
+
isDateDisabled={({ gregorian }) => gregorian.getDay() === 5}
|
|
93
|
+
/>
|
|
94
|
+
|
|
95
|
+
// Dark theme, or your own colors on top of the light/dark default
|
|
96
|
+
<HilalCalendar theme="dark" />
|
|
97
|
+
<HilalCalendar theme={{ primary: '#B45309', radius: 24 }} />
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The [example app](example) shows every feature side by side. Run it with `yarn example start` and open it in Expo Go.
|
|
101
|
+
|
|
102
|
+
## `<HilalCalendar />` props
|
|
103
|
+
|
|
104
|
+
| Prop | Type | Default | Description |
|
|
105
|
+
| -------------------- | ---------------------------------------------------- | ----------------------------------- | ---------------------------------------------------------------------------------------- |
|
|
106
|
+
| `value` | `Date` | | Selected day (controlled). Only the local calendar day is used. |
|
|
107
|
+
| `defaultValue` | `Date` | | Initially selected day (uncontrolled). |
|
|
108
|
+
| `onChange` | `(date: SelectedDate) => void` | | Called when the user picks a day. |
|
|
109
|
+
| `calendar` | `'hijri' \| 'gregorian'` | `'hijri'` | Calendar of the month grid. The grid follows this prop when it changes. |
|
|
110
|
+
| `onCalendarChange` | `(calendar) => void` | | Called when the user switches calendars with the toggle. |
|
|
111
|
+
| `showCalendarToggle` | `boolean` | `true` | Show the Hijri / Gregorian toggle. |
|
|
112
|
+
| `showSecondaryDate` | `boolean` | `true` | Show the other calendar's day under each day. |
|
|
113
|
+
| `locale` | `'ar' \| 'en'` | `'ar'` | Language of month names, weekdays and labels. |
|
|
114
|
+
| `digits` | `'arabic' \| 'latin'` | `'arabic'` for `ar`, else `'latin'` | Arabic-Indic (١٢٣) or Latin (123) digits. |
|
|
115
|
+
| `direction` | `'rtl' \| 'ltr' \| 'auto'` | `'auto'` | `auto` is right-to-left when the app is RTL (`I18nManager.isRTL`) or the locale is `ar`. |
|
|
116
|
+
| `firstDayOfWeek` | `0 \| 1 \| 6` | `0` | `0` Sunday, `1` Monday, `6` Saturday. |
|
|
117
|
+
| `minDate` | `Date` | | Earliest selectable day. Navigation stops at its month. |
|
|
118
|
+
| `maxDate` | `Date` | | Latest selectable day. Navigation stops at its month. |
|
|
119
|
+
| `isDateDisabled` | `(date: SelectedDate) => boolean` | | Return `true` to disable a day. |
|
|
120
|
+
| `theme` | `'light' \| 'dark' \| 'auto' \| Partial<HilalTheme>` | `'auto'` | `auto` follows `useColorScheme()`. A partial theme is merged over the `auto` theme. |
|
|
121
|
+
| `style` | `StyleProp<ViewStyle>` | | Style of the outer container. |
|
|
122
|
+
| `dayStyle` | `StyleProp<ViewStyle>` | | Style of every day cell. |
|
|
123
|
+
|
|
124
|
+
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
|
+
|
|
126
|
+
### Theme
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
type HilalTheme = {
|
|
130
|
+
background: string; // calendar background
|
|
131
|
+
text: string; // day numbers, month title, arrows
|
|
132
|
+
textSecondary: string; // secondary dates, weekday names
|
|
133
|
+
primary: string; // selected day, active toggle
|
|
134
|
+
onPrimary: string; // text on primary
|
|
135
|
+
today: string; // ring around today
|
|
136
|
+
disabled: string; // disabled days and arrows
|
|
137
|
+
border: string; // toggle outline
|
|
138
|
+
radius: number; // corner radius of a day cell
|
|
139
|
+
};
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
`lightTheme` and `darkTheme` are exported if you want to build a full theme from one of them.
|
|
143
|
+
|
|
144
|
+
## Core API
|
|
145
|
+
|
|
146
|
+
The conversion engine is exported on its own: pure functions, no React.
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
import {
|
|
150
|
+
toHijri,
|
|
151
|
+
toGregorian,
|
|
152
|
+
formatHijri,
|
|
153
|
+
getHijriMonthLength,
|
|
154
|
+
} from 'react-native-hilal';
|
|
155
|
+
|
|
156
|
+
toHijri(new Date(2024, 6, 7)); // { year: 1446, month: 1, day: 1 }
|
|
157
|
+
toGregorian({ year: 1445, month: 9, day: 1 }); // Mon Mar 11 2024, local midnight
|
|
158
|
+
formatHijri({ year: 1446, month: 9, day: 1 }, { locale: 'en' }); // '1 Ramadan 1446 AH'
|
|
159
|
+
getHijriMonthLength(1446, 9); // 29
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Without options, `formatHijri` returns ١ رمضان ١٤٤٦ هـ (Arabic, Arabic-Indic digits).
|
|
163
|
+
|
|
164
|
+
| Function | Description |
|
|
165
|
+
| --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
|
|
166
|
+
| `toHijri(date: Date): HijriDate` | Hijri date of the local calendar day of `date`. The time of day is ignored. |
|
|
167
|
+
| `toGregorian(hijri: HijriDate): Date` | A `Date` at local midnight of the matching Gregorian day. |
|
|
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 (يناير، فبراير، مارس), not the Levantine one. |
|
|
173
|
+
| `getWeekdayNames(locale, format?): string[]` | 7 weekday names, Sunday first (matches `Date#getDay()`), `'long'` or `'short'`. |
|
|
174
|
+
| `toArabicDigits(input: string \| number): string` | `'1446'` → `'١٤٤٦'`. |
|
|
175
|
+
|
|
176
|
+
`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
|
+
|
|
178
|
+
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
|
+
|
|
180
|
+
## Why Hilal?
|
|
181
|
+
|
|
182
|
+
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.
|
|
183
|
+
|
|
184
|
+
| | Hilal |
|
|
185
|
+
| -------------------------------------- | -------------------------------------------------------------- |
|
|
186
|
+
| iOS, Android and web from one codebase | ✅ pure TypeScript, React Native core components only |
|
|
187
|
+
| Runs in Expo Go | ✅ no native modules |
|
|
188
|
+
| Runtime dependencies | ✅ none |
|
|
189
|
+
| Hijri calendar | ✅ Umm al-Qura, checked against ICU for every day of 1937–2077 |
|
|
190
|
+
| UI included | ✅ month grid, both calendars, themes, RTL, accessibility |
|
|
191
|
+
| Use the engine without the UI | ✅ `toHijri`, `toGregorian`, `formatHijri`, ... |
|
|
192
|
+
|
|
193
|
+
## Accuracy
|
|
194
|
+
|
|
195
|
+
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.
|
|
196
|
+
|
|
197
|
+
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
|
+
|
|
199
|
+
### How the Umm al-Qura table is made and verified
|
|
200
|
+
|
|
201
|
+
- **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
|
+
- **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
|
+
- **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`. The suite runs in a UTC+14 time zone, so any code that takes the day from a UTC timestamp fails.
|
|
205
|
+
|
|
206
|
+
## Roadmap
|
|
207
|
+
|
|
208
|
+
Ideas for v2:
|
|
209
|
+
|
|
210
|
+
- Range selection
|
|
211
|
+
- Quick year and month picker
|
|
212
|
+
- Event dots on days
|
|
213
|
+
- Swipe between months
|
|
214
|
+
- Ready-made bottom sheet and modal variants
|
|
215
|
+
|
|
216
|
+
## Contributing
|
|
217
|
+
|
|
218
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for the development workflow, commit conventions and how to send a pull request.
|
|
219
|
+
|
|
220
|
+
## License
|
|
221
|
+
|
|
222
|
+
[MIT](LICENSE) © 2ve2
|
|
@@ -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,48 @@
|
|
|
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
|
+
onSelect
|
|
22
|
+
}) {
|
|
23
|
+
return /*#__PURE__*/_jsx(View, {
|
|
24
|
+
style: styles.slot,
|
|
25
|
+
children: /*#__PURE__*/_jsxs(Pressable, {
|
|
26
|
+
accessibilityRole: "button",
|
|
27
|
+
accessibilityLabel: accessibilityLabel,
|
|
28
|
+
accessibilityState: {
|
|
29
|
+
selected,
|
|
30
|
+
disabled
|
|
31
|
+
},
|
|
32
|
+
disabled: disabled,
|
|
33
|
+
onPress: () => onSelect(epochDay),
|
|
34
|
+
style: ({
|
|
35
|
+
pressed
|
|
36
|
+
}) => [styles.day, today && styles.today, selected && styles.selected, pressed && !selected && styles.pressed, dayStyle],
|
|
37
|
+
children: [/*#__PURE__*/_jsx(Text, {
|
|
38
|
+
style: [styles.dayText, disabled && styles.disabledText, selected && styles.selectedText],
|
|
39
|
+
children: label
|
|
40
|
+
}), secondaryLabel !== null && /*#__PURE__*/_jsx(Text, {
|
|
41
|
+
style: [styles.secondaryText, disabled && styles.disabledText, selected && styles.selectedSecondaryText],
|
|
42
|
+
children: secondaryLabel
|
|
43
|
+
})]
|
|
44
|
+
})
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export const DayCell = /*#__PURE__*/memo(DayCellView);
|
|
48
|
+
//# 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","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;AAiBtB;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;AACY,CAAC,EAAE;EACf,oBACEb,IAAA,CAACF,IAAI;IAACgB,KAAK,EAAEH,MAAM,CAACI,IAAK;IAAAC,QAAA,eACvBd,KAAA,CAACN,SAAS;MACRqB,iBAAiB,EAAC,QAAQ;MAC1BV,kBAAkB,EAAEA,kBAAmB;MACvCW,kBAAkB,EAAE;QAAEV,QAAQ;QAAEE;MAAS,CAAE;MAC3CA,QAAQ,EAAEA,QAAS;MACnBS,OAAO,EAAEA,CAAA,KAAMN,QAAQ,CAACT,QAAQ,CAAE;MAClCU,KAAK,EAAEA,CAAC;QAAEM;MAAQ,CAAC,KAAK,CACtBT,MAAM,CAACU,GAAG,EACVZ,KAAK,IAAIE,MAAM,CAACF,KAAK,EACrBD,QAAQ,IAAIG,MAAM,CAACH,QAAQ,EAC3BY,OAAO,IAAI,CAACZ,QAAQ,IAAIG,MAAM,CAACS,OAAO,EACtCR,QAAQ,CACR;MAAAI,QAAA,gBAEFhB,IAAA,CAACH,IAAI;QACHiB,KAAK,EAAE,CACLH,MAAM,CAACW,OAAO,EACdZ,QAAQ,IAAIC,MAAM,CAACY,YAAY,EAC/Bf,QAAQ,IAAIG,MAAM,CAACa,YAAY,CAC/B;QAAAR,QAAA,EAEDX;MAAK,CACF,CAAC,EACNC,cAAc,KAAK,IAAI,iBACtBN,IAAA,CAACH,IAAI;QACHiB,KAAK,EAAE,CACLH,MAAM,CAACc,aAAa,EACpBf,QAAQ,IAAIC,MAAM,CAACY,YAAY,EAC/Bf,QAAQ,IAAIG,MAAM,CAACe,qBAAqB,CACxC;QAAAV,QAAA,EAEDV;MAAc,CACX,CACP;IAAA,CACQ;EAAC,CACR,CAAC;AAEX;AAEA,OAAO,MAAMqB,OAAO,gBAAGhC,IAAI,CAACQ,WAAW,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { I18nManager, Pressable, Text, useColorScheme, View } from 'react-native';
|
|
5
|
+
import { hijriOfEpochDay } from "../core/convert.js";
|
|
6
|
+
import { civilFromDays, epochDayOfLocalDate, localDateOfEpochDay, weekdayOfEpochDay } from "../core/days.js";
|
|
7
|
+
import { formatGregorian, formatHijri } from "../core/format.js";
|
|
8
|
+
import { defaultDigits, formatNumber, getWeekdayNames } from "../core/locale.js";
|
|
9
|
+
import { Chevron } from "./Chevron.js";
|
|
10
|
+
import { DayCell } from "./DayCell.js";
|
|
11
|
+
import { addMonths, buildMonthGrid, clampDay, monthContaining, monthOverlaps, monthStart, monthTitle, secondaryTitle, selectableRange } from "./month.js";
|
|
12
|
+
import { createStyles } from "./styles.js";
|
|
13
|
+
import { resolveTheme } from "./theme.js";
|
|
14
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
|
+
const LABELS = {
|
|
16
|
+
ar: {
|
|
17
|
+
hijri: 'هجري',
|
|
18
|
+
gregorian: 'ميلادي',
|
|
19
|
+
previous: 'الشهر السابق',
|
|
20
|
+
next: 'الشهر التالي',
|
|
21
|
+
separator: '، '
|
|
22
|
+
},
|
|
23
|
+
en: {
|
|
24
|
+
hijri: 'Hijri',
|
|
25
|
+
gregorian: 'Gregorian',
|
|
26
|
+
previous: 'Previous month',
|
|
27
|
+
next: 'Next month',
|
|
28
|
+
separator: ', '
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
function epochDayOf(date) {
|
|
32
|
+
return date instanceof Date && !Number.isNaN(date.getTime()) ? epochDayOfLocalDate(date) : undefined;
|
|
33
|
+
}
|
|
34
|
+
function selectedDateOf(epochDay, locale, digits) {
|
|
35
|
+
const hijri = hijriOfEpochDay(epochDay);
|
|
36
|
+
return {
|
|
37
|
+
gregorian: localDateOfEpochDay(epochDay),
|
|
38
|
+
hijri,
|
|
39
|
+
formatted: {
|
|
40
|
+
gregorian: formatGregorian(civilFromDays(epochDay), {
|
|
41
|
+
locale,
|
|
42
|
+
digits
|
|
43
|
+
}),
|
|
44
|
+
hijri: formatHijri(hijri, {
|
|
45
|
+
locale,
|
|
46
|
+
digits
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** A function with a stable identity that always calls the latest `fn`. */
|
|
53
|
+
function useStableCallback(fn) {
|
|
54
|
+
const ref = useRef(fn);
|
|
55
|
+
useLayoutEffect(() => {
|
|
56
|
+
ref.current = fn;
|
|
57
|
+
});
|
|
58
|
+
return useCallback((...args) => ref.current(...args), []);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The month to show: `preferred` if it can be shown, else a sensible one. */
|
|
62
|
+
function visibleMonth(preferred, calendar, range, fallbackDay) {
|
|
63
|
+
return preferred.calendar === calendar && monthOverlaps(preferred, range) ? preferred : monthContaining(clampDay(fallbackDay, range), calendar);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A month-grid date picker for the Umm al-Qura Hijri and the Gregorian
|
|
68
|
+
* calendar.
|
|
69
|
+
*/
|
|
70
|
+
export function HilalCalendar({
|
|
71
|
+
value,
|
|
72
|
+
defaultValue,
|
|
73
|
+
onChange,
|
|
74
|
+
calendar: calendarProp = 'hijri',
|
|
75
|
+
onCalendarChange,
|
|
76
|
+
showCalendarToggle = true,
|
|
77
|
+
showSecondaryDate = true,
|
|
78
|
+
locale = 'ar',
|
|
79
|
+
digits: digitsProp,
|
|
80
|
+
direction = 'auto',
|
|
81
|
+
firstDayOfWeek = 0,
|
|
82
|
+
minDate,
|
|
83
|
+
maxDate,
|
|
84
|
+
isDateDisabled,
|
|
85
|
+
theme: themeProp = 'auto',
|
|
86
|
+
style,
|
|
87
|
+
dayStyle
|
|
88
|
+
}) {
|
|
89
|
+
const digits = digitsProp ?? defaultDigits(locale);
|
|
90
|
+
const labels = LABELS[locale];
|
|
91
|
+
// React Native Web leaves I18nManager.isRTL undefined, not false.
|
|
92
|
+
const appRTL = I18nManager.isRTL === true;
|
|
93
|
+
const rtl = direction === 'rtl' || direction === 'auto' && (appRTL || locale === 'ar');
|
|
94
|
+
// React Native already mirrors 'row' when the whole app is RTL.
|
|
95
|
+
const row = rtl === appRTL ? 'row' : 'row-reverse';
|
|
96
|
+
const colorScheme = useColorScheme();
|
|
97
|
+
const themeKey = typeof themeProp === 'string' ? themeProp : JSON.stringify(themeProp);
|
|
98
|
+
const theme = useMemo(() => resolveTheme(themeProp, colorScheme),
|
|
99
|
+
// A partial theme is usually an inline object; compare it by value.
|
|
100
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
101
|
+
[themeKey, colorScheme]);
|
|
102
|
+
const styles = useMemo(() => createStyles(theme), [theme]);
|
|
103
|
+
// Same for an inline dayStyle: a new object every render would re-render
|
|
104
|
+
// every day cell.
|
|
105
|
+
const dayStyleKey = JSON.stringify(dayStyle);
|
|
106
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
107
|
+
const stableDayStyle = useMemo(() => dayStyle, [dayStyleKey]);
|
|
108
|
+
const minDay = epochDayOf(minDate);
|
|
109
|
+
const maxDay = epochDayOf(maxDate);
|
|
110
|
+
const range = useMemo(() => selectableRange(minDay, maxDay), [minDay, maxDay]);
|
|
111
|
+
const today = epochDayOfLocalDate(new Date());
|
|
112
|
+
|
|
113
|
+
// Selection: controlled through `value`, otherwise internal state.
|
|
114
|
+
const [internalDay, setInternalDay] = useState(() => epochDayOf(defaultValue));
|
|
115
|
+
const selectedDay = value !== undefined ? epochDayOf(value) : internalDay;
|
|
116
|
+
|
|
117
|
+
// Calendar: internal state that follows the prop when the prop changes.
|
|
118
|
+
const [calendar, setCalendar] = useState(calendarProp);
|
|
119
|
+
const [lastCalendarProp, setLastCalendarProp] = useState(calendarProp);
|
|
120
|
+
const [month, setMonth] = useState(() => monthContaining(clampDay(selectedDay ?? today, range), calendarProp));
|
|
121
|
+
const [lastSelectedDay, setLastSelectedDay] = useState(selectedDay);
|
|
122
|
+
const switchTo = (next, current) => {
|
|
123
|
+
setCalendar(next);
|
|
124
|
+
// Keep the selected day in view, or else the month being looked at.
|
|
125
|
+
const anchor = selectedDay ?? clampDay(monthStart(current), range);
|
|
126
|
+
setMonth(monthContaining(clampDay(anchor, range), next));
|
|
127
|
+
};
|
|
128
|
+
const shown = visibleMonth(month, calendar, range, selectedDay ?? today);
|
|
129
|
+
|
|
130
|
+
// Adjust state while rendering when props change (React's recommended
|
|
131
|
+
// alternative to effects for derived state).
|
|
132
|
+
if (calendarProp !== lastCalendarProp) {
|
|
133
|
+
setLastCalendarProp(calendarProp);
|
|
134
|
+
switchTo(calendarProp, shown);
|
|
135
|
+
}
|
|
136
|
+
if (selectedDay !== lastSelectedDay) {
|
|
137
|
+
setLastSelectedDay(selectedDay);
|
|
138
|
+
if (selectedDay !== undefined && selectedDay >= range.min && selectedDay <= range.max) {
|
|
139
|
+
const containing = monthContaining(selectedDay, calendar);
|
|
140
|
+
if (containing.year !== shown.year || containing.month !== shown.month) {
|
|
141
|
+
setMonth(containing);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const grid = useMemo(() => buildMonthGrid(shown, firstDayOfWeek),
|
|
146
|
+
// `shown` is a new object on every render; its fields identify it.
|
|
147
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
148
|
+
[shown.calendar, shown.year, shown.month, firstDayOfWeek]);
|
|
149
|
+
|
|
150
|
+
// Everything about a day except `selected` and `today`, so that changing
|
|
151
|
+
// the selection doesn't recompute labels or call isDateDisabled.
|
|
152
|
+
const cells = useMemo(() => grid.map(week => week.map(cell => {
|
|
153
|
+
if (cell === null) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
const {
|
|
157
|
+
epochDay,
|
|
158
|
+
day,
|
|
159
|
+
secondaryDay
|
|
160
|
+
} = cell;
|
|
161
|
+
const inSupportedRange = secondaryDay !== null;
|
|
162
|
+
const disabled = !inSupportedRange || epochDay < range.min || epochDay > range.max || (isDateDisabled?.(selectedDateOf(epochDay, locale, digits)) ?? false);
|
|
163
|
+
const weekday = getWeekdayNames(locale)[weekdayOfEpochDay(epochDay)];
|
|
164
|
+
const gregorianText = formatGregorian(civilFromDays(epochDay), {
|
|
165
|
+
locale,
|
|
166
|
+
digits
|
|
167
|
+
});
|
|
168
|
+
const spoken = inSupportedRange ? [formatHijri(hijriOfEpochDay(epochDay), {
|
|
169
|
+
locale,
|
|
170
|
+
digits
|
|
171
|
+
}), gregorianText] : [gregorianText];
|
|
172
|
+
if (shown.calendar === 'gregorian') {
|
|
173
|
+
spoken.reverse();
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
epochDay,
|
|
177
|
+
label: formatNumber(day, digits),
|
|
178
|
+
secondaryLabel: showSecondaryDate && secondaryDay !== null ? formatNumber(secondaryDay, digits) : null,
|
|
179
|
+
accessibilityLabel: [weekday, ...spoken].join(labels.separator),
|
|
180
|
+
disabled
|
|
181
|
+
};
|
|
182
|
+
})), [grid, shown.calendar, range, isDateDisabled, locale, digits, showSecondaryDate, labels]);
|
|
183
|
+
const onSelect = useStableCallback(epochDay => {
|
|
184
|
+
if (value === undefined) {
|
|
185
|
+
setInternalDay(epochDay);
|
|
186
|
+
}
|
|
187
|
+
onChange?.(selectedDateOf(epochDay, locale, digits));
|
|
188
|
+
});
|
|
189
|
+
const toggleCalendar = next => {
|
|
190
|
+
if (next === calendar) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
switchTo(next, shown);
|
|
194
|
+
onCalendarChange?.(next);
|
|
195
|
+
};
|
|
196
|
+
const previous = addMonths(shown, -1);
|
|
197
|
+
const next = addMonths(shown, 1);
|
|
198
|
+
const canGoBack = monthOverlaps(previous, range);
|
|
199
|
+
const canGoForward = monthOverlaps(next, range);
|
|
200
|
+
const weekdayNames = getWeekdayNames(locale, 'short');
|
|
201
|
+
const weekdays = Array.from({
|
|
202
|
+
length: 7
|
|
203
|
+
}, (_, i) => weekdayNames[(firstDayOfWeek + i) % 7]);
|
|
204
|
+
const renderArrow = kind => {
|
|
205
|
+
const enabled = kind === 'previous' ? canGoBack : canGoForward;
|
|
206
|
+
// Arrows point the way the months move: outward in reading order.
|
|
207
|
+
const pointsLeft = kind === 'previous' !== rtl;
|
|
208
|
+
return /*#__PURE__*/_jsx(Pressable, {
|
|
209
|
+
accessibilityRole: "button",
|
|
210
|
+
accessibilityLabel: labels[kind],
|
|
211
|
+
accessibilityState: {
|
|
212
|
+
disabled: !enabled
|
|
213
|
+
},
|
|
214
|
+
disabled: !enabled,
|
|
215
|
+
hitSlop: 8,
|
|
216
|
+
onPress: () => setMonth(kind === 'previous' ? previous : next),
|
|
217
|
+
style: ({
|
|
218
|
+
pressed
|
|
219
|
+
}) => [styles.arrow, pressed && styles.arrowPressed],
|
|
220
|
+
children: /*#__PURE__*/_jsx(Chevron, {
|
|
221
|
+
direction: pointsLeft ? 'left' : 'right',
|
|
222
|
+
color: enabled ? theme.text : theme.disabled
|
|
223
|
+
})
|
|
224
|
+
});
|
|
225
|
+
};
|
|
226
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
227
|
+
style: [styles.container, style],
|
|
228
|
+
children: [showCalendarToggle && /*#__PURE__*/_jsx(View, {
|
|
229
|
+
style: [styles.toggle, {
|
|
230
|
+
flexDirection: row
|
|
231
|
+
}],
|
|
232
|
+
children: ['hijri', 'gregorian'].map(option => {
|
|
233
|
+
const active = option === calendar;
|
|
234
|
+
return /*#__PURE__*/_jsx(Pressable, {
|
|
235
|
+
accessibilityRole: "button",
|
|
236
|
+
accessibilityState: {
|
|
237
|
+
selected: active
|
|
238
|
+
},
|
|
239
|
+
onPress: () => toggleCalendar(option),
|
|
240
|
+
style: [styles.toggleOption, active && styles.toggleOptionActive],
|
|
241
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
242
|
+
style: [styles.toggleText, active && styles.toggleTextActive],
|
|
243
|
+
children: labels[option]
|
|
244
|
+
})
|
|
245
|
+
}, option);
|
|
246
|
+
})
|
|
247
|
+
}), /*#__PURE__*/_jsxs(View, {
|
|
248
|
+
testID: "hilal-header",
|
|
249
|
+
style: [styles.header, {
|
|
250
|
+
flexDirection: row
|
|
251
|
+
}],
|
|
252
|
+
children: [renderArrow('previous'), /*#__PURE__*/_jsxs(View, {
|
|
253
|
+
style: styles.titles,
|
|
254
|
+
children: [/*#__PURE__*/_jsx(Text, {
|
|
255
|
+
accessibilityRole: "header",
|
|
256
|
+
style: styles.title,
|
|
257
|
+
children: monthTitle(shown, locale, digits)
|
|
258
|
+
}), /*#__PURE__*/_jsx(Text, {
|
|
259
|
+
style: styles.subtitle,
|
|
260
|
+
children: secondaryTitle(shown, locale, digits)
|
|
261
|
+
})]
|
|
262
|
+
}), renderArrow('next')]
|
|
263
|
+
}), /*#__PURE__*/_jsx(View, {
|
|
264
|
+
style: [styles.weekdays, {
|
|
265
|
+
flexDirection: row
|
|
266
|
+
}],
|
|
267
|
+
children: weekdays.map(name => /*#__PURE__*/_jsx(Text, {
|
|
268
|
+
style: styles.weekday,
|
|
269
|
+
children: name
|
|
270
|
+
}, name))
|
|
271
|
+
}), cells.map((week, w) => /*#__PURE__*/_jsx(View, {
|
|
272
|
+
style: [styles.week, {
|
|
273
|
+
flexDirection: row
|
|
274
|
+
}],
|
|
275
|
+
children: week.map((cell, d) => cell === null ? /*#__PURE__*/_jsx(View, {
|
|
276
|
+
style: styles.slot
|
|
277
|
+
}, `empty-${d}`) : /*#__PURE__*/_jsx(DayCell, {
|
|
278
|
+
...cell,
|
|
279
|
+
selected: cell.epochDay === selectedDay,
|
|
280
|
+
today: cell.epochDay === today,
|
|
281
|
+
styles: styles,
|
|
282
|
+
dayStyle: stableDayStyle,
|
|
283
|
+
onSelect: onSelect
|
|
284
|
+
}, cell.epochDay))
|
|
285
|
+
}, w))]
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
//# sourceMappingURL=HilalCalendar.js.map
|