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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { StyleProp, ViewStyle } from 'react-native';
|
|
1
|
+
import type { StyleProp, TextStyle, ViewStyle } from 'react-native';
|
|
2
2
|
import type { CalendarType, Digits, Locale } from '../core/locale.js';
|
|
3
3
|
import type { HijriDate } from '../core/types.js';
|
|
4
4
|
import type { ThemeProp } from './theme.js';
|
|
@@ -13,6 +13,96 @@ export type SelectedDate = {
|
|
|
13
13
|
hijri: string;
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
|
+
/** A range of days picked in the calendar (`selectionMode="range"`). */
|
|
17
|
+
export type SelectedRange = {
|
|
18
|
+
start: SelectedDate;
|
|
19
|
+
/** Null while only the start is picked. */
|
|
20
|
+
end: SelectedDate | null;
|
|
21
|
+
/** Days in the range, both ends included, or null while `end` is null. */
|
|
22
|
+
days: number | null;
|
|
23
|
+
};
|
|
24
|
+
/** A range to show as picked. Leave `end` out while only the start is picked. */
|
|
25
|
+
export type DateRange = {
|
|
26
|
+
start: Date;
|
|
27
|
+
end?: Date | null;
|
|
28
|
+
};
|
|
29
|
+
type ViewSlot = StyleProp<ViewStyle>;
|
|
30
|
+
type TextSlot = StyleProp<TextStyle>;
|
|
31
|
+
/**
|
|
32
|
+
* Styles for parts of the calendar, merged over the theme's styles. Each
|
|
33
|
+
* is optional.
|
|
34
|
+
*/
|
|
35
|
+
export type HilalStyles = {
|
|
36
|
+
/** The outer container (the same as the `style` prop). */
|
|
37
|
+
container?: ViewSlot;
|
|
38
|
+
/** The Hijri / Gregorian toggle. */
|
|
39
|
+
toggle?: ViewSlot;
|
|
40
|
+
/** Each option of the toggle. */
|
|
41
|
+
toggleOption?: ViewSlot;
|
|
42
|
+
toggleText?: TextSlot;
|
|
43
|
+
/** The row of arrows and titles. */
|
|
44
|
+
header?: ViewSlot;
|
|
45
|
+
/** The month title. */
|
|
46
|
+
title?: TextSlot;
|
|
47
|
+
/** The other calendar's months under the title. */
|
|
48
|
+
subtitle?: TextSlot;
|
|
49
|
+
/** Each arrow button. */
|
|
50
|
+
arrow?: ViewSlot;
|
|
51
|
+
/** Each weekday name. */
|
|
52
|
+
weekdayText?: TextSlot;
|
|
53
|
+
/** Each day cell (the pressable circle). */
|
|
54
|
+
day?: ViewSlot;
|
|
55
|
+
/** The day number. */
|
|
56
|
+
dayText?: TextSlot;
|
|
57
|
+
/** The other calendar's day under the day number. */
|
|
58
|
+
secondaryDayText?: TextSlot;
|
|
59
|
+
/** The selected day cell. */
|
|
60
|
+
selectedDay?: ViewSlot;
|
|
61
|
+
/** The selected day's number. */
|
|
62
|
+
selectedDayText?: TextSlot;
|
|
63
|
+
/** Today's day cell. */
|
|
64
|
+
today?: ViewSlot;
|
|
65
|
+
/** Today's day number, bold by default. */
|
|
66
|
+
todayDayText?: TextSlot;
|
|
67
|
+
/** Both texts of a disabled day. */
|
|
68
|
+
disabledDayText?: TextSlot;
|
|
69
|
+
/** The band behind the days of a picked range. */
|
|
70
|
+
rangeBand?: ViewSlot;
|
|
71
|
+
/** Each month or year in the month and year picker. */
|
|
72
|
+
pickerItem?: ViewSlot;
|
|
73
|
+
pickerText?: TextSlot;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Texts of the calendar's buttons, read by screen readers too. Each is
|
|
77
|
+
* optional; the rest come from the locale.
|
|
78
|
+
*/
|
|
79
|
+
export type HilalLabels = {
|
|
80
|
+
/** The toggle's Hijri option. */
|
|
81
|
+
hijri?: string;
|
|
82
|
+
/** The toggle's Gregorian option. */
|
|
83
|
+
gregorian?: string;
|
|
84
|
+
/** Read by screen readers after today's date. */
|
|
85
|
+
today?: string;
|
|
86
|
+
/** Read after the first day of a picked range. */
|
|
87
|
+
rangeStart?: string;
|
|
88
|
+
/** Read after the last day of a picked range. */
|
|
89
|
+
rangeEnd?: string;
|
|
90
|
+
/** Read after the current month in the month picker. */
|
|
91
|
+
thisMonth?: string;
|
|
92
|
+
/** Read after the current year in the year picker. */
|
|
93
|
+
thisYear?: string;
|
|
94
|
+
/** Arrows, read by screen readers. */
|
|
95
|
+
previousMonth?: string;
|
|
96
|
+
nextMonth?: string;
|
|
97
|
+
previousYear?: string;
|
|
98
|
+
nextYear?: string;
|
|
99
|
+
previousYears?: string;
|
|
100
|
+
nextYears?: string;
|
|
101
|
+
/** The month title button, read by screen readers before the title. */
|
|
102
|
+
chooseMonth?: string;
|
|
103
|
+
/** The year title button in the month picker. */
|
|
104
|
+
chooseYear?: string;
|
|
105
|
+
};
|
|
16
106
|
export type HilalCalendarProps = {
|
|
17
107
|
/** Selected day (controlled). Only the local calendar day is used. */
|
|
18
108
|
value?: Date;
|
|
@@ -20,6 +110,34 @@ export type HilalCalendarProps = {
|
|
|
20
110
|
defaultValue?: Date;
|
|
21
111
|
/** Called when the user picks a day. */
|
|
22
112
|
onChange?: (date: SelectedDate) => void;
|
|
113
|
+
/**
|
|
114
|
+
* 'single' (default) picks one day. 'range' picks a start and an end:
|
|
115
|
+
* the first press picks the start, the second the end, and a third
|
|
116
|
+
* starts over. A range never crosses a disabled day. In range mode,
|
|
117
|
+
* `value`, `defaultValue` and `onChange` are not used.
|
|
118
|
+
*/
|
|
119
|
+
selectionMode?: 'single' | 'range';
|
|
120
|
+
/**
|
|
121
|
+
* Picked range (controlled), with `selectionMode="range"`. `null` shows
|
|
122
|
+
* no range.
|
|
123
|
+
*/
|
|
124
|
+
rangeValue?: DateRange | null;
|
|
125
|
+
/** Initially picked range (uncontrolled), with `selectionMode="range"`. */
|
|
126
|
+
defaultRangeValue?: DateRange;
|
|
127
|
+
/** Called when the user changes the range, after each press. */
|
|
128
|
+
onRangeChange?: (range: SelectedRange) => void;
|
|
129
|
+
/**
|
|
130
|
+
* Fewest days a range may have, both ends included (so 3 nights are 4
|
|
131
|
+
* days). After the start is picked, days that would make the range
|
|
132
|
+
* shorter can't be pressed. Default 1.
|
|
133
|
+
*/
|
|
134
|
+
minRangeDays?: number;
|
|
135
|
+
/**
|
|
136
|
+
* Most days a range may have, both ends included. After the start is
|
|
137
|
+
* picked, days that would make the range longer can't be pressed.
|
|
138
|
+
* Default: no limit.
|
|
139
|
+
*/
|
|
140
|
+
maxRangeDays?: number;
|
|
23
141
|
/** Calendar of the month grid. Default 'hijri'. */
|
|
24
142
|
calendar?: CalendarType;
|
|
25
143
|
/** Called when the user switches calendars with the toggle. */
|
|
@@ -39,20 +157,53 @@ export type HilalCalendarProps = {
|
|
|
39
157
|
direction?: 'rtl' | 'ltr' | 'auto';
|
|
40
158
|
/** 0 = Sunday (default), 1 = Monday, 6 = Saturday. */
|
|
41
159
|
firstDayOfWeek?: 0 | 1 | 6;
|
|
160
|
+
/**
|
|
161
|
+
* Weekday names above the days: 'short' (default, أحد / Sun) or
|
|
162
|
+
* 'narrow' (ح / S). Full names don't fit seven columns on a phone.
|
|
163
|
+
*/
|
|
164
|
+
weekdayFormat?: 'short' | 'narrow';
|
|
42
165
|
/** Earliest selectable day. */
|
|
43
166
|
minDate?: Date;
|
|
44
167
|
/** Latest selectable day. */
|
|
45
168
|
maxDate?: Date;
|
|
46
169
|
/** Return true to disable a day. */
|
|
47
170
|
isDateDisabled?: (date: SelectedDate) => boolean;
|
|
171
|
+
/**
|
|
172
|
+
* Shift the Hijri calendar by whole days, from -2 to 2, for places where
|
|
173
|
+
* the month started before or after Umm al-Qura. `1` makes every Hijri
|
|
174
|
+
* date one day later. Gregorian dates never change. Default 0.
|
|
175
|
+
*/
|
|
176
|
+
hijriAdjustment?: number;
|
|
177
|
+
/**
|
|
178
|
+
* Pressing the month title opens a grid of months, and from there a
|
|
179
|
+
* grid of years, to jump far without paging month by month. Default
|
|
180
|
+
* true.
|
|
181
|
+
*/
|
|
182
|
+
showMonthYearPicker?: boolean;
|
|
48
183
|
/**
|
|
49
184
|
* 'light', 'dark', 'auto' (default, follows the system color scheme),
|
|
50
185
|
* or a partial theme merged over the 'auto' theme.
|
|
51
186
|
*/
|
|
52
187
|
theme?: ThemeProp;
|
|
188
|
+
/** Texts of the toggle and buttons, see `HilalLabels`. */
|
|
189
|
+
labels?: HilalLabels;
|
|
190
|
+
/** Styles for parts of the calendar, see `HilalStyles`. */
|
|
191
|
+
styles?: HilalStyles;
|
|
53
192
|
/** Style of the outer container. */
|
|
54
193
|
style?: StyleProp<ViewStyle>;
|
|
55
|
-
/**
|
|
194
|
+
/**
|
|
195
|
+
* Style of every day cell (the pressable circle). Unlike `styles.day`,
|
|
196
|
+
* it also wins over the selected and today styles.
|
|
197
|
+
*/
|
|
56
198
|
dayStyle?: StyleProp<ViewStyle>;
|
|
199
|
+
/**
|
|
200
|
+
* How far the phone's text size setting may grow the calendar's text,
|
|
201
|
+
* like React Native's prop of the same name: `1` turns it off, `0`
|
|
202
|
+
* removes the limit. By default, text in day cells, weekday names and
|
|
203
|
+
* picker buttons grows up to 1.3 times (as far as it fits a cell), and
|
|
204
|
+
* the header and toggle up to 2 times.
|
|
205
|
+
*/
|
|
206
|
+
maxFontSizeMultiplier?: number;
|
|
57
207
|
};
|
|
208
|
+
export {};
|
|
58
209
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/calendar/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/calendar/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,mBAAgB,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAS,CAAC;AAEzC,uDAAuD;AACvD,MAAM,MAAM,YAAY,GAAG;IACzB,iCAAiC;IACjC,SAAS,EAAE,IAAI,CAAC;IAChB,KAAK,EAAE,SAAS,CAAC;IACjB,8DAA8D;IAC9D,SAAS,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CACjD,CAAC;AAEF,wEAAwE;AACxE,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,YAAY,CAAC;IACpB,2CAA2C;IAC3C,GAAG,EAAE,YAAY,GAAG,IAAI,CAAC;IACzB,0EAA0E;IAC1E,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB,CAAC;AAEF,iFAAiF;AACjF,MAAM,MAAM,SAAS,GAAG;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,GAAG,CAAC,EAAE,IA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AMG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC,CAAC"}
|
|
@@ -1,7 +1,33 @@
|
|
|
1
1
|
import type { HijriDate } from './types.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* First and last epoch day of the Umm al-Qura table (both inclusive). With
|
|
4
|
+
* a Hijri adjustment of `n` days, the supported Gregorian days move by
|
|
5
|
+
* `-n`: see `supportedEpochDays`.
|
|
6
|
+
*/
|
|
3
7
|
export declare const FIRST_DAY: number;
|
|
4
8
|
export declare const LAST_DAY: number;
|
|
9
|
+
/** The largest Hijri adjustment accepted, in days, in either direction. */
|
|
10
|
+
export declare const MAX_HIJRI_ADJUSTMENT = 2;
|
|
11
|
+
export type HijriConversionOptions = {
|
|
12
|
+
/**
|
|
13
|
+
* Days to shift the Hijri calendar by, from -2 to 2. `1` makes every
|
|
14
|
+
* Hijri date one day later than Umm al-Qura (Umm al-Qura's 29 Sha'ban
|
|
15
|
+
* becomes 30 Sha'ban), for places where the month started a day
|
|
16
|
+
* earlier. Default 0.
|
|
17
|
+
*/
|
|
18
|
+
adjustment?: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Checks a Hijri adjustment and returns it.
|
|
22
|
+
*
|
|
23
|
+
* @throws {RangeError} unless it is an integer from -2 to 2.
|
|
24
|
+
*/
|
|
25
|
+
export declare function checkAdjustment(adjustment: number, caller: string): number;
|
|
26
|
+
/** First and last epoch day that have a Hijri date, for an adjustment. */
|
|
27
|
+
export declare function supportedEpochDays(adjustment?: number): {
|
|
28
|
+
min: number;
|
|
29
|
+
max: number;
|
|
30
|
+
};
|
|
5
31
|
/** First and last Hijri dates the table covers. */
|
|
6
32
|
export declare function getSupportedRange(): {
|
|
7
33
|
min: HijriDate;
|
|
@@ -17,38 +43,35 @@ export declare function getHijriMonthLength(year: number, month: number): 29 | 3
|
|
|
17
43
|
/** Whether `hijri` is a real day within the supported range. */
|
|
18
44
|
export declare function isValidHijri(hijri: HijriDate): boolean;
|
|
19
45
|
/**
|
|
20
|
-
* Hijri date of an epoch day. Internal: the
|
|
21
|
-
* `toHijri`.
|
|
46
|
+
* Hijri date of an epoch day, shifted by `adjustment` days. Internal: the
|
|
47
|
+
* public entry point is `toHijri`.
|
|
22
48
|
*
|
|
23
49
|
* @throws {RangeError} if the day is outside the supported range.
|
|
24
50
|
*/
|
|
25
|
-
export declare function hijriOfEpochDay(epochDay: number, caller?: string):
|
|
26
|
-
year: number;
|
|
27
|
-
month: number;
|
|
28
|
-
day: number;
|
|
29
|
-
};
|
|
51
|
+
export declare function hijriOfEpochDay(epochDay: number, caller?: string, adjustment?: number): HijriDate;
|
|
30
52
|
/**
|
|
31
|
-
* Epoch day of a Hijri date. Internal: the
|
|
32
|
-
* `toGregorian`.
|
|
53
|
+
* Epoch day of a Hijri date, shifted by `adjustment` days. Internal: the
|
|
54
|
+
* public entry point is `toGregorian`.
|
|
33
55
|
*
|
|
34
56
|
* @throws {RangeError} if `hijri` is not a valid date in the supported
|
|
35
57
|
* range.
|
|
36
58
|
*/
|
|
37
|
-
export declare function epochDayOfHijri(hijri: HijriDate, caller?: string): number;
|
|
59
|
+
export declare function epochDayOfHijri(hijri: HijriDate, caller?: string, adjustment?: number): number;
|
|
38
60
|
/**
|
|
39
61
|
* Converts the local calendar day of `date` to a Hijri date. The time of
|
|
40
62
|
* day and the time zone offset are ignored: 23:59 and 00:00 on the same
|
|
41
63
|
* local day give the same result.
|
|
42
64
|
*
|
|
43
|
-
* @throws {RangeError} if `date` is invalid or outside the supported
|
|
65
|
+
* @throws {RangeError} if `date` is invalid or outside the supported
|
|
66
|
+
* range, or the adjustment is not an integer from -2 to 2.
|
|
44
67
|
*/
|
|
45
|
-
export declare function toHijri(date: Date): HijriDate;
|
|
68
|
+
export declare function toHijri(date: Date, options?: HijriConversionOptions): HijriDate;
|
|
46
69
|
/**
|
|
47
70
|
* Converts a Hijri date to a `Date` at local midnight of the matching
|
|
48
71
|
* Gregorian day.
|
|
49
72
|
*
|
|
50
73
|
* @throws {RangeError} if `hijri` is not a valid date in the supported
|
|
51
|
-
* range.
|
|
74
|
+
* range, or the adjustment is not an integer from -2 to 2.
|
|
52
75
|
*/
|
|
53
|
-
export declare function toGregorian(hijri: HijriDate): Date;
|
|
76
|
+
export declare function toGregorian(hijri: HijriDate, options?: HijriConversionOptions): Date;
|
|
54
77
|
//# sourceMappingURL=convert.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../../../src/core/convert.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAS,CAAC;AA0BzC
|
|
1
|
+
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../../../src/core/convert.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAS,CAAC;AA0BzC;;;;GAIG;AACH,eAAO,MAAM,SAAS,QAAmB,CAAC;AAC1C,eAAO,MAAM,QAAQ,QAA6C,CAAC;AAEnE,2EAA2E;AAC3E,eAAO,MAAM,oBAAoB,IAAI,CAAC;AAEtC,MAAM,MAAM,sBAAsB,GAAG;IACnC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAWjE;AAED,0EAA0E;AAC1E,wBAAgB,kBAAkB,CAAC,UAAU,SAAI;;;EAEhD;AAqBD,mDAAmD;AACnD,wBAAgB,iBAAiB,IAAI;IAAE,GAAG,EAAE,SAAS,CAAC;IAAC,GAAG,EAAE,SAAS,CAAA;CAAE,CAStE;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,EAAE,GAAG,EAAE,CAgBxE;AAED,gEAAgE;AAChE,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAkBtD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,MAAM,SAAY,EAClB,UAAU,SAAI,GACb,SAAS,CA8BX;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,SAAS,EAChB,MAAM,SAAgB,EACtB,UAAU,SAAI,UAkBf;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CACrB,IAAI,EAAE,IAAI,EACV,OAAO,GAAE,sBAA2B,GACnC,SAAS,CAMX;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,SAAS,EAChB,OAAO,GAAE,sBAA2B,GACnC,IAAI,CAGN"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { getHijriMonthLength, getSupportedRange, isValidHijri, toGregorian, toHijri, } from './convert.js';
|
|
1
|
+
export { getHijriMonthLength, getSupportedRange, isValidHijri, toGregorian, toHijri, type HijriConversionOptions, } from './convert.js';
|
|
2
2
|
export { formatHijri, type FormatHijriOptions } from './format.js';
|
|
3
3
|
export { getMonthNames, getWeekdayNames, toArabicDigits, type CalendarType, type Digits, type Locale, type WeekdayFormat, } from './locale.js';
|
|
4
4
|
export type { HijriDate } from './types.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,OAAO,EACP,KAAK,sBAAsB,GAC5B,MAAM,cAAW,CAAC;AACnB,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,aAAU,CAAC;AAChE,OAAO,EACL,aAAa,EACb,eAAe,EACf,cAAc,EACd,KAAK,YAAY,EACjB,KAAK,MAAM,EACX,KAAK,MAAM,EACX,KAAK,aAAa,GACnB,MAAM,aAAU,CAAC;AAClB,YAAY,EAAE,SAAS,EAAE,MAAM,YAAS,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type Locale = 'ar' | 'en';
|
|
2
2
|
export type Digits = 'arabic' | 'latin';
|
|
3
3
|
export type CalendarType = 'hijri' | 'gregorian';
|
|
4
|
-
export type WeekdayFormat = 'short' | 'long';
|
|
4
|
+
export type WeekdayFormat = 'short' | 'long' | 'narrow';
|
|
5
5
|
/**
|
|
6
6
|
* The 12 month names of a calendar, January / Muharram first. Returns a
|
|
7
7
|
* new array on every call.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locale.d.ts","sourceRoot":"","sources":["../../../../src/core/locale.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;AACjC,MAAM,MAAM,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;AACxC,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,WAAW,CAAC;AACjD,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"locale.d.ts","sourceRoot":"","sources":["../../../../src/core/locale.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;AACjC,MAAM,MAAM,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;AACxC,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,WAAW,CAAC;AACjD,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;AAiGxD;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,YAAY,EACtB,MAAM,EAAE,MAAM,GACb,MAAM,EAAE,CAGV;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,aAAsB,GAC7B,MAAM,EAAE,CAEV;AAID,oEAAoE;AACpE,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAI7D;AAED,+EAA+E;AAC/E,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,kDAAkD;AAClD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAElE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-hilal",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Hijri (Umm al-Qura) and Gregorian date picker for React Native. Cross-platform, Expo Go ready, zero dependencies.",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { useEffect, useState, type ReactNode } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
AccessibilityInfo,
|
|
4
|
+
Animated,
|
|
5
|
+
Easing,
|
|
6
|
+
Platform,
|
|
7
|
+
View,
|
|
8
|
+
type LayoutChangeEvent,
|
|
9
|
+
type StyleProp,
|
|
10
|
+
type ViewStyle,
|
|
11
|
+
} from 'react-native';
|
|
12
|
+
|
|
13
|
+
const DURATION = 220;
|
|
14
|
+
/** Scale the content starts from, just under its full size. */
|
|
15
|
+
const FROM_SCALE = 0.96;
|
|
16
|
+
|
|
17
|
+
type AppearProps = {
|
|
18
|
+
/**
|
|
19
|
+
* Fade and zoom in on mount. False renders a plain View. Read once, on
|
|
20
|
+
* mount, so the content never remounts when it changes.
|
|
21
|
+
*/
|
|
22
|
+
animate: boolean;
|
|
23
|
+
style?: StyleProp<ViewStyle>;
|
|
24
|
+
onLayout?: (event: LayoutChangeEvent) => void;
|
|
25
|
+
children: ReactNode;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Fades its content in with a slight zoom when it mounts, so switching
|
|
30
|
+
* between the days and the month or year picker is not an abrupt jump.
|
|
31
|
+
* Give it a new `key` to play it again.
|
|
32
|
+
*/
|
|
33
|
+
export function Appear({ animate, style, onLayout, children }: AppearProps) {
|
|
34
|
+
const [animated] = useState(animate);
|
|
35
|
+
const [progress] = useState(() => new Animated.Value(animated ? 0 : 1));
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (!animated) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const animation = Animated.timing(progress, {
|
|
42
|
+
toValue: 1,
|
|
43
|
+
duration: DURATION,
|
|
44
|
+
easing: Easing.out(Easing.cubic),
|
|
45
|
+
// React Native Web has no native animation driver.
|
|
46
|
+
useNativeDriver: Platform.OS !== 'web',
|
|
47
|
+
});
|
|
48
|
+
animation.start();
|
|
49
|
+
return () => animation.stop();
|
|
50
|
+
// Plays once, on mount.
|
|
51
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
52
|
+
}, []);
|
|
53
|
+
|
|
54
|
+
if (!animated) {
|
|
55
|
+
return (
|
|
56
|
+
<View style={style} onLayout={onLayout}>
|
|
57
|
+
{children}
|
|
58
|
+
</View>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
const scale = progress.interpolate({
|
|
62
|
+
inputRange: [0, 1],
|
|
63
|
+
outputRange: [FROM_SCALE, 1],
|
|
64
|
+
});
|
|
65
|
+
return (
|
|
66
|
+
<Animated.View
|
|
67
|
+
style={[style, { opacity: progress, transform: [{ scale }] }]}
|
|
68
|
+
onLayout={onLayout}
|
|
69
|
+
>
|
|
70
|
+
{children}
|
|
71
|
+
</Animated.View>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Whether the user asked the system to reduce motion. */
|
|
76
|
+
export function useReduceMotion() {
|
|
77
|
+
const [reduceMotion, setReduceMotion] = useState(false);
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
let mounted = true;
|
|
80
|
+
AccessibilityInfo.isReduceMotionEnabled().then(
|
|
81
|
+
(enabled) => mounted && setReduceMotion(enabled),
|
|
82
|
+
() => {}
|
|
83
|
+
);
|
|
84
|
+
const subscription = AccessibilityInfo.addEventListener(
|
|
85
|
+
'reduceMotionChanged',
|
|
86
|
+
setReduceMotion
|
|
87
|
+
);
|
|
88
|
+
return () => {
|
|
89
|
+
mounted = false;
|
|
90
|
+
subscription.remove();
|
|
91
|
+
};
|
|
92
|
+
}, []);
|
|
93
|
+
return reduceMotion;
|
|
94
|
+
}
|
package/src/calendar/DayCell.tsx
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
type ViewStyle,
|
|
8
8
|
} from 'react-native';
|
|
9
9
|
|
|
10
|
+
import type { RangePosition } from './range';
|
|
10
11
|
import type { CalendarStyles } from './styles';
|
|
11
12
|
|
|
12
13
|
export type DayCellProps = {
|
|
@@ -15,10 +16,16 @@ export type DayCellProps = {
|
|
|
15
16
|
secondaryLabel: string | null;
|
|
16
17
|
accessibilityLabel: string;
|
|
17
18
|
selected: boolean;
|
|
19
|
+
/** Where the day sits in a picked range, or null outside one. */
|
|
20
|
+
rangePosition: RangePosition | null;
|
|
21
|
+
/** The side of the cell where the next day is: 'start' or 'end'. */
|
|
22
|
+
nextSide: 'start' | 'end';
|
|
18
23
|
today: boolean;
|
|
19
24
|
disabled: boolean;
|
|
20
25
|
styles: CalendarStyles;
|
|
21
26
|
dayStyle: StyleProp<ViewStyle>;
|
|
27
|
+
/** maxFontSizeMultiplier of the texts. */
|
|
28
|
+
maxFontScale: number;
|
|
22
29
|
onSelect: (epochDay: number) => void;
|
|
23
30
|
};
|
|
24
31
|
|
|
@@ -33,18 +40,38 @@ export function DayCellView({
|
|
|
33
40
|
secondaryLabel,
|
|
34
41
|
accessibilityLabel,
|
|
35
42
|
selected,
|
|
43
|
+
rangePosition,
|
|
44
|
+
nextSide,
|
|
36
45
|
today,
|
|
37
46
|
disabled,
|
|
38
47
|
styles,
|
|
39
48
|
dayStyle,
|
|
49
|
+
maxFontScale,
|
|
40
50
|
onSelect,
|
|
41
51
|
}: DayCellProps) {
|
|
42
52
|
return (
|
|
43
53
|
<View style={styles.slot}>
|
|
54
|
+
{rangePosition !== null && rangePosition !== 'single' && (
|
|
55
|
+
// Joins the days of a range; half a band at its ends.
|
|
56
|
+
<View
|
|
57
|
+
testID="hilal-range-band"
|
|
58
|
+
style={[
|
|
59
|
+
styles.rangeBand,
|
|
60
|
+
rangePosition === 'middle'
|
|
61
|
+
? fullBand
|
|
62
|
+
: halfBand[
|
|
63
|
+
rangePosition === 'start' ? nextSide : otherSide(nextSide)
|
|
64
|
+
],
|
|
65
|
+
]}
|
|
66
|
+
/>
|
|
67
|
+
)}
|
|
44
68
|
<Pressable
|
|
45
69
|
accessibilityRole="button"
|
|
46
70
|
accessibilityLabel={accessibilityLabel}
|
|
47
|
-
accessibilityState={{
|
|
71
|
+
accessibilityState={{
|
|
72
|
+
selected: selected || rangePosition === 'middle',
|
|
73
|
+
disabled,
|
|
74
|
+
}}
|
|
48
75
|
disabled={disabled}
|
|
49
76
|
onPress={() => onSelect(epochDay)}
|
|
50
77
|
style={({ pressed }) => [
|
|
@@ -56,9 +83,11 @@ export function DayCellView({
|
|
|
56
83
|
]}
|
|
57
84
|
>
|
|
58
85
|
<Text
|
|
86
|
+
maxFontSizeMultiplier={maxFontScale}
|
|
59
87
|
style={[
|
|
60
88
|
styles.dayText,
|
|
61
89
|
disabled && styles.disabledText,
|
|
90
|
+
today && styles.todayText,
|
|
62
91
|
selected && styles.selectedText,
|
|
63
92
|
]}
|
|
64
93
|
>
|
|
@@ -66,6 +95,7 @@ export function DayCellView({
|
|
|
66
95
|
</Text>
|
|
67
96
|
{secondaryLabel !== null && (
|
|
68
97
|
<Text
|
|
98
|
+
maxFontSizeMultiplier={maxFontScale}
|
|
69
99
|
style={[
|
|
70
100
|
styles.secondaryText,
|
|
71
101
|
disabled && styles.disabledText,
|
|
@@ -80,4 +110,14 @@ export function DayCellView({
|
|
|
80
110
|
);
|
|
81
111
|
}
|
|
82
112
|
|
|
113
|
+
const fullBand = { start: 0, end: 0 } as const;
|
|
114
|
+
/** Half a band, on the start or the end side of the cell. */
|
|
115
|
+
const halfBand = {
|
|
116
|
+
start: { start: 0, width: '50%' },
|
|
117
|
+
end: { end: 0, width: '50%' },
|
|
118
|
+
} as const;
|
|
119
|
+
|
|
120
|
+
const otherSide = (side: 'start' | 'end') =>
|
|
121
|
+
side === 'start' ? 'end' : 'start';
|
|
122
|
+
|
|
83
123
|
export const DayCell = memo(DayCellView);
|