-
Notifications
You must be signed in to change notification settings - Fork 31
/
LinearCalendar.tsx
105 lines (98 loc) · 2.84 KB
/
LinearCalendar.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import type {
CalendarActiveDateRange,
CalendarTheme,
} from "@marceloterreiro/flash-calendar";
import { Calendar, toDateId } from "@marceloterreiro/flash-calendar";
import { loggingHandler } from "@marceloterreiro/flash-calendar/src/developer/loggginHandler";
import { add, startOfMonth } from "date-fns";
import { format } from "date-fns/fp";
import { memo } from "react";
import { StyleSheet, View } from "react-native";
const today = new Date();
const startOfThisMonth = startOfMonth(today);
const styles = StyleSheet.create({
linearContainer: {
flex: 1,
backgroundColor: "#252630",
padding: 12,
},
});
const linearAccent = "#585ABF";
const linearTheme: CalendarTheme = {
rowMonth: {
content: {
textAlign: "left",
color: "rgba(255, 255, 255, 0.5)",
fontWeight: "700",
},
},
rowWeek: {
container: {
borderBottomWidth: 1,
borderBottomColor: "rgba(255, 255, 255, 0.1)",
borderStyle: "solid",
},
},
itemWeekName: { content: { color: "rgba(255, 255, 255, 0.5)" } },
itemDayContainer: {
activeDayFiller: {
backgroundColor: linearAccent,
},
},
itemDay: {
idle: ({ isPressed, isWeekend }) => ({
container: {
backgroundColor: isPressed ? linearAccent : "transparent",
borderRadius: 4,
},
content: {
color: isWeekend && !isPressed ? "rgba(255, 255, 255, 0.5)" : "#ffffff",
},
}),
today: ({ isPressed }) => ({
container: {
borderColor: "rgba(255, 255, 255, 0.5)",
borderRadius: isPressed ? 4 : 30,
backgroundColor: isPressed ? linearAccent : "transparent",
},
content: {
color: isPressed ? "#ffffff" : "rgba(255, 255, 255, 0.5)",
},
}),
active: ({ isEndOfRange, isStartOfRange }) => ({
container: {
backgroundColor: linearAccent,
borderTopLeftRadius: isStartOfRange ? 4 : 0,
borderBottomLeftRadius: isStartOfRange ? 4 : 0,
borderTopRightRadius: isEndOfRange ? 4 : 0,
borderBottomRightRadius: isEndOfRange ? 4 : 0,
},
content: {
color: "#ffffff",
},
}),
},
};
const calendarActiveDateRanges: CalendarActiveDateRange[] = [
{
startId: toDateId(add(startOfThisMonth, { days: 3 })),
endId: toDateId(add(startOfThisMonth, { days: 8 })),
},
];
export const LinearCalendar = memo(() => {
return (
<View style={styles.linearContainer}>
<Calendar
calendarActiveDateRanges={calendarActiveDateRanges}
calendarDayHeight={30}
calendarFirstDayOfWeek="sunday"
calendarMonthId={toDateId(startOfThisMonth)}
calendarRowHorizontalSpacing={16}
calendarRowVerticalSpacing={16}
getCalendarWeekDayFormat={format("iiiiii")}
onCalendarDayPress={loggingHandler("onCalendarDayPress")}
theme={linearTheme}
/>
</View>
);
});