react-native-hilal 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +300 -2
- package/lib/module/calendar/Appear.js +75 -0
- package/lib/module/calendar/Appear.js.map +1 -0
- package/lib/module/calendar/Chevron.js +60 -0
- package/lib/module/calendar/Chevron.js.map +1 -0
- package/lib/module/calendar/DayCell.js +51 -0
- package/lib/module/calendar/DayCell.js.map +1 -0
- package/lib/module/calendar/HilalCalendar.js +565 -0
- package/lib/module/calendar/HilalCalendar.js.map +1 -0
- package/lib/module/calendar/PickerGrid.js +66 -0
- package/lib/module/calendar/PickerGrid.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 +291 -0
- package/lib/module/calendar/month.js.map +1 -0
- package/lib/module/calendar/styles.js +338 -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 +191 -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 +62 -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/Appear.d.ts +22 -0
- package/lib/typescript/src/calendar/Appear.d.ts.map +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 +24 -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/PickerGrid.d.ts +28 -0
- package/lib/typescript/src/calendar/PickerGrid.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 +86 -0
- package/lib/typescript/src/calendar/month.d.ts.map +1 -0
- package/lib/typescript/src/calendar/styles.d.ts +206 -0
- package/lib/typescript/src/calendar/styles.d.ts.map +1 -0
- package/lib/typescript/src/calendar/theme.d.ts +51 -0
- package/lib/typescript/src/calendar/theme.d.ts.map +1 -0
- package/lib/typescript/src/calendar/types.d.ts +162 -0
- package/lib/typescript/src/calendar/types.d.ts.map +1 -0
- package/lib/typescript/src/core/convert.d.ts +77 -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/Appear.tsx +94 -0
- package/src/calendar/Chevron.tsx +55 -0
- package/src/calendar/DayCell.tsx +89 -0
- package/src/calendar/HilalCalendar.tsx +728 -0
- package/src/calendar/PickerGrid.tsx +99 -0
- package/src/calendar/index.ts +13 -0
- package/src/calendar/month.ts +364 -0
- package/src/calendar/styles.ts +357 -0
- package/src/calendar/theme.ts +89 -0
- package/src/calendar/types.ts +168 -0
- package/src/core/convert.ts +256 -0
- package/src/core/days.ts +64 -0
- package/src/core/format.ts +65 -0
- package/src/core/index.ts +19 -0
- package/src/core/locale.ts +141 -0
- package/src/core/types.ts +6 -0
- package/src/core/umalqura-data.ts +34 -0
- package/src/index.tsx +2 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Digits, type Locale } from './locale.js';
|
|
2
|
+
import type { CivilDate } from './days.js';
|
|
3
|
+
import type { HijriDate } from './types.js';
|
|
4
|
+
export type FormatHijriOptions = {
|
|
5
|
+
/** Default: 'ar'. */
|
|
6
|
+
locale?: Locale;
|
|
7
|
+
/** Default: 'arabic' when locale is 'ar', 'latin' otherwise. */
|
|
8
|
+
digits?: Digits;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Formats a Hijri date as "day month year era", for example
|
|
12
|
+
* "١ رمضان ١٤٤٦ هـ" or "1 Ramadan 1446 AH".
|
|
13
|
+
*
|
|
14
|
+
* @throws {RangeError} if `hijri` is not a valid date in the supported
|
|
15
|
+
* range.
|
|
16
|
+
*/
|
|
17
|
+
export declare function formatHijri(hijri: HijriDate, options?: FormatHijriOptions): string;
|
|
18
|
+
/**
|
|
19
|
+
* Formats a Gregorian date as "day month year", for example
|
|
20
|
+
* "١١ مارس ٢٠٢٤" or "11 March 2024". Internal: used by the calendar.
|
|
21
|
+
*/
|
|
22
|
+
export declare function formatGregorian(date: CivilDate, options?: FormatHijriOptions): string;
|
|
23
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../../src/core/format.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,MAAM,EACX,KAAK,MAAM,EACZ,MAAM,aAAU,CAAC;AAClB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAQ,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAS,CAAC;AAEzC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,qBAAqB;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAIF;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,SAAS,EAChB,OAAO,GAAE,kBAAuB,GAC/B,MAAM,CAgBR;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,SAAS,EACf,OAAO,GAAE,kBAAuB,GAC/B,MAAM,CASR"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { getHijriMonthLength, getSupportedRange, isValidHijri, toGregorian, toHijri, type HijriConversionOptions, } from './convert.js';
|
|
2
|
+
export { formatHijri, type FormatHijriOptions } from './format.js';
|
|
3
|
+
export { getMonthNames, getWeekdayNames, toArabicDigits, type CalendarType, type Digits, type Locale, type WeekdayFormat, } from './locale.js';
|
|
4
|
+
export type { HijriDate } from './types.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,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"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type Locale = 'ar' | 'en';
|
|
2
|
+
export type Digits = 'arabic' | 'latin';
|
|
3
|
+
export type CalendarType = 'hijri' | 'gregorian';
|
|
4
|
+
export type WeekdayFormat = 'short' | 'long' | 'narrow';
|
|
5
|
+
/**
|
|
6
|
+
* The 12 month names of a calendar, January / Muharram first. Returns a
|
|
7
|
+
* new array on every call.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getMonthNames(calendar: CalendarType, locale: Locale): string[];
|
|
10
|
+
/**
|
|
11
|
+
* The 7 weekday names, Sunday first (index matches `Date#getDay()`).
|
|
12
|
+
* Returns a new array on every call.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getWeekdayNames(locale: Locale, format?: WeekdayFormat): string[];
|
|
15
|
+
/** Replaces the Latin digits 0-9 with Arabic-Indic digits (٠-٩). */
|
|
16
|
+
export declare function toArabicDigits(input: string | number): string;
|
|
17
|
+
/** The default digits for a locale: Arabic-Indic for 'ar', Latin otherwise. */
|
|
18
|
+
export declare function defaultDigits(locale: Locale): Digits;
|
|
19
|
+
/** Formats a number with the requested digits. */
|
|
20
|
+
export declare function formatNumber(value: number, digits: Digits): string;
|
|
21
|
+
//# sourceMappingURL=locale.d.ts.map
|
|
@@ -0,0 +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,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/core/types.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** First Hijri year in the table. */
|
|
2
|
+
export declare const UMALQURA_MIN_YEAR = 1356;
|
|
3
|
+
/** Last Hijri year in the table. */
|
|
4
|
+
export declare const UMALQURA_MAX_YEAR = 1500;
|
|
5
|
+
/**
|
|
6
|
+
* Days since 1970-01-01 (in the proleptic Gregorian calendar) of
|
|
7
|
+
* 1 Muharram 1356.
|
|
8
|
+
*/
|
|
9
|
+
export declare const UMALQURA_START_EPOCH_DAY = -11981;
|
|
10
|
+
/**
|
|
11
|
+
* One entry per Hijri year from 1356 to 1500. Bit (month - 1) is
|
|
12
|
+
* set when that month has 30 days and clear when it has 29.
|
|
13
|
+
*/
|
|
14
|
+
export declare const UMALQURA_MONTH_LENGTH_MASKS: readonly number[];
|
|
15
|
+
//# sourceMappingURL=umalqura-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"umalqura-data.d.ts","sourceRoot":"","sources":["../../../../src/core/umalqura-data.ts"],"names":[],"mappings":"AAIA,qCAAqC;AACrC,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAEtC,oCAAoC;AACpC,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAEtC;;;GAGG;AACH,eAAO,MAAM,wBAAwB,SAAS,CAAC;AAE/C;;;GAGG;AACH,eAAO,MAAM,2BAA2B,EAAE,SAAS,MAAM,EAaxD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,iBAAQ,CAAC;AACvB,cAAc,qBAAY,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,182 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-hilal",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Hijri (Umm al-Qura) and Gregorian date picker for React Native. Cross-platform, Expo Go ready, zero dependencies.",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"react-native-hilal-source": "./src/index.tsx",
|
|
10
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
11
|
+
"default": "./lib/module/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"lib",
|
|
18
|
+
"!**/__tests__",
|
|
19
|
+
"!**/__fixtures__",
|
|
20
|
+
"!**/__mocks__",
|
|
21
|
+
"!**/.*"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"example": "yarn workspace react-native-hilal-example",
|
|
25
|
+
"clean": "del-cli lib",
|
|
26
|
+
"prepare": "husky && bob build",
|
|
27
|
+
"typecheck": "tsc",
|
|
28
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
29
|
+
"test": "jest",
|
|
30
|
+
"release": "release-it",
|
|
31
|
+
"generate:umalqura": "node scripts/generate-umalqura-table.ts && prettier --write src/core/umalqura-data.ts"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"react-native",
|
|
35
|
+
"hijri",
|
|
36
|
+
"umm-al-qura",
|
|
37
|
+
"calendar",
|
|
38
|
+
"date-picker",
|
|
39
|
+
"arabic",
|
|
40
|
+
"rtl",
|
|
41
|
+
"expo",
|
|
42
|
+
"islamic-calendar"
|
|
43
|
+
],
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/2ve2/hilal.git"
|
|
47
|
+
},
|
|
48
|
+
"author": "2ve2 (https://github.com/2ve2)",
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/2ve2/hilal/issues"
|
|
52
|
+
},
|
|
53
|
+
"homepage": "https://github.com/2ve2/hilal#readme",
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"registry": "https://registry.npmjs.org/",
|
|
56
|
+
"access": "public"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@commitlint/cli": "^21.2.4",
|
|
60
|
+
"@commitlint/config-conventional": "^21.2.4",
|
|
61
|
+
"@eslint/compat": "^2.1.1",
|
|
62
|
+
"@eslint/eslintrc": "^3.3.7",
|
|
63
|
+
"@eslint/js": "^9.39.5",
|
|
64
|
+
"@jest/globals": "^29.7.0",
|
|
65
|
+
"@react-native/babel-preset": "0.88.0",
|
|
66
|
+
"@react-native/eslint-config": "0.88.0",
|
|
67
|
+
"@react-native/jest-preset": "0.88.0",
|
|
68
|
+
"@release-it/conventional-changelog": "^12.0.2",
|
|
69
|
+
"@testing-library/react-native": "^14.1.0",
|
|
70
|
+
"@types/node": "^24",
|
|
71
|
+
"@types/react": "^19.2.0",
|
|
72
|
+
"del-cli": "^8.0.1",
|
|
73
|
+
"eslint": "^9.39.5",
|
|
74
|
+
"eslint-config-prettier": "^10.1.8",
|
|
75
|
+
"eslint-plugin-ft-flow": "^3.0.11",
|
|
76
|
+
"eslint-plugin-prettier": "^5.5.7",
|
|
77
|
+
"husky": "^9.1.7",
|
|
78
|
+
"jest": "^29.7.0",
|
|
79
|
+
"lint-staged": "^17.6.0",
|
|
80
|
+
"prettier": "^3.9.10",
|
|
81
|
+
"react": "19.3.0",
|
|
82
|
+
"react-native": "0.88.0",
|
|
83
|
+
"react-native-builder-bob": "^0.44.1",
|
|
84
|
+
"release-it": "^21.1.1",
|
|
85
|
+
"test-renderer": "^1.3.1",
|
|
86
|
+
"typescript": "^6.0.3"
|
|
87
|
+
},
|
|
88
|
+
"peerDependencies": {
|
|
89
|
+
"react": "*",
|
|
90
|
+
"react-native": "*"
|
|
91
|
+
},
|
|
92
|
+
"workspaces": [
|
|
93
|
+
"example"
|
|
94
|
+
],
|
|
95
|
+
"packageManager": "yarn@4.18.1",
|
|
96
|
+
"react-native-builder-bob": {
|
|
97
|
+
"source": "src",
|
|
98
|
+
"output": "lib",
|
|
99
|
+
"targets": [
|
|
100
|
+
[
|
|
101
|
+
"module",
|
|
102
|
+
{
|
|
103
|
+
"esm": true
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
[
|
|
107
|
+
"typescript",
|
|
108
|
+
{
|
|
109
|
+
"project": "tsconfig.build.json"
|
|
110
|
+
}
|
|
111
|
+
]
|
|
112
|
+
]
|
|
113
|
+
},
|
|
114
|
+
"prettier": {
|
|
115
|
+
"quoteProps": "consistent",
|
|
116
|
+
"singleQuote": true,
|
|
117
|
+
"tabWidth": 2,
|
|
118
|
+
"trailingComma": "es5",
|
|
119
|
+
"useTabs": false
|
|
120
|
+
},
|
|
121
|
+
"jest": {
|
|
122
|
+
"preset": "@react-native/jest-preset",
|
|
123
|
+
"testEnvironmentOptions": {
|
|
124
|
+
"customExportConditions": [
|
|
125
|
+
"require",
|
|
126
|
+
"react-native",
|
|
127
|
+
"react-native-hilal-source"
|
|
128
|
+
]
|
|
129
|
+
},
|
|
130
|
+
"modulePathIgnorePatterns": [
|
|
131
|
+
"<rootDir>/example/node_modules",
|
|
132
|
+
"<rootDir>/lib/"
|
|
133
|
+
],
|
|
134
|
+
"globalSetup": "<rootDir>/jest.global-setup.js"
|
|
135
|
+
},
|
|
136
|
+
"release-it": {
|
|
137
|
+
"git": {
|
|
138
|
+
"commitMessage": "chore: release ${version}",
|
|
139
|
+
"requireBranch": "release/*",
|
|
140
|
+
"requireCleanWorkingDir": true,
|
|
141
|
+
"requireUpstream": false,
|
|
142
|
+
"tag": false,
|
|
143
|
+
"push": true
|
|
144
|
+
},
|
|
145
|
+
"hooks": {
|
|
146
|
+
"before:init": [
|
|
147
|
+
"yarn lint",
|
|
148
|
+
"yarn typecheck",
|
|
149
|
+
"yarn test"
|
|
150
|
+
]
|
|
151
|
+
},
|
|
152
|
+
"npm": {
|
|
153
|
+
"publish": false
|
|
154
|
+
},
|
|
155
|
+
"github": {
|
|
156
|
+
"release": false
|
|
157
|
+
},
|
|
158
|
+
"plugins": {
|
|
159
|
+
"@release-it/conventional-changelog": {
|
|
160
|
+
"preset": {
|
|
161
|
+
"name": "conventionalcommits"
|
|
162
|
+
},
|
|
163
|
+
"infile": "CHANGELOG.md",
|
|
164
|
+
"header": "# Changelog"
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
"create-react-native-library": {
|
|
169
|
+
"type": "library",
|
|
170
|
+
"languages": "js",
|
|
171
|
+
"tools": [
|
|
172
|
+
"eslint",
|
|
173
|
+
"jest",
|
|
174
|
+
"release-it"
|
|
175
|
+
],
|
|
176
|
+
"version": "0.64.0"
|
|
177
|
+
},
|
|
178
|
+
"lint-staged": {
|
|
179
|
+
"*.{js,mjs,cjs,ts,tsx}": "eslint --fix",
|
|
180
|
+
"*.{json,md,yml,yaml}": "prettier --write"
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { StyleSheet, View } from 'react-native';
|
|
2
|
+
|
|
3
|
+
type ChevronProps = {
|
|
4
|
+
direction: 'left' | 'right';
|
|
5
|
+
color: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const SIZE = 14;
|
|
9
|
+
const LENGTH = 10;
|
|
10
|
+
const THICKNESS = 2.5;
|
|
11
|
+
// Vertical offset of each stroke's center so their ends meet at the tip.
|
|
12
|
+
const OFFSET = LENGTH / (2 * Math.SQRT2);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A chevron drawn with two rotated strokes. Not a text glyph: '‹' and '›'
|
|
16
|
+
* are mirrored by the Unicode bidi algorithm in right-to-left text, so they
|
|
17
|
+
* would point the wrong way in RTL apps. No left/right styles either, since
|
|
18
|
+
* React Native swaps those in RTL layouts.
|
|
19
|
+
*/
|
|
20
|
+
export function Chevron({ direction, color }: ChevronProps) {
|
|
21
|
+
const upper = direction === 'left' ? '-45deg' : '45deg';
|
|
22
|
+
const lower = direction === 'left' ? '45deg' : '-45deg';
|
|
23
|
+
return (
|
|
24
|
+
<View testID={`hilal-chevron-${direction}`} style={styles.box}>
|
|
25
|
+
<View
|
|
26
|
+
style={[
|
|
27
|
+
styles.stroke,
|
|
28
|
+
{ backgroundColor: color, top: SIZE / 2 - OFFSET - THICKNESS / 2 },
|
|
29
|
+
{ transform: [{ rotate: upper }] },
|
|
30
|
+
]}
|
|
31
|
+
/>
|
|
32
|
+
<View
|
|
33
|
+
style={[
|
|
34
|
+
styles.stroke,
|
|
35
|
+
{ backgroundColor: color, top: SIZE / 2 + OFFSET - THICKNESS / 2 },
|
|
36
|
+
{ transform: [{ rotate: lower }] },
|
|
37
|
+
]}
|
|
38
|
+
/>
|
|
39
|
+
</View>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const styles = StyleSheet.create({
|
|
44
|
+
box: {
|
|
45
|
+
alignItems: 'center',
|
|
46
|
+
height: SIZE,
|
|
47
|
+
width: SIZE,
|
|
48
|
+
},
|
|
49
|
+
stroke: {
|
|
50
|
+
borderRadius: THICKNESS / 2,
|
|
51
|
+
height: THICKNESS,
|
|
52
|
+
position: 'absolute',
|
|
53
|
+
width: LENGTH,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { memo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Pressable,
|
|
4
|
+
Text,
|
|
5
|
+
View,
|
|
6
|
+
type StyleProp,
|
|
7
|
+
type ViewStyle,
|
|
8
|
+
} from 'react-native';
|
|
9
|
+
|
|
10
|
+
import type { CalendarStyles } from './styles';
|
|
11
|
+
|
|
12
|
+
export type DayCellProps = {
|
|
13
|
+
epochDay: number;
|
|
14
|
+
label: string;
|
|
15
|
+
secondaryLabel: string | null;
|
|
16
|
+
accessibilityLabel: string;
|
|
17
|
+
selected: boolean;
|
|
18
|
+
today: boolean;
|
|
19
|
+
disabled: boolean;
|
|
20
|
+
styles: CalendarStyles;
|
|
21
|
+
dayStyle: StyleProp<ViewStyle>;
|
|
22
|
+
/** maxFontSizeMultiplier of the texts. */
|
|
23
|
+
maxFontScale: number;
|
|
24
|
+
onSelect: (epochDay: number) => void;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* One day of the grid. Memoized: every prop is either a primitive or kept
|
|
29
|
+
* stable by the calendar, so pressing a day only re-renders the old and
|
|
30
|
+
* the new selected day.
|
|
31
|
+
*/
|
|
32
|
+
export function DayCellView({
|
|
33
|
+
epochDay,
|
|
34
|
+
label,
|
|
35
|
+
secondaryLabel,
|
|
36
|
+
accessibilityLabel,
|
|
37
|
+
selected,
|
|
38
|
+
today,
|
|
39
|
+
disabled,
|
|
40
|
+
styles,
|
|
41
|
+
dayStyle,
|
|
42
|
+
maxFontScale,
|
|
43
|
+
onSelect,
|
|
44
|
+
}: DayCellProps) {
|
|
45
|
+
return (
|
|
46
|
+
<View style={styles.slot}>
|
|
47
|
+
<Pressable
|
|
48
|
+
accessibilityRole="button"
|
|
49
|
+
accessibilityLabel={accessibilityLabel}
|
|
50
|
+
accessibilityState={{ selected, disabled }}
|
|
51
|
+
disabled={disabled}
|
|
52
|
+
onPress={() => onSelect(epochDay)}
|
|
53
|
+
style={({ pressed }) => [
|
|
54
|
+
styles.day,
|
|
55
|
+
today && styles.today,
|
|
56
|
+
selected && styles.selected,
|
|
57
|
+
pressed && !selected && styles.pressed,
|
|
58
|
+
dayStyle,
|
|
59
|
+
]}
|
|
60
|
+
>
|
|
61
|
+
<Text
|
|
62
|
+
maxFontSizeMultiplier={maxFontScale}
|
|
63
|
+
style={[
|
|
64
|
+
styles.dayText,
|
|
65
|
+
disabled && styles.disabledText,
|
|
66
|
+
today && styles.todayText,
|
|
67
|
+
selected && styles.selectedText,
|
|
68
|
+
]}
|
|
69
|
+
>
|
|
70
|
+
{label}
|
|
71
|
+
</Text>
|
|
72
|
+
{secondaryLabel !== null && (
|
|
73
|
+
<Text
|
|
74
|
+
maxFontSizeMultiplier={maxFontScale}
|
|
75
|
+
style={[
|
|
76
|
+
styles.secondaryText,
|
|
77
|
+
disabled && styles.disabledText,
|
|
78
|
+
selected && styles.selectedSecondaryText,
|
|
79
|
+
]}
|
|
80
|
+
>
|
|
81
|
+
{secondaryLabel}
|
|
82
|
+
</Text>
|
|
83
|
+
)}
|
|
84
|
+
</Pressable>
|
|
85
|
+
</View>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const DayCell = memo(DayCellView);
|