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,357 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
|
|
3
|
+
import type { HilalTheme } from './theme';
|
|
4
|
+
import type { HilalStyles } from './types';
|
|
5
|
+
|
|
6
|
+
/** Fills the parent; left/right are both 0, so RTL mirroring can't move it. */
|
|
7
|
+
const fill = {
|
|
8
|
+
bottom: 0,
|
|
9
|
+
left: 0,
|
|
10
|
+
position: 'absolute',
|
|
11
|
+
right: 0,
|
|
12
|
+
top: 0,
|
|
13
|
+
} as const;
|
|
14
|
+
|
|
15
|
+
export type CalendarStyles = ReturnType<typeof createStyles>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* How far the phone's text size setting may grow the text of day cells,
|
|
19
|
+
* weekday names and picker buttons, which have a fixed size: up to 1.3 a
|
|
20
|
+
* day number and the date under it still fit a 48 pt cell.
|
|
21
|
+
*/
|
|
22
|
+
export const MAX_CELL_FONT_SCALE = 1.3;
|
|
23
|
+
/** The same for the header and the toggle, which have room to grow. */
|
|
24
|
+
export const MAX_HEADER_FONT_SCALE = 2;
|
|
25
|
+
|
|
26
|
+
/** The text styles, which take the theme's fonts and font scale. */
|
|
27
|
+
const TEXT_STYLES = [
|
|
28
|
+
'toggleText',
|
|
29
|
+
'title',
|
|
30
|
+
'subtitle',
|
|
31
|
+
'weekday',
|
|
32
|
+
'dayText',
|
|
33
|
+
'secondaryText',
|
|
34
|
+
'pickerText',
|
|
35
|
+
// Only a weight, for the bold font.
|
|
36
|
+
'selectedText',
|
|
37
|
+
'todayText',
|
|
38
|
+
] as const;
|
|
39
|
+
|
|
40
|
+
/** Text in columns of a fixed width: shrinks with the font scale only. */
|
|
41
|
+
const FIXED_WIDTH_TEXT = new Set<string>(['weekday', 'pickerText']);
|
|
42
|
+
|
|
43
|
+
type TextStyleObject = {
|
|
44
|
+
fontSize?: number;
|
|
45
|
+
lineHeight?: number;
|
|
46
|
+
fontWeight?: string;
|
|
47
|
+
fontFamily?: string;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export function createStyles(theme: HilalTheme) {
|
|
51
|
+
return StyleSheet.create(applyFonts(baseStyles(theme), theme));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Applies `fontFamily`, `fontFamilyBold` and `fontScale`. Only adds keys
|
|
56
|
+
* when the theme sets them, so a theme without fonts gives exactly the
|
|
57
|
+
* base styles.
|
|
58
|
+
*/
|
|
59
|
+
function applyFonts<T extends Record<string, object>>(
|
|
60
|
+
styles: T,
|
|
61
|
+
theme: HilalTheme
|
|
62
|
+
): T {
|
|
63
|
+
const scale = theme.fontScale ?? 1;
|
|
64
|
+
if (!(Number.isFinite(scale) && scale > 0)) {
|
|
65
|
+
throw new RangeError(
|
|
66
|
+
`HilalCalendar: theme.fontScale must be a positive number, got ${scale}`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
const { fontFamily, fontFamilyBold } = theme;
|
|
70
|
+
if (scale === 1 && !fontFamily && !fontFamilyBold) {
|
|
71
|
+
return styles;
|
|
72
|
+
}
|
|
73
|
+
const out: Record<string, object> = { ...styles };
|
|
74
|
+
for (const key of TEXT_STYLES) {
|
|
75
|
+
const style = { ...(styles[key] as TextStyleObject) };
|
|
76
|
+
// Weekday names (أربعاء خميس) only just fit seven columns on small
|
|
77
|
+
// phones, and long month names (Dhu al-Qi'dah) three, so these never
|
|
78
|
+
// grow.
|
|
79
|
+
const factor = FIXED_WIDTH_TEXT.has(key) ? Math.min(scale, 1) : scale;
|
|
80
|
+
if (factor !== 1) {
|
|
81
|
+
if (style.fontSize) style.fontSize = round(style.fontSize * factor);
|
|
82
|
+
if (style.lineHeight) style.lineHeight = round(style.lineHeight * factor);
|
|
83
|
+
}
|
|
84
|
+
const bold = style.fontWeight === '600' || style.fontWeight === '700';
|
|
85
|
+
if (bold && fontFamilyBold) {
|
|
86
|
+
// A bold font file plus a bold weight would be bolded twice.
|
|
87
|
+
style.fontFamily = fontFamilyBold;
|
|
88
|
+
style.fontWeight = 'normal';
|
|
89
|
+
} else if (fontFamily) {
|
|
90
|
+
style.fontFamily = fontFamily;
|
|
91
|
+
}
|
|
92
|
+
out[key] = style;
|
|
93
|
+
}
|
|
94
|
+
if (scale > 1) {
|
|
95
|
+
// Larger text needs larger day cells.
|
|
96
|
+
const day = styles.day as { height: number; maxWidth: number };
|
|
97
|
+
out.day = {
|
|
98
|
+
...day,
|
|
99
|
+
height: round(day.height * scale),
|
|
100
|
+
maxWidth: round(day.maxWidth * scale),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return out as T;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const round = (n: number) => Math.round(n * 10) / 10;
|
|
107
|
+
|
|
108
|
+
/** The calendar style each `styles` slot is merged into. */
|
|
109
|
+
const SLOTS = {
|
|
110
|
+
container: 'container',
|
|
111
|
+
toggle: 'toggle',
|
|
112
|
+
toggleOption: 'toggleOption',
|
|
113
|
+
toggleText: 'toggleText',
|
|
114
|
+
header: 'header',
|
|
115
|
+
title: 'title',
|
|
116
|
+
subtitle: 'subtitle',
|
|
117
|
+
arrow: 'arrow',
|
|
118
|
+
weekdayText: 'weekday',
|
|
119
|
+
day: 'day',
|
|
120
|
+
dayText: 'dayText',
|
|
121
|
+
secondaryDayText: 'secondaryText',
|
|
122
|
+
pickerItem: 'pickerItem',
|
|
123
|
+
pickerText: 'pickerText',
|
|
124
|
+
} as const;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* The slots for day states. The picker shares these calendar styles, so
|
|
128
|
+
* they are merged into a copy used only by the day cells.
|
|
129
|
+
*/
|
|
130
|
+
const DAY_SLOTS = {
|
|
131
|
+
selectedDay: 'selected',
|
|
132
|
+
selectedDayText: 'selectedText',
|
|
133
|
+
today: 'today',
|
|
134
|
+
disabledDayText: 'disabledText',
|
|
135
|
+
todayDayText: 'todayText',
|
|
136
|
+
} as const;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Merges the `styles` prop over the calendar styles: `styles` for the
|
|
140
|
+
* calendar and the picker, `dayStyles` for the day cells. Slots that are
|
|
141
|
+
* not set leave the calendar styles as they are.
|
|
142
|
+
*/
|
|
143
|
+
export function withSlots(
|
|
144
|
+
styles: CalendarStyles,
|
|
145
|
+
slots: HilalStyles | undefined
|
|
146
|
+
): { styles: CalendarStyles; dayStyles: CalendarStyles } {
|
|
147
|
+
if (!slots) {
|
|
148
|
+
return { styles, dayStyles: styles };
|
|
149
|
+
}
|
|
150
|
+
const merge = (
|
|
151
|
+
target: CalendarStyles,
|
|
152
|
+
map: Record<string, keyof CalendarStyles>
|
|
153
|
+
) => {
|
|
154
|
+
const out: Record<string, unknown> = { ...target };
|
|
155
|
+
for (const [slot, key] of Object.entries(map)) {
|
|
156
|
+
const style = slots[slot as keyof HilalStyles];
|
|
157
|
+
if (style) {
|
|
158
|
+
out[key] = StyleSheet.flatten([target[key], style]);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return out as CalendarStyles;
|
|
162
|
+
};
|
|
163
|
+
const merged = merge(styles, SLOTS);
|
|
164
|
+
return { styles: merged, dayStyles: merge(merged, DAY_SLOTS) };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function baseStyles(theme: HilalTheme) {
|
|
168
|
+
return {
|
|
169
|
+
container: {
|
|
170
|
+
backgroundColor: theme.background,
|
|
171
|
+
borderRadius: 20,
|
|
172
|
+
padding: 12,
|
|
173
|
+
},
|
|
174
|
+
toggle: {
|
|
175
|
+
alignSelf: 'center',
|
|
176
|
+
borderColor: theme.border,
|
|
177
|
+
borderRadius: 999,
|
|
178
|
+
borderWidth: 1,
|
|
179
|
+
marginBottom: 12,
|
|
180
|
+
padding: 3,
|
|
181
|
+
},
|
|
182
|
+
toggleOption: {
|
|
183
|
+
borderRadius: 999,
|
|
184
|
+
paddingHorizontal: 16,
|
|
185
|
+
paddingVertical: 6,
|
|
186
|
+
},
|
|
187
|
+
toggleOptionActive: {
|
|
188
|
+
backgroundColor: theme.primary,
|
|
189
|
+
},
|
|
190
|
+
toggleText: {
|
|
191
|
+
color: theme.textSecondary,
|
|
192
|
+
fontSize: 14,
|
|
193
|
+
fontWeight: '600',
|
|
194
|
+
},
|
|
195
|
+
toggleTextActive: {
|
|
196
|
+
color: theme.onPrimary,
|
|
197
|
+
},
|
|
198
|
+
header: {
|
|
199
|
+
alignItems: 'center',
|
|
200
|
+
marginBottom: 8,
|
|
201
|
+
},
|
|
202
|
+
titles: {
|
|
203
|
+
alignItems: 'center',
|
|
204
|
+
flex: 1,
|
|
205
|
+
},
|
|
206
|
+
title: {
|
|
207
|
+
color: theme.text,
|
|
208
|
+
fontSize: 18,
|
|
209
|
+
fontWeight: '700',
|
|
210
|
+
},
|
|
211
|
+
subtitle: {
|
|
212
|
+
color: theme.textSecondary,
|
|
213
|
+
fontSize: 13,
|
|
214
|
+
marginTop: 2,
|
|
215
|
+
},
|
|
216
|
+
arrow: {
|
|
217
|
+
alignItems: 'center',
|
|
218
|
+
borderRadius: 999,
|
|
219
|
+
height: 40,
|
|
220
|
+
justifyContent: 'center',
|
|
221
|
+
width: 40,
|
|
222
|
+
},
|
|
223
|
+
arrowPressed: {
|
|
224
|
+
backgroundColor: theme.border,
|
|
225
|
+
},
|
|
226
|
+
weekdays: {
|
|
227
|
+
marginBottom: 8,
|
|
228
|
+
},
|
|
229
|
+
weekday: {
|
|
230
|
+
color: theme.textSecondary,
|
|
231
|
+
flex: 1,
|
|
232
|
+
fontSize: 12,
|
|
233
|
+
fontWeight: '600',
|
|
234
|
+
textAlign: 'center',
|
|
235
|
+
},
|
|
236
|
+
week: {},
|
|
237
|
+
slot: {
|
|
238
|
+
alignItems: 'center',
|
|
239
|
+
flex: 1,
|
|
240
|
+
// Keeps a gap between neighbouring days when the grid is narrower
|
|
241
|
+
// than 7 full-size cells, so today's ring never touches the
|
|
242
|
+
// selected day.
|
|
243
|
+
paddingHorizontal: 3,
|
|
244
|
+
paddingVertical: 2,
|
|
245
|
+
},
|
|
246
|
+
day: {
|
|
247
|
+
alignItems: 'center',
|
|
248
|
+
borderColor: 'transparent',
|
|
249
|
+
borderRadius: theme.radius,
|
|
250
|
+
borderWidth: 1.5,
|
|
251
|
+
height: 48,
|
|
252
|
+
justifyContent: 'center',
|
|
253
|
+
maxWidth: 48,
|
|
254
|
+
width: '100%',
|
|
255
|
+
},
|
|
256
|
+
today: {
|
|
257
|
+
borderColor: theme.today,
|
|
258
|
+
},
|
|
259
|
+
selected: {
|
|
260
|
+
backgroundColor: theme.primary,
|
|
261
|
+
borderColor: theme.primary,
|
|
262
|
+
},
|
|
263
|
+
pressed: {
|
|
264
|
+
backgroundColor: theme.border,
|
|
265
|
+
},
|
|
266
|
+
// Medium, so the selected day and today stand out in bold. Fixed line
|
|
267
|
+
// heights: fonts with tall lines (Noto Naskh, many custom fonts) would
|
|
268
|
+
// otherwise push the date under the number to the next row.
|
|
269
|
+
dayText: {
|
|
270
|
+
color: theme.text,
|
|
271
|
+
fontSize: 16,
|
|
272
|
+
fontWeight: '500',
|
|
273
|
+
lineHeight: 20,
|
|
274
|
+
},
|
|
275
|
+
secondaryText: {
|
|
276
|
+
color: theme.textSecondary,
|
|
277
|
+
fontSize: 11,
|
|
278
|
+
lineHeight: 14,
|
|
279
|
+
marginTop: 1,
|
|
280
|
+
},
|
|
281
|
+
selectedText: {
|
|
282
|
+
color: theme.onPrimary,
|
|
283
|
+
fontWeight: '700',
|
|
284
|
+
},
|
|
285
|
+
todayText: {
|
|
286
|
+
fontWeight: '700',
|
|
287
|
+
},
|
|
288
|
+
selectedSecondaryText: {
|
|
289
|
+
color: theme.onPrimary,
|
|
290
|
+
opacity: 0.8,
|
|
291
|
+
},
|
|
292
|
+
disabledText: {
|
|
293
|
+
color: theme.disabled,
|
|
294
|
+
},
|
|
295
|
+
// Month and year picker.
|
|
296
|
+
titleButton: {
|
|
297
|
+
alignItems: 'center',
|
|
298
|
+
borderRadius: 10,
|
|
299
|
+
overflow: 'hidden',
|
|
300
|
+
paddingHorizontal: 10,
|
|
301
|
+
paddingVertical: 2,
|
|
302
|
+
},
|
|
303
|
+
// The title inside the button: centered and shrinkable when a long
|
|
304
|
+
// name wraps on a narrow phone.
|
|
305
|
+
titleInButton: {
|
|
306
|
+
flexShrink: 1,
|
|
307
|
+
textAlign: 'center',
|
|
308
|
+
},
|
|
309
|
+
// The title of the year picker, which is not a button.
|
|
310
|
+
titleStatic: {
|
|
311
|
+
paddingVertical: 2,
|
|
312
|
+
},
|
|
313
|
+
titleButtonPressed: {
|
|
314
|
+
backgroundColor: theme.border,
|
|
315
|
+
},
|
|
316
|
+
// Tints are layers with opacity, so any theme color format works.
|
|
317
|
+
titleTint: {
|
|
318
|
+
...fill,
|
|
319
|
+
backgroundColor: theme.primary,
|
|
320
|
+
opacity: 0.1,
|
|
321
|
+
},
|
|
322
|
+
picker: {
|
|
323
|
+
marginTop: 4,
|
|
324
|
+
},
|
|
325
|
+
pickerSlot: {
|
|
326
|
+
flex: 1,
|
|
327
|
+
padding: 3,
|
|
328
|
+
},
|
|
329
|
+
pickerItem: {
|
|
330
|
+
alignItems: 'center',
|
|
331
|
+
borderColor: 'transparent',
|
|
332
|
+
borderRadius: theme.radius,
|
|
333
|
+
borderWidth: 1.5,
|
|
334
|
+
justifyContent: 'center',
|
|
335
|
+
minHeight: 52,
|
|
336
|
+
overflow: 'hidden',
|
|
337
|
+
paddingHorizontal: 4,
|
|
338
|
+
paddingVertical: 6,
|
|
339
|
+
},
|
|
340
|
+
// Grows into the free height of its parent.
|
|
341
|
+
grow: {
|
|
342
|
+
flexGrow: 1,
|
|
343
|
+
},
|
|
344
|
+
pickerItemTint: {
|
|
345
|
+
...fill,
|
|
346
|
+
backgroundColor: theme.text,
|
|
347
|
+
opacity: 0.05,
|
|
348
|
+
},
|
|
349
|
+
pickerText: {
|
|
350
|
+
color: theme.text,
|
|
351
|
+
fontSize: 14,
|
|
352
|
+
fontWeight: '600',
|
|
353
|
+
lineHeight: 18,
|
|
354
|
+
textAlign: 'center',
|
|
355
|
+
},
|
|
356
|
+
} as const;
|
|
357
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/** Colors, fonts and shape of the calendar. */
|
|
2
|
+
export type HilalTheme = {
|
|
3
|
+
/** Calendar background. */
|
|
4
|
+
background: string;
|
|
5
|
+
/** Day numbers, month title, arrows. */
|
|
6
|
+
text: string;
|
|
7
|
+
/** Secondary-calendar dates and weekday names. */
|
|
8
|
+
textSecondary: string;
|
|
9
|
+
/** Selected day and active calendar toggle. */
|
|
10
|
+
primary: string;
|
|
11
|
+
/** Text on `primary`. */
|
|
12
|
+
onPrimary: string;
|
|
13
|
+
/** Ring around today's date. */
|
|
14
|
+
today: string;
|
|
15
|
+
/** Days that can't be selected, and disabled arrows. */
|
|
16
|
+
disabled: string;
|
|
17
|
+
/** Toggle outline. */
|
|
18
|
+
border: string;
|
|
19
|
+
/** Corner radius of a day cell. */
|
|
20
|
+
radius: number;
|
|
21
|
+
/** Month arrows. Default: `text`. */
|
|
22
|
+
arrow?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Font of all text, for example 'Cairo-Regular'. Default: the system
|
|
25
|
+
* font.
|
|
26
|
+
*/
|
|
27
|
+
fontFamily?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Font of the bold text (month title, selected day and today, toggle,
|
|
30
|
+
* weekdays, picker), for example 'Cairo-Bold'. When set, it is used as is,
|
|
31
|
+
* without a fontWeight on top. Default: `fontFamily` with a bold weight.
|
|
32
|
+
*/
|
|
33
|
+
fontFamilyBold?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Multiplies every font size, for example 1.15 for larger text. Day
|
|
36
|
+
* cells grow with it. Weekday names and the picker's month and year
|
|
37
|
+
* names shrink with it but never grow, so they still fit their columns
|
|
38
|
+
* on small phones. Default 1.
|
|
39
|
+
*/
|
|
40
|
+
fontScale?: number;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type ThemeProp = 'light' | 'dark' | 'auto' | Partial<HilalTheme>;
|
|
44
|
+
|
|
45
|
+
export const lightTheme: HilalTheme = {
|
|
46
|
+
background: '#FFFFFF',
|
|
47
|
+
text: '#1B1F24',
|
|
48
|
+
textSecondary: '#6B7280',
|
|
49
|
+
primary: '#0F766E',
|
|
50
|
+
onPrimary: '#FFFFFF',
|
|
51
|
+
today: '#0F766E',
|
|
52
|
+
disabled: '#9EA5AF',
|
|
53
|
+
border: '#E3E6EA',
|
|
54
|
+
radius: 12,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const darkTheme: HilalTheme = {
|
|
58
|
+
background: '#14171B',
|
|
59
|
+
text: '#F2F4F7',
|
|
60
|
+
textSecondary: '#9AA3AF',
|
|
61
|
+
primary: '#2DD4BF',
|
|
62
|
+
onPrimary: '#042F2C',
|
|
63
|
+
today: '#2DD4BF',
|
|
64
|
+
disabled: '#56606B',
|
|
65
|
+
border: '#2A3038',
|
|
66
|
+
radius: 12,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The theme to render with. 'auto' follows the system color scheme. A
|
|
71
|
+
* partial theme is merged over the 'auto' theme, so a custom `primary`
|
|
72
|
+
* color works in both light and dark mode.
|
|
73
|
+
*/
|
|
74
|
+
export function resolveTheme(
|
|
75
|
+
theme: ThemeProp,
|
|
76
|
+
colorScheme: string | null | undefined
|
|
77
|
+
): HilalTheme {
|
|
78
|
+
const system = colorScheme === 'dark' ? darkTheme : lightTheme;
|
|
79
|
+
if (theme === 'light') {
|
|
80
|
+
return lightTheme;
|
|
81
|
+
}
|
|
82
|
+
if (theme === 'dark') {
|
|
83
|
+
return darkTheme;
|
|
84
|
+
}
|
|
85
|
+
if (theme === 'auto') {
|
|
86
|
+
return system;
|
|
87
|
+
}
|
|
88
|
+
return { ...system, ...theme };
|
|
89
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import type { StyleProp, TextStyle, ViewStyle } from 'react-native';
|
|
2
|
+
|
|
3
|
+
import type { CalendarType, Digits, Locale } from '../core/locale';
|
|
4
|
+
import type { HijriDate } from '../core/types';
|
|
5
|
+
import type { ThemeProp } from './theme';
|
|
6
|
+
|
|
7
|
+
/** A day picked in the calendar, in both calendars. */
|
|
8
|
+
export type SelectedDate = {
|
|
9
|
+
/** Local midnight of the day. */
|
|
10
|
+
gregorian: Date;
|
|
11
|
+
hijri: HijriDate;
|
|
12
|
+
/** Both dates as text in the calendar's locale and digits. */
|
|
13
|
+
formatted: { gregorian: string; hijri: string };
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type ViewSlot = StyleProp<ViewStyle>;
|
|
17
|
+
type TextSlot = StyleProp<TextStyle>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Styles for parts of the calendar, merged over the theme's styles. Each
|
|
21
|
+
* is optional.
|
|
22
|
+
*/
|
|
23
|
+
export type HilalStyles = {
|
|
24
|
+
/** The outer container (the same as the `style` prop). */
|
|
25
|
+
container?: ViewSlot;
|
|
26
|
+
/** The Hijri / Gregorian toggle. */
|
|
27
|
+
toggle?: ViewSlot;
|
|
28
|
+
/** Each option of the toggle. */
|
|
29
|
+
toggleOption?: ViewSlot;
|
|
30
|
+
toggleText?: TextSlot;
|
|
31
|
+
/** The row of arrows and titles. */
|
|
32
|
+
header?: ViewSlot;
|
|
33
|
+
/** The month title. */
|
|
34
|
+
title?: TextSlot;
|
|
35
|
+
/** The other calendar's months under the title. */
|
|
36
|
+
subtitle?: TextSlot;
|
|
37
|
+
/** Each arrow button. */
|
|
38
|
+
arrow?: ViewSlot;
|
|
39
|
+
/** Each weekday name. */
|
|
40
|
+
weekdayText?: TextSlot;
|
|
41
|
+
/** Each day cell (the pressable circle). */
|
|
42
|
+
day?: ViewSlot;
|
|
43
|
+
/** The day number. */
|
|
44
|
+
dayText?: TextSlot;
|
|
45
|
+
/** The other calendar's day under the day number. */
|
|
46
|
+
secondaryDayText?: TextSlot;
|
|
47
|
+
/** The selected day cell. */
|
|
48
|
+
selectedDay?: ViewSlot;
|
|
49
|
+
/** The selected day's number. */
|
|
50
|
+
selectedDayText?: TextSlot;
|
|
51
|
+
/** Today's day cell. */
|
|
52
|
+
today?: ViewSlot;
|
|
53
|
+
/** Today's day number, bold by default. */
|
|
54
|
+
todayDayText?: TextSlot;
|
|
55
|
+
/** Both texts of a disabled day. */
|
|
56
|
+
disabledDayText?: TextSlot;
|
|
57
|
+
/** Each month or year in the month and year picker. */
|
|
58
|
+
pickerItem?: ViewSlot;
|
|
59
|
+
pickerText?: TextSlot;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Texts of the calendar's buttons, read by screen readers too. Each is
|
|
64
|
+
* optional; the rest come from the locale.
|
|
65
|
+
*/
|
|
66
|
+
export type HilalLabels = {
|
|
67
|
+
/** The toggle's Hijri option. */
|
|
68
|
+
hijri?: string;
|
|
69
|
+
/** The toggle's Gregorian option. */
|
|
70
|
+
gregorian?: string;
|
|
71
|
+
/** Read by screen readers after today's date. */
|
|
72
|
+
today?: string;
|
|
73
|
+
/** Read after the current month in the month picker. */
|
|
74
|
+
thisMonth?: string;
|
|
75
|
+
/** Read after the current year in the year picker. */
|
|
76
|
+
thisYear?: string;
|
|
77
|
+
/** Arrows, read by screen readers. */
|
|
78
|
+
previousMonth?: string;
|
|
79
|
+
nextMonth?: string;
|
|
80
|
+
previousYear?: string;
|
|
81
|
+
nextYear?: string;
|
|
82
|
+
previousYears?: string;
|
|
83
|
+
nextYears?: string;
|
|
84
|
+
/** The month title button, read by screen readers before the title. */
|
|
85
|
+
chooseMonth?: string;
|
|
86
|
+
/** The year title button in the month picker. */
|
|
87
|
+
chooseYear?: string;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export type HilalCalendarProps = {
|
|
91
|
+
/** Selected day (controlled). Only the local calendar day is used. */
|
|
92
|
+
value?: Date;
|
|
93
|
+
/** Initially selected day (uncontrolled). */
|
|
94
|
+
defaultValue?: Date;
|
|
95
|
+
/** Called when the user picks a day. */
|
|
96
|
+
onChange?: (date: SelectedDate) => void;
|
|
97
|
+
|
|
98
|
+
/** Calendar of the month grid. Default 'hijri'. */
|
|
99
|
+
calendar?: CalendarType;
|
|
100
|
+
/** Called when the user switches calendars with the toggle. */
|
|
101
|
+
onCalendarChange?: (calendar: CalendarType) => void;
|
|
102
|
+
/** Show the Hijri / Gregorian toggle. Default true. */
|
|
103
|
+
showCalendarToggle?: boolean;
|
|
104
|
+
/** Show the other calendar's day under each day. Default true. */
|
|
105
|
+
showSecondaryDate?: boolean;
|
|
106
|
+
|
|
107
|
+
/** Language of names and labels. Default 'ar'. */
|
|
108
|
+
locale?: Locale;
|
|
109
|
+
/** Default 'arabic' when locale is 'ar', otherwise 'latin'. */
|
|
110
|
+
digits?: Digits;
|
|
111
|
+
/**
|
|
112
|
+
* Layout direction. 'auto' (default) is right-to-left when the app runs
|
|
113
|
+
* right-to-left (`I18nManager.isRTL`) or the locale is 'ar'.
|
|
114
|
+
*/
|
|
115
|
+
direction?: 'rtl' | 'ltr' | 'auto';
|
|
116
|
+
/** 0 = Sunday (default), 1 = Monday, 6 = Saturday. */
|
|
117
|
+
firstDayOfWeek?: 0 | 1 | 6;
|
|
118
|
+
/**
|
|
119
|
+
* Weekday names above the days: 'short' (default, أحد / Sun) or
|
|
120
|
+
* 'narrow' (ح / S). Full names don't fit seven columns on a phone.
|
|
121
|
+
*/
|
|
122
|
+
weekdayFormat?: 'short' | 'narrow';
|
|
123
|
+
|
|
124
|
+
/** Earliest selectable day. */
|
|
125
|
+
minDate?: Date;
|
|
126
|
+
/** Latest selectable day. */
|
|
127
|
+
maxDate?: Date;
|
|
128
|
+
/** Return true to disable a day. */
|
|
129
|
+
isDateDisabled?: (date: SelectedDate) => boolean;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Shift the Hijri calendar by whole days, from -2 to 2, for places where
|
|
133
|
+
* the month started before or after Umm al-Qura. `1` makes every Hijri
|
|
134
|
+
* date one day later. Gregorian dates never change. Default 0.
|
|
135
|
+
*/
|
|
136
|
+
hijriAdjustment?: number;
|
|
137
|
+
/**
|
|
138
|
+
* Pressing the month title opens a grid of months, and from there a
|
|
139
|
+
* grid of years, to jump far without paging month by month. Default
|
|
140
|
+
* true.
|
|
141
|
+
*/
|
|
142
|
+
showMonthYearPicker?: boolean;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* 'light', 'dark', 'auto' (default, follows the system color scheme),
|
|
146
|
+
* or a partial theme merged over the 'auto' theme.
|
|
147
|
+
*/
|
|
148
|
+
theme?: ThemeProp;
|
|
149
|
+
/** Texts of the toggle and buttons, see `HilalLabels`. */
|
|
150
|
+
labels?: HilalLabels;
|
|
151
|
+
/** Styles for parts of the calendar, see `HilalStyles`. */
|
|
152
|
+
styles?: HilalStyles;
|
|
153
|
+
/** Style of the outer container. */
|
|
154
|
+
style?: StyleProp<ViewStyle>;
|
|
155
|
+
/**
|
|
156
|
+
* Style of every day cell (the pressable circle). Unlike `styles.day`,
|
|
157
|
+
* it also wins over the selected and today styles.
|
|
158
|
+
*/
|
|
159
|
+
dayStyle?: StyleProp<ViewStyle>;
|
|
160
|
+
/**
|
|
161
|
+
* How far the phone's text size setting may grow the calendar's text,
|
|
162
|
+
* like React Native's prop of the same name: `1` turns it off, `0`
|
|
163
|
+
* removes the limit. By default, text in day cells, weekday names and
|
|
164
|
+
* picker buttons grows up to 1.3 times (as far as it fits a cell), and
|
|
165
|
+
* the header and toggle up to 2 times.
|
|
166
|
+
*/
|
|
167
|
+
maxFontSizeMultiplier?: number;
|
|
168
|
+
};
|