react-native-dot-calendar 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.
@@ -0,0 +1,50 @@
1
+ import React from 'react';
2
+ import type { StyleProp, ViewStyle } from 'react-native';
3
+ import type { WeekDay } from './dates.js';
4
+ import type { CalendarTheme } from './theme.js';
5
+ export interface CalendarDot {
6
+ color: string;
7
+ /** Stable React key. Falls back to the dot's position. */
8
+ key?: string;
9
+ }
10
+ export interface DayMarking {
11
+ dots?: CalendarDot[];
12
+ }
13
+ /** Markings by day, keyed `YYYY-MM-DD`. */
14
+ export type MarkedDates = Record<string, DayMarking | undefined>;
15
+ export interface MonthCalendarProps {
16
+ /**
17
+ * Month on screen, as `YYYY-MM` or any `YYYY-MM-DD` inside it. When set, the
18
+ * calendar is controlled: update it from `onMonthChange`.
19
+ */
20
+ month?: string;
21
+ /** Month shown first when `month` is not set. Defaults to the current month. */
22
+ initialMonth?: string;
23
+ /** Highlighted day, `YYYY-MM-DD`. */
24
+ selectedDate?: string | null;
25
+ markedDates?: MarkedDates;
26
+ onDayPress?: (date: string) => void;
27
+ /** Called with the first day of the new month, `YYYY-MM-01`. */
28
+ onMonthChange?: (month: string) => void;
29
+ /** 0 is Sunday (default), 1 is Monday. */
30
+ firstDayOfWeek?: WeekDay;
31
+ /** Earlier days cannot be pressed, and earlier months cannot be reached. */
32
+ minDate?: string;
33
+ /** Later days cannot be pressed, and later months cannot be reached. */
34
+ maxDate?: string;
35
+ /** Most dots drawn under one day. Defaults to 3. */
36
+ maxDots?: number;
37
+ /** Show days of the neighbouring months in the first and last weeks. Defaults to true. */
38
+ showAdjacentDays?: boolean;
39
+ /** Twelve names, January first. */
40
+ monthNames?: readonly string[];
41
+ /** Seven column labels, Sunday first whatever `firstDayOfWeek` is. */
42
+ weekdayNames?: readonly string[];
43
+ previousMonthLabel?: string;
44
+ nextMonthLabel?: string;
45
+ theme?: Partial<CalendarTheme>;
46
+ style?: StyleProp<ViewStyle>;
47
+ testID?: string;
48
+ }
49
+ export declare const MonthCalendar: ({ month, initialMonth, selectedDate, markedDates, onDayPress, onMonthChange, firstDayOfWeek, minDate, maxDate, maxDots, showAdjacentDays, monthNames, weekdayNames, previousMonthLabel, nextMonthLabel, theme: themeOverrides, style, testID, }: MonthCalendarProps) => React.JSX.Element;
50
+ //# sourceMappingURL=MonthCalendar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MonthCalendar.d.ts","sourceRoot":"","sources":["../../src/MonthCalendar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkC,MAAM,OAAO,CAAC;AAEvD,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzD,OAAO,KAAK,EAAe,OAAO,EAAE,MAAM,YAAS,CAAC;AAEpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAS,CAAC;AAE7C,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,0DAA0D;IAC1D,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,WAAW,EAAE,CAAC;CACtB;AAED,2CAA2C;AAC3C,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,SAAS,CAAC,CAAC;AAEjE,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gFAAgF;IAChF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qCAAqC;IACrC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,gEAAgE;IAChE,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,0CAA0C;IAC1C,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oDAAoD;IACpD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0FAA0F;IAC1F,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,mCAAmC;IACnC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,sEAAsE;IACtE,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IAC/B,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AA+HD,eAAO,MAAM,aAAa,GAAI,iPAmB3B,kBAAkB,sBAuGpB,CAAC"}
@@ -0,0 +1,35 @@
1
+ export interface CalendarDay {
2
+ /** `YYYY-MM-DD` */
3
+ date: string;
4
+ /** Day of the month, 1-31. */
5
+ day: number;
6
+ /** False for the leading and trailing days that belong to the neighbouring months. */
7
+ inMonth: boolean;
8
+ }
9
+ export type WeekDay = 0 | 1 | 2 | 3 | 4 | 5 | 6;
10
+ interface DateParts {
11
+ year: number;
12
+ /** 0-11 */
13
+ month: number;
14
+ day: number;
15
+ }
16
+ /** Formats a `Date` as `YYYY-MM-DD` in the device's time zone. */
17
+ export declare const toDateString: (date: Date) => string;
18
+ /** Today as `YYYY-MM-DD` in the device's time zone. */
19
+ export declare const todayString: () => string;
20
+ /** Reads `YYYY-MM-DD` or `YYYY-MM` (day defaults to 1). Returns null when it is not a real date. */
21
+ export declare const parseDate: (value: string | null | undefined) => DateParts | null;
22
+ export declare const isValidDate: (value: string | null | undefined) => boolean;
23
+ /** First day of the month that holds `value`, as `YYYY-MM-01`. */
24
+ export declare const startOfMonth: (value: string) => string;
25
+ /** Last day of the month that holds `value`. */
26
+ export declare const endOfMonth: (value: string) => string;
27
+ /** First day of the month `count` months away from the month that holds `value`. */
28
+ export declare const addMonths: (value: string, count: number) => string;
29
+ /**
30
+ * The weeks to draw for a month. Every week has seven days, so the first and
31
+ * last weeks are filled with days from the neighbouring months.
32
+ */
33
+ export declare const buildMonthGrid: (value: string, firstDayOfWeek?: WeekDay) => CalendarDay[][];
34
+ export {};
35
+ //# sourceMappingURL=dates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dates.d.ts","sourceRoot":"","sources":["../../src/dates.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,8BAA8B;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,sFAAsF;IACtF,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,MAAM,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAEhD,UAAU,SAAS;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW;IACX,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAgBD,kEAAkE;AAClE,eAAO,MAAM,YAAY,GAAI,MAAM,IAAI,KAAG,MACgD,CAAC;AAE3F,uDAAuD;AACvD,eAAO,MAAM,WAAW,QAAO,MAAkC,CAAC;AAElE,oGAAoG;AACpG,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,GAAG,IAAI,GAAG,SAAS,KAAG,SAAS,GAAG,IAYxE,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,GAAG,IAAI,GAAG,SAAS,KAAG,OAAoC,CAAC;AAUpG,kEAAkE;AAClE,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,KAAG,MAG5C,CAAC;AAEF,gDAAgD;AAChD,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,MAG1C,CAAC;AAEF,oFAAoF;AACpF,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,EAAE,OAAO,MAAM,KAAG,MAGxD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,EAAE,iBAAgB,OAAW,KAAG,WAAW,EAAE,EAexF,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { MonthCalendar } from './MonthCalendar.js';
2
+ export type { CalendarDot, DayMarking, MarkedDates, MonthCalendarProps } from './MonthCalendar.js';
3
+ export { defaultTheme } from './theme.js';
4
+ export type { CalendarTheme } from './theme.js';
5
+ export { addMonths, buildMonthGrid, endOfMonth, isValidDate, startOfMonth, toDateString, todayString, } from './dates.js';
6
+ export type { CalendarDay, WeekDay } from './dates.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAiB,CAAC;AAChD,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,oBAAiB,CAAC;AAChG,OAAO,EAAE,YAAY,EAAE,MAAM,YAAS,CAAC;AACvC,YAAY,EAAE,aAAa,EAAE,MAAM,YAAS,CAAC;AAC7C,OAAO,EACL,SAAS,EACT,cAAc,EACd,UAAU,EACV,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,GACZ,MAAM,YAAS,CAAC;AACjB,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,YAAS,CAAC"}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,25 @@
1
+ export interface CalendarTheme {
2
+ backgroundColor: string;
3
+ borderRadius: number;
4
+ headerTextColor: string;
5
+ headerBorderColor: string;
6
+ arrowColor: string;
7
+ arrowBackgroundColor: string;
8
+ weekdayTextColor: string;
9
+ dayTextColor: string;
10
+ /** Days of the previous and next month shown in the first and last weeks. */
11
+ adjacentDayTextColor: string;
12
+ /** Days outside `minDate` / `maxDate`. */
13
+ disabledDayTextColor: string;
14
+ todayTextColor: string;
15
+ todayBackgroundColor: string;
16
+ selectedDayTextColor: string;
17
+ selectedDayBackgroundColor: string;
18
+ /** Dots take this colour on the selected day so they stay visible. */
19
+ selectedDotColor: string;
20
+ headerFontFamily?: string;
21
+ weekdayFontFamily?: string;
22
+ dayFontFamily?: string;
23
+ }
24
+ export declare const defaultTheme: CalendarTheme;
25
+ //# sourceMappingURL=theme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/theme.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,6EAA6E;IAC7E,oBAAoB,EAAE,MAAM,CAAC;IAC7B,0CAA0C;IAC1C,oBAAoB,EAAE,MAAM,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,0BAA0B,EAAE,MAAM,CAAC;IACnC,sEAAsE;IACtE,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,eAAO,MAAM,YAAY,EAAE,aAgB1B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,92 @@
1
1
  {
2
2
  "name": "react-native-dot-calendar",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "A light month calendar for React Native with event dots, day selection and theming. Pure JS, no native code and no date library.",
5
+ "main": "./lib/module/index.js",
6
+ "types": "./lib/typescript/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "source": "./src/index.ts",
10
+ "types": "./lib/typescript/index.d.ts",
11
+ "default": "./lib/module/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "lib",
18
+ "CHANGELOG.md",
19
+ "!**/__tests__"
20
+ ],
21
+ "sideEffects": false,
22
+ "scripts": {
23
+ "build": "bob build",
24
+ "typecheck": "tsc --noEmit",
25
+ "test": "jest",
26
+ "prepare": "bob build"
27
+ },
28
+ "keywords": [
29
+ "react-native",
30
+ "calendar",
31
+ "month-calendar",
32
+ "event-calendar",
33
+ "dots",
34
+ "date",
35
+ "ios",
36
+ "android"
37
+ ],
38
+ "author": "Jay Singh",
39
+ "license": "MIT",
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/jaykksingh/react-native-dot-calendar.git"
43
+ },
44
+ "bugs": {
45
+ "url": "https://github.com/jaykksingh/react-native-dot-calendar/issues"
46
+ },
47
+ "homepage": "https://github.com/jaykksingh/react-native-dot-calendar#readme",
48
+ "peerDependencies": {
49
+ "react": ">=18.0.0",
50
+ "react-native": ">=0.73.0"
51
+ },
52
+ "devDependencies": {
53
+ "@babel/core": "^7.25.2",
54
+ "@babel/preset-env": "^7.25.3",
55
+ "@babel/runtime": "^7.25.0",
56
+ "@react-native/babel-preset": "0.83.0",
57
+ "@react-native/typescript-config": "0.83.0",
58
+ "@types/jest": "^29.5.13",
59
+ "@types/react": "^19.2.0",
60
+ "@types/react-test-renderer": "^19.3.1",
61
+ "jest": "^29.6.3",
62
+ "react": "19.2.0",
63
+ "react-native": "0.83.0",
64
+ "react-native-builder-bob": "^0.44.1",
65
+ "react-test-renderer": "19.2.0",
66
+ "typescript": "^5.8.3"
67
+ },
68
+ "react-native-builder-bob": {
69
+ "source": "src",
70
+ "output": "lib",
71
+ "targets": [
72
+ [
73
+ "module",
74
+ {
75
+ "esm": true
76
+ }
77
+ ],
78
+ [
79
+ "typescript",
80
+ {
81
+ "project": "tsconfig.build.json"
82
+ }
83
+ ]
84
+ ]
85
+ },
86
+ "jest": {
87
+ "preset": "react-native",
88
+ "modulePathIgnorePatterns": [
89
+ "<rootDir>/lib/"
90
+ ]
91
+ }
92
+ }
@@ -0,0 +1,401 @@
1
+ import React, { memo, useMemo, useState } from 'react';
2
+ import { Pressable, StyleSheet, Text, View } from 'react-native';
3
+ import type { StyleProp, ViewStyle } from 'react-native';
4
+ import { addMonths, buildMonthGrid, endOfMonth, isValidDate, parseDate, startOfMonth, todayString } from './dates';
5
+ import type { CalendarDay, WeekDay } from './dates';
6
+ import { defaultTheme } from './theme';
7
+ import type { CalendarTheme } from './theme';
8
+
9
+ export interface CalendarDot {
10
+ color: string;
11
+ /** Stable React key. Falls back to the dot's position. */
12
+ key?: string;
13
+ }
14
+
15
+ export interface DayMarking {
16
+ dots?: CalendarDot[];
17
+ }
18
+
19
+ /** Markings by day, keyed `YYYY-MM-DD`. */
20
+ export type MarkedDates = Record<string, DayMarking | undefined>;
21
+
22
+ export interface MonthCalendarProps {
23
+ /**
24
+ * Month on screen, as `YYYY-MM` or any `YYYY-MM-DD` inside it. When set, the
25
+ * calendar is controlled: update it from `onMonthChange`.
26
+ */
27
+ month?: string;
28
+ /** Month shown first when `month` is not set. Defaults to the current month. */
29
+ initialMonth?: string;
30
+ /** Highlighted day, `YYYY-MM-DD`. */
31
+ selectedDate?: string | null;
32
+ markedDates?: MarkedDates;
33
+ onDayPress?: (date: string) => void;
34
+ /** Called with the first day of the new month, `YYYY-MM-01`. */
35
+ onMonthChange?: (month: string) => void;
36
+ /** 0 is Sunday (default), 1 is Monday. */
37
+ firstDayOfWeek?: WeekDay;
38
+ /** Earlier days cannot be pressed, and earlier months cannot be reached. */
39
+ minDate?: string;
40
+ /** Later days cannot be pressed, and later months cannot be reached. */
41
+ maxDate?: string;
42
+ /** Most dots drawn under one day. Defaults to 3. */
43
+ maxDots?: number;
44
+ /** Show days of the neighbouring months in the first and last weeks. Defaults to true. */
45
+ showAdjacentDays?: boolean;
46
+ /** Twelve names, January first. */
47
+ monthNames?: readonly string[];
48
+ /** Seven column labels, Sunday first whatever `firstDayOfWeek` is. */
49
+ weekdayNames?: readonly string[];
50
+ previousMonthLabel?: string;
51
+ nextMonthLabel?: string;
52
+ theme?: Partial<CalendarTheme>;
53
+ style?: StyleProp<ViewStyle>;
54
+ testID?: string;
55
+ }
56
+
57
+ const DEFAULT_MONTH_NAMES = [
58
+ 'January',
59
+ 'February',
60
+ 'March',
61
+ 'April',
62
+ 'May',
63
+ 'June',
64
+ 'July',
65
+ 'August',
66
+ 'September',
67
+ 'October',
68
+ 'November',
69
+ 'December',
70
+ ] as const;
71
+ const DEFAULT_WEEKDAY_NAMES = ['S', 'M', 'T', 'W', 'T', 'F', 'S'] as const;
72
+ const WEEKDAYS: readonly WeekDay[] = [0, 1, 2, 3, 4, 5, 6];
73
+ const DEFAULT_MAX_DOTS = 3;
74
+ const ARROW_HIT_SLOP = 8;
75
+ const NO_DOTS: CalendarDot[] = [];
76
+
77
+ interface ArrowProps {
78
+ direction: 'previous' | 'next';
79
+ label: string;
80
+ disabled: boolean;
81
+ theme: CalendarTheme;
82
+ onPress: () => void;
83
+ testID: string;
84
+ }
85
+
86
+ const Arrow = ({ direction, label, disabled, theme, onPress, testID }: ArrowProps) => (
87
+ <Pressable
88
+ accessibilityRole="button"
89
+ accessibilityLabel={label}
90
+ accessibilityState={{ disabled }}
91
+ disabled={disabled}
92
+ hitSlop={ARROW_HIT_SLOP}
93
+ onPress={onPress}
94
+ style={[styles.arrow, { backgroundColor: theme.arrowBackgroundColor }, disabled && styles.arrowDisabled]}
95
+ testID={testID}
96
+ >
97
+ <View
98
+ style={[
99
+ styles.chevron,
100
+ direction === 'previous' ? styles.chevronPrevious : styles.chevronNext,
101
+ { borderColor: theme.arrowColor },
102
+ ]}
103
+ />
104
+ </Pressable>
105
+ );
106
+
107
+ interface DayCellProps {
108
+ day: CalendarDay;
109
+ label: string;
110
+ isToday: boolean;
111
+ isSelected: boolean;
112
+ isDisabled: boolean;
113
+ dots: CalendarDot[];
114
+ theme: CalendarTheme;
115
+ onPress?: (date: string) => void;
116
+ testID: string;
117
+ }
118
+
119
+ const dayTextColor = ({ day, isToday, isSelected, isDisabled, theme }: DayCellProps) => {
120
+ if (isSelected) {
121
+ return theme.selectedDayTextColor;
122
+ }
123
+ if (isDisabled) {
124
+ return theme.disabledDayTextColor;
125
+ }
126
+ if (isToday) {
127
+ return theme.todayTextColor;
128
+ }
129
+ return day.inMonth ? theme.dayTextColor : theme.adjacentDayTextColor;
130
+ };
131
+
132
+ const dayBackgroundColor = ({ isToday, isSelected, theme }: DayCellProps) => {
133
+ if (isSelected) {
134
+ return theme.selectedDayBackgroundColor;
135
+ }
136
+ return isToday ? theme.todayBackgroundColor : 'transparent';
137
+ };
138
+
139
+ const DayCell = memo((props: DayCellProps) => {
140
+ const { day, label, isToday, isSelected, isDisabled, dots, theme, onPress, testID } = props;
141
+ const emphasised = isSelected || isToday;
142
+
143
+ return (
144
+ <Pressable
145
+ accessibilityRole="button"
146
+ accessibilityLabel={label}
147
+ accessibilityState={{ selected: isSelected, disabled: isDisabled }}
148
+ disabled={isDisabled || !onPress}
149
+ onPress={() => onPress?.(day.date)}
150
+ style={styles.cell}
151
+ testID={testID}
152
+ >
153
+ <View style={[styles.dayCircle, { backgroundColor: dayBackgroundColor(props) }]}>
154
+ <Text
155
+ style={[
156
+ styles.dayText,
157
+ emphasised && styles.dayTextEmphasised,
158
+ { color: dayTextColor(props), fontFamily: theme.dayFontFamily },
159
+ ]}
160
+ >
161
+ {day.day}
162
+ </Text>
163
+ {dots.length > 0 && (
164
+ <View style={styles.dots}>
165
+ {dots.map((dot, index) => (
166
+ <View
167
+ key={dot.key ?? index}
168
+ style={[styles.dot, { backgroundColor: isSelected ? theme.selectedDotColor : dot.color }]}
169
+ />
170
+ ))}
171
+ </View>
172
+ )}
173
+ </View>
174
+ </Pressable>
175
+ );
176
+ });
177
+ DayCell.displayName = 'DayCell';
178
+
179
+ const resolveMonth = (month: string | undefined, fallback: string) =>
180
+ month !== undefined && isValidDate(month) ? startOfMonth(month) : fallback;
181
+
182
+ export const MonthCalendar = ({
183
+ month,
184
+ initialMonth,
185
+ selectedDate,
186
+ markedDates,
187
+ onDayPress,
188
+ onMonthChange,
189
+ firstDayOfWeek = 0,
190
+ minDate,
191
+ maxDate,
192
+ maxDots = DEFAULT_MAX_DOTS,
193
+ showAdjacentDays = true,
194
+ monthNames = DEFAULT_MONTH_NAMES,
195
+ weekdayNames = DEFAULT_WEEKDAY_NAMES,
196
+ previousMonthLabel = 'Previous month',
197
+ nextMonthLabel = 'Next month',
198
+ theme: themeOverrides,
199
+ style,
200
+ testID = 'month-calendar',
201
+ }: MonthCalendarProps) => {
202
+ const today = todayString();
203
+ const [ownMonth, setOwnMonth] = useState(() => resolveMonth(initialMonth, startOfMonth(today)));
204
+ const visibleMonth = resolveMonth(month, ownMonth);
205
+
206
+ const theme = useMemo(() => ({ ...defaultTheme, ...themeOverrides }), [themeOverrides]);
207
+ const weeks = useMemo(() => buildMonthGrid(visibleMonth, firstDayOfWeek), [visibleMonth, firstDayOfWeek]);
208
+
209
+ // Zero-padded YYYY-MM-DD strings sort the same way the dates do.
210
+ const lowerBound = isValidDate(minDate) ? minDate : undefined;
211
+ const upperBound = isValidDate(maxDate) ? maxDate : undefined;
212
+ const isOutOfRange = (date: string) =>
213
+ (lowerBound !== undefined && date < lowerBound) || (upperBound !== undefined && date > upperBound);
214
+
215
+ const goToMonth = (offset: number) => {
216
+ const next = addMonths(visibleMonth, offset);
217
+ if (month === undefined) {
218
+ setOwnMonth(next);
219
+ }
220
+ onMonthChange?.(next);
221
+ };
222
+
223
+ const dayLabel = (date: string) => {
224
+ const parts = parseDate(date);
225
+ return parts ? `${monthNames[parts.month]} ${parts.day}, ${parts.year}` : date;
226
+ };
227
+
228
+ const visible = parseDate(visibleMonth);
229
+ const title = visible ? `${monthNames[visible.month]} ${visible.year}` : '';
230
+
231
+ return (
232
+ <View
233
+ style={[styles.container, { backgroundColor: theme.backgroundColor, borderRadius: theme.borderRadius }, style]}
234
+ testID={testID}
235
+ >
236
+ <View style={[styles.header, { borderBottomColor: theme.headerBorderColor }]}>
237
+ <Text
238
+ accessibilityRole="header"
239
+ style={[styles.title, { color: theme.headerTextColor, fontFamily: theme.headerFontFamily }]}
240
+ testID={`${testID}-title`}
241
+ >
242
+ {title}
243
+ </Text>
244
+ <View style={styles.arrows}>
245
+ <Arrow
246
+ direction="previous"
247
+ label={previousMonthLabel}
248
+ disabled={isOutOfRange(endOfMonth(addMonths(visibleMonth, -1)))}
249
+ theme={theme}
250
+ onPress={() => goToMonth(-1)}
251
+ testID={`${testID}-previous`}
252
+ />
253
+ <Arrow
254
+ direction="next"
255
+ label={nextMonthLabel}
256
+ disabled={isOutOfRange(addMonths(visibleMonth, 1))}
257
+ theme={theme}
258
+ onPress={() => goToMonth(1)}
259
+ testID={`${testID}-next`}
260
+ />
261
+ </View>
262
+ </View>
263
+
264
+ <View style={styles.weekdays} accessibilityElementsHidden importantForAccessibility="no-hide-descendants">
265
+ {WEEKDAYS.map((offset) => {
266
+ const weekday = (firstDayOfWeek + offset) % WEEKDAYS.length;
267
+ return (
268
+ <Text
269
+ key={weekday}
270
+ style={[styles.weekday, { color: theme.weekdayTextColor, fontFamily: theme.weekdayFontFamily }]}
271
+ >
272
+ {weekdayNames[weekday]}
273
+ </Text>
274
+ );
275
+ })}
276
+ </View>
277
+
278
+ <View style={styles.grid}>
279
+ {weeks.map((week) => (
280
+ <View key={week[0].date} style={styles.week}>
281
+ {week.map((day) =>
282
+ day.inMonth || showAdjacentDays ? (
283
+ <DayCell
284
+ key={day.date}
285
+ day={day}
286
+ label={dayLabel(day.date)}
287
+ isToday={day.date === today}
288
+ isSelected={day.date === selectedDate}
289
+ isDisabled={isOutOfRange(day.date)}
290
+ dots={markedDates?.[day.date]?.dots?.slice(0, maxDots) ?? NO_DOTS}
291
+ theme={theme}
292
+ onPress={onDayPress}
293
+ testID={`${testID}-day-${day.date}`}
294
+ />
295
+ ) : (
296
+ <View key={day.date} style={styles.cell} />
297
+ ),
298
+ )}
299
+ </View>
300
+ ))}
301
+ </View>
302
+ </View>
303
+ );
304
+ };
305
+
306
+ const styles = StyleSheet.create({
307
+ container: {
308
+ overflow: 'hidden',
309
+ },
310
+ header: {
311
+ flexDirection: 'row',
312
+ justifyContent: 'space-between',
313
+ alignItems: 'center',
314
+ paddingHorizontal: 16,
315
+ paddingVertical: 14,
316
+ borderBottomWidth: 1,
317
+ },
318
+ title: {
319
+ fontSize: 16,
320
+ fontWeight: '700',
321
+ },
322
+ arrows: {
323
+ flexDirection: 'row',
324
+ alignItems: 'center',
325
+ gap: 12,
326
+ },
327
+ arrow: {
328
+ width: 32,
329
+ height: 32,
330
+ borderRadius: 16,
331
+ alignItems: 'center',
332
+ justifyContent: 'center',
333
+ },
334
+ arrowDisabled: {
335
+ opacity: 0.4,
336
+ },
337
+ chevron: {
338
+ width: 8,
339
+ height: 8,
340
+ borderTopWidth: 2,
341
+ borderLeftWidth: 2,
342
+ },
343
+ chevronPrevious: {
344
+ marginLeft: 3,
345
+ transform: [{ rotate: '-45deg' }],
346
+ },
347
+ chevronNext: {
348
+ marginRight: 3,
349
+ transform: [{ rotate: '135deg' }],
350
+ },
351
+ weekdays: {
352
+ flexDirection: 'row',
353
+ paddingHorizontal: 8,
354
+ paddingTop: 12,
355
+ paddingBottom: 8,
356
+ },
357
+ weekday: {
358
+ flex: 1,
359
+ textAlign: 'center',
360
+ fontSize: 12,
361
+ fontWeight: '500',
362
+ },
363
+ grid: {
364
+ paddingHorizontal: 8,
365
+ paddingBottom: 12,
366
+ },
367
+ week: {
368
+ flexDirection: 'row',
369
+ },
370
+ cell: {
371
+ flex: 1,
372
+ height: 48,
373
+ alignItems: 'center',
374
+ justifyContent: 'center',
375
+ marginBottom: 4,
376
+ },
377
+ dayCircle: {
378
+ width: 36,
379
+ height: 36,
380
+ borderRadius: 18,
381
+ alignItems: 'center',
382
+ justifyContent: 'center',
383
+ },
384
+ dayText: {
385
+ fontSize: 15,
386
+ fontWeight: '400',
387
+ },
388
+ dayTextEmphasised: {
389
+ fontWeight: '600',
390
+ },
391
+ dots: {
392
+ flexDirection: 'row',
393
+ gap: 3,
394
+ marginTop: 1,
395
+ },
396
+ dot: {
397
+ width: 6,
398
+ height: 6,
399
+ borderRadius: 3,
400
+ },
401
+ });